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 lines
9.7 KiB

define(["jquery","core/user_date","core_message/message_drawer_view_conversation_constants"],function(a,b,c){var d=function(a,c){var d=a.reduce(function(a,d){var e=b.getUserMidnightForTimestamp(d.timeCreated,c);return a.hasOwnProperty(e)?a[e].push(d):a[e]=[d],a},{});return Object.keys(d).map(function(a){return{timestamp:a,messages:d[a]}})},e=function(a,b,c){b=b.slice();var d=[],e=[],f=[];return a.forEach(function(a){for(var d=!1,g=0;g<b.length;g++){var h=b[g];if(c(a,h)){d=!0,f.push({a:a,b:h});break}}d?b.splice(g,1):e.push(a)}),d=b,{missingFromA:d,missingFromB:e,matches:f}},f=function(a,b){for(var c=null,d=0;d<a.length;d++){var e=a[d];if(b(e))return e}return c},g=function(a,b){a.sort(),b.sort();var c=a.length,d=b.length;return c<1&&d<1||c==d&&a.every(function(a,c){return a==b[c]})},h=function(a,b){return{remove:b.missingFromB,add:b.missingFromA.map(function(b){var c=f(a,function(a){return b.timestamp<a.timestamp});return{before:c,value:b}})}},i=function(a){var b=[],c=[];return a.forEach(function(a){var d=a.a,g=a.b,h=e(d.messages,g.messages,function(a,b){return a.id==b.id});b=b.concat(h.missingFromB),h.missingFromA.forEach(function(a){var b=f(d.messages,function(b){return a.timeCreated==b.timeCreated?a.id<b.id:a.timeCreated<b.timeCreated});c.push({before:b,value:a,day:d})})}),{add:c,remove:b}},j=function(a,b){var c=a.messages.map(function(a){return a.id}),f=b.messages.map(function(a){return a.id});if(g(c,f))return null;var j=d(a.messages,a.midnight),k=d(b.messages,b.midnight),l=e(j,k,function(a,b){return a.timestamp==b.timestamp});return{days:h(j,l),messages:i(l.matches)}},k=function(a,b){var d=I(a,b),e=y(a,b),f=G(a),g=G(b),h=d&&d.show&&!d.hasMessages,i=d&&!d.show,j=!f&&g;return j=j||h||i,j=j||null!==e,j?{type:c.CONVERSATION_TYPES.PRIVATE,showControls:!h&&!e,context:{id:b.id,name:b.name,subname:b.subname,totalmembercount:b.totalMemberCount,imageurl:b.imageUrl,isfavourite:b.isFavourite,ismuted:b.isMuted,showfavourite:null!==b.id,userid:g.id,showonlinestatus:g.showonlinestatus,isonline:g.isonline,isblocked:g.isblocked,iscontact:g.iscontact}}:null},l=function(a,b){var d=null===a.name&&null!==b.name;return d?{type:c.CONVERSATION_TYPES.SELF,showControls:!1,context:{id:b.id,name:b.name,subname:b.subname,imageurl:b.imageUrl,isfavourite:b.isFavourite,showfavourite:null!==b.id,showonlinestatus:!0}}:null},m=function(a,b){var d=a.totalMemberCount,e=b.totalMemberCount;return d!=e?{type:c.CONVERSATION_TYPES.PUBLIC,showControls:!0,context:{id:b.id,name:b.name,subname:b.subname,totalmembercount:b.totalMemberCount,imageurl:b.imageUrl,isfavourite:b.isFavourite,ismuted:b.isMuted,showfavourite:null!==b.id}}:null},n=function(a,b){var c=a.messages,d=b.messages;if(d.length<1)return null;if(c.length<1)return d[d.length-1].id;var e=c[a.messages.length-1],f=d[d.length-1],g=c[0],h=d[0];return e.id!=f.id?f.id:g.id!=h.id?g.id:null},o=function(a,b){return!(a.loadingMembers||!b.loadingMembers)||!(a.loadingMembers&&!b.loadingMembers)&&null},p=function(a,b){return a.hasTriedToLoadMessages===b.hasTriedToLoadMessages?null:!(b.hasTriedToLoadMessages||!b.loadingMessages)||!(b.hasTriedToLoadMessages&&!b.loadingMessages)&&null},q=function(a,b){return!(a.loadingMessages||!b.loadingMessages)||!(a.loadingMessages&&!b.loadingMessages)&&null},r=function(a,b){return!(a.sendingMessage||!b.sendingMessage)||!(a.sendingMessage&&!b.sendingMessage)&&null},s=function(a,b){if(b.pendingBlockUserIds.length){var c=b.pendingBlockUserIds[0];return b.members[c]}return!a.pendingBlockUserIds.length&&null},t=function(a,b){if(b.pendingUnblockUserIds.length){var c=b.pendingUnblockUserIds[0];return b.members[c]}return!a.pendingUnblockUserIds.length&&null},u=function(a,b){if(b.pendingAddContactIds.length){var c=b.pendingAddContactIds[0];return b.members[c]}return!a.pendingAddContactIds.length&&null},v=function(a,b){if(b.pendingRemoveContactIds.length){var c=b.pendingRemoveContactIds[0];return b.members[c]}return!a.pendingRemoveContactIds.length&&null},w=function(a,b){var c=a.pendingDeleteMessageIds.length,d=b.pendingDeleteMessageIds.length;return d&&!c?{show:!0,type:b.type,canDeleteMessagesForAllUsers:b.canDeleteMessagesForAllUsers}:c&&!d?{show:!1}:null},x=function(a,b){return!a.pendingDeleteConversation&&b.pendingDeleteConversation?b.type:!(a.pendingDeleteConversation&&!b.pendingDeleteConversation)&&null},y=function(a,b){var c=a.loggedInUserId,d=G(a),e=G(b),f=d?d.contactrequests.filter(function(a){return a.requesteduserid==c&&a.userid==d.id}):[],g=e?e.contactrequests.filter(function(a){return a.requesteduserid==c&&a.userid==e.id}):[],h=f.length?f[0]:null,i=g.length?g[0]:null;return!h&&i?e:!(h&&!i)&&null},z=function(a,b){var c=G(a),d=G(b);return c||d?!c&&d?!!d.isblocked||null:!d&&c?!c.isblocked&&null:!(c.isblocked&&!d.isblocked)&&(!(c.isblocked||!d.isblocked)||null):null},A=function(a,b){var c=a.isFavourite,d=b.isFavourite;return null===a.id&&null===b.id?null:null===a.id&&null!==b.id?"show-add":null!==a.id&&null===b.id?"hide":c==d?null:!c&&d?"show-remove":c&&!d?"show-add":null},B=function(a,b){var c=a.isMuted,d=b.isMuted;return null===a.id&&null===b.id?null:null===a.id&&null!==b.id?"show-mute":null!==a.id&&null===b.id?"hide":c==d?null:!c&&d?"show-unmute":c&&!d?"show-mute":null},C=function(a,b){var c=a.loggedInUserId,d=G(a),e=G(b),f=d?d.contactrequests.filter(function(a){return a.userid==c&&a.requesteduserid==d.id||a.userid==d.id&&a.requesteduserid==c}):[],g=e?e.contactrequests.filter(function(a){return a.userid==c&&a.requesteduserid==e.id||a.userid==e.id&&a.requesteduserid==c}):[],h=f.length>0,i=g.length>0;return d||e?h&&i?null:h||!i||e.iscontact?!d&&e?e.iscontact?"contact":null:!e&&d?d.iscontact?"non-contact":null:d.iscontact&&!e.iscontact?i?"pending-contact":"non-contact":!d.iscontact&&e.iscontact?"contact":null:"pending-contact":null},D=function(a,b){return!(a.loadingConfirmAction||!b.loadingConfirmAction)||!(a.loadingConfirmAction&&!b.loadingConfirmAction)&&null},E=function(a,b){var c=a.selectedMessageIds.length>0,d=b.selectedMessageIds.length>0,e=a.messages.length!=b.messages.length;return!(c||!d)||!(c&&!d)&&(!(!c||!e)||null)},F=function(a,b){var c=a.selectedMessageIds,d=b.selectedMessageIds;if(g(c,d))return null;var f=e(c,d,function(a,b){return a==b});return{count:d.length,add:f.missingFromA,remove:f.missingFromB}},G=function(a){return Object.keys(a.members).reduce(function(b,c){return c==a.loggedInUserId||b||(b=a.members[c]),b},null)},H=function(a,b){var c=b.contactrequests.filter(function(b){return b.userid==a||b.requesteduserid}),d=c.length>0;return b.requirescontact&&!b.iscontact&&!d},I=function(a,b){var c=G(a),d=G(b),e=a.messages.length>0,f=b.messages.length>0,g=b.loggedInUserId,h=c&&H(g,c),i=d&&H(g,d),j=u(a,b),k=j===!1;if(!a.hasTriedToLoadMessages&&!b.hasTriedToLoadMessages)return null;if(!c&&!d)return null;if(!c&&i)return{show:!0,hasMessages:f,user:d};if(k&&i)return{show:!0,hasMessages:f,user:d};if(a.hasTriedToLoadMessages&&b.hasTriedToLoadMessages){if(!h&&i)return{show:!0,hasMessages:f,user:d};if(h&&!i)return{show:!1,hasMessages:f}}return!a.hasTriedToLoadMessages&&b.hasTriedToLoadMessages&&i?{show:!0,hasMessages:f,user:d}:a.hasTriedToLoadMessages&&!b.hasTriedToLoadMessages&&h?{show:!1,hasMessages:e}:null},J=function(a,b){var c=G(a),d=G(b);return c||d?c&&!d?!c.isblocked&&null:!c&&d?!!d.isblocked||null:!(c.isblocked||!d.isblocked)||!(c.isblocked&&!d.isblocked)&&null:null},K=function(a,b){var d=G(a),e=G(b);return b.type==c.CONVERSATION_TYPES.SELF?null:d||e?d&&!e?!d.canmessage||null:!d&&e?!e.canmessage||null:!(!d.canmessage&&e.canmessage)&&(!(!d.canmessage||e.canmessage)||null):null},L=function(a,b){var c=p(a,b),d=E(a,b),e=I(a,b),f=J(a,b),g=K(a,b),h=null!==e?e.show&&e.hasMessages:null,i=G(b),j=function(a,c){if(a)return c;if(null!==a&&!a){if(!i)return{type:"content"};if(i.isblocked)return{type:"unblock"};if(b.messages.length&&H(b.loggedInUserId,i))return{type:"add-contact",user:i};if(!i.canmessage||i.requirescontact&&!i.iscontact)return{type:"unable-to-message"}}return null};if(null===c&&null===d&&null===e&&null===f)return null;for(var k=[[c,{type:"placeholder"}],[d,{type:"edit-mode"}],[g,{type:"unable-to-message"}],[f,{type:"unblock"}],[h,{type:"add-contact",user:i}]],l=0;l<k.length;l++){var m=k[l][0],n=k[l][1],o=j(m,n);if(null!==o)return o}return{type:"content"}},M=function(a,b){var c=p(a,b),d=E(a,b);return null===c&&null===d?null:c?{type:"placeholder"}:d?{type:"edit-mode"}:{type:"content"}},N=function(a,b){var c=a.type,d=b.type,e=a.id,f=b.id,g=Object.keys(a.members),h=Object.keys(b.members);g.sort(),h.sort();var i=g.every(function(a,b){return a==h[b]});return c!=d||(!(!e||f)||(!(!e||!f||e==f)||(!(e||f||i)||null)))},O=function(a,b){return a.type!=b.type?b.type==c.CONVERSATION_TYPES.SELF:null},P=function(a,b){var c=b.loggedInUserId,d=G(a),e=G(b),f=d?d.contactrequests.filter(function(a){return a.userid==c}):[],g=e?e.contactrequests.filter(function(a){return a.userid==c}):[],h=f.length>0,i=g.length>0,j=a.messages.length>0,k=a.messages.length>0;return h||!i||e.iscontact||k?!(d&&!d.iscontact&&i&&e.iscontact)&&(!(h&&!i)&&(!(!j&&k)&&null)):e.fullname},Q=function(b,d){var e={all:{reset:N,conversation:j,scrollToMessage:n,loadingMembers:o,loadingFirstMessages:p,loadingMessages:q,sendingMessage:r,confirmDeleteSelectedMessages:w,inEditMode:E,selectedMessages:F,isFavourite:A,isMuted:B}};e[c.CONVERSATION_TYPES.PRIVATE]={header:k,footer:L,confirmBlockUser:s,confirmUnblockUser:t,confirmAddContact:u,confirmRemoveContact:v,confirmContactRequest:y,confirmDeleteConversation:x,isBlocked:z,isContact:C,loadingConfirmAction:D,requireAddContact:I,contactRequestSent:P},e[c.CONVERSATION_TYPES.PUBLIC]={header:m,footer:M},e[c.CONVERSATION_TYPES.SELF]={header:l,footer:M,confirmDeleteConversation:x,selfConversationMessage:O};var f=a.extend({},e.all);return d.type&&d.type in e&&(f=a.extend(f,e[d.type])),Object.keys(f).reduce(function(a,c){var e=f[c],g=e(b,d);return null!==g&&(a[c]=g),a},{})};return{buildPatch:Q}});