MDL-67637 core_message: only preview lastmessage text if safe to do so
[moodle.git] / message / amd / build / message_drawer_view_overview_section.min.js
CommitLineData
4e809346 1function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){c(a);return}if(h.done){b(i)}else{Promise.resolve(i).then(d,e)}}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){var h=a.apply(b,c);function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}f(void 0)})}}define ("core_message/message_drawer_view_overview_section",["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/str","core/pending","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,n){var o={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\"]"},p={CONVERSATIONS_LIST:"core_message/message_drawer_conversations_list",CONVERSATIONS_LIST_ITEMS_PLACEHOLDER:"core_message/message_drawer_conversations_list_items_placeholder"},q=50,r={},s=!1,t=!1,u=function(a){return m.getRoot(a).hasClass("show")},v=function(a){a.addClass("expanded")},w=function(a){a.removeClass("expanded")},x=function(a,b){var c=a.find(o.SECTION_TOTAL_COUNT_CONTAINER),d=c.find(o.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 f=20<b?20:b,h=Array.apply(null,Array(f)).map(function(){return!0});g.render(p.CONVERSATIONS_LIST_ITEMS_PLACEHOLDER,{placeholders:h}).then(function(b){var c=a.find(o.PLACEHOLDER_CONTAINER);c.html(b)}).catch(function(){})},y=function(a,b){var c=a.find(o.SECTION_UNREAD_COUNT);c.text(b);e.get_string("unreadconversations","core_message",b).done(function(a){c.attr("aria-label",a)});if(0<b){c.removeClass("hidden")}},z=function(b){var c=function(b){return Object.keys(b).reduce(function(d,e){if(a.isArray(b[e])){d[e.toLowerCase()]=b[e].map(c)}else{d[e.toLowerCase()]=b[e]}return d},{})},d=c(b);d.messages=d.messages.map(function(a){a.useridfrom=a.userfrom.id;return a});return d},A=function(b,d){var h=new f,i=function(){var b=_asyncToGenerator(regeneratorRuntime.mark(function b(d){var f,h,i,j,k,l,m;return regeneratorRuntime.wrap(function(b){while(1){switch(b.prev=b.next){case 0:if(d){b.next=2;break}return b.abrupt("return",null);case 2:f=document.createElement("element");f.innerHTML=d.text.replace(/<img /g,"<noimg ");h=f.querySelector("[src]")||!1;if(h){b.next=10;break}i=a(d.text).text();if(!i){b.next=10;break}if(!(-1==i.indexOf("<"))){b.next=10;break}return b.abrupt("return",i);case 10:j="i/messagecontentmultimediageneral";k="messagecontentmultimediageneral";if(d.text.includes("<img")){j="i/messagecontentimage";k="messagecontentimage"}else if(d.text.includes("<video")){j="i/messagecontentvideo";k="messagecontentvideo"}else if(d.text.includes("<audio")){j="i/messagecontentaudio";k="messagecontentaudio"}b.prev=13;b.next=16;return e.get_string(k,"core_message");case 16:l=b.sent;b.next=19;return g.renderPix(j,"core",l);case 19:m=b.sent;return b.abrupt("return",m+" "+l);case 23:b.prev=23;b.t0=b["catch"](13);c.exception(b.t0);return b.abrupt("return",null);case 27:case"end":return b.stop();}}},b,null,[[13,23]])}));return function(){return b.apply(this,arguments)}}(),j=b.map(function(a){var b=a.messages.length?a.messages[a.messages.length-1]:null;return i(b).then(function(c){var e={id:a.id,imageurl:a.imageurl,name:a.name,subname:a.subname,unreadcount:a.unreadcount,ismuted:a.ismuted,lastmessagedate:b?b.timecreated:null,sentfromcurrentuser:b?b.useridfrom==d:null,lastmessage:c},f=null;if(a.type==n.CONVERSATION_TYPES.SELF){f=a.members[0]}else if(a.type==n.CONVERSATION_TYPES.PRIVATE){f=a.members.reduce(function(a,b){if(!a&&b.id!=d){a=b}return a},null)}if(null!==f){e.userid=f.id;e.showonlinestatus=f.showonlinestatus;e.isonline=f.isonline;e.isblocked=f.isblocked}if(a.type==n.CONVERSATION_TYPES.PUBLIC){e.lastsendername=a.members.reduce(function(a,c){if(!a&&b&&c.id==b.useridfrom){a=c.fullname}return a},null)}return e}).catch(c.exception)});return Promise.all(j).then(function(a){a.forEach(function(a){if(new Date().toDateString()==new Date(1e3*a.lastmessagedate).toDateString()){a.istoday=!0}});return g.render(p.CONVERSATIONS_LIST,{conversations:a})}).then(function(b,c){h.resolve();return a.Deferred().resolve(b,c)}).catch(function(a){h.resolve();c.exception(a)})},B=function(a,b,d){var e=null,f=!0;if(a&&a.length){var g=a.filter(function(a){return a!=n.CONVERSATION_TYPES.SELF});f=a.length!=g.length;e=g[0]}return function(a,g){return i.getConversations(g,e,q+1,d,b,f).then(function(b){var c=b.conversations;if(c.length>q){c=c.slice(0,-1)}else{m.setLoadedAll(a,!0)}d=d+q;c.forEach(function(a){r[a.id]=a});return c}).catch(c.exception)}},C=function(a){return a.find(o.SECTION_TOTAL_COUNT)},D=function(a){return a.find(o.SECTION_UNREAD_COUNT)},E=function(a){if(s){var b=C(a),c=parseInt(b.text());c=c+1;b.text(c)}},F=function(a){if(s){var b=C(a),c=parseInt(b.text());c=c-1;b.text(c)}},G=function(a){if(t){var b=D(a),c=parseInt(b.text());c=c-1;b.text(c);if(1>c){b.addClass("hidden")}}},H=function(a,b){return a.find("[data-conversation-id=\""+b+"\"]")},I=function(a,b){return a.find("[data-user-id=\""+b+"\"]")},J=function(a){a.find(o.MUTED_ICON_CONTAINER).removeClass("hidden")},K=function(a){a.find(o.MUTED_ICON_CONTAINER).addClass("hidden")},L=function(a){a.find(o.BLOCKED_ICON_CONTAINER).removeClass("hidden")},M=function(a){a.find(o.BLOCKED_ICON_CONTAINER).addClass("hidden")},N=function(a,b,d){var e=a.find(o.CONVERSATION);if(!e.length){var f=m.getRoot(a);m.showContent(f);m.hideEmptyMessage(f)}r[b.id]=b;return A([b],d).then(function(b){var c=m.getContentContainer(a);return c.prepend(b)}).then(function(){return E(a)}).catch(c.exception)},O=function(a,b){b.remove();F(a);var c=a.find(o.CONVERSATION);if(!c.length){var d=m.getRoot(a);m.hideContent(d);m.showEmptyMessage(d)}},P=function(a,b){var c=b.find(o.UNREAD_COUNT);c.text("0");c.addClass("hidden");G(a)},Q=function(f,g,h,i,n,p){var q=m.getRoot(g),s=function(a){var b=parseInt(a.type,10);if(i&&0>i.indexOf(b)||n&&!a.isFavourite||!n&&a.isFavourite){return!1}return!0},t=g.find(o.TOGGLE);g.css("min-height",t.outerHeight());g.on("show.bs.collapse",function(){v(g);m.show(q,h,function(a,b,d){return A(b,d).then(function(b){a.append(b);return b}).catch(c.exception)})});g.on("hidden.bs.collapse",function(){w(g)});d.subscribe(j.CONTACT_BLOCKED,function(a){var b=I(g,a);if(b.length){L(b)}});d.subscribe(j.CONTACT_UNBLOCKED,function(a){var b=I(g,a);if(b.length){M(b)}});d.subscribe(j.CONVERSATION_SET_MUTED,function(a){var b=a.id,c=H(g,b);if(c.length){J(c)}});d.subscribe(j.CONVERSATION_UNSET_MUTED,function(a){var b=a.id,c=H(g,b);if(c.length){K(c)}});d.subscribe(j.CONVERSATION_NEW_LAST_MESSAGE,function(a){if(!s(a)){return}var b=a.loggedInUserId,d=a.id,e=H(g,d);a=z(a);if(e.length){var f=m.getContentContainer(g);A([a],b).then(function(a){f.prepend(a);e.remove();return a}).catch(c.exception)}else{N(g,a,b)}});d.subscribe(j.CONVERSATION_DELETED,function(a){var b=H(g,a);delete r[a];if(b.length){O(g,b)}});d.subscribe(j.CONVERSATION_READ,function(a){var b=H(g,a);if(b.length){P(g,b)}});d.subscribe(j.CONVERSATION_SET_FAVOURITE,function(a){var b=null;if(s(a)){b=H(g,a.id);if(!b.length){N(g,z(a),a.loggedInUserId)}}else{b=H(g,a.id);if(b.length){O(g,b)}}});d.subscribe(j.CONVERSATION_UNSET_FAVOURITE,function(a){var b=null;if(s(a)){b=H(g,a.id);if(!b.length){N(g,z(a),a.loggedInUserId)}}else{b=H(g,a.id);if(b.length){O(g,b)}}});b.define(g,[b.events.activate]);g.on(b.events.activate,o.CONVERSATION,function(b,c){var d=a(b.target).closest(o.CONVERSATION),e=d.attr("data-conversation-id"),g=r[e];k.go(f,l.VIEW_CONVERSATION,g,p);c.originalEvent.preventDefault()})};return{show:function show(b,d,e,f,g,h,i,j,k){var l=a(e);if(!l.attr("data-init")){var n=B(g,h,0);Q(b,l,n,g,h,k);if(u(l)){v(l);var o=m.getRoot(l);m.show(o,n,function(a,b,d){return A(b,d).then(function(b){a.append(b);return b}).catch(c.exception)})}i.then(function(a){x(l,a);s=!0}).catch(function(){});j.then(function(a){y(l,a);t=!0}).catch(function(){});l.attr("data-init",!0)}},isVisible:u}});
195ea448 2//# sourceMappingURL=message_drawer_view_overview_section.min.js.map