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
6.7 KiB
1 lines
6.7 KiB
define(["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/str","core/templates","core/user_date","core_message/message_repository","core_message/message_drawer_events","core_message/message_drawer_router","core_message/message_drawer_routes","core_message/message_drawer_lazy_load_list","core_message/message_drawer_view_conversation_constants"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={TOGGLE:'[data-region="toggle"]',CONVERSATION:"[data-conversation-id]",BLOCKED_ICON_CONTAINER:'[data-region="contact-icon-blocked"]',LAST_MESSAGE:'[data-region="last-message"]',LAST_MESSAGE_DATE:'[data-region="last-message-date"]',MUTED_ICON_CONTAINER:'[data-region="muted-icon-container"]',UNREAD_COUNT:'[data-region="unread-count"]',SECTION_TOTAL_COUNT:'[data-region="section-total-count"]',SECTION_TOTAL_COUNT_CONTAINER:'[data-region="section-total-count-container"]',SECTION_UNREAD_COUNT:'[data-region="section-unread-count"]',PLACEHOLDER_CONTAINER:'[data-region="placeholder-container"]'},o={CONVERSATIONS_LIST:"core_message/message_drawer_conversations_list",CONVERSATIONS_LIST_ITEMS_PLACEHOLDER:"core_message/message_drawer_conversations_list_items_placeholder"},p=50,q={},r=!1,s=!1,t=function(a){return l.getRoot(a).hasClass("show")},u=function(a){a.addClass("expanded")},v=function(a){a.removeClass("expanded")},w=function(a,b){var c=a.find(n.SECTION_TOTAL_COUNT_CONTAINER),d=c.find(n.SECTION_TOTAL_COUNT);d.text(b),c.removeClass("hidden"),e.get_string("totalconversations","core_message",b).done(function(a){c.attr("aria-label",a)});var g=b>20?20:b,h=Array.apply(null,Array(g)).map(function(){return!0});f.render(o.CONVERSATIONS_LIST_ITEMS_PLACEHOLDER,{placeholders:h}).then(function(b){var c=a.find(n.PLACEHOLDER_CONTAINER);c.html(b)})["catch"](function(){})},x=function(a,b){var c=a.find(n.SECTION_UNREAD_COUNT);c.text(b),e.get_string("unreadconversations","core_message",b).done(function(a){c.attr("aria-label",a)}),b>0&&c.removeClass("hidden")},y=function(b){var c=function(b){return Object.keys(b).reduce(function(d,e){return a.isArray(b[e])?d[e.toLowerCase()]=b[e].map(c):d[e.toLowerCase()]=b[e],d},{})},d=c(b);return d.messages=d.messages.map(function(a){return a.useridfrom=a.userfrom.id,a}),d},z=function(b,c){var d=b.map(function(b){var d=b.messages.length?b.messages[b.messages.length-1]:null,e={id:b.id,imageurl:b.imageurl,name:b.name,subname:b.subname,unreadcount:b.unreadcount,ismuted:b.ismuted,lastmessagedate:d?d.timecreated:null,sentfromcurrentuser:d?d.useridfrom==c:null,lastmessage:d?a(d.text).text()||d.text:null},f=null;return b.type==m.CONVERSATION_TYPES.SELF?f=b.members[0]:b.type==m.CONVERSATION_TYPES.PRIVATE&&(f=b.members.reduce(function(a,b){return a||b.id==c||(a=b),a},null)),null!==f&&(e.userid=f.id,e.showonlinestatus=f.showonlinestatus,e.isonline=f.isonline,e.isblocked=f.isblocked),b.type==m.CONVERSATION_TYPES.PUBLIC&&(e.lastsendername=b.members.reduce(function(a,b){return!a&&d&&b.id==d.useridfrom&&(a=b.fullname),a},null)),e});return d.forEach(function(a){(new Date).toDateString()==new Date(1e3*a.lastmessagedate).toDateString()&&(a.istoday=!0)}),f.render(o.CONVERSATIONS_LIST,{conversations:d})},A=function(a,b,d){var e=null,f=!0;if(a&&a.length){var g=a.filter(function(a){return a!=m.CONVERSATION_TYPES.SELF});f=a.length!=g.length,e=g[0]}return function(a,g){return h.getConversations(g,e,p+1,d,b,f).then(function(b){var c=b.conversations;return c.length>p?c=c.slice(0,-1):l.setLoadedAll(a,!0),d+=p,c.forEach(function(a){q[a.id]=a}),c})["catch"](c.exception)}},B=function(a){return a.find(n.SECTION_TOTAL_COUNT)},C=function(a){return a.find(n.SECTION_UNREAD_COUNT)},D=function(a){if(r){var b=B(a),c=parseInt(b.text());c+=1,b.text(c)}},E=function(a){if(r){var b=B(a),c=parseInt(b.text());c-=1,b.text(c)}},F=function(a){if(s){var b=C(a),c=parseInt(b.text());c-=1,b.text(c),c<1&&b.addClass("hidden")}},G=function(a,b){return a.find('[data-conversation-id="'+b+'"]')},H=function(a,b){return a.find('[data-user-id="'+b+'"]')},I=function(a){a.find(n.MUTED_ICON_CONTAINER).removeClass("hidden")},J=function(a){a.find(n.MUTED_ICON_CONTAINER).addClass("hidden")},K=function(a){a.find(n.BLOCKED_ICON_CONTAINER).removeClass("hidden")},L=function(a){a.find(n.BLOCKED_ICON_CONTAINER).addClass("hidden")},M=function(a,b,d){var e=a.find(n.CONVERSATION);if(!e.length){var f=l.getRoot(a);l.showContent(f),l.hideEmptyMessage(f)}return q[b.id]=b,z([b],d).then(function(b){var c=l.getContentContainer(a);return c.prepend(b)}).then(function(){return D(a)})["catch"](c.exception)},N=function(a,b){b.remove(),E(a);var c=a.find(n.CONVERSATION);if(!c.length){var d=l.getRoot(a);l.hideContent(d),l.showEmptyMessage(d)}},O=function(a,b){var c=b.find(n.UNREAD_COUNT);c.text("0"),c.addClass("hidden"),F(a)},P=function(e,f,g,h,m,o){var p=l.getRoot(f),r=function(a){var b=parseInt(a.type,10);return!(h&&h.indexOf(b)<0||m&&!a.isFavourite||!m&&a.isFavourite)},s=f.find(n.TOGGLE);f.css("min-height",s.outerHeight()),f.on("show.bs.collapse",function(){u(f),l.show(p,g,function(a,b,d){return z(b,d).then(function(b){return a.append(b),b})["catch"](c.exception)})}),f.on("hidden.bs.collapse",function(){v(f)}),d.subscribe(i.CONTACT_BLOCKED,function(a){var b=H(f,a);b.length&&K(b)}),d.subscribe(i.CONTACT_UNBLOCKED,function(a){var b=H(f,a);b.length&&L(b)}),d.subscribe(i.CONVERSATION_SET_MUTED,function(a){var b=a.id,c=G(f,b);c.length&&I(c)}),d.subscribe(i.CONVERSATION_UNSET_MUTED,function(a){var b=a.id,c=G(f,b);c.length&&J(c)}),d.subscribe(i.CONVERSATION_NEW_LAST_MESSAGE,function(a){if(r(a)){var b=a.loggedInUserId,d=a.id,e=G(f,d);if(a=y(a),e.length){var g=l.getContentContainer(f);z([a],b).then(function(a){return g.prepend(a),e.remove(),a})["catch"](c.exception)}else M(f,a,b)}}),d.subscribe(i.CONVERSATION_DELETED,function(a){var b=G(f,a);delete q[a],b.length&&N(f,b)}),d.subscribe(i.CONVERSATION_READ,function(a){var b=G(f,a);b.length&&O(f,b)}),d.subscribe(i.CONVERSATION_SET_FAVOURITE,function(a){var b=null;r(a)?(b=G(f,a.id),b.length||M(f,y(a),a.loggedInUserId)):(b=G(f,a.id),b.length&&N(f,b))}),d.subscribe(i.CONVERSATION_UNSET_FAVOURITE,function(a){var b=null;r(a)?(b=G(f,a.id),b.length||M(f,y(a),a.loggedInUserId)):(b=G(f,a.id),b.length&&N(f,b))}),b.define(f,[b.events.activate]),f.on(b.events.activate,n.CONVERSATION,function(b,c){var d=a(b.target).closest(n.CONVERSATION),f=d.attr("data-conversation-id"),g=q[f];j.go(e,k.VIEW_CONVERSATION,g,o),c.originalEvent.preventDefault()})},Q=function(b,d,e,f,g,h,i,j,k){var m=a(e);if(!m.attr("data-init")){var n=A(g,h,0);if(P(b,m,n,g,h,k),t(m)){u(m);var o=l.getRoot(m);l.show(o,n,function(a,b,d){return z(b,d).then(function(b){return a.append(b),b})["catch"](c.exception)})}i.then(function(a){w(m,a),r=!0})["catch"](function(){}),j.then(function(a){x(m,a),s=!0})["catch"](function(){}),m.attr("data-init",!0)}};return{show:Q,isVisible:t}});
|