From 3e79a7bbe83310b5a4c5d60ce0aa76ab302fe32b Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Tue, 22 Jan 2019 14:37:13 +0800 Subject: [PATCH] MDL-63915 core_message: fix view contacts loading only on one app --- ...awer_view_contacts_section_contacts.min.js | 2 +- ...e_drawer_view_contacts_section_contacts.js | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/message/amd/build/message_drawer_view_contacts_section_contacts.min.js b/message/amd/build/message_drawer_view_contacts_section_contacts.min.js index 7035c6b4252..679b9007840 100644 --- a/message/amd/build/message_drawer_view_contacts_section_contacts.min.js +++ b/message/amd/build/message_drawer_view_contacts_section_contacts.min.js @@ -1 +1 @@ -define(["jquery","core/notification","core/pubsub","core/templates","core_message/message_repository","core_message/message_drawer_events","core_message/message_drawer_lazy_load_list"],function(a,b,c,d,e,f,g){var h=100,i=0,j={BLOCK_ICON_CONTAINER:'[data-region="block-icon-container"]',CONTACT:'[data-region="contact"]',CONTENT_CONTAINER:'[data-region="contacts-content-container"]'},k={CONTACTS_LIST:"core_message/message_drawer_contacts_list"},l=function(a,b){return a.find('[data-contact-user-id="'+b+'"]')},m=function(c,e){var f=e.map(function(b){return a.extend(b,{id:b.userid})});return d.render(k.CONTACTS_LIST,{contacts:f}).then(function(a){return c.append(a),a})["catch"](b.exception)},n=function(a,c){return e.getContacts(c,h+1,i).then(function(a){return a}).then(function(b){return b.length>h?b.pop():g.setLoadedAll(a,!0),b}).then(function(a){return i+=h,a})["catch"](b.exception)},o=function(a,b){l(a,b).remove()},p=function(a,b){var c=l(a,b);c.length&&c.find(j.BLOCK_ICON_CONTAINER).removeClass("hidden")},q=function(a,b){var c=l(a,b);c.length&&c.find(j.BLOCK_ICON_CONTAINER).addClass("hidden")},r=function(a){c.subscribe(f.CONTACT_ADDED,function(b){var c=g.getContentContainer(a);m(c,[b]),g.hideEmptyMessage(a),g.showContent(a)}),c.subscribe(f.CONTACT_REMOVED,function(b){o(a,b);var c=a.find(j.CONTACT);c.length||(g.hideContent(a),g.showEmptyMessage(a))}),c.subscribe(f.CONTACT_BLOCKED,function(b){p(a,b)}),c.subscribe(f.CONTACT_UNBLOCKED,function(b){q(a,b)})},s=function(a){a.attr("data-contacts-init")||(r(a),a.attr("data-contacts-init",!0)),g.show(a,n,m)};return{show:s}}); \ No newline at end of file +define(["jquery","core/notification","core/pubsub","core/templates","core_message/message_repository","core_message/message_drawer_events","core_message/message_drawer_lazy_load_list"],function(a,b,c,d,e,f,g){var h=100,i=0,j={BLOCK_ICON_CONTAINER:'[data-region="block-icon-container"]',CONTACT:'[data-region="contact"]',CONTENT_CONTAINER:'[data-region="contacts-content-container"]'},k={CONTACTS_LIST:"core_message/message_drawer_contacts_list"},l=function(a,b){return a.find('[data-contact-user-id="'+b+'"]')},m=function(c,e){var f=e.map(function(b){return a.extend(b,{id:b.userid})});return d.render(k.CONTACTS_LIST,{contacts:f}).then(function(a){return c.append(a),a})["catch"](b.exception)},n=function(a){return function(c,d){return e.getContacts(d,h+1,a).then(function(a){return a}).then(function(a){return a.length>h?a.pop():g.setLoadedAll(c,!0),a}).then(function(b){return a+=h,b})["catch"](b.exception)}},o=function(a,b){l(a,b).remove()},p=function(a,b){var c=l(a,b);c.length&&c.find(j.BLOCK_ICON_CONTAINER).removeClass("hidden")},q=function(a,b){var c=l(a,b);c.length&&c.find(j.BLOCK_ICON_CONTAINER).addClass("hidden")},r=function(a){c.subscribe(f.CONTACT_ADDED,function(b){var c=g.getContentContainer(a);m(c,[b]),g.hideEmptyMessage(a),g.showContent(a)}),c.subscribe(f.CONTACT_REMOVED,function(b){o(a,b);var c=a.find(j.CONTACT);c.length||(g.hideContent(a),g.showEmptyMessage(a))}),c.subscribe(f.CONTACT_BLOCKED,function(b){p(a,b)}),c.subscribe(f.CONTACT_UNBLOCKED,function(b){q(a,b)})},s=function(a){a.attr("data-contacts-init")||(r(a),a.attr("data-contacts-init",!0)),g.show(a,n(i),m)};return{show:s}}); \ No newline at end of file diff --git a/message/amd/src/message_drawer_view_contacts_section_contacts.js b/message/amd/src/message_drawer_view_contacts_section_contacts.js index 84c0f51010f..17f8260e2a9 100644 --- a/message/amd/src/message_drawer_view_contacts_section_contacts.js +++ b/message/amd/src/message_drawer_view_contacts_section_contacts.js @@ -42,7 +42,7 @@ function( ) { var limit = 100; - var offset = 0; + var initialOffset = 0; var SELECTORS = { BLOCK_ICON_CONTAINER: '[data-region="block-icon-container"]', @@ -87,28 +87,29 @@ function( /** * Load the user contacts and call the renderer. * - * @param {Object} listRoot The lazy loaded list root element - * @param {Integer} userId The logged in user id. - * @return {Object} jQuery promise + * @param {Number} offset The offset to use for loading contacts + * @return {Function} the callback. */ - var load = function(listRoot, userId) { - return MessageRepository.getContacts(userId, (limit + 1), offset) - .then(function(result) { - return result; - }) - .then(function(contacts) { - if (contacts.length > limit) { - contacts.pop(); - } else { - LazyLoadList.setLoadedAll(listRoot, true); - } - return contacts; - }) - .then(function(contacts) { - offset = offset + limit; - return contacts; - }) - .catch(Notification.exception); + var getLoadFunction = function(offset) { + return function(listRoot, userId) { + return MessageRepository.getContacts(userId, (limit + 1), offset) + .then(function(result) { + return result; + }) + .then(function(contacts) { + if (contacts.length > limit) { + contacts.pop(); + } else { + LazyLoadList.setLoadedAll(listRoot, true); + } + return contacts; + }) + .then(function(contacts) { + offset = offset + limit; + return contacts; + }) + .catch(Notification.exception); + }; }; /** @@ -191,7 +192,7 @@ function( } // The root element is already the lazy loaded list root. - LazyLoadList.show(root, load, render); + LazyLoadList.show(root, getLoadFunction(initialOffset), render); }; return {