芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/.trash/cepali/message/amd/build/message_drawer_view_conversation.min.js
define(["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"],function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){var q={},r=null,s=!1,t=0,u=null,v=!1,w=[],x=!0,y=!1,z=!1,A=null,B=[],C=k.NEWEST_MESSAGES_FIRST,D=k.LOAD_MESSAGE_LIMIT,E=k.MILLISECONDS_IN_SEC,F=k.SELECTORS,G=k.CONVERSATION_TYPES,H=function(){if(!r||r.type==G.PUBLIC)return null;var a=r.loggedInUserId;if(r.type==G.SELF)return a;var b=Object.keys(r.members).filter(function(b){return a!=b});return b.length?b[0]:null},I=function(a){return Object.keys(q).reduce(function(b,c){if(!b){var d=q[c].state;d.type!=G.PUBLIC&&a in d.members&&(b=d.id)}return b},null)},J=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:[]}},K=function(){return t},L=function(a){t=a,q[r.id].messagesOffset=a},M=function(){return s},N=function(a){s=a,q[r.id].loadedAllMessages=a},O=function(a){return a.find(F.MESSAGES_CONTAINER)},P=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})}},Q=function(a,b){var c=a.id,d=c==b?G.SELF:G.PRIVATE,f=n.setLoadingMembers(r,!0);return f=n.setLoadingMessages(f,!0),A(f),i.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==G.SELF?[b]:[b,a],e=n.addMembers(r,c);return e=n.setLoadingMembers(e,!1),e=n.setLoadingMessages(e,!1),e=n.setName(e,b.fullname),e=n.setType(e,d),e=n.setImageUrl(e,b.profileimageurl),e=n.setTotalMemberCount(e,c.length),A(e),b})["catch"](function(a){var b=n.setLoadingMembers(r,!1);A(b),e.exception(a)})},R=function(a,b){var c=null;if(a.type==G.PRIVATE){var d=a.members.filter(function(a){return a.id!=b});c=d.length?d[0]:null}else a.type==G.SELF&&(c=a.members[0]);var e=a.name,f=a.imageurl;a.type!=G.PUBLIC&&(e=e||c?c.fullname:"",f=f||c?c.profileimageurl:"");var g=n.addMembers(r,a.members);return g=n.setName(g,e),g=n.setSubname(g,a.subname),g=n.setType(g,a.type),g=n.setImageUrl(g,f),g=n.setTotalMemberCount(g,a.membercount),g=n.setIsFavourite(g,a.isfavourite),g=n.setIsMuted(g,a.ismuted),g=n.addMessages(g,a.messages),g=n.setCanDeleteMessagesForAllUsers(g,a.candeletemessagesforallusers)},S=function(a,b,c,d,f){var g=b.id,h=n.setLoadingMembers(r,!0);return h=n.setLoadingMessages(h,!0),A(h),i.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):N(!0),L(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=R(a,b.id);return d=n.setLoadingMembers(d,!1),d=n.setLoadingMessages(d,!1),A(d).then(function(){return a})}).then(function(){return W(a)})["catch"](function(a){var b=n.setLoadingMembers(r,!1);b=n.setLoadingMessages(b,!1),A(b),e.exception(a)})},T=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=a.messages.length,h=g>=c,i=R(a,b.id);i=n.setLoadingMembers(i,!1),i=n.setLoadingMessages(i,!h);var j=A(i);return j.then(function(){return h?{messages:a.messages}:U(a.id,c,g,d,[])}).then(function(){var a=r.messages;return L(a.length),W(r.id),a})["catch"](e.exception)},U=function(a,b,c,d,e,f){return i.getMessages(r.loggedInUserId,a,b?b+1:b,c,d,f).then(function(a){return a.messages.length&&e.length&&(a.messages=a.messages.filter(function(a){return e.indexOf(parseInt(a.id,10))<0})),a}).then(function(a){return b?(a.messages.length>b?a.messages=a.messages.slice(0,-1):N(!0),a):a}).then(function(a){var b=a.members.filter(function(a){return!(a.id in r.members)}),c=n.addMembers(r,b);return c=n.addMessages(c,a.messages),c=n.setLoadingMessages(c,!1),A(c).then(function(){return a})})["catch"](function(a){var b=n.setLoadingMessages(r,!1);throw A(b),a})},V=function(b,c){return function(){var d=r.messages,e=d.length?d[d.length-1]:null;if(e&&!x&&!y&&!z){for(var f=[],h=d.length-1;h>=0;h--){var i=d[h];if(i.timeCreated!==e.timeCreated)break;f.push(i.id)}return U(b,0,0,c,f,e.timeCreated).then(function(a){if(a.messages.length){u.restart();var c=P(r);return g.publish(j.CONVERSATION_NEW_LAST_MESSAGE,c),W(b)}return a})}return a.Deferred().resolve().promise()}},W=function(a){var b=r.loggedInUserId,c=new f("core_message/message_drawer_view_conversation:markConversationAsRead");return i.markAllConversationMessagesAsRead(b,a).then(function(){var b=n.markMessagesAsRead(r,r.messages);return g.publish(j.CONVERSATION_READ,a),A(b)}).then(function(a){return c.resolve(),a})},X=function(a){la(a);var b=n.addPendingBlockUsersById(r,[a]);A(b)},Y=function(a){var b=n.setLoadingConfirmAction(r,!0),c=new f("core_message/message_drawer_view_conversation:blockUser");return A(b),i.blockUser(r.loggedInUserId,a).then(function(b){var c=n.addMembers(r,[b]);return c=n.removePendingBlockUsersById(c,[a]),c=n.setLoadingConfirmAction(c,!1),g.publish(j.CONTACT_BLOCKED,a),A(c)}).then(function(a){return c.resolve(),a})},Z=function(a){la(a);var b=n.addPendingUnblockUsersById(r,[a]);A(b)},$=function(a){var b=n.setLoadingConfirmAction(r,!0),c=new f("core_message/message_drawer_view_conversation:unblockUser");return A(b),i.unblockUser(r.loggedInUserId,a).then(function(b){var c=n.addMembers(r,[b]);return c=n.removePendingUnblockUsersById(c,[a]),c=n.setLoadingConfirmAction(c,!1),g.publish(j.CONTACT_UNBLOCKED,a),A(c)}).then(function(a){return c.resolve(),a})},_=function(a){la(a);var b=n.addPendingRemoveContactsById(r,[a]);A(b)},aa=function(a){var b=n.setLoadingConfirmAction(r,!0),c=new f("core_message/message_drawer_view_conversation:removeContact");return A(b),i.deleteContacts(r.loggedInUserId,[a]).then(function(b){var c=n.addMembers(r,b);return c=n.removePendingRemoveContactsById(c,[a]),c=n.setLoadingConfirmAction(c,!1),g.publish(j.CONTACT_REMOVED,a),A(c)}).then(function(a){return c.resolve(),a})},ba=function(a){la(a);var b=n.addPendingAddContactsById(r,[a]);A(b)},ca=function(a){var b=n.setLoadingConfirmAction(r,!0),c=new f("core_message/message_drawer_view_conversation:addContactRequests");return A(b),i.createContactRequest(r.loggedInUserId,a).then(function(a){if(!a.request)throw new Error(a.warnings[0].message);return a.request}).then(function(b){var c=n.removePendingAddContactsById(r,[a]);return c=n.addContactRequests(c,[b]),c=n.setLoadingConfirmAction(c,!1),A(c)}).then(function(a){return c.resolve(),a})},da=function(){var a=r.loggedInUserId,b=r.id,c=new f("core_message/message_drawer_view_conversation:setFavourite");return i.setFavouriteConversations(a,[b]).then(function(){var a=n.setIsFavourite(r,!0);return A(a)}).then(function(){return g.publish(j.CONVERSATION_SET_FAVOURITE,P(r))}).then(function(a){return c.resolve(),a})},ea=function(){var a=r.loggedInUserId,b=r.id,c=new f("core_message/message_drawer_view_conversation:unsetFavourite");return i.unsetFavouriteConversations(a,[b]).then(function(){var a=n.setIsFavourite(r,!1);return A(a)}).then(function(){return g.publish(j.CONVERSATION_UNSET_FAVOURITE,P(r))}).then(function(a){return c.resolve(),a})},fa=function(){var a=r.loggedInUserId,b=r.id,c=new f("core_message/message_drawer_view_conversation:markConversationAsRead");return i.setMutedConversations(a,[b]).then(function(){var a=n.setIsMuted(r,!0);return A(a)}).then(function(){return g.publish(j.CONVERSATION_SET_MUTED,P(r))}).then(function(a){return c.resolve(),a})},ga=function(){var a=r.loggedInUserId,b=r.id;return i.unsetMutedConversations(a,[b]).then(function(){var a=n.setIsMuted(r,!1);return A(a)}).then(function(){return g.publish(j.CONVERSATION_UNSET_MUTED,P(r))})},ha=function(a){var b=r.selectedMessageIds;la(a);var c=n.addPendingDeleteMessagesById(r,b);A(c)},ia=function(){var a=new f("core_message/message_drawer_view_conversation:deleteSelectedMessages"),b=r.pendingDeleteMessageIds,c=n.setLoadingConfirmAction(r,!0);A(c);var d=null;return d=c.deleteMessagesForAllUsers?i.deleteMessagesForAllUsers(r.loggedInUserId,b):i.deleteMessages(r.loggedInUserId,b),z=!0,u&&u.stop(),d.then(function(){var a=n.removeMessagesById(r,b);a=n.removePendingDeleteMessagesById(a,b),a=n.removeSelectedMessagesById(a,b),a=n.setLoadingConfirmAction(a,!1),a=n.setDeleteMessagesForAllUsers(a,!1);var c=r.messages[r.messages.length-1],d=a.messages.length?a.messages[a.messages.length-1]:null;if(d&&d.id!=c.id){var e=P(a);g.publish(j.CONVERSATION_NEW_LAST_MESSAGE,e)}else a.messages.length||g.publish(j.CONVERSATION_DELETED,a.id);return z=!1,A(a)}).then(function(b){return a.resolve(),b})["catch"](e.exception)},ja=function(a){la(a);var b=n.setPendingDeleteConversation(r,!0);A(b)},ka=function(){var a=new f("core_message/message_drawer_view_conversation:markConversationAsRead"),b=n.setLoadingConfirmAction(r,!0);return A(b),z=!0,u&&u.stop(),i.deleteConversation(r.loggedInUserId,r.id).then(function(){var a=n.removeMessages(r,r.messages);return a=n.removeSelectedMessagesById(a,r.selectedMessageIds),a=n.setPendingDeleteConversation(a,!1),a=n.setLoadingConfirmAction(a,!1),g.publish(j.CONVERSATION_DELETED,a.id),z=!1,A(a)}).then(function(b){return a.resolve(),b})},la=function(a){var b=r.pendingDeleteMessageIds,c=n.removePendingAddContactsById(r,[a]);c=n.removePendingRemoveContactsById(c,[a]),c=n.removePendingUnblockUsersById(c,[a]),c=n.removePendingBlockUsersById(c,[a]),c=n.removePendingDeleteMessagesById(c,b),c=n.setPendingDeleteConversation(c,!1),c=n.setDeleteMessagesForAllUsers(c,!1),A(c)},ma=function(a){var b=new f("core_message/message_drawer_view_conversation:acceptContactRequest"),c=r.loggedInUserId,d=r.members[a].contactrequests.filter(function(a){return a.requesteduserid==c}),e=d[0],h=n.setLoadingConfirmAction(r,!0);return A(h),i.acceptContactRequest(a,c).then(function(a){var b=n.removeContactRequests(r,[e]);return b=n.addMembers(r,[a]),b=n.setLoadingConfirmAction(b,!1),A(b)}).then(function(){g.publish(j.CONTACT_ADDED,r.members[a]),g.publish(j.CONTACT_REQUEST_ACCEPTED,e)}).then(function(a){return b.resolve(),a})},na=function(a){var b=new f("core_message/message_drawer_view_conversation:declineContactRequest"),c=r.loggedInUserId,d=r.members[a].contactrequests.filter(function(a){return a.requesteduserid==c}),e=d[0],h=n.setLoadingConfirmAction(r,!0);return A(h),i.declineContactRequest(a,c).then(function(a){var b=n.removeContactRequests(r,[e]);return b=n.addMembers(r,[a]),b=n.setLoadingConfirmAction(b,!1),A(b)}).then(function(){g.publish(j.CONTACT_REQUEST_DECLINED,e)}).then(function(a){return b.resolve(),a})},oa=function(a,b){var c=new f("core_message/message_drawer_view_conversation:sendMessage");y=!0;var d=n.setSendingMessage(r,!0),h=null;A(d);var k=null,l=null;if(a||r.type==G.PUBLIC)k=i.sendMessageToConversation(a,b);else{var m=H();k=i.sendMessageToUser(m,b).then(function(a){return h=parseInt(a.conversationid,10),l=a.candeletemessagesforallusers,a})}k.then(function(a){var b=n.addMessages(r,[a]);b=n.setSendingMessage(b,!1);var c=P(b);b.id||(b=n.setId(b,h),c.id=h,Fa(h),g.publish(j.CONVERSATION_CREATED,c),b=n.setCanDeleteMessagesForAllUsers(b,l)),A(b),y=!1,g.publish(j.CONVERSATION_NEW_LAST_MESSAGE,c)}).then(function(a){return c.resolve(),a})["catch"](function(a){y=!1;var b=n.setSendingMessage(r,!1);A(b),e.exception(a)})},pa=function(a){var b=r;b=r.selectedMessageIds.indexOf(a)>-1?n.removeSelectedMessagesById(r,[a]):n.addSelectedMessagesById(r,[a]),A(b)},qa=function(){la(H());var a=n.removeSelectedMessagesById(r,r.selectedMessageIds);A(a)},ra=function(b,c,d){if(!v&&w.length){v=!0;var f=w.shift(),g=B.map(function(a){return a(f.patch)});a.when.apply(null,g).then(function(){v=!1,f.deferred.resolve(!0),ra(b,c,d)})["catch"](function(a){v=!1,f.deferred.reject(a),e.exception(a)})}},sa=function(b,c,d,e){var f=function(a){return m.render(b,c,d,a)};if(!e){var g=n.buildInitialState(r.midnight,r.loggedInUserId,r.id),h=l.buildPatch(g,r);f(h)}return B.push(f),function(e){var f=l.buildPatch(r,e),g=a.Deferred();return Object.keys(f).length?w.push({patch:f,deferred:g}):g.resolve(!0),r=e,e.id&&(q[e.id]={state:e,messagesOffset:K(),loadedAllMessages:M()}),ra(b,c,d),g.promise()}},ta=function(a){return function(b,c){if(!r.loadingConfirmAction){a(H());var d=n.setLoadingConfirmAction(r,!1);A(d)}c.originalEvent.preventDefault()}},ua=function(b,c){var d=a(b.target),e=d.closest(F.FOOTER_CONTAINER),f=e.find(F.MESSAGE_TEXT_AREA),g=f.val().trim();""!==g&&oa(r.id,g),c.originalEvent.preventDefault()},va=function(b,c){var d=window.getSelection(),e=a(b.target);if(""==d.toString()&&!e.is("a")){var f=e.closest(F.MESSAGE),g=parseInt(f.attr("data-message-id"),10);pa(g),c.originalEvent.preventDefault()}},wa=function(a,b){qa(),b.originalEvent.preventDefault()},xa=function(a){return function(b,c){var d=H(),e=r.members[d];o.go(a,p.VIEW_CONTACT,e),c.originalEvent.preventDefault()}},ya=function(a,b){da()["catch"](e.exception),b.originalEvent.preventDefault()},za=function(a,b){ea()["catch"](e.exception),b.originalEvent.preventDefault()},Aa=function(a,b){fa()["catch"](e.exception),b.originalEvent.preventDefault()},Ba=function(a,b){ga()["catch"](e.exception),b.originalEvent.preventDefault()},Ca=function(b){var c=a(b.target).prop("checked"),d=n.setDeleteMessagesForAllUsers(r,c);A(d)},Da=function(a){return function(b,c){o.go(a,p.VIEW_GROUP_INFO,{id:r.id,name:r.name,subname:r.subname,imageUrl:r.imageUrl,totalMemberCount:r.totalMemberCount},r.loggedInUserId),c.originalEvent.preventDefault()}},Ea=function(a,c,f,h){var i=!1,k=O(f),l=[[F.ACTION_REQUEST_BLOCK,ta(X)],[F.ACTION_REQUEST_UNBLOCK,ta(Z)],[F.ACTION_REQUEST_ADD_CONTACT,ta(ba)],[F.ACTION_REQUEST_REMOVE_CONTACT,ta(_)],[F.ACTION_REQUEST_DELETE_CONVERSATION,ta(ja)],[F.ACTION_CANCEL_EDIT_MODE,wa],[F.ACTION_VIEW_CONTACT,xa(a)],[F.ACTION_VIEW_GROUP_INFO,Da(a)],[F.ACTION_CONFIRM_FAVOURITE,ya],[F.ACTION_CONFIRM_MUTE,Aa],[F.ACTION_CONFIRM_UNFAVOURITE,za],[F.ACTION_CONFIRM_UNMUTE,Ba]],m=[[F.ACTION_CANCEL_CONFIRM,ta(la)],[F.ACTION_CONFIRM_BLOCK,ta(Y)],[F.ACTION_CONFIRM_UNBLOCK,ta($)],[F.ACTION_CONFIRM_ADD_CONTACT,ta(ca)],[F.ACTION_CONFIRM_REMOVE_CONTACT,ta(aa)],[F.ACTION_CONFIRM_DELETE_SELECTED_MESSAGES,ta(ia)],[F.ACTION_CONFIRM_DELETE_CONVERSATION,ta(ka)],[F.ACTION_REQUEST_ADD_CONTACT,ta(ba)],[F.ACTION_ACCEPT_CONTACT_REQUEST,ta(ma)],[F.ACTION_DECLINE_CONTACT_REQUEST,ta(na)],[F.MESSAGE,va],[F.DELETE_MESSAGES_FOR_ALL_USERS_TOGGLE,Ca]],o=[[F.SEND_MESSAGE_BUTTON,ua],[F.ACTION_REQUEST_DELETE_SELECTED_MESSAGES,ta(ha)],[F.ACTION_REQUEST_ADD_CONTACT,ta(ba)],[F.ACTION_REQUEST_UNBLOCK,ta(Z)]];b.init(h),d.define(c,[d.events.activate]),d.define(f,[d.events.activate]),d.define(h,[d.events.activate,d.events.enter]),d.define(k,[d.events.scrollTop,d.events.scrollLock]),k.on(d.events.scrollTop,function(a,b){var c=Object.keys(r.members).length>1;if(!x&&!i&&!M()&&c){i=!0;var d=n.setLoadingMessages(r,!0);A(d),U(r.id,D,K(),C,[]).then(function(){i=!1,L(K()+D)})["catch"](function(a){i=!1,e.exception(a)})}b.originalEvent.preventDefault()}),l.forEach(function(a){var b=a[0],e=a[1];c.on(d.events.activate,b,e)}),m.forEach(function(a){var b=a[0],c=a[1];f.on(d.events.activate,b,c)}),o.forEach(function(a){var b=a[0],c=a[1];h.on(d.events.activate,b,c)}),h.on(d.events.enter,F.MESSAGE_TEXT_AREA,function(a,b){var c=h.attr("data-enter-to-send");c&&"false"!=c&&"0"!=c&&ua(a,b)}),g.subscribe(j.ROUTE_CHANGED,function(a){u&&a.route!=p.VIEW_CONVERSATION&&u.stop()})},Fa=function(a){u&&u.stop(),u=new c(V(a,C),c.getIncrementalCallback(r.messagePollMin*E,E,r.messagePollMax*E,r.messagePollAfterMax*E)),u.start()},Ga=function(a,b,c){x=!0,v=!1,w=[],y=!1,z=!1;var d=c.id,e=parseInt(a.attr("data-midnight"),10),f=parseInt(a.attr("data-message-poll-min"),10),g=parseInt(a.attr("data-message-poll-max"),10),h=parseInt(a.attr("data-message-poll-after-max"),10),i=n.buildInitialState(e,d,b,f,g,h);r||(r=i),u&&u.stop(),A(i)},Ha=function(a,b,c){Ga(a,null,b);var d=null;return d=b.id!=c?i.getConversationBetweenUsers(b.id,c,!0,!0,0,0,D,0,C):i.getSelfConversation(b.id,D,0,C),d.then(function(c){return Ja(a,c,b)})["catch"](function(){return Q(b,c)})},Ia=function(b,c,d){var e=null;c in q&&(e=q[c]),Ga(b,c,d);var f=a.Deferred().resolve({}).promise();if(e){var g=e.state;g=n.setLoadingMessages(g,!1),g=n.setLoadingMembers(g,!1),L(e.messagesOffset),N(e.loadedAllMessages),A(g)}else f=S(c,d,D,0,C);return f.then(function(){return Fa(c)})},Ja=function(b,c,d){var e=null;c.id in q&&(e=q[c.id]),Ga(b,c.id,d);var f=a.Deferred().resolve({}).promise();if(e){var g=e.state;g=n.setLoadingMessages(g,!1),g=n.setLoadingMembers(g,!1),L(e.messagesOffset),N(e.loadedAllMessages),A(g)}else f=T(c,d,D,C);return f.then(function(){return Fa(c.id)})},Ka=function(b,c,d,f,g,h,i){var j=null,l=null;g&&null!==g&&"object"==typeof g?(j=g,l=parseInt(j.id,10)):(j=null,l=parseInt(g,10),l=isNaN(l)?null:l),!l&&h&&i&&(l=I(i));var m=!r||r.id!=l||i&&i!=H();if(d.attr("data-init")||(A=sa(c,d,f,m),Ea(b,c,d,f),d.attr("data-init",!0)),m){var n=null,o=J(d);return n=j?Ja(d,j,o,i):l?Ia(d,l,o,i):Ha(d,o,i),n.then(function(){x=!1,c.find(k.SELECTORS.CAN_RECEIVE_FOCUS).first().focus()})["catch"](function(a){x=!1,e.exception(a)})}if(Fa(l),r.type==G.PRIVATE&&h){var p=H();switch(h){case"block":return X(p);case"unblock":return Z(p);case"add-contact":return ba(p);case"remove-contact":return _(p)}}return a.Deferred().resolve().promise()},La=function(){return h.get_string("messagedrawerviewconversation","core_message",r.name)};return{show:Ka,description:La}});