You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
16 KiB

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=!0,v=!1,w=null,x=[],y=j.NEWEST_MESSAGES_FIRST,z=j.LOAD_MESSAGE_LIMIT,A=j.INITIAL_NEW_MESSAGE_POLL_TIMEOUT,B=j.SELECTORS,C=j.CONVERSATION_TYPES,D=function(){if(!q||q.type==C.PUBLIC)return null;var a=q.loggedInUserId;if(q.type==C.SELF)return a;var b=Object.keys(q.members).filter(function(b){return a!=b});return b.length?b[0]:null},E=function(a){return Object.keys(p).reduce(function(b,c){if(!b){var d=p[c].state;d.type!=C.PUBLIC&&a in d.members&&(b=d.id)}return b},null)},F=function(a){return{id:parseInt(a.attr("data-user-id"),10),fullname:null,profileimageurl:null,profileimageurlsmall:null,isonline:null,showonlinestatus:null,isblocked:null,iscontact:null,isdeleted:null,canmessage:null,requirescontact:null,contactrequests:[]}},G=function(){return s},H=function(a){s=a,p[q.id].messagesOffset=a},I=function(){return r},J=function(a){r=a,p[q.id].loadedAllMessages=a},K=function(a){return a.find(B.MESSAGES_CONTAINER)},L=function(b){return{id:b.id,name:b.name,subname:b.subname,imageUrl:b.imageUrl,isFavourite:b.isFavourite,isMuted:b.isMuted,type:b.type,totalMemberCount:b.totalMemberCount,loggedInUserId:b.loggedInUserId,messages:b.messages.map(function(b){return a.extend({},b)}),members:Object.keys(b.members).map(function(c){var d=a.extend({},b.members[c]);return d.contactrequests=b.members[c].contactrequests.map(function(b){return a.extend({},b)}),d})}},M=function(a,b){var c=a.id,d=c==b?C.SELF:C.PRIVATE,f=m.setLoadingMembers(q,!0);return f=m.setLoadingMessages(f,!0),w(f).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=d==C.SELF?[b]:[b,a],e=m.addMembers(q,c);return e=m.setLoadingMembers(e,!1),e=m.setLoadingMessages(e,!1),e=m.setName(e,b.fullname),e=m.setType(e,d),e=m.setImageUrl(e,b.profileimageurl),e=m.setTotalMemberCount(e,c.length),w(e).then(function(){return b})})["catch"](function(a){var b=m.setLoadingMembers(q,!1);w(b),e.exception(a)})},N=function(a,b){var c=null;if(a.type==C.PRIVATE){var d=a.members.filter(function(a){return a.id!=b});c=d.length?d[0]:null}else a.type==C.SELF&&(c=a.members[0]);var e=a.name,f=a.imageurl;a.type!=C.PUBLIC&&(e=e||c?c.fullname:"",f=f||c?c.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.setIsMuted(g,a.ismuted),g=m.addMessages(g,a.messages),g=m.setCanDeleteMessagesForAllUsers(g,a.candeletemessagesforallusers)},O=function(a,b,c,d,f){var g=b.id,i=m.setLoadingMembers(q,!0);return i=m.setLoadingMessages(i,!0),w(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):J(!0),H(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=N(a,b.id);return d=m.setLoadingMembers(d,!1),d=m.setLoadingMessages(d,!1),w(d).then(function(){return a})}).then(function(){return S(a)})["catch"](function(a){var b=m.setLoadingMembers(q,!1);b=m.setLoadingMessages(b,!1),w(b),e.exception(a)})},P=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=N(a,b.id);g=m.setLoadingMembers(g,!1),g=m.setLoadingMessages(g,!0);var h=a.messages.length;return w(g).then(function(){if(h<c)return Q(a.id,c,h,d,[]).then(function(a){return a.messag