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;g0,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;l0,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}});