diff --git a/lib/classes/output/icon_system_fontawesome.php b/lib/classes/output/icon_system_fontawesome.php index e5e8ec76d31..a40689ccdc4 100644 --- a/lib/classes/output/icon_system_fontawesome.php +++ b/lib/classes/output/icon_system_fontawesome.php @@ -303,6 +303,7 @@ class icon_system_fontawesome extends icon_system_font { 'core:i/stats' => 'fa-line-chart', 'core:i/switch' => 'fa-exchange', 'core:i/switchrole' => 'fa-user-secret', + 'core:i/trash' => 'fa-trash', 'core:i/twoway' => 'fa-arrows-h', 'core:i/unchecked' => 'fa-square-o', 'core:i/unflagged' => 'fa-flag-o', @@ -313,6 +314,7 @@ class icon_system_fontawesome extends icon_system_font { 'core:i/users' => 'fa-users', 'core:i/valid' => 'fa-check text-success', 'core:i/warning' => 'fa-exclamation text-warning', + 'core:i/window_close' => 'fa-window-close', 'core:i/withsubcat' => 'fa-plus-square', 'core:m/USD' => 'fa-usd', 'core:t/addcontact' => 'fa-address-card', @@ -378,6 +380,7 @@ class icon_system_fontawesome extends icon_system_font { 'core:t/reset' => 'fa-repeat', 'core:t/restore' => 'fa-arrow-circle-up', 'core:t/right' => 'fa-arrow-right', + 'core:t/sendmessage' => 'fa-paper-plane', 'core:t/show' => 'fa-eye-slash', 'core:t/sort_asc' => 'fa-sort-asc', 'core:t/sort_desc' => 'fa-sort-desc', diff --git a/message/amd/build/message_drawer_router.min.js b/message/amd/build/message_drawer_router.min.js index c5aeb95060b..c65abdd647d 100644 --- a/message/amd/build/message_drawer_router.min.js +++ b/message/amd/build/message_drawer_router.min.js @@ -1 +1 @@ -define(["jquery","core/pubsub","core/str","core_message/message_drawer_events"],function(a,b,c,d){var e={},f=[],g={CAN_RECEIVE_FOCUS:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',ROUTES_BACK:"[data-route-back]"},h=function(a,b,c,d){e[a]={elements:b,onGo:c,getDescription:d}},i=function(c){var f,h=[].slice.call(arguments,1),i=a.Deferred().resolve().promise();if(Object.keys(e).forEach(function(a){var b=e[a],d=a===c;d&&(f=b),b.elements.forEach(function(a){a.removeClass("previous"),d?(a.removeClass("hidden"),a.attr("aria-hidden",!1)):(a.addClass("hidden"),a.attr("aria-hidden",!0))})}),f&&f.onGo){i=f.onGo.apply(void 0,f.elements.concat(h));for(var j=a(document.activeElement),k=!1,l=0;lc?a.messages=a.messages.slice(1):G(!0),E(d+c),a}).then(function(a){var c=a.members.filter(function(a){return a.id==b.id});c.length<1&&(a.members=a.members.concat([b]));var d=K(a,b.id);return d=m.setLoadingMembers(d,!1),d=m.setLoadingMessages(d,!1),u(d).then(function(){return a})}).then(function(){return P(a)})["catch"](function(a){var b=m.setLoadingMembers(q,!1);b=m.setLoadingMessages(b,!1),u(b),e.exception(a)})},M=function(a,b,c,d){var f=a.members.filter(function(a){return a.id==b.id});f.length<1&&(a.members=a.members.concat([b]));var g=K(a,b.id);g=m.setLoadingMembers(g,!1),g=m.setLoadingMessages(g,!0);var h=a.messages.length;return u(g).then(function(){if(hb?a.messages=a.messages.slice(1):G(!0),a):a}).then(function(a){var b=a.members.filter(function(a){return!(a.id in q.members)}),c=m.addMembers(q,b);return c=m.addMessages(c,a.messages),c=m.setLoadingMessages(c,!1),u(c).then(function(){return a})})["catch"](function(a){var b=m.setLoadingMessages(q,!1);throw u(b),a})},O=function(a,b){return function(){var c=q.messages,d=c.length?c[c.length-1]:null;if(d){for(var e=[],f=c.length-1;f>=0;f--){var g=c[f];if(g.timeCreated!==d.timeCreated)break;e.push(g.id)}return N(a,0,0,b,e,d.timeCreated).then(function(b){return b.messages.length?(t.restart(),P(a)):b})}}},P=function(a){var b=q.loggedInUserId;return h.markAllConversationMessagesAsRead(b,a).then(function(){var b=m.markMessagesAsRead(q,q.messages);return f.publish(i.CONVERSATION_READ,a),u(b)})},Q=function(a){return ca(a).then(function(){var b=m.addPendingBlockUsersById(q,[a]);return u(b)})},R=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.blockUser(q.loggedInUserId,a)}).then(function(b){var c=m.addMembers(q,[b]);return c=m.removePendingBlockUsersById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_BLOCKED,c.id),u(c)})},S=function(a){return ca(a).then(function(){var b=m.addPendingUnblockUsersById(q,[a]);return u(b)})},T=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.unblockUser(q.loggedInUserId,a)}).then(function(b){var c=m.addMembers(q,[b]);return c=m.removePendingUnblockUsersById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_UNBLOCKED,c.id),u(c)})},U=function(a){return ca(a).then(function(){var b=m.addPendingRemoveContactsById(q,[a]);return u(b)})},V=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.deleteContacts(q.loggedInUserId,[a])}).then(function(b){var c=m.addMembers(q,b);return c=m.removePendingRemoveContactsById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_REMOVED,a),u(c)})},W=function(a){return ca(a).then(function(){var b=m.addPendingAddContactsById(q,[a]);return u(b)})},X=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.createContactRequest(q.loggedInUserId,a)}).then(function(a){if(!a.request)throw new Error(a.warnings[0].message);return a.request}).then(function(b){var c=m.removePendingAddContactsById(q,[a]);return c=m.addContactRequests(c,[b]),c=m.setLoadingConfirmAction(c,!1),u(c)})},Y=function(){var a=q.loggedInUserId,b=q.id;return h.setFavouriteConversations(a,[b]).then(function(){var a=m.setIsFavourite(q,!0);return u(a)}).then(function(){return f.publish(i.CONVERSATION_SET_FAVOURITE,I(q))})},Z=function(){var a=q.loggedInUserId,b=q.id;return h.unsetFavouriteConversations(a,[b]).then(function(){var a=m.setIsFavourite(q,!1);return u(a)}).then(function(){return f.publish(i.CONVERSATION_UNSET_FAVOURITE,I(q))})},$=function(a){var b=q.selectedMessageIds;return ca(a).then(function(){var a=m.addPendingDeleteMessagesById(q,b);return u(a)})},_=function(){var a=q.pendingDeleteMessageIds,b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.deleteMessages(q.loggedInUserId,a)}).then(function(){var b=m.removeMessagesById(q,a);b=m.removePendingDeleteMessagesById(b,a),b=m.removeSelectedMessagesById(b,a),b=m.setLoadingConfirmAction(b,!1);var c=q.messages[q.messages.length-1],d=b.messages.length?b.messages[b.messages.length-1]:null;if(d&&d.id!=c.id){var e=I(b);f.publish(i.CONVERSATION_NEW_LAST_MESSAGE,e)}else b.messages.length||f.publish(i.CONVERSATION_DELETED,b.id);return u(b)})},aa=function(a){return ca(a).then(function(){var a=m.setPendingDeleteConversation(q,!0);return u(a)})},ba=function(){var a=m.setLoadingConfirmAction(q,!0);return u(a).then(function(){return h.deleteCoversation(q.loggedInUserId,A())}).then(function(){var a=m.removeMessages(q,q.messages);return a=m.removeSelectedMessagesById(a,q.selectedMessageIds),a=m.setPendingDeleteConversation(a,!1),a=m.setLoadingConfirmAction(a,!1),f.publish(i.CONVERSATION_DELETED,a.id),u(a)})},ca=function(a){var b=q.pendingDeleteMessageIds,c=m.removePendingAddContactsById(q,[a]);return c=m.removePendingRemoveContactsById(c,[a]),c=m.removePendingUnblockUsersById(c,[a]),c=m.removePendingBlockUsersById(c,[a]),c=m.removePendingDeleteMessagesById(c,b),c=m.setPendingDeleteConversation(c,!1),u(c)},da=function(a){var b=q.loggedInUserId,c=q.members[a].contactrequests.filter(function(a){return a.requesteduserid==b}),d=c[0],e=m.setLoadingConfirmAction(q,!0);return u(e).then(function(){return h.acceptContactRequest(a,b)}).then(function(a){var b=m.removeContactRequests(q,[d]);return b=m.addMembers(q,[a]),b=m.setLoadingConfirmAction(b,!1),u(b)}).then(function(){f.publish(i.CONTACT_ADDED,q.members[a]),f.publish(i.CONTACT_REQUEST_ACCEPTED,d)})},ea=function(a){var b=q.loggedInUserId,c=q.members[b].contactrequests.filter(function(b){return b.userid==a}),d=c[0],e=m.setLoadingConfirmAction(q,!0);return u(e).then(function(){return h.declineContactRequest(a,b)}).then(function(a){var b=m.removeContactRequests(q,[d]);return b=m.addMembers(q,[a]),b=m.setLoadingConfirmAction(b,!1),u(b)}).then(function(){f.publish(i.CONTACT_REQUEST_DECLINED,d)})},fa=function(a,b){var c=m.setSendingMessage(q,!0),d=null;return u(c).then(function(){if(a||q.type!=z.PRIVATE)return h.sendMessageToConversation(a,b);var c=A();return h.sendMessageToUser(c,b).then(function(a){return d=parseInt(a.conversationid,10),a})}).then(function(a){var b=m.addMessages(q,[a]);b=m.setSendingMessage(b,!1);var c=I(b);return b.id||(b=m.setId(b,d),c.id=d,va(d),f.publish(i.CONVERSATION_CREATED,c)),u(b).then(function(){f.publish(i.CONVERSATION_NEW_LAST_MESSAGE,c)})})["catch"](function(a){var b=m.setSendingMessage(q,!1);u(b),e.exception(a)})},ga=function(a){var b=q;return b=q.selectedMessageIds.indexOf(a)>-1?m.removeSelectedMessagesById(q,[a]):m.addSelectedMessagesById(q,[a]),u(b)},ha=function(){return ca(A()).then(function(){var a=m.removeSelectedMessagesById(q,q.selectedMessageIds);return u(a)})},ia=function(a,b,c){return function(d){var e=k.buildPatch(q,d);return l.render(a,b,c,e).then(function(){q=d,d.id&&(p[d.id]={state:d,messagesOffset:D(),loadedAllMessages:F()})})}},ja=function(a){return function(b,c){q.loadingConfirmAction||a(A())["catch"](function(a){var b=m.setLoadingConfirmAction(q,!1);u(b),e.exception(a)}),c.originalEvent.preventDefault()}},ka=function(b,c){var d=a(b.target),e=d.closest(y.FOOTER_CONTAINER),f=e.find(y.MESSAGE_TEXT_AREA),g=f.val().trim();""!==g&&fa(q.id,g),c.originalEvent.preventDefault()},la=function(b,c){var d=window.getSelection(),f=a(b.target);if(""==d.toString()&&!f.is("a")){var g=f.closest(y.MESSAGE),h=parseInt(g.attr("data-message-id"),10);ga(h)["catch"](e.exception),c.originalEvent.preventDefault()}},ma=function(a,b){ha()["catch"](e.exception),b.originalEvent.preventDefault()},na=function(a,b){var c=A(),d=q.members[c];n.go(o.VIEW_CONTACT,d),b.originalEvent.preventDefault()},oa=function(a,b){Y()["catch"](e.exception),b.originalEvent.preventDefault()},pa=function(a,b){Z()["catch"](e.exception),b.originalEvent.preventDefault()},qa=function(a,b){n.go(o.VIEW_GROUP_INFO,{id:q.id,name:q.name,subname:q.subname,imageUrl:q.imageUrl,totalMemberCount:q.totalMemberCount},q.loggedInUserId),b.originalEvent.preventDefault()},ra=[[y.ACTION_REQUEST_BLOCK,ja(Q)],[y.ACTION_REQUEST_UNBLOCK,ja(S)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_REQUEST_REMOVE_CONTACT,ja(U)],[y.ACTION_REQUEST_DELETE_CONVERSATION,ja(aa)],[y.ACTION_CANCEL_EDIT_MODE,ma],[y.ACTION_VIEW_CONTACT,na],[y.ACTION_VIEW_GROUP_INFO,qa],[y.ACTION_CONFIRM_FAVOURITE,oa],[y.ACTION_CONFIRM_UNFAVOURITE,pa]],sa=[[y.ACTION_CANCEL_CONFIRM,ja(ca)],[y.ACTION_CONFIRM_BLOCK,ja(R)],[y.ACTION_CONFIRM_UNBLOCK,ja(T)],[y.ACTION_CONFIRM_ADD_CONTACT,ja(X)],[y.ACTION_CONFIRM_REMOVE_CONTACT,ja(V)],[y.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES,ja(_)],[y.ACTION_CONFIRM_DELETE_CONVERSATION,ja(ba)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_ACCEPT_CONTACT_REQUEST,ja(da)],[y.ACTION_DECLINE_CONTACT_REQUEST,ja(ea)],[y.MESSAGE,la]],ta=[[y.SEND_MESSAGE_BUTTON,ka],[y.ACTION_REQUEST_DELETE_SELECTED_MESSAGES,ja($)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_REQUEST_UNBLOCK,ja(S)]],ua=function(a,c,g){var h=!1,j=H(c);b.init(g),d.define(a,[d.events.activate]),d.define(c,[d.events.activate]),d.define(g,[d.events.activate,d.events.enter]),d.define(j,[d.events.scrollTop,d.events.scrollLock]),j.on(d.events.scrollTop,function(a,b){var c=Object.keys(q.members).length>1;if(!h&&!F()&&c){var d=m.setLoadingMessages(q,!0);u(d).then(function(){return N(q.id,w,D(),v,[])}).then(function(){h=!1,E(D()+w)})["catch"](function(a){h=!1,e.exception(a)})}b.originalEvent.preventDefault()}),ra.forEach(function(b){var c=b[0],e=b[1];a.on(d.events.activate,c,e)}),sa.forEach(function(a){var b=a[0],e=a[1];c.on(d.events.activate,b,e)}),ta.forEach(function(a){var b=a[0],c=a[1];g.on(d.events.activate,b,c)}),g.on(d.events.enter,y.MESSAGE_TEXT_AREA,function(a,b){var c=g.attr("data-enter-to-send");1==c&&ka(a,b)}),f.subscribe(i.ROUTE_CHANGED,function(a){t&&(a.route==o.VIEW_CONVERSATION?t.restart():t.stop())}),f.subscribe(i.PREFERENCES_UPDATED,function(a){var b=a.filter(function(a){return"message_entertosend"==a.type}),c=b.length?b[0]:null;c&&g.attr("data-enter-to-send",c.value)})},va=function(a){t&&t.stop(),t=new c(O(a,v),function(a){return a?2*a:x}),t.start()},wa=function(a,b,c){var d=c.id,e=parseInt(a.attr("data-midnight"),10),f=m.buildInitialState(e,d,b);return q||(q=f),t&&t.stop(),u(f)},xa=function(a,b,c){return wa(a,null,b).then(function(){return h.getConversationBetweenUsers(b.id,c,!0,!0,0,0,w,0,v).then(function(c){return za(a,c,b)})["catch"](function(){return J(b,c)})})},ya=function(a,b,c){var d=null;return b in p&&(d=p[b]),wa(a,b,c).then(function(){if(d){var a=d.state;return a=m.setLoadingMessages(a,!1),a=m.setLoadingMembers(a,!1),E(d.messagesOffset),G(d.loadedAllMessages),u(a)}return L(b,c,w,0,v)}).then(function(){return va(b)})},za=function(a,b,c){var d=null;return b.id in p&&(d=p[b.id]),wa(a,b.id,c).then(function(){if(d){var a=d.state;return a=m.setLoadingMessages(a,!1),a=m.setLoadingMembers(a,!1),E(d.messagesOffset),G(d.loadedAllMessages),u(a)}return M(b,c,w,v)}).then(function(){return va(b.id)})},Aa=function(b,c,d,f,g,h){var i=null,k=null;f&&null!==f&&"object"==typeof f?(i=f,k=parseInt(i.id,10)):(i=null,k=parseInt(f,10),k=isNaN(k)?null:k),!k&&g&&h&&(k=B(h)),c.attr("data-init")||(u=ia(b,c,d),ua(b,c,d),c.attr("data-init",!0));var l=!q||q.id!=k||h&&h!=A();if(l){var m=null,n=C(c);return m=i?za(c,i,n,h):k?ya(c,k,n,h):xa(c,n,h),m.then(function(){b.find(j.SELECTORS.CAN_RECEIVE_FOCUS).first().focus()})["catch"](e.exception)}if(q.type==z.PRIVATE&&g){var o=A();switch(g){case"block":return Q(o);case"unblock":return S(o);case"add-contact":return W(o);case"remove-contact":return U(o)}}return a.Deferred().resolve().promise()},Ba=function(){return g.get_string("messagedrawerviewconversation","core_message",q.name)};return{show:Aa,description:Ba}}); \ No newline at end of file +define(["jquery","core/auto_rows","core/backoff_timer","core/custom_interaction_events","core/notification","core/pubsub","core/str","core_message/message_repository","core_message/message_drawer_events","core_message/message_drawer_view_conversation_constants","core_message/message_drawer_view_conversation_patcher","core_message/message_drawer_view_conversation_renderer","core_message/message_drawer_view_conversation_state_manager","core_message/message_drawer_router","core_message/message_drawer_routes"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){var p={},q=null,r=!1,s=0,t=null,u=null,v=j.NEWEST_MESSAGES_FIRST,w=j.LOAD_MESSAGE_LIMIT,x=j.INITIAL_NEW_MESSAGE_POLL_TIMEOUT,y=j.SELECTORS,z=j.CONVERSATION_TYPES,A=function(){if(!q||q.type!=z.PRIVATE)return null;var a=q.loggedInUserId,b=Object.keys(q.members).filter(function(b){return a!=b});return b.length?b[0]:null},B=function(a){return Object.keys(p).reduce(function(b,c){if(!b){var d=p[c].state;d.type==z.PRIVATE&&a in d.members&&(b=d.id)}return b},null)},C=function(a){return{id:parseInt(a.attr("data-user-id"),10),contactrequests:[]}},D=function(){return s},E=function(a){s=a,p[q.id].messagesOffset=a},F=function(){return r},G=function(a){r=a,p[q.id].loadedAllMessages=a},H=function(a){return a.find(y.MESSAGES_CONTAINER)},I=function(b){return{id:b.id,name:b.name,subname:b.subname,imageUrl:b.imageUrl,isFavourite:b.isFavourite,type:b.type,totalMemberCount:b.totalMemberCount,loggedInUserId:b.loggedInUserId,messages:b.messages.map(function(b){return a.extend({},b)}),members:Object.keys(b.members).reduce(function(c,d){return c[d]=a.extend({},b.members[d]),c[d].contactrequests=b.members[d].contactrequests.map(function(b){return a.extend({},b)}),c},{})}},J=function(a,b){var c=a.id,d=m.setLoadingMembers(q,!0);return d=m.setLoadingMessages(d,!0),u(d).then(function(){return h.getMemberInfo(c,[b],!0,!0)}).then(function(a){if(a.length)return a[0];throw new Error("Unable to load other user profile")}).then(function(b){var c=m.addMembers(q,[b,a]);return c=m.setLoadingMembers(c,!1),c=m.setLoadingMessages(c,!1),c=m.setName(c,b.fullname),c=m.setType(c,1),c=m.setImageUrl(c,b.profileimageurl),c=m.setTotalMemberCount(c,2),u(c).then(function(){return b})})["catch"](function(a){var b=m.setLoadingMembers(q,!1);u(b),e.exception(a)})},K=function(a,b){var c=a.members.filter(function(a){return a.id!=b}),d=c.length?c[0]:null,e=a.name,f=a.imageurl;a.type==z.PRIVATE&&(e=e||d?d.fullname:"",f=f||d?d.profileimageurl:"");var g=m.addMembers(q,a.members);return g=m.setName(g,e),g=m.setSubname(g,a.subname),g=m.setType(g,a.type),g=m.setImageUrl(g,f),g=m.setTotalMemberCount(g,a.membercount),g=m.setIsFavourite(g,a.isfavourite),g=m.addMessages(g,a.messages)},L=function(a,b,c,d,f){var g=b.id,i=m.setLoadingMembers(q,!0);return i=m.setLoadingMessages(i,!0),u(i).then(function(){return h.getConversation(g,a,!0,!0,0,0,c+1,d,f)}).then(function(a){return a.messages.length>c?a.messages=a.messages.slice(1):G(!0),E(d+c),a}).then(function(a){var c=a.members.filter(function(a){return a.id==b.id});c.length<1&&(a.members=a.members.concat([b]));var d=K(a,b.id);return d=m.setLoadingMembers(d,!1),d=m.setLoadingMessages(d,!1),u(d).then(function(){return a})}).then(function(){return P(a)})["catch"](function(a){var b=m.setLoadingMembers(q,!1);b=m.setLoadingMessages(b,!1),u(b),e.exception(a)})},M=function(a,b,c,d){var f=a.members.filter(function(a){return a.id==b.id});f.length<1&&(a.members=a.members.concat([b]));var g=K(a,b.id);g=m.setLoadingMembers(g,!1),g=m.setLoadingMessages(g,!0);var h=a.messages.length;return u(g).then(function(){if(hb?a.messages=a.messages.slice(1):G(!0),a):a}).then(function(a){var b=a.members.filter(function(a){return!(a.id in q.members)}),c=m.addMembers(q,b);return c=m.addMessages(c,a.messages),c=m.setLoadingMessages(c,!1),u(c).then(function(){return a})})["catch"](function(a){var b=m.setLoadingMessages(q,!1);throw u(b),a})},O=function(a,b){return function(){var c=q.messages,d=c.length?c[c.length-1]:null;if(d){for(var e=[],f=c.length-1;f>=0;f--){var g=c[f];if(g.timeCreated!==d.timeCreated)break;e.push(g.id)}return N(a,0,0,b,e,d.timeCreated).then(function(b){return b.messages.length?(t.restart(),P(a)):b})}}},P=function(a){var b=q.loggedInUserId;return h.markAllConversationMessagesAsRead(b,a).then(function(){var b=m.markMessagesAsRead(q,q.messages);return f.publish(i.CONVERSATION_READ,a),u(b)})},Q=function(a){return ca(a).then(function(){var b=m.addPendingBlockUsersById(q,[a]);return u(b)})},R=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.blockUser(q.loggedInUserId,a)}).then(function(b){var c=m.addMembers(q,[b]);return c=m.removePendingBlockUsersById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_BLOCKED,a),u(c)})},S=function(a){return ca(a).then(function(){var b=m.addPendingUnblockUsersById(q,[a]);return u(b)})},T=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.unblockUser(q.loggedInUserId,a)}).then(function(b){var c=m.addMembers(q,[b]);return c=m.removePendingUnblockUsersById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_UNBLOCKED,a),u(c)})},U=function(a){return ca(a).then(function(){var b=m.addPendingRemoveContactsById(q,[a]);return u(b)})},V=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.deleteContacts(q.loggedInUserId,[a])}).then(function(b){var c=m.addMembers(q,b);return c=m.removePendingRemoveContactsById(c,[a]),c=m.setLoadingConfirmAction(c,!1),f.publish(i.CONTACT_REMOVED,a),u(c)})},W=function(a){return ca(a).then(function(){var b=m.addPendingAddContactsById(q,[a]);return u(b)})},X=function(a){var b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.createContactRequest(q.loggedInUserId,a)}).then(function(a){if(!a.request)throw new Error(a.warnings[0].message);return a.request}).then(function(b){var c=m.removePendingAddContactsById(q,[a]);return c=m.addContactRequests(c,[b]),c=m.setLoadingConfirmAction(c,!1),u(c)})},Y=function(){var a=q.loggedInUserId,b=q.id;return h.setFavouriteConversations(a,[b]).then(function(){var a=m.setIsFavourite(q,!0);return u(a)}).then(function(){return f.publish(i.CONVERSATION_SET_FAVOURITE,I(q))})},Z=function(){var a=q.loggedInUserId,b=q.id;return h.unsetFavouriteConversations(a,[b]).then(function(){var a=m.setIsFavourite(q,!1);return u(a)}).then(function(){return f.publish(i.CONVERSATION_UNSET_FAVOURITE,I(q))})},$=function(a){var b=q.selectedMessageIds;return ca(a).then(function(){var a=m.addPendingDeleteMessagesById(q,b);return u(a)})},_=function(){var a=q.pendingDeleteMessageIds,b=m.setLoadingConfirmAction(q,!0);return u(b).then(function(){return h.deleteMessages(q.loggedInUserId,a)}).then(function(){var b=m.removeMessagesById(q,a);b=m.removePendingDeleteMessagesById(b,a),b=m.removeSelectedMessagesById(b,a),b=m.setLoadingConfirmAction(b,!1);var c=q.messages[q.messages.length-1],d=b.messages.length?b.messages[b.messages.length-1]:null;if(d&&d.id!=c.id){var e=I(b);f.publish(i.CONVERSATION_NEW_LAST_MESSAGE,e)}else b.messages.length||f.publish(i.CONVERSATION_DELETED,b.id);return u(b)})},aa=function(a){return ca(a).then(function(){var a=m.setPendingDeleteConversation(q,!0);return u(a)})},ba=function(){var a=m.setLoadingConfirmAction(q,!0);return u(a).then(function(){return h.deleteCoversation(q.loggedInUserId,A())}).then(function(){var a=m.removeMessages(q,q.messages);return a=m.removeSelectedMessagesById(a,q.selectedMessageIds),a=m.setPendingDeleteConversation(a,!1),a=m.setLoadingConfirmAction(a,!1),f.publish(i.CONVERSATION_DELETED,a.id),u(a)})},ca=function(a){var b=q.pendingDeleteMessageIds,c=m.removePendingAddContactsById(q,[a]);return c=m.removePendingRemoveContactsById(c,[a]),c=m.removePendingUnblockUsersById(c,[a]),c=m.removePendingBlockUsersById(c,[a]),c=m.removePendingDeleteMessagesById(c,b),c=m.setPendingDeleteConversation(c,!1),u(c)},da=function(a){var b=q.loggedInUserId,c=q.members[a].contactrequests.filter(function(a){return a.requesteduserid==b}),d=c[0],e=m.setLoadingConfirmAction(q,!0);return u(e).then(function(){return h.acceptContactRequest(a,b)}).then(function(a){var b=m.removeContactRequests(q,[d]);return b=m.addMembers(q,[a]),b=m.setLoadingConfirmAction(b,!1),u(b)}).then(function(){f.publish(i.CONTACT_ADDED,q.members[a]),f.publish(i.CONTACT_REQUEST_ACCEPTED,d)})},ea=function(a){var b=q.loggedInUserId,c=q.members[b].contactrequests.filter(function(b){return b.userid==a}),d=c[0],e=m.setLoadingConfirmAction(q,!0);return u(e).then(function(){return h.declineContactRequest(a,b)}).then(function(a){var b=m.removeContactRequests(q,[d]);return b=m.addMembers(q,[a]),b=m.setLoadingConfirmAction(b,!1),u(b)}).then(function(){f.publish(i.CONTACT_REQUEST_DECLINED,d)})},fa=function(a,b){var c=m.setSendingMessage(q,!0),d=null;return u(c).then(function(){if(a||q.type!=z.PRIVATE)return h.sendMessageToConversation(a,b);var c=A();return h.sendMessageToUser(c,b).then(function(a){return d=parseInt(a.conversationid,10),a})}).then(function(a){var b=m.addMessages(q,[a]);b=m.setSendingMessage(b,!1);var c=I(b);return b.id||(b=m.setId(b,d),c.id=d,va(d),f.publish(i.CONVERSATION_CREATED,c)),u(b).then(function(){f.publish(i.CONVERSATION_NEW_LAST_MESSAGE,c)})})["catch"](function(a){var b=m.setSendingMessage(q,!1);u(b),e.exception(a)})},ga=function(a){var b=q;return b=q.selectedMessageIds.indexOf(a)>-1?m.removeSelectedMessagesById(q,[a]):m.addSelectedMessagesById(q,[a]),u(b)},ha=function(){return ca(A()).then(function(){var a=m.removeSelectedMessagesById(q,q.selectedMessageIds);return u(a)})},ia=function(a,b,c){return function(d){var e=k.buildPatch(q,d);return l.render(a,b,c,e).then(function(){q=d,d.id&&(p[d.id]={state:d,messagesOffset:D(),loadedAllMessages:F()})})}},ja=function(a){return function(b,c){q.loadingConfirmAction||a(A())["catch"](function(a){var b=m.setLoadingConfirmAction(q,!1);u(b),e.exception(a)}),c.originalEvent.preventDefault()}},ka=function(b,c){var d=a(b.target),e=d.closest(y.FOOTER_CONTAINER),f=e.find(y.MESSAGE_TEXT_AREA),g=f.val().trim();""!==g&&fa(q.id,g),c.originalEvent.preventDefault()},la=function(b,c){var d=window.getSelection(),f=a(b.target);if(""==d.toString()&&!f.is("a")){var g=f.closest(y.MESSAGE),h=parseInt(g.attr("data-message-id"),10);ga(h)["catch"](e.exception),c.originalEvent.preventDefault()}},ma=function(a,b){ha()["catch"](e.exception),b.originalEvent.preventDefault()},na=function(a,b){var c=A(),d=q.members[c];n.go(o.VIEW_CONTACT,d),b.originalEvent.preventDefault()},oa=function(a,b){Y()["catch"](e.exception),b.originalEvent.preventDefault()},pa=function(a,b){Z()["catch"](e.exception),b.originalEvent.preventDefault()},qa=function(a,b){n.go(o.VIEW_GROUP_INFO,{id:q.id,name:q.name,subname:q.subname,imageUrl:q.imageUrl,totalMemberCount:q.totalMemberCount},q.loggedInUserId),b.originalEvent.preventDefault()},ra=[[y.ACTION_REQUEST_BLOCK,ja(Q)],[y.ACTION_REQUEST_UNBLOCK,ja(S)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_REQUEST_REMOVE_CONTACT,ja(U)],[y.ACTION_REQUEST_DELETE_CONVERSATION,ja(aa)],[y.ACTION_CANCEL_EDIT_MODE,ma],[y.ACTION_VIEW_CONTACT,na],[y.ACTION_VIEW_GROUP_INFO,qa],[y.ACTION_CONFIRM_FAVOURITE,oa],[y.ACTION_CONFIRM_UNFAVOURITE,pa]],sa=[[y.ACTION_CANCEL_CONFIRM,ja(ca)],[y.ACTION_CONFIRM_BLOCK,ja(R)],[y.ACTION_CONFIRM_UNBLOCK,ja(T)],[y.ACTION_CONFIRM_ADD_CONTACT,ja(X)],[y.ACTION_CONFIRM_REMOVE_CONTACT,ja(V)],[y.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES,ja(_)],[y.ACTION_CONFIRM_DELETE_CONVERSATION,ja(ba)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_ACCEPT_CONTACT_REQUEST,ja(da)],[y.ACTION_DECLINE_CONTACT_REQUEST,ja(ea)],[y.MESSAGE,la]],ta=[[y.SEND_MESSAGE_BUTTON,ka],[y.ACTION_REQUEST_DELETE_SELECTED_MESSAGES,ja($)],[y.ACTION_REQUEST_ADD_CONTACT,ja(W)],[y.ACTION_REQUEST_UNBLOCK,ja(S)]],ua=function(a,c,g){var h=!1,j=H(c);b.init(g),d.define(a,[d.events.activate]),d.define(c,[d.events.activate]),d.define(g,[d.events.activate,d.events.enter]),d.define(j,[d.events.scrollTop,d.events.scrollLock]),j.on(d.events.scrollTop,function(a,b){var c=Object.keys(q.members).length>1;if(!h&&!F()&&c){var d=m.setLoadingMessages(q,!0);u(d).then(function(){return N(q.id,w,D(),v,[])}).then(function(){h=!1,E(D()+w)})["catch"](function(a){h=!1,e.exception(a)})}b.originalEvent.preventDefault()}),ra.forEach(function(b){var c=b[0],e=b[1];a.on(d.events.activate,c,e)}),sa.forEach(function(a){var b=a[0],e=a[1];c.on(d.events.activate,b,e)}),ta.forEach(function(a){var b=a[0],c=a[1];g.on(d.events.activate,b,c)}),g.on(d.events.enter,y.MESSAGE_TEXT_AREA,function(a,b){var c=g.attr("data-enter-to-send");1==c&&ka(a,b)}),f.subscribe(i.ROUTE_CHANGED,function(a){t&&(a.route==o.VIEW_CONVERSATION?t.restart():t.stop())}),f.subscribe(i.PREFERENCES_UPDATED,function(a){var b=a.filter(function(a){return"message_entertosend"==a.type}),c=b.length?b[0]:null;c&&g.attr("data-enter-to-send",c.value)})},va=function(a){t&&t.stop(),t=new c(O(a,v),function(a){return a?2*a:x}),t.start()},wa=function(a,b,c){var d=c.id,e=parseInt(a.attr("data-midnight"),10),f=m.buildInitialState(e,d,b);return q||(q=f),t&&t.stop(),u(f)},xa=function(a,b,c){return wa(a,null,b).then(function(){return h.getConversationBetweenUsers(b.id,c,!0,!0,0,0,w,0,v).then(function(c){return za(a,c,b)})["catch"](function(){return J(b,c)})})},ya=function(a,b,c){var d=null;return b in p&&(d=p[b]),wa(a,b,c).then(function(){if(d){var a=d.state;return a=m.setLoadingMessages(a,!1),a=m.setLoadingMembers(a,!1),E(d.messagesOffset),G(d.loadedAllMessages),u(a)}return L(b,c,w,0,v)}).then(function(){return va(b)})},za=function(a,b,c){var d=null;return b.id in p&&(d=p[b.id]),wa(a,b.id,c).then(function(){if(d){var a=d.state;return a=m.setLoadingMessages(a,!1),a=m.setLoadingMembers(a,!1),E(d.messagesOffset),G(d.loadedAllMessages),u(a)}return M(b,c,w,v)}).then(function(){return va(b.id)})},Aa=function(b,c,d,f,g,h){var i=null,k=null;f&&null!==f&&"object"==typeof f?(i=f,k=parseInt(i.id,10)):(i=null,k=parseInt(f,10),k=isNaN(k)?null:k),!k&&g&&h&&(k=B(h)),c.attr("data-init")||(u=ia(b,c,d),ua(b,c,d),c.attr("data-init",!0));var l=!q||q.id!=k||h&&h!=A();if(l){var m=null,n=C(c);return m=i?za(c,i,n,h):k?ya(c,k,n,h):xa(c,n,h),m.then(function(){b.find(j.SELECTORS.CAN_RECEIVE_FOCUS).first().focus()})["catch"](e.exception)}if(q.type==z.PRIVATE&&g){var o=A();switch(g){case"block":return Q(o);case"unblock":return S(o);case"add-contact":return W(o);case"remove-contact":return U(o)}}return a.Deferred().resolve().promise()},Ba=function(){return g.get_string("messagedrawerviewconversation","core_message",q.name)};return{show:Aa,description:Ba}}); \ No newline at end of file diff --git a/message/amd/build/message_drawer_view_conversation_renderer.min.js b/message/amd/build/message_drawer_view_conversation_renderer.min.js index 8fd856c43b0..bb711729e9e 100644 --- a/message/amd/build/message_drawer_view_conversation_renderer.min.js +++ b/message/amd/build/message_drawer_view_conversation_renderer.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/str","core/templates","core/user_date","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d,e,f){var g=f.SELECTORS,h=f.TEMPLATES,i=f.CONVERSATION_TYPES,j=function(a){return a.find(g.CONTENT_MESSAGES_CONTAINER)},k=function(a){j(a).removeClass("hidden")},l=function(a){j(a).addClass("hidden")},m=function(a){return a.find(g.CONTACT_REQUEST_SENT_MESSAGE_CONTAINER)},n=function(a){return m(a).addClass("hidden")},o=function(a){return a.find(g.CONTENT_MESSAGES_FOOTER_CONTAINER)},p=function(a){o(a).removeClass("hidden")},q=function(a){o(a).addClass("hidden")},r=function(a){return a.find(g.CONTENT_MESSAGES_FOOTER_EDIT_MODE_CONTAINER)},s=function(a){r(a).removeClass("hidden")},t=function(a){r(a).addClass("hidden")},u=function(a){return a.find(g.PLACEHOLDER_CONTAINER)},v=function(a){u(a).removeClass("hidden")},w=function(a){u(a).addClass("hidden")},x=function(a){return a.find(g.CONTENT_MESSAGES_FOOTER_REQUIRE_CONTACT_CONTAINER)},y=function(a){x(a).removeClass("hidden")},z=function(a){x(a).addClass("hidden")},A=function(a){return a.find(g.CONTENT_MESSAGES_FOOTER_REQUIRE_UNBLOCK_CONTAINER)},B=function(a){A(a).removeClass("hidden")},C=function(a){A(a).addClass("hidden")},D=function(a){return a.find(g.CONTENT_MESSAGES_FOOTER_UNABLE_TO_MESSAGE_CONTAINER)},E=function(a){D(a).removeClass("hidden")},F=function(a){D(a).addClass("hidden")},G=function(a){N(a),Q(a),T(a)},H=function(a){q(a),t(a),w(a),z(a),C(a),F(a)},I=function(a){return a.find(g.CONTENT_PLACEHOLDER_CONTAINER)},J=function(a){I(a).removeClass("hidden")},K=function(a){I(a).addClass("hidden")},L=function(a){return a.find(g.HEADER)},M=function(a){L(a).removeClass("hidden")},N=function(a){L(a).addClass("hidden")},O=function(a){return a.find(g.HEADER_EDIT_MODE)},P=function(a){O(a).removeClass("hidden")},Q=function(a){O(a).addClass("hidden")},R=function(a){return a.find(g.HEADER_PLACEHOLDER_CONTAINER)},S=function(a){R(a).removeClass("hidden")},T=function(a){R(a).addClass("hidden")},U=function(a){return a.find(g.MESSAGE_TEXT_AREA)},V=function(a,b){var c=j(a);return c.find('[data-message-id="'+b+'"]')},W=function(a,b){var c=j(a);return c.find('[data-day-id="'+b+'"]')},X=function(a){return a.find(g.MORE_MESSAGES_LOADING_ICON_CONTAINER)},Y=function(a){X(a).removeClass("hidden")},Z=function(a){X(a).addClass("hidden")},$=function(a){a.find(g.SEND_MESSAGE_BUTTON).prop("disabled",!0),U(a).prop("disabled",!0)},_=function(a){a.find(g.SEND_MESSAGE_BUTTON).prop("disabled",!1),U(a).prop("disabled",!1)},aa=function(a){$(a),a.find(g.SEND_MESSAGE_ICON_CONTAINER).addClass("hidden"),a.find(g.LOADING_ICON_CONTAINER).removeClass("hidden")},ba=function(a){_(a),a.find(g.SEND_MESSAGE_ICON_CONTAINER).removeClass("hidden"),a.find(g.LOADING_ICON_CONTAINER).addClass("hidden")},ca=function(a){var b=U(a);b.val(""),b.focus()},da=function(a){return a.find(g.CONFIRM_DIALOGUE_CONTAINER)},ea=function(a){var b=da(a),c=b.siblings(":not(.hidden)");c.attr("aria-hidden",!0),c.attr("tabindex",-1),c.attr("data-confirm-dialogue-hidden",!0),b.removeClass("hidden")},fa=function(a){var b=da(a),c=b.siblings('[data-confirm-dialogue-hidden="true"]');c.removeAttr("aria-hidden"),c.removeAttr("tabindex"),c.removeAttr("data-confirm-dialogue-hidden"),b.addClass("hidden")},ga=function(a,b){O(a).find(g.MESSAGES_SELECTED_COUNT).text(b)},ha=function(a,b){return a.map(function(a){return{id:a.id,isread:a.isRead,fromloggedinuser:a.fromLoggedInUser,userfrom:a.userFrom,text:a.text,formattedtime:b[a.timeCreated]}})},ia=function(b,c,e,f,g){var i=j(c),k=f.map(function(a){return d.render(h.DAY,{timestamp:a.value.timestamp,messages:ha(a.value.messages,g)})});return a.when.apply(a,k).then(function(){f.forEach(function(b,d){k[d].then(function(d){if(b.before){var e=W(c,b.before.timestamp);return a(d).insertBefore(e)}return i.append(d)})["catch"](function(){})})})},ja=function(b,c,e,f,i){var j=f.map(function(a){var b=ha([a.value],i);return d.render(h.MESSAGE,b[0])});return a.when.apply(a,j).then(function(){f.forEach(function(b,d){j[d].then(function(d){if(b.before){var e=V(c,b.before.id);return a(d).insertBefore(e)}var f=W(c,b.day.timestamp),h=f.find(g.DAY_MESSAGES_CONTAINER);return h.append(d)})["catch"](function(){})})})},ka=function(a,b){b.forEach(function(b){W(a,b.timestamp).remove()})},la=function(a,b){b.forEach(function(b){V(a,b.id).remove()})},ma=function(b,d,f,g){var h=[],i=g.days.add.length>0,j=g.messages.add.length>0,k=[],l=a.Deferred().resolve({}).promise();return i&&(k=k.concat(g.days.add.reduce(function(a,b){return a.concat(b.value.messages.map(function(a){return a.timeCreated}))},[]))),j&&(k=k.concat(g.messages.add.map(function(a){return a.value.timeCreated}))),k.length&&(l=c.get_string("strftimetime24","core_langconfig").then(function(a){var b=k.map(function(b){return{timestamp:b,format:a}});return e.get(b)}).then(function(a){return k.reduce(function(b,c,d){return b[c]=a[d],b},{})})),i&&h.push(l.then(function(a){return ia(b,d,f,g.days.add,a)})),j&&h.push(l.then(function(a){return ja(b,d,f,g.messages.add,a)})),g.days.remove.length>0&&ka(d,g.days.remove),g.messages.remove.length>0&&la(d,g.messages.remove),a.when.apply(a,h)},na=function(a,b,c,e){var f=L(a),g=h.HEADER_PUBLIC;return e.type==i.PRIVATE&&(g=e.showControls?h.HEADER_PRIVATE:h.HEADER_PRIVATE_NO_CONTROLS),d.render(g,e.context).then(function(a,b){d.replaceNodeContents(f,a,b)})},oa=function(a,b,d,e){switch(H(d),e.type){case"placeholder":return v(d);case"add-contact":return c.get_strings([{key:"requirecontacttomessage",component:"core_message",param:e.user.fullname},{key:"isnotinyourcontacts",component:"core_message",param:e.user.fullname}]).then(function(a){var b=a[1],c=a[0],e=x(d);return e.find(g.TITLE).text(b),e.find(g.TEXT).text(c),y(d),a});case"edit-mode":return s(d);case"content":return p(d);case"unblock":return B(d);case"unable-to-message":return E(d)}return!0},pa=function(a,b,c,d){var e=j(b),f=V(b,d),g=f.position();if(g){var h=e.scrollTop()+g.top;e.scrollTop(h)}},qa=function(a,b,c,d){d?(N(a),S(a)):(M(a),T(a))},ra=function(a,b,c,d){d?(l(b),J(b)):(k(b),K(b))},sa=function(a,b,c,d){d?Y(b):Z(b)},ta=function(a,b,c,d){d?aa(c):(ba(c),ca(c))},ua=function(a,b,c,d,e,f,h,i){var j=da(b),k=d.map(function(a){return j.find(a)}),l=j.find(g.CONFIRM_DIALOGUE_CANCEL_BUTTON),m=j.find(g.CONFIRM_DIALOGUE_TEXT),n=j.find(g.CONFIRM_DIALOGUE_HEADER);j.find("button").addClass("hidden"),h?l.removeClass("hidden"):l.addClass("hidden"),f?(n.removeClass("hidden"),n.text(f)):(n.addClass("hidden"),n.text("")),k.forEach(function(a){a.removeClass("hidden")}),m.text(e),ea(c),ea(b),i||ea(a),j.find(g.CAN_RECEIVE_FOCUS).first().focus()},va=function(a,b,c){var d=da(b),e=d.find(g.CONFIRM_DIALOGUE_CANCEL_BUTTON),f=d.find(g.CONFIRM_DIALOGUE_TEXT),h=d.find(g.CONFIRM_DIALOGUE_HEADER);return fa(b),fa(c),fa(a),d.find("button").addClass("hidden"),e.removeClass("hidden"),f.text(""),h.addClass("hidden"),h.text(""),a.find(g.CAN_RECEIVE_FOCUS).first().focus(),!0},wa=function(a,b,d,e){return e?c.get_string("blockuserconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_BLOCK],c,"",!0,!1)}):va(a,b,d)},xa=function(a,b,d,e){return e?c.get_string("unblockuserconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_UNBLOCK],c,"",!0,!1)}):va(a,b,d)},ya=function(a,b,d,e){return e?c.get_string("addcontactconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_ADD_CONTACT],c,"",!0,!1)}):va(a,b,d)},za=function(a,b,d,e){return e?c.get_string("removecontactconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_REMOVE_CONTACT],c,"",!0,!1)}):va(a,b,d)},Aa=function(a,b,d,e){return e?c.get_string("deleteselectedmessagesconfirm","core_message").then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES],c,"",!0,!1)}):va(a,b,d)},Ba=function(a,b,d,e){return e?c.get_string("deleteallconfirm","core_message").then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_DELETE_CONVERSATION],c,"",!0,!1)}):va(a,b,d)},Ca=function(a,b,d,e){return e?c.get_string("userwouldliketocontactyou","core_message",e.fullname).then(function(c){var e=[g.ACTION_ACCEPT_CONTACT_REQUEST,g.ACTION_DECLINE_CONTACT_REQUEST];return ua(a,b,d,e,c,"",!1,!0)}):va(a,b,d)},Da=function(a,b,c,d){d?(a.find(g.ACTION_REQUEST_BLOCK).addClass("hidden"),a.find(g.ACTION_REQUEST_UNBLOCK).removeClass("hidden")):(a.find(g.ACTION_REQUEST_BLOCK).removeClass("hidden"),a.find(g.ACTION_REQUEST_UNBLOCK).addClass("hidden"))},Ea=function(a,b,c,d){d?(a.find(g.FAVOURITE_ICON_CONTAINER).removeClass("hidden"),a.find(g.ACTION_CONFIRM_FAVOURITE).addClass("hidden"),a.find(g.ACTION_CONFIRM_UNFAVOURITE).removeClass("hidden")):(a.find(g.FAVOURITE_ICON_CONTAINER).addClass("hidden"),a.find(g.ACTION_CONFIRM_FAVOURITE).removeClass("hidden"),a.find(g.ACTION_CONFIRM_UNFAVOURITE).addClass("hidden"))},Fa=function(a,b,c,d){var e=a.find(g.ACTION_REQUEST_ADD_CONTACT),f=a.find(g.ACTION_REQUEST_REMOVE_CONTACT);switch(d){case"pending-contact":e.addClass("hidden"),f.addClass("hidden");break;case"contact":e.addClass("hidden"),f.removeClass("hidden");break;case"non-contact":e.removeClass("hidden"),f.addClass("hidden")}},Ga=function(a,b,c,d){var e=da(b),f=e.find("button"),h=e.find(g.CONFIRM_DIALOGUE_BUTTON_TEXT),i=e.find(g.LOADING_ICON_CONTAINER);d?(f.prop("disabled",!0),h.addClass("hidden"),i.removeClass("hidden")):(f.prop("disabled",!1),h.removeClass("hidden"),i.addClass("hidden"))},Ha=function(a,b,c,d){var e=null;d?(e=b.find(g.MESSAGE_NOT_SELECTED),e.find(g.MESSAGE_NOT_SELECTED_ICON).removeClass("hidden"),N(a),P(a)):(e=j(b),e.find(g.MESSAGE_NOT_SELECTED_ICON).addClass("hidden"),e.find(g.MESSAGE_SELECTED_ICON).addClass("hidden"),M(a),Q(a))},Ia=function(a,b,c,d){var e=d.count>0;d.add.length&&d.add.forEach(function(a){var c=V(b,a);c.find(g.MESSAGE_NOT_SELECTED_ICON).addClass("hidden"),c.find(g.MESSAGE_SELECTED_ICON).removeClass("hidden"),c.attr("aria-checked",!0)}),d.remove.length&&d.remove.forEach(function(a){var c=V(b,a);e&&c.find(g.MESSAGE_NOT_SELECTED_ICON).removeClass("hidden"),c.find(g.MESSAGE_SELECTED_ICON).addClass("hidden"),c.attr("aria-checked",!1)}),ga(a,d.count)},Ja=function(a,b,d,e){return e.show&&!e.hasMessages?c.get_strings([{key:"requirecontacttomessage",component:"core_message",param:e.user.fullname},{key:"isnotinyourcontacts",component:"core_message",param:e.user.fullname}]).then(function(c){var e=c[1],f=c[0];return ua(a,b,d,[g.ACTION_REQUEST_ADD_CONTACT],f,e,!1,!0)}):va(a,b,d)},Ka=function(a,b,d,e){var f=m(b);return e?c.get_string("yourcontactrequestpending","core_message",e).then(function(a){return f.find(g.TEXT).text(a),f.removeClass("hidden"),a}):(f.addClass("hidden"),!0)},La=function(a,b,c){return va(a,b,c),n(b),G(a),S(a),H(c),v(c),!0},Ma=function(c,d,e,f){var g=[{reset:La},{conversation:ma,header:na,footer:oa,confirmBlockUser:wa,confirmUnblockUser:xa,confirmAddContact:ya,confirmRemoveContact:za,confirmDeleteSelectedMessages:Aa,confirmDeleteConversation:Ba,confirmContactRequest:Ca,requireAddContact:Ja,contactRequestSent:Ka},{loadingMembers:qa,loadingFirstMessages:ra,loadingMessages:sa,sendingMessage:ta,isBlocked:Da,isContact:Fa,isFavourite:Ea,loadingConfirmAction:Ga,inEditMode:Ha},{scrollToMessage:pa,selectedMessages:Ia}],h=function(a){var b=[];for(var g in f)if(a.hasOwnProperty(g)){var h=a[g],i=f[g];b.push(h(c,d,e,i))}return b},i=h(g[0]);return i=i.concat(h(g[1])),a.when.apply(a,i).then(function(){for(var a=2;a0,j=g.messages.add.length>0,k=[],l=a.Deferred().resolve({}).promise();return i&&(k=k.concat(g.days.add.reduce(function(a,b){return a.concat(b.value.messages.map(function(a){return a.timeCreated}))},[]))),j&&(k=k.concat(g.messages.add.map(function(a){return a.value.timeCreated}))),k.length&&(l=c.get_string("strftimetime24","core_langconfig").then(function(a){var b=k.map(function(b){return{timestamp:b,format:a}});return e.get(b)}).then(function(a){return k.reduce(function(b,c,d){return b[c]=a[d],b},{})})),i&&h.push(l.then(function(a){return ia(b,d,f,g.days.add,a)})),j&&h.push(l.then(function(a){return ja(b,d,f,g.messages.add,a)})),g.days.remove.length>0&&ka(d,g.days.remove),g.messages.remove.length>0&&la(d,g.messages.remove),a.when.apply(a,h)},na=function(a,b,c,e){var f=L(a),g=h.HEADER_PUBLIC;return e.type==i.PRIVATE&&(g=e.showControls?h.HEADER_PRIVATE:h.HEADER_PRIVATE_NO_CONTROLS),d.render(g,e.context).then(function(a,b){d.replaceNodeContents(f,a,b)})},oa=function(a,b,d,e){switch(H(d),e.type){case"placeholder":return v(d);case"add-contact":return c.get_strings([{key:"requirecontacttomessage",component:"core_message",param:e.user.fullname},{key:"isnotinyourcontacts",component:"core_message",param:e.user.fullname}]).then(function(a){var b=a[1],c=a[0],e=x(d);return e.find(g.TITLE).text(b),e.find(g.TEXT).text(c),y(d),a});case"edit-mode":return s(d);case"content":return p(d);case"unblock":return B(d);case"unable-to-message":return E(d)}return!0},pa=function(a,b,c,d){var e=j(b),f=V(b,d),g=f.position();if(g){var h=e.scrollTop()+g.top;e.scrollTop(h)}},qa=function(a,b,c,d){d?(N(a),S(a)):(M(a),T(a))},ra=function(a,b,c,d){d?(l(b),J(b)):(k(b),K(b))},sa=function(a,b,c,d){d?Y(b):Z(b)},ta=function(a,b,c,d){d?aa(c):(ba(c),ca(c))},ua=function(a,b,c,d,e,f,h,i){var j=da(b),k=d.map(function(a){return j.find(a)}),l=j.find(g.CONFIRM_DIALOGUE_CANCEL_BUTTON),m=j.find(g.CONFIRM_DIALOGUE_TEXT),n=j.find(g.CONFIRM_DIALOGUE_HEADER);j.find("button").addClass("hidden"),h?l.removeClass("hidden"):l.addClass("hidden"),f?(n.removeClass("hidden"),n.text(f)):(n.addClass("hidden"),n.text("")),k.forEach(function(a){a.removeClass("hidden")}),m.text(e),ea(c),ea(b),i||ea(a),j.find(g.CAN_RECEIVE_FOCUS).filter(":visible").first().focus()},va=function(a,b,c){var d=da(b),e=d.find(g.CONFIRM_DIALOGUE_CANCEL_BUTTON),f=d.find(g.CONFIRM_DIALOGUE_TEXT),h=d.find(g.CONFIRM_DIALOGUE_HEADER);return fa(b),fa(c),fa(a),d.find("button").addClass("hidden"),e.removeClass("hidden"),f.text(""),h.addClass("hidden"),h.text(""),a.find(g.CAN_RECEIVE_FOCUS).first().focus(),!0},wa=function(a,b,d,e){return e?c.get_string("blockuserconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_BLOCK],c,"",!0,!1)}):va(a,b,d)},xa=function(a,b,d,e){return e?c.get_string("unblockuserconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_UNBLOCK],c,"",!0,!1)}):va(a,b,d)},ya=function(a,b,d,e){return e?c.get_string("addcontactconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_ADD_CONTACT],c,"",!0,!1)}):va(a,b,d)},za=function(a,b,d,e){return e?c.get_string("removecontactconfirm","core_message",e.fullname).then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_REMOVE_CONTACT],c,"",!0,!1)}):va(a,b,d)},Aa=function(a,b,d,e){return e?c.get_string("deleteselectedmessagesconfirm","core_message").then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES],c,"",!0,!1)}):va(a,b,d)},Ba=function(a,b,d,e){return e?c.get_string("deleteallconfirm","core_message").then(function(c){return ua(a,b,d,[g.ACTION_CONFIRM_DELETE_CONVERSATION],c,"",!0,!1)}):va(a,b,d)},Ca=function(a,b,d,e){return e?c.get_string("userwouldliketocontactyou","core_message",e.fullname).then(function(c){var e=[g.ACTION_ACCEPT_CONTACT_REQUEST,g.ACTION_DECLINE_CONTACT_REQUEST];return ua(a,b,d,e,c,"",!1,!0)}):va(a,b,d)},Da=function(a,b,c,d){d?(a.find(g.ACTION_REQUEST_BLOCK).addClass("hidden"),a.find(g.ACTION_REQUEST_UNBLOCK).removeClass("hidden")):(a.find(g.ACTION_REQUEST_BLOCK).removeClass("hidden"),a.find(g.ACTION_REQUEST_UNBLOCK).addClass("hidden"))},Ea=function(a,b,c,d){d?(a.find(g.FAVOURITE_ICON_CONTAINER).removeClass("hidden"),a.find(g.ACTION_CONFIRM_FAVOURITE).addClass("hidden"),a.find(g.ACTION_CONFIRM_UNFAVOURITE).removeClass("hidden")):(a.find(g.FAVOURITE_ICON_CONTAINER).addClass("hidden"),a.find(g.ACTION_CONFIRM_FAVOURITE).removeClass("hidden"),a.find(g.ACTION_CONFIRM_UNFAVOURITE).addClass("hidden"))},Fa=function(a,b,c,d){var e=a.find(g.ACTION_REQUEST_ADD_CONTACT),f=a.find(g.ACTION_REQUEST_REMOVE_CONTACT);switch(d){case"pending-contact":e.addClass("hidden"),f.addClass("hidden");break;case"contact":e.addClass("hidden"),f.removeClass("hidden");break;case"non-contact":e.removeClass("hidden"),f.addClass("hidden")}},Ga=function(a,b,c,d){var e=da(b),f=e.find("button"),h=e.find(g.CONFIRM_DIALOGUE_BUTTON_TEXT),i=e.find(g.LOADING_ICON_CONTAINER);d?(f.prop("disabled",!0),h.addClass("hidden"),i.removeClass("hidden")):(f.prop("disabled",!1),h.removeClass("hidden"),i.addClass("hidden"))},Ha=function(a,b,c,d){var e=null;d?(e=b.find(g.MESSAGE_NOT_SELECTED),e.find(g.MESSAGE_NOT_SELECTED_ICON).removeClass("hidden"),N(a),P(a)):(e=j(b),e.find(g.MESSAGE_NOT_SELECTED_ICON).addClass("hidden"),e.find(g.MESSAGE_SELECTED_ICON).addClass("hidden"),M(a),Q(a))},Ia=function(a,b,c,d){var e=d.count>0;d.add.length&&d.add.forEach(function(a){var c=V(b,a);c.find(g.MESSAGE_NOT_SELECTED_ICON).addClass("hidden"),c.find(g.MESSAGE_SELECTED_ICON).removeClass("hidden"),c.attr("aria-checked",!0)}),d.remove.length&&d.remove.forEach(function(a){var c=V(b,a);e&&c.find(g.MESSAGE_NOT_SELECTED_ICON).removeClass("hidden"),c.find(g.MESSAGE_SELECTED_ICON).addClass("hidden"),c.attr("aria-checked",!1)}),ga(a,d.count)},Ja=function(a,b,d,e){return e.show&&!e.hasMessages?c.get_strings([{key:"requirecontacttomessage",component:"core_message",param:e.user.fullname},{key:"isnotinyourcontacts",component:"core_message",param:e.user.fullname}]).then(function(c){var e=c[1],f=c[0];return ua(a,b,d,[g.ACTION_REQUEST_ADD_CONTACT],f,e,!1,!0)}):va(a,b,d)},Ka=function(a,b,d,e){var f=m(b);return e?c.get_string("yourcontactrequestpending","core_message",e).then(function(a){return f.find(g.TEXT).text(a),f.removeClass("hidden"),a}):(f.addClass("hidden"),!0)},La=function(a,b,c){return va(a,b,c),n(b),G(a),S(a),H(c),v(c),!0},Ma=function(c,d,e,f){var g=[{reset:La},{conversation:ma,header:na,footer:oa,confirmBlockUser:wa,confirmUnblockUser:xa,confirmAddContact:ya,confirmRemoveContact:za,confirmDeleteSelectedMessages:Aa,confirmDeleteConversation:Ba,confirmContactRequest:Ca,requireAddContact:Ja,contactRequestSent:Ka},{loadingMembers:qa,loadingFirstMessages:ra,loadingMessages:sa,sendingMessage:ta,isBlocked:Da,isContact:Fa,isFavourite:Ea,loadingConfirmAction:Ga,inEditMode:Ha},{scrollToMessage:pa,selectedMessages:Ia}],h=function(a){var b=[];for(var g in f)if(a.hasOwnProperty(g)){var h=a[g],i=f[g];b.push(h(c,d,e,i))}return b},i=h(g[0]);return i=i.concat(h(g[1])),a.when.apply(a,i).then(function(){for(var a=2;ap?b=b.slice(0,-1):l.setLoadedAll(e,!0),d+=p,b.forEach(function(a){q[a.id]=a}),b})["catch"](c.exception)}},w=function(a){return a.find(n.SECTION_TOTAL_COUNT)},x=function(a){return a.find(n.SECTION_UNREAD_COUNT)},y=function(a){var b=w(a),c=parseInt(b.text());c+=1,b.text(c)},z=function(a){var b=w(a),c=parseInt(b.text());c-=1,b.text(c)},A=function(a){var b=x(a),c=parseInt(b.text());c-=1,b.text(c),c<1&&b.addClass("hidden")},B=function(a,b){return a.find('[data-conversation-id="'+b+'"]')},C=function(a){a.find(n.BLOCKED_ICON_CONTAINER).removeClass("hidden")},D=function(a){a.find(n.BLOCKED_ICON_CONTAINER).addClass("hidden")},E=function(b,d){var f=d.messages[d.messages.length-1],h="",i=[{key:"you",component:"core_message"},{key:"strftimetime24",component:"core_langconfig"}];return e.get_strings(i).then(function(a){return h=a[0],g.get([{timestamp:f.timeCreated,format:a[1]}])}).then(function(a){return a[0]}).then(function(c){var d=a(f.text).text();return f.fromLoggedInUser&&(d=h+" "+d),b.find(n.LAST_MESSAGE).html(d),b.find(n.LAST_MESSAGE_DATE).text(c).removeClass("hidden"),c})["catch"](c.exception)},F=function(b,d){var e=b.find(n.CONVERSATION),g="";if(!e.length){var h=l.getRoot(b);l.showContent(h),l.hideEmptyMessage(h)}var i=d.messages.length,j=i?d.messages[i-1]:null;j&&(g=a(j.text).text()||j.text);var k={id:d.id,name:d.name,subname:d.subname,lastmessagedate:j?j.timeCreated:null,sentfromcurrentuser:j?j.fromLoggedInUser:null,lastmessage:g,imageurl:d.imageUrl};return f.render(o.CONVERSATIONS_LIST,{conversations:[k]}).then(function(a){var c=l.getContentContainer(b);return c.prepend(a)}).then(function(){return y(b)})["catch"](c.exception)},G=function(a,b){b.remove(),z(a);var c=a.find(n.CONVERSATION);if(!c.length){var d=l.getRoot(a);l.hideContent(d),l.showEmptyMessage(d)}},H=function(a,b){var c=b.find(n.UNREAD_COUNT);c.text("0"),c.addClass("hidden"),A(a)},I=function(c,e,f,g){var h=l.getRoot(c),m=c.find(n.TOGGLE);c.css("min-height",m.outerHeight()),c.on("show.bs.collapse",function(){s(c),l.show(h,e,u)}),c.on("hidden.bs.collapse",function(){t(c)}),d.subscribe(i.CONTACT_BLOCKED,function(a){var b=B(c,a);b.length&&C(b)}),d.subscribe(i.CONTACT_UNBLOCKED,function(a){var b=B(c,a);b.length&&D(b)}),d.subscribe(i.CONVERSATION_NEW_LAST_MESSAGE,function(a){if(!(f&&a.type!=f||g&&!a.isFavourite||!g&&a.isFavourite)){var b=a.id,d=B(c,b);d.length?E(d,a):F(c,a)}}),d.subscribe(i.CONVERSATION_DELETED,function(a){var b=B(c,a);b.length&&G(c,b)}),d.subscribe(i.CONVERSATION_READ,function(a){var b=B(c,a);b.length&&H(c,b)}),d.subscribe(i.CONVERSATION_SET_FAVOURITE,function(a){var b=null;!g||f&&f!=a.type?f==a.type&&(b=B(c,a.id),b.length&&G(c,b)):(b=B(c,a.id),b.length||F(c,a))}),d.subscribe(i.CONVERSATION_UNSET_FAVOURITE,function(a){var b=null;g?(b=B(c,a.id),b.length&&G(c,b)):f==a.type&&(b=B(c,a.id),b.length||F(c,a))}),b.define(c,[b.events.activate]),c.on(b.events.activate,n.CONVERSATION,function(b,c){var d=a(b.target).closest(n.CONVERSATION),e=d.attr("data-conversation-id"),f=q[e];j.go(k.VIEW_CONVERSATION,f),c.originalEvent.preventDefault()})},J=function(b,c,d){if(b=a(b),!b.attr("data-init")){var e=v(c,d,0);if(I(b,e,c,d),r(b)){s(b);var f=l.getRoot(b);l.show(f,e,u)}b.attr("data-init",!0)}};return{show:J}}); \ No newline at end of file +define(["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/str","core/templates","core/user_date","core_message/message_repository","core_message/message_drawer_events","core_message/message_drawer_router","core_message/message_drawer_routes","core_message/message_drawer_lazy_load_list","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={TOGGLE:'[data-region="toggle"]',CONVERSATION:"[data-conversation-id]",BLOCKED_ICON_CONTAINER:'[data-region="contact-icon-blocked"]',LAST_MESSAGE:'[data-region="last-message"]',LAST_MESSAGE_DATE:'[data-region="last-message-date"]',UNREAD_COUNT:'[data-region="unread-count"]',SECTION_TOTAL_COUNT:'[data-region="section-total-count"]',SECTION_UNREAD_COUNT:'[data-region="section-unread-count"]'},o={CONVERSATIONS_LIST:"core_message/message_drawer_conversations_list"},p=50,q={},r=function(a){return l.getRoot(a).hasClass("show")},s=function(a){a.addClass("expanded")},t=function(a){a.removeClass("expanded")},u=function(b,d,e){var g=d.map(function(b){var c=b.messages.length?b.messages[b.messages.length-1]:null,d={id:b.id,imageurl:b.imageurl,name:b.name,subname:b.subname,unreadcount:b.unreadcount,lastmessagedate:c?c.timecreated:null,sentfromcurrentuser:c?c.useridfrom==e:null,lastmessage:c?a(c.text).text()||c.text:null};if(b.type==m.CONVERSATION_TYPES.PRIVATE){var f=b.members.reduce(function(a,b){return a||b.id==e||(a=b),a},null);d.userid=f.id,d.showonlinestatus=f.showonlinestatus,d.isonline=f.isosnline,d.isblocked=f.isblocked}return d});return f.render(o.CONVERSATIONS_LIST,{conversations:g}).then(function(a){return b.append(a),a})["catch"](c.exception)},v=function(a,b,d){return function(e,f){return h.getConversations(f,a,p+1,d,b).then(function(a){var b=a.conversations;return b.length>p?b=b.slice(0,-1):l.setLoadedAll(e,!0),d+=p,b.forEach(function(a){q[a.id]=a}),b})["catch"](c.exception)}},w=function(a){return a.find(n.SECTION_TOTAL_COUNT)},x=function(a){return a.find(n.SECTION_UNREAD_COUNT)},y=function(a){var b=w(a),c=parseInt(b.text());c+=1,b.text(c)},z=function(a){var b=w(a),c=parseInt(b.text());c-=1,b.text(c)},A=function(a){var b=x(a),c=parseInt(b.text());c-=1,b.text(c),c<1&&b.addClass("hidden")},B=function(a,b){return a.find('[data-conversation-id="'+b+'"]')},C=function(a,b){return a.find('[data-user-id="'+b+'"]')},D=function(a){a.find(n.BLOCKED_ICON_CONTAINER).removeClass("hidden")},E=function(a){a.find(n.BLOCKED_ICON_CONTAINER).addClass("hidden")},F=function(b,c){var d=c.messages[c.messages.length-1],f="",h=[{key:"you",component:"core_message"},{key:"strftimetime24",component:"core_langconfig"}];return e.get_strings(h).then(function(a){return f=a[0],g.get([{timestamp:d.timeCreated,format:a[1]}])}).then(function(a){return a[0]}).then(function(c){var e=a(d.text).text();return d.fromLoggedInUser&&(e=f+" "+e),b.find(n.LAST_MESSAGE).html(e),b.find(n.LAST_MESSAGE_DATE).text(c).removeClass("hidden"),c})},G=function(b,d){var e=b.find(n.CONVERSATION),g="";if(!e.length){var h=l.getRoot(b);l.showContent(h),l.hideEmptyMessage(h)}var i=d.messages.length,j=i?d.messages[i-1]:null;j&&(g=a(j.text).text()||j.text);var k={id:d.id,name:d.name,subname:d.subname,lastmessagedate:j?j.timeCreated:null,sentfromcurrentuser:j?j.fromLoggedInUser:null,lastmessage:g,imageurl:d.imageUrl};return f.render(o.CONVERSATIONS_LIST,{conversations:[k]}).then(function(a){var c=l.getContentContainer(b);return c.prepend(a)}).then(function(){return y(b)})["catch"](c.exception)},H=function(a,b){b.remove(),z(a);var c=a.find(n.CONVERSATION);if(!c.length){var d=l.getRoot(a);l.hideContent(d),l.showEmptyMessage(d)}},I=function(a,b){var c=b.find(n.UNREAD_COUNT);c.text("0"),c.addClass("hidden"),A(a)},J=function(c,e,f,g){var h=l.getRoot(c),m=c.find(n.TOGGLE);c.css("min-height",m.outerHeight()),c.on("show.bs.collapse",function(){s(c),l.show(h,e,u)}),c.on("hidden.bs.collapse",function(){t(c)}),d.subscribe(i.CONTACT_BLOCKED,function(a){var b=C(c,a);b.length&&D(b)}),d.subscribe(i.CONTACT_UNBLOCKED,function(a){var b=C(c,a);b.length&&E(b)}),d.subscribe(i.CONVERSATION_NEW_LAST_MESSAGE,function(a){if(!(f&&a.type!=f||g&&!a.isFavourite||!g&&a.isFavourite)){var b=a.id,d=B(c,b);d.length?F(d,a):G(c,a)}}),d.subscribe(i.CONVERSATION_DELETED,function(a){var b=B(c,a);b.length&&H(c,b)}),d.subscribe(i.CONVERSATION_READ,function(a){var b=B(c,a);b.length&&I(c,b)}),d.subscribe(i.CONVERSATION_SET_FAVOURITE,function(a){var b=null;!g||f&&f!=a.type?f==a.type&&(b=B(c,a.id),b.length&&H(c,b)):(b=B(c,a.id),b.length||G(c,a))}),d.subscribe(i.CONVERSATION_UNSET_FAVOURITE,function(a){var b=null;g?(b=B(c,a.id),b.length&&H(c,b)):f==a.type&&(b=B(c,a.id),b.length||G(c,a))}),b.define(c,[b.events.activate]),c.on(b.events.activate,n.CONVERSATION,function(b,c){var d=a(b.target).closest(n.CONVERSATION),e=d.attr("data-conversation-id"),f=q[e];j.go(k.VIEW_CONVERSATION,f),c.originalEvent.preventDefault()})},K=function(b,c,d){if(b=a(b),!b.attr("data-init")){var e=v(c,d,0);if(J(b,e,c,d),r(b)){s(b);var f=l.getRoot(b);l.show(f,e,u)}b.attr("data-init",!0)}};return{show:K}}); \ No newline at end of file diff --git a/message/amd/src/message_drawer_router.js b/message/amd/src/message_drawer_router.js index 5b82df9d9e8..62ca83ceaf0 100644 --- a/message/amd/src/message_drawer_router.js +++ b/message/amd/src/message_drawer_router.js @@ -116,7 +116,7 @@ function( if (!hasFocus) { // This page doesn't have focus yet so focus the first focusable // element in the new view. - newConfig.elements[0].find(SELECTORS.CAN_RECEIVE_FOCUS).first().focus(); + newConfig.elements[0].find(SELECTORS.CAN_RECEIVE_FOCUS).filter(':visible').first().focus(); } } } diff --git a/message/amd/src/message_drawer_view_conversation.js b/message/amd/src/message_drawer_view_conversation.js index f2587fd07e0..324e2ef2131 100644 --- a/message/amd/src/message_drawer_view_conversation.js +++ b/message/amd/src/message_drawer_view_conversation.js @@ -598,7 +598,7 @@ function( var newState = StateManager.addMembers(viewState, [profile]); newState = StateManager.removePendingBlockUsersById(newState, [userId]); newState = StateManager.setLoadingConfirmAction(newState, false); - PubSub.publish(MessageDrawerEvents.CONTACT_BLOCKED, newState.id); + PubSub.publish(MessageDrawerEvents.CONTACT_BLOCKED, userId); return render(newState); }); }; @@ -634,7 +634,7 @@ function( var newState = StateManager.addMembers(viewState, [profile]); newState = StateManager.removePendingUnblockUsersById(newState, [userId]); newState = StateManager.setLoadingConfirmAction(newState, false); - PubSub.publish(MessageDrawerEvents.CONTACT_UNBLOCKED, newState.id); + PubSub.publish(MessageDrawerEvents.CONTACT_UNBLOCKED, userId); return render(newState); }); }; diff --git a/message/amd/src/message_drawer_view_conversation_renderer.js b/message/amd/src/message_drawer_view_conversation_renderer.js index a1b4b0fd20f..56ef9366e2f 100644 --- a/message/amd/src/message_drawer_view_conversation_renderer.js +++ b/message/amd/src/message_drawer_view_conversation_renderer.js @@ -992,7 +992,7 @@ function( showConfirmDialogueContainer(header); } - dialogue.find(SELECTORS.CAN_RECEIVE_FOCUS).first().focus(); + dialogue.find(SELECTORS.CAN_RECEIVE_FOCUS).filter(':visible').first().focus(); }; /** diff --git a/message/amd/src/message_drawer_view_overview_section.js b/message/amd/src/message_drawer_view_overview_section.js index f10eeaffc09..92a6e831fe2 100644 --- a/message/amd/src/message_drawer_view_overview_section.js +++ b/message/amd/src/message_drawer_view_overview_section.js @@ -128,6 +128,7 @@ function( return carry; }, null); + formattedConversation.userid = otherUser.id; formattedConversation.showonlinestatus = otherUser.showonlinestatus; formattedConversation.isonline = otherUser.isosnline; formattedConversation.isblocked = otherUser.isblocked; @@ -253,6 +254,17 @@ function( return root.find('[data-conversation-id="' + conversationId + '"]'); }; + /** + * Get a contact / conversation element from a user id. + * + * @param {Object} root Overview messages container element. + * @param {Number} userId The user id. + * @return {Object} Conversation element. + */ + var getConversationElementFromUserId = function(root, userId) { + return root.find('[data-user-id="' + userId + '"]'); + }; + /** * Show the contact is blocked icon. * @@ -303,8 +315,7 @@ function( element.find(SELECTORS.LAST_MESSAGE).html(lastMessage); element.find(SELECTORS.LAST_MESSAGE_DATE).text(dateString).removeClass('hidden'); return dateString; - }) - .catch(Notification.exception); + }); }; /** @@ -412,15 +423,15 @@ function( setCollapsed(root); }); - PubSub.subscribe(MessageDrawerEvents.CONTACT_BLOCKED, function(conversationId) { - var conversationElement = getConversationElement(root, conversationId); + PubSub.subscribe(MessageDrawerEvents.CONTACT_BLOCKED, function(userId) { + var conversationElement = getConversationElementFromUserId(root, userId); if (conversationElement.length) { blockContact(conversationElement); } }); - PubSub.subscribe(MessageDrawerEvents.CONTACT_UNBLOCKED, function(conversationId) { - var conversationElement = getConversationElement(root, conversationId); + PubSub.subscribe(MessageDrawerEvents.CONTACT_UNBLOCKED, function(userId) { + var conversationElement = getConversationElementFromUserId(root, userId); if (conversationElement.length) { unblockContact(conversationElement); } diff --git a/message/externallib.php b/message/externallib.php index ddc5e12d0c0..d3f60422aa9 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -90,8 +90,13 @@ class core_message_external extends external_api { $messages = []; foreach ($params['messages'] as $message) { - $messages[] = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'], + $createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'], $message['textformat']); + $createdmessage->text = message_format_message_text((object) [ + 'smallmessage' => $createdmessage->text, + 'fullmessageformat' => external_validate_format($message['textformat']) + ]); + $messages[] = $createdmessage; } return $messages; diff --git a/message/index.php b/message/index.php index a46ff220ab1..090381d3a74 100644 --- a/message/index.php +++ b/message/index.php @@ -107,10 +107,12 @@ if ($currentuser) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('messages', 'message')); $conversationid = empty($user2id) ? null : \core_message\api::get_conversation_between_users([$USER->id, $user2id]); - if (empty($conversationid)) { + if (empty($conversationid) && !empty($user2id)) { $PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'createConversationWithUser', [$user2id]); - } else { + } else if (!empty($conversationid)) { $PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'showConversation', [$conversationid]); + } else { + $PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'show'); } echo $OUTPUT->footer(); exit(); diff --git a/message/lib.php b/message/lib.php index fd0f05ba748..5b22e8bef05 100644 --- a/message/lib.php +++ b/message/lib.php @@ -901,7 +901,10 @@ function core_message_before_standard_top_of_body_html() { 'contacts' => [ 'sectioncontacts' => [ 'placeholders' => array_fill(0, $contactscount > 50 ? 50 : $contactscount, true) - ] + ], + 'sectionrequests' => [ + 'placeholders' => array_fill(0, $requestcount > 50 ? 50 : $requestcount, true) + ], ], 'settings' => [ 'privacy' => $choices, diff --git a/message/templates/message_drawer_contacts_list_item_placeholder.mustache b/message/templates/message_drawer_contacts_list_item_placeholder.mustache index fa3d9c51873..607c3900655 100644 --- a/message/templates/message_drawer_contacts_list_item_placeholder.mustache +++ b/message/templates/message_drawer_contacts_list_item_placeholder.mustache @@ -34,7 +34,7 @@ {} }} -
+
{{#imageurl}} +
+
core_message/message_drawer_contacts_list_item_placeholder }} {{/placeholders}} - {{/sectioncontacts}} + {{/sectionrequests}} {{/contacts}} {{/placeholder}} {{/ core_message/message_drawer_lazy_load_list }} diff --git a/message/templates/message_drawer_view_contacts_body_section_requests.mustache b/message/templates/message_drawer_view_contacts_body_section_requests.mustache index cb532ef6444..120bf214ce8 100644 --- a/message/templates/message_drawer_view_contacts_body_section_requests.mustache +++ b/message/templates/message_drawer_view_contacts_body_section_requests.mustache @@ -37,45 +37,12 @@ {{< core_message/message_drawer_lazy_load_list }} {{$emptymessage}}{{#str}} nocontactrequests, core_message {{/str}}{{/emptymessage}} {{$placeholder}} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} - {{> core_message/message_drawer_contacts_list_item_placeholder }} + {{#contacts}} + {{#sectioncontacts}} + {{#placeholders}} + {{> core_message/message_drawer_contacts_list_item_placeholder }} + {{/placeholders}} + {{/sectioncontacts}} + {{/contacts}} {{/placeholder}} {{/ core_message/message_drawer_lazy_load_list }}