446a342b8bb0fa1d9eed1bbf47cc3d957e59526c
[moodle.git] / message / amd / build / message_drawer_view_conversation.min.js
1 function _typeof(e){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(e){return typeof e}}else{_typeof=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e}}return _typeof(e)}define ("core_message/message_drawer_view_conversation",["jquery","core/auto_rows","core/backoff_timer","core/custom_interaction_events","core/notification","core/pending","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","core/emoji/auto_complete","core/emoji/picker"],function(s,e,t,n,a,o,r,d,i,g,l,m,c,_,E,C,I,u){var v={},h=null,T=!1,A=0,f=null,O=!1,p=[],M=!0,S=!1,N=!1,b=[],R=null,U=[],L=l.NEWEST_MESSAGES_FIRST,D=l.LOAD_MESSAGE_LIMIT,w=l.MILLISECONDS_IN_SEC,y=l.SELECTORS,P=l.CONVERSATION_TYPES,B=function(){if(!h||h.type==P.PUBLIC){return null}var e=h.loggedInUserId;if(h.type==P.SELF){return e}var s=Object.keys(h.members).filter(function(s){return e!=s});return s.length?s[0]:null},F=function(e){return Object.keys(v).reduce(function(s,t){if(!s){var n=v[t].state;if(n.type!=P.PUBLIC){if(e in n.members){s=n.id}}}return s},null)},k=function(e){return{id:parseInt(e.attr("data-user-id"),10),fullname:null,profileimageurl:null,profileimageurlsmall:null,isonline:null,showonlinestatus:null,isblocked:null,iscontact:null,isdeleted:null,canmessage:null,canmessageevenifblocked:null,requirescontact:null,contactrequests:[]}},V=function(){return A},x=function(e){A=e;v[h.id].messagesOffset=e},G=function(){return T},q=function(e){T=e;v[h.id].loadedAllMessages=e},j=function(e){return e.find(y.MESSAGES_CONTAINER)},K=function(e){return{id:e.id,name:e.name,subname:e.subname,imageUrl:e.imageUrl,isFavourite:e.isFavourite,isMuted:e.isMuted,type:e.type,totalMemberCount:e.totalMemberCount,loggedInUserId:e.loggedInUserId,messages:e.messages.map(function(e){return s.extend({},e)}),members:Object.keys(e.members).map(function(t){var n=s.extend({},e.members[t]);n.contactrequests=e.members[t].contactrequests.map(function(e){return s.extend({},e)});return n})}},Q=function(e,s){var t=e.id,n=t==s?P.SELF:P.PRIVATE,o=_.setLoadingMembers(h,!0);o=_.setLoadingMessages(o,!0);R(o);return i.getMemberInfo(t,[s],!0,!0).then(function(e){if(e.length){return e[0]}else{throw new Error("Unable to load other user profile")}}).then(function(s){var t=n==P.SELF?[s]:[s,e],a=_.addMembers(h,t);a=_.setLoadingMembers(a,!1);a=_.setLoadingMessages(a,!1);a=_.setName(a,s.fullname);a=_.setType(a,n);a=_.setImageUrl(a,s.profileimageurl);a=_.setTotalMemberCount(a,t.length);R(a);return s}).catch(function(e){var s=_.setLoadingMembers(h,!1);R(s);a.exception(e)})},W=function(e,s){var t=null;if(e.type==P.PRIVATE){var n=e.members.filter(function(e){return e.id!=s});t=n.length?n[0]:null}else if(e.type==P.SELF){t=e.members[0]}var a=e.name,o=e.imageurl;if(e.type!=P.PUBLIC){a=a||t?t.fullname:"";o=o||t?t.profileimageurl:""}var r=_.addMembers(h,e.members);r=_.setName(r,a);r=_.setSubname(r,e.subname);r=_.setType(r,e.type);r=_.setImageUrl(r,o);r=_.setTotalMemberCount(r,e.membercount);r=_.setIsFavourite(r,e.isfavourite);r=_.setIsMuted(r,e.ismuted);r=_.addMessages(r,e.messages);r=_.setCanDeleteMessagesForAllUsers(r,e.candeletemessagesforallusers);return r},J=function(e,s,t,n,o){var r=s.id,d=_.setLoadingMembers(h,!0);d=_.setLoadingMessages(d,!0);R(d);return i.getConversation(r,e,!0,!0,0,0,t+1,n,o).then(function(e){if(e.messages.length>t){e.messages=e.messages.slice(1)}else{q(!0)}x(n+t);return e}).then(function(e){var t=e.members.filter(function(e){return e.id==s.id});if(1>t.length){e.members=e.members.concat([s])}var n=W(e,s.id);n=_.setLoadingMembers(n,!1);n=_.setLoadingMessages(n,!1);return R(n).then(function(){return e})}).then(function(){return z(e)}).catch(function(e){var s=_.setLoadingMembers(h,!1);s=_.setLoadingMessages(s,!1);R(s);a.exception(e)})},X=function(e,s,t,n){var o=e.members.filter(function(e){return e.id==s.id});if(1>o.length){e.members=e.members.concat([s])}var r=e.messages.length,d=r>=t,i=W(e,s.id);i=_.setLoadingMembers(i,!1);i=_.setLoadingMessages(i,!d);var g=R(i);return g.then(function(){if(!d){return Y(e.id,t,r,n,[])}else{return{messages:e.messages}}}).then(function(){var e=h.messages;x(e.length);z(h.id);return e}).catch(a.exception)},Y=function(e,s,t,n,a,o){return i.getMessages(h.loggedInUserId,e,s?s+1:s,t,n,o).then(function(e){if(e.messages.length&&a.length){e.messages=e.messages.filter(function(e){return 0>a.indexOf(parseInt(e.id,10))})}return e}).then(function(e){if(!s){return e}else if(e.messages.length>s){e.messages=e.messages.slice(0,-1)}else{q(!0)}return e}).then(function(e){var s=e.members.filter(function(e){return!(e.id in h.members)}),t=_.addMembers(h,s);t=_.addMessages(t,e.messages);t=_.setLoadingMessages(t,!1);return R(t).then(function(){return e})}).catch(function(e){var s=_.setLoadingMessages(h,!1);R(s);throw e})},H=function(e,t){return function(){var n=h.messages,a=n.length?n[n.length-1]:null,o=a?a.timeCreated:null;if(o&&!M&&!S&&!N){for(var d=[],l=n.length-1,m;0<=l;l--){m=n[l];if(m.timeCreated===o){d.push(m.id)}else{break}}return Y(e,0,0,t,d,o).then(function(s){if(s.messages.length){f.restart();var t=K(h);r.publish(g.CONVERSATION_NEW_LAST_MESSAGE,t);return z(e)}else{return s}})}return s.Deferred().resolve().promise()}},z=function(e){var s=h.loggedInUserId,t=new o("core_message/message_drawer_view_conversation:markConversationAsRead");return i.markAllConversationMessagesAsRead(s,e).then(function(){var s=_.markMessagesAsRead(h,h.messages);r.publish(g.CONVERSATION_READ,e);return R(s)}).then(function(e){t.resolve();return e})},Z=function(e){Ee(e);var s=_.addPendingBlockUsersById(h,[e]);R(s)},$=function(e){var s=_.setLoadingConfirmAction(h,!0),t=new o("core_message/message_drawer_view_conversation:blockUser");R(s);return i.blockUser(h.loggedInUserId,e).then(function(s){var t=_.addMembers(h,[s]);t=_.removePendingBlockUsersById(t,[e]);t=_.setLoadingConfirmAction(t,!1);r.publish(g.CONTACT_BLOCKED,e);return R(t)}).then(function(e){t.resolve();return e})},ee=function(e){Ee(e);var s=_.addPendingUnblockUsersById(h,[e]);R(s)},se=function(e){var s=_.setLoadingConfirmAction(h,!0),t=new o("core_message/message_drawer_view_conversation:unblockUser");R(s);return i.unblockUser(h.loggedInUserId,e).then(function(s){var t=_.addMembers(h,[s]);t=_.removePendingUnblockUsersById(t,[e]);t=_.setLoadingConfirmAction(t,!1);r.publish(g.CONTACT_UNBLOCKED,e);return R(t)}).then(function(e){t.resolve();return e})},te=function(e){Ee(e);var s=_.addPendingRemoveContactsById(h,[e]);R(s)},ne=function(e){var s=_.setLoadingConfirmAction(h,!0),t=new o("core_message/message_drawer_view_conversation:removeContact");R(s);return i.deleteContacts(h.loggedInUserId,[e]).then(function(s){var t=_.addMembers(h,s);t=_.removePendingRemoveContactsById(t,[e]);t=_.setLoadingConfirmAction(t,!1);r.publish(g.CONTACT_REMOVED,e);return R(t)}).then(function(e){t.resolve();return e})},ae=function(e){Ee(e);var s=_.addPendingAddContactsById(h,[e]);R(s)},oe=function(e){var s=_.setLoadingConfirmAction(h,!0),t=new o("core_message/message_drawer_view_conversation:addContactRequests");R(s);return i.createContactRequest(h.loggedInUserId,e).then(function(e){if(!e.request){throw new Error(e.warnings[0].message)}return e.request}).then(function(s){var t=_.removePendingAddContactsById(h,[e]);t=_.addContactRequests(t,[s]);t=_.setLoadingConfirmAction(t,!1);return R(t)}).then(function(e){t.resolve();return e})},re=function(){var e=h.loggedInUserId,s=h.id,t=new o("core_message/message_drawer_view_conversation:setFavourite");return i.setFavouriteConversations(e,[s]).then(function(){var e=_.setIsFavourite(h,!0);return R(e)}).then(function(){return r.publish(g.CONVERSATION_SET_FAVOURITE,K(h))}).then(function(e){t.resolve();return e})},de=function(){var e=h.loggedInUserId,s=h.id,t=new o("core_message/message_drawer_view_conversation:unsetFavourite");return i.unsetFavouriteConversations(e,[s]).then(function(){var e=_.setIsFavourite(h,!1);return R(e)}).then(function(){return r.publish(g.CONVERSATION_UNSET_FAVOURITE,K(h))}).then(function(e){t.resolve();return e})},ie=function(){var e=h.loggedInUserId,s=h.id,t=new o("core_message/message_drawer_view_conversation:markConversationAsRead");return i.setMutedConversations(e,[s]).then(function(){var e=_.setIsMuted(h,!0);return R(e)}).then(function(){return r.publish(g.CONVERSATION_SET_MUTED,K(h))}).then(function(e){t.resolve();return e})},ge=function(){var e=h.loggedInUserId,s=h.id;return i.unsetMutedConversations(e,[s]).then(function(){var e=_.setIsMuted(h,!1);return R(e)}).then(function(){return r.publish(g.CONVERSATION_UNSET_MUTED,K(h))})},le=function(e){var s=h.selectedMessageIds;Ee(e);var t=_.addPendingDeleteMessagesById(h,s);R(t)},me=function(){var e=new o("core_message/message_drawer_view_conversation:deleteSelectedMessages"),t=h.pendingDeleteMessageIds,n=h.messages.filter(function(e){return 0<=t.indexOf(e.id)&&("sent"==e.sendState||null===e.sendState)}),d=_.setLoadingConfirmAction(h,!0);R(d);var l=s.Deferred().resolve().promise();if(n.length){var m=n.map(function(e){return e.id});if(d.deleteMessagesForAllUsers){l=i.deleteMessagesForAllUsers(h.loggedInUserId,m)}else{l=i.deleteMessages(h.loggedInUserId,m)}}N=!0;if(f){f.stop()}return l.then(function(){var e=_.removeMessagesById(h,t);e=_.removePendingDeleteMessagesById(e,t);e=_.removeSelectedMessagesById(e,t);e=_.setLoadingConfirmAction(e,!1);e=_.setDeleteMessagesForAllUsers(e,!1);var s=h.messages[h.messages.length-1],n=e.messages.length?e.messages[e.messages.length-1]:null;if(n&&n.id!=s.id){var a=K(e);r.publish(g.CONVERSATION_NEW_LAST_MESSAGE,a)}else if(!e.messages.length){r.publish(g.CONVERSATION_DELETED,e.id)}N=!1;return R(e)}).then(function(s){e.resolve();return s}).catch(a.exception)},ce=function(e){Ee(e);var s=_.setPendingDeleteConversation(h,!0);R(s)},_e=function(){var e=new o("core_message/message_drawer_view_conversation:markConversationAsRead"),s=_.setLoadingConfirmAction(h,!0);R(s);N=!0;if(f){f.stop()}return i.deleteConversation(h.loggedInUserId,h.id).then(function(){var e=_.removeMessages(h,h.messages);e=_.removeSelectedMessagesById(e,h.selectedMessageIds);e=_.setPendingDeleteConversation(e,!1);e=_.setLoadingConfirmAction(e,!1);r.publish(g.CONVERSATION_DELETED,e.id);N=!1;return R(e)}).then(function(s){e.resolve();return s})},Ee=function(e){var s=h.pendingDeleteMessageIds,t=_.removePendingAddContactsById(h,[e]);t=_.removePendingRemoveContactsById(t,[e]);t=_.removePendingUnblockUsersById(t,[e]);t=_.removePendingBlockUsersById(t,[e]);t=_.removePendingDeleteMessagesById(t,s);t=_.setPendingDeleteConversation(t,!1);t=_.setDeleteMessagesForAllUsers(t,!1);R(t)},Ce=function(e){var s=new o("core_message/message_drawer_view_conversation:acceptContactRequest"),t=h.loggedInUserId,n=h.members[e].contactrequests.filter(function(e){return e.requesteduserid==t}),a=n[0],d=_.setLoadingConfirmAction(h,!0);R(d);return i.acceptContactRequest(e,t).then(function(e){var s=_.removeContactRequests(h,[a]);s=_.addMembers(h,[e]);s=_.setLoadingConfirmAction(s,!1);return R(s)}).then(function(){r.publish(g.CONTACT_ADDED,h.members[e]);r.publish(g.CONTACT_REQUEST_ACCEPTED,a)}).then(function(e){s.resolve();return e})},Ie=function(e){var s=new o("core_message/message_drawer_view_conversation:declineContactRequest"),t=h.loggedInUserId,n=h.members[e].contactrequests.filter(function(e){return e.requesteduserid==t}),a=n[0],d=_.setLoadingConfirmAction(h,!0);R(d);return i.declineContactRequest(e,t).then(function(e){var s=_.removeContactRequests(h,[a]);s=_.addMembers(h,[e]);s=_.setLoadingConfirmAction(s,!1);return R(s)}).then(function(){r.publish(g.CONTACT_REQUEST_DECLINED,a)}).then(function(e){s.resolve();return e})},ue=function(){if(S){return}if(!b.length){return}var e=new o("core_message/message_drawer_view_conversation:processSendMessageBuffer");S=!0;var t=b.slice();b=[];var n=h.id,a=null,l=t.map(function(e){return e.text}),m=t.map(function(e){return e.id}),c=null,E=null;if(!n&&h.type!=P.PUBLIC){var C=B();c=i.sendMessagesToUser(C,l).then(function(e){if(e.length){a=parseInt(e[0].conversationid,10);E=e[0].candeletemessagesforallusers}return e})}else{c=i.sendMessagesToConversation(n,l)}c.then(function(e){var s=e.map(function(e){return e.id}),n=[],o=[],d=[];t.forEach(function(s,t){var a=e[t];n.push([s,a]);if(0<=h.selectedMessageIds.indexOf(s.id)){o.push(s.id);d.push(a.id)}});var i=_.updateMessages(h,n);i=_.setMessagesSendSuccessById(i,s);if(o.length){i=_.removeSelectedMessagesById(i,o)}if(d.length){i=_.addSelectedMessagesById(i,d)}var l=K(i);if(!i.id){i=_.setId(i,a);l.id=a;Ve(a);r.publish(g.CONVERSATION_CREATED,l);i=_.setCanDeleteMessagesForAllUsers(i,E)}R(i);S=!1;ue();r.publish(g.CONVERSATION_NEW_LAST_MESSAGE,l)}).then(function(s){e.resolve();return s}).catch(function(t){var n;if(t.message){n=s.Deferred().resolve(t.message).promise()}else{n=d.get_string("unknownerror","core")}var a=function(e){var s=_.setMessagesSendFailById(h,m,e);R(s);S=!1;ue()};n.then(a).then(function(s){e.resolve();return s}).catch(function(s){var e=s.message||"Something went wrong!";a(e)})})},ve=function(e){var s="temp"+Date.now(),t={id:s,useridfrom:h.loggedInUserId,text:e,timecreated:null},n=_.addMessages(h,[t]);R(n);b.push(t);ue()},he=function(e){var s=_.setMessagesSendPendingById(h,[e.id]);R(s);b.push(e);ue()},Te=function(e){var s=h;if(-1<h.selectedMessageIds.indexOf(e)){s=_.removeSelectedMessagesById(h,[e])}else{s=_.addSelectedMessagesById(h,[e])}R(s)},Ae=function(){Ee(B());var e=_.removeSelectedMessagesById(h,h.selectedMessageIds);R(e)},fe=function(e,t,n){if(O){return}if(!p.length){return}O=!0;var o=p.shift(),r=U.map(function(e){return e(o.patch)});s.when.apply(null,r).then(function(){O=!1;o.deferred.resolve(!0);fe(e,t,n)}).catch(function(e){O=!1;o.deferred.reject(e);a.exception(e)})},Oe=function(e,t,n,a){var o=function(s){return c.render(e,t,n,s)};if(!a){var r=_.buildInitialState(h.midnight,h.loggedInUserId,h.id),d=m.buildPatch(r,h);o(d)}U.push(o);return function(a){var o=m.buildPatch(h,a),r=s.Deferred();if(Object.keys(o).length){p.push({patch:o,deferred:r})}else{r.resolve(!0)}h=a;if(a.id){v[a.id]={state:a,messagesOffset:V(),loadedAllMessages:G()}}fe(e,t,n);return r.promise()}},pe=function(e){return function(s,t){if(!h.loadingConfirmAction){e(B());var n=_.setLoadingConfirmAction(h,!1);R(n)}t.originalEvent.preventDefault()}},Me=function(t,e){var n=s(t.target),a=n.closest(y.FOOTER_CONTAINER),o=a.find(y.MESSAGE_TEXT_AREA),r=o.val().trim();if(""!==r){ve(r);o.val("");o.focus()}e.originalEvent.preventDefault()},Se=function(t,e){var n=window.getSelection(),a=s(t.target);if(""!=n.toString()){return}if(a.is("a")){return}var o=a.closest(y.MESSAGE),r=o.attr("data-message-id");Te(r);e.originalEvent.preventDefault()},Ne=function(t,e){var n=s(t.target),a=n.closest(y.MESSAGE),o=a.attr("data-message-id"),r=h.messages.filter(function(e){return e.id==o}),d=r.length?r[0]:null;if(d){he(d)}e.originalEvent.preventDefault();e.originalEvent.stopPropagation();t.stopPropagation()},be=function(s,e){Ae();e.originalEvent.preventDefault()},Re=function(s){return function(t,e){var n=B(),a=h.members[n];E.go(s,C.VIEW_CONTACT,a);e.originalEvent.preventDefault()}},Ue=function(s,e){re().catch(a.exception);e.originalEvent.preventDefault()},Le=function(s,e){de().catch(a.exception);e.originalEvent.preventDefault()},De=function(s,e){ie().catch(a.exception);e.originalEvent.preventDefault()},we=function(s,e){ge().catch(a.exception);e.originalEvent.preventDefault()},ye=function(t){var e=s(t.target).prop("checked"),n=_.setDeleteMessagesForAllUsers(h,e);R(n)},Pe=function(s){return function(t,e){E.go(s,C.VIEW_GROUP_INFO,{id:h.id,name:h.name,subname:h.subname,imageUrl:h.imageUrl,totalMemberCount:h.totalMemberCount},h.loggedInUserId);e.originalEvent.preventDefault()}},Be=function(s,e){var t=_.setShowEmojiPicker(h,!h.showEmojiPicker);R(t);e.originalEvent.preventDefault()},Fe=function(t){var e=s(t.target);if(h.showEmojiPicker&&!e.closest(y.EMOJI_PICKER_CONTAINER).length&&!e.closest(y.TOGGLE_EMOJI_PICKER_BUTTON).length){var n=_.setShowEmojiPicker(h,!1);R(n)}},ke=function(t,o,d,i){var l=!1,m=j(d),c=i.find(y.EMOJI_PICKER),E=i.find(y.EMOJI_AUTO_COMPLETE_CONTAINER),v=i.find(y.MESSAGE_TEXT_AREA),T=[[y.ACTION_REQUEST_BLOCK,pe(Z)],[y.ACTION_REQUEST_UNBLOCK,pe(ee)],[y.ACTION_REQUEST_ADD_CONTACT,pe(ae)],[y.ACTION_REQUEST_REMOVE_CONTACT,pe(te)],[y.ACTION_REQUEST_DELETE_CONVERSATION,pe(ce)],[y.ACTION_CANCEL_EDIT_MODE,be],[y.ACTION_VIEW_CONTACT,Re(t)],[y.ACTION_VIEW_GROUP_INFO,Pe(t)],[y.ACTION_CONFIRM_FAVOURITE,Ue],[y.ACTION_CONFIRM_MUTE,De],[y.ACTION_CONFIRM_UNFAVOURITE,Le],[y.ACTION_CONFIRM_UNMUTE,we]],A=[[y.ACTION_CANCEL_CONFIRM,pe(Ee)],[y.ACTION_CONFIRM_BLOCK,pe($)],[y.ACTION_CONFIRM_UNBLOCK,pe(se)],[y.ACTION_CONFIRM_ADD_CONTACT,pe(oe)],[y.ACTION_CONFIRM_REMOVE_CONTACT,pe(ne)],[y.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES,pe(me)],[y.ACTION_CONFIRM_DELETE_CONVERSATION,pe(_e)],[y.ACTION_OKAY_CONFIRM,pe(Ee)],[y.ACTION_REQUEST_ADD_CONTACT,pe(ae)],[y.ACTION_ACCEPT_CONTACT_REQUEST,pe(Ce)],[y.ACTION_DECLINE_CONTACT_REQUEST,pe(Ie)],[y.MESSAGE,Se],[y.DELETE_MESSAGES_FOR_ALL_USERS_TOGGLE,ye],[y.RETRY_SEND,Ne]],O=[[y.SEND_MESSAGE_BUTTON,Me],[y.TOGGLE_EMOJI_PICKER_BUTTON,Be],[y.ACTION_REQUEST_DELETE_SELECTED_MESSAGES,pe(le)],[y.ACTION_REQUEST_ADD_CONTACT,pe(ae)],[y.ACTION_REQUEST_UNBLOCK,pe(ee)]];e.init(i);if(E.length){I(E[0],v[0],function(e){var s=_.setShowEmojiAutoComplete(h,e);R(s)},function(e){var s=_.setShowEmojiAutoComplete(h,!1);R(s);v.focus();var t=v.prop("selectionStart"),n=v.val(),a=n.substring(0,t).replace(/\S*$/,""),o=n.substring(t).replace(/^\S*/,"");v.val(a+e+o);v.prop("selectionStart",a.length+e.length);v.prop("selectionEnd",a.length+e.length)})}if(c.length){u(c[0],function(e){var s=_.setShowEmojiPicker(h,!h.showEmojiPicker);R(s);v.focus();var t=v.prop("selectionStart"),n=v.val(),a=n.substring(0,t),o=n.substring(t,n.length);v.val(a+e+o);v.prop("selectionStart",t+e.length);v.prop("selectionEnd",t+e.length)})}n.define(o,[n.events.activate]);n.define(d,[n.events.activate]);n.define(i,[n.events.activate,n.events.enter,n.events.escape]);n.define(m,[n.events.scrollTop,n.events.scrollLock]);m.on(n.events.scrollTop,function(s,e){var t=1<Object.keys(h.members).length;if(!M&&!l&&!G()&&t){l=!0;var n=_.setLoadingMessages(h,!0);R(n);Y(h.id,D,V(),L,[]).then(function(){l=!1;x(V()+D)}).catch(function(e){l=!1;a.exception(e)})}e.originalEvent.preventDefault()});T.forEach(function(e){var s=e[0],t=e[1];o.on(n.events.activate,s,t)});A.forEach(function(e){var s=e[0],t=e[1];d.on(n.events.activate,s,t)});O.forEach(function(e){var s=e[0],t=e[1];i.on(n.events.activate,s,t)});i.on(n.events.enter,y.MESSAGE_TEXT_AREA,function(s,e){var t=i.attr("data-enter-to-send");if(t&&"false"!=t&&"0"!=t){Me(s,e)}});i.on(n.events.escape,y.EMOJI_PICKER_CONTAINER,Be);s(document.body).on("click",Fe);r.subscribe(g.ROUTE_CHANGED,function(e){if(f){if(e.route!=C.VIEW_CONVERSATION){f.stop()}}})},Ve=function(e){if(f){f.stop()}f=new t(H(e,L),t.getIncrementalCallback(h.messagePollMin*w,w,h.messagePollMax*w,h.messagePollAfterMax*w));f.start()},xe=function(e,s,t){if(f){f.stop()}T=!1;A=0;f=null;O=!1;p=[];M=!0;S=!1;N=!1;b=[];var n=t.id,a=parseInt(e.attr("data-midnight"),10),o=parseInt(e.attr("data-message-poll-min"),10),r=parseInt(e.attr("data-message-poll-max"),10),d=parseInt(e.attr("data-message-poll-after-max"),10),i=_.buildInitialState(a,n,s,o,r,d);if(!h){h=i}R(i)},Ge=function(e,s,t){xe(e,null,s);var n=null;if(s.id!=t){n=i.getConversationBetweenUsers(s.id,t,!0,!0,0,0,D,0,L)}else{n=i.getSelfConversation(s.id,D,0,L)}return n.then(function(t){return je(e,t,s)}).catch(function(){return Q(s,t)})},qe=function(e,t,n){var a=null;if(t in v){a=v[t]}xe(e,t,n);var o=s.Deferred().resolve({}).promise();if(a){var r=a.state;r=_.setLoadingMessages(r,!1);r=_.setLoadingMembers(r,!1);x(a.messagesOffset);q(a.loadedAllMessages);R(r)}else{o=J(t,n,D,0,L)}return o.then(function(){return Ve(t)})},je=function(e,t,n){var a=null;if(t.id in v){a=v[t.id]}xe(e,t.id,n);var o=s.Deferred().resolve({}).promise();if(a){var r=a.state;r=_.setLoadingMessages(r,!1);r=_.setLoadingMembers(r,!1);x(a.messagesOffset);q(a.loadedAllMessages);R(r)}else{o=X(t,n,D,L)}return o.then(function(){return Ve(t.id)})},Ke=function(e,t,n,o,r,d,i){var g=null,m=null;if(r&&null!==r&&"object"==_typeof(r)){g=r;m=parseInt(g.id,10)}else{g=null;m=parseInt(r,10);m=isNaN(m)?null:m}if(!m&&d&&i){m=F(i)}var c=!h||h.id!=m||i&&i!=B();if(!n.attr("data-init")){R=Oe(t,n,o,c);ke(e,t,n,o);n.attr("data-init",!0)}if(c){var _=null,E=k(n);if(g){_=je(n,g,E,i)}else if(m){_=qe(n,m,E,i)}else{_=Ge(n,E,i)}return _.then(function(){M=!1;t.find(l.SELECTORS.CAN_RECEIVE_FOCUS).first().focus()}).catch(function(e){M=!1;a.exception(e)})}Ve(m);if(h.type==P.PRIVATE&&d){var C=B();switch(d){case"block":return Z(C);case"unblock":return ee(C);case"add-contact":return ae(C);case"remove-contact":return te(C);}}return s.Deferred().resolve().promise()},Qe=function(){return d.get_string("messagedrawerviewconversation","core_message",h.name)};return{show:Ke,description:Qe}});
2 //# sourceMappingURL=message_drawer_view_conversation.min.js.map