mirror of
https://github.com/moodle/moodle.git
synced 2025-04-23 09:23:09 +02:00
MDL-75936 core_message: Drawer must be ready before firing drawer events
This commit addresses a race condition when showing the message drawer and opening the settings page from the Message preferences page. In that situation, the message/edit.php page calls the message_drawer_helper.showSettings function, which publishes a request to show the drawer. In some conditions (notably faster machines, or after MDL-66107) this event is fired before the message_drawer.init has listened to it. The solution here is to delay firing of the event until the drawer announces itself as ready. This ensures that the event is subscribed to before it is fired.
This commit is contained in:
parent
046e48c49c
commit
723d450c8c
2
message/amd/build/message_drawer.min.js
vendored
2
message/amd/build/message_drawer.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -5,6 +5,6 @@
|
||||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("core_message/message_drawer_events",[],(function(){return{CREATE_CONVERSATION_WITH_USER:"message-drawer-create-conversation-with-user",CONTACT_BLOCKED:"message-drawer-contact-blocked",CONTACT_UNBLOCKED:"message-drawer-contact-unblocked",CONTACT_ADDED:"message-drawer-contact-added",CONTACT_REMOVED:"message-drawer-contact-removed",CONTACT_REQUEST_ACCEPTED:"message-drawer-contact-request-accepted",CONTACT_REQUEST_DECLINED:"message-drawer-contact-request-declined",CONVERSATION_CREATED:"message-drawer-conversation-created",CONVERSATION_NEW_LAST_MESSAGE:"message-drawer-conversation-new-last-message",CONVERSATION_DELETED:"message-drawer-conversation-deleted",CONVERSATION_READ:"message-drawer-conversation-read",CONVERSATION_SET_FAVOURITE:"message-drawer-conversation-set-favourite",CONVERSATION_SET_MUTED:"message-drawer-conversation-set-muted",CONVERSATION_UNSET_FAVOURITE:"message-drawer-conversation-unset-favourite",CONVERSATION_UNSET_MUTED:"message-drawer-conversation-unset-muted",PREFERENCES_UPDATED:"message-drawer-preferences-updated",ROUTE_CHANGED:"message-drawer-route-change",SHOW:"message-drawer-show",HIDE:"message-drawer-hide",TOGGLE_VISIBILITY:"message-drawer-toggle",SHOW_CONVERSATION:"message-drawer-show-conversation",SHOW_SETTINGS:"message-drawer-show-settings"}}));
|
||||
define("core_message/message_drawer_events",[],(function(){return{CREATE_CONVERSATION_WITH_USER:"message-drawer-create-conversation-with-user",CONTACT_BLOCKED:"message-drawer-contact-blocked",CONTACT_UNBLOCKED:"message-drawer-contact-unblocked",CONTACT_ADDED:"message-drawer-contact-added",CONTACT_REMOVED:"message-drawer-contact-removed",CONTACT_REQUEST_ACCEPTED:"message-drawer-contact-request-accepted",CONTACT_REQUEST_DECLINED:"message-drawer-contact-request-declined",CONVERSATION_CREATED:"message-drawer-conversation-created",CONVERSATION_NEW_LAST_MESSAGE:"message-drawer-conversation-new-last-message",CONVERSATION_DELETED:"message-drawer-conversation-deleted",CONVERSATION_READ:"message-drawer-conversation-read",CONVERSATION_SET_FAVOURITE:"message-drawer-conversation-set-favourite",CONVERSATION_SET_MUTED:"message-drawer-conversation-set-muted",CONVERSATION_UNSET_FAVOURITE:"message-drawer-conversation-unset-favourite",CONVERSATION_UNSET_MUTED:"message-drawer-conversation-unset-muted",PREFERENCES_UPDATED:"message-drawer-preferences-updated",READY:"message-drawer-ready",ROUTE_CHANGED:"message-drawer-route-change",SHOW:"message-drawer-show",HIDE:"message-drawer-hide",TOGGLE_VISIBILITY:"message-drawer-toggle",SHOW_CONVERSATION:"message-drawer-show-conversation",SHOW_SETTINGS:"message-drawer-show-settings"}}));
|
||||
|
||||
//# sourceMappingURL=message_drawer_events.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"message_drawer_events.min.js","sources":["../src/message_drawer_events.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Events for the message drawer.\n *\n * @module core_message/message_drawer_events\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([], function() {\n return {\n CREATE_CONVERSATION_WITH_USER: 'message-drawer-create-conversation-with-user',\n CONTACT_BLOCKED: 'message-drawer-contact-blocked',\n CONTACT_UNBLOCKED: 'message-drawer-contact-unblocked',\n CONTACT_ADDED: 'message-drawer-contact-added',\n CONTACT_REMOVED: 'message-drawer-contact-removed',\n CONTACT_REQUEST_ACCEPTED: 'message-drawer-contact-request-accepted',\n CONTACT_REQUEST_DECLINED: 'message-drawer-contact-request-declined',\n CONVERSATION_CREATED: 'message-drawer-conversation-created',\n CONVERSATION_NEW_LAST_MESSAGE: 'message-drawer-conversation-new-last-message',\n CONVERSATION_DELETED: 'message-drawer-conversation-deleted',\n CONVERSATION_READ: 'message-drawer-conversation-read',\n CONVERSATION_SET_FAVOURITE: 'message-drawer-conversation-set-favourite',\n CONVERSATION_SET_MUTED: 'message-drawer-conversation-set-muted',\n CONVERSATION_UNSET_FAVOURITE: 'message-drawer-conversation-unset-favourite',\n CONVERSATION_UNSET_MUTED: 'message-drawer-conversation-unset-muted',\n PREFERENCES_UPDATED: 'message-drawer-preferences-updated',\n ROUTE_CHANGED: 'message-drawer-route-change',\n SHOW: 'message-drawer-show',\n HIDE: 'message-drawer-hide',\n TOGGLE_VISIBILITY: 'message-drawer-toggle',\n SHOW_CONVERSATION: 'message-drawer-show-conversation',\n SHOW_SETTINGS: 'message-drawer-show-settings',\n };\n});\n"],"names":["define","CREATE_CONVERSATION_WITH_USER","CONTACT_BLOCKED","CONTACT_UNBLOCKED","CONTACT_ADDED","CONTACT_REMOVED","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","CONVERSATION_CREATED","CONVERSATION_NEW_LAST_MESSAGE","CONVERSATION_DELETED","CONVERSATION_READ","CONVERSATION_SET_FAVOURITE","CONVERSATION_SET_MUTED","CONVERSATION_UNSET_FAVOURITE","CONVERSATION_UNSET_MUTED","PREFERENCES_UPDATED","ROUTE_CHANGED","SHOW","HIDE","TOGGLE_VISIBILITY","SHOW_CONVERSATION","SHOW_SETTINGS"],"mappings":";;;;;;;AAsBAA,4CAAO,IAAI,iBACA,CACHC,8BAA+B,+CAC/BC,gBAAiB,iCACjBC,kBAAmB,mCACnBC,cAAe,+BACfC,gBAAiB,iCACjBC,yBAA0B,0CAC1BC,yBAA0B,0CAC1BC,qBAAsB,sCACtBC,8BAA+B,+CAC/BC,qBAAsB,sCACtBC,kBAAmB,mCACnBC,2BAA4B,4CAC5BC,uBAAwB,wCACxBC,6BAA8B,8CAC9BC,yBAA0B,0CAC1BC,oBAAqB,qCACrBC,cAAe,8BACfC,KAAM,sBACNC,KAAM,sBACNC,kBAAmB,wBACnBC,kBAAmB,mCACnBC,cAAe"}
|
||||
{"version":3,"file":"message_drawer_events.min.js","sources":["../src/message_drawer_events.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Events for the message drawer.\n *\n * @module core_message/message_drawer_events\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([], function() {\n return {\n CREATE_CONVERSATION_WITH_USER: 'message-drawer-create-conversation-with-user',\n CONTACT_BLOCKED: 'message-drawer-contact-blocked',\n CONTACT_UNBLOCKED: 'message-drawer-contact-unblocked',\n CONTACT_ADDED: 'message-drawer-contact-added',\n CONTACT_REMOVED: 'message-drawer-contact-removed',\n CONTACT_REQUEST_ACCEPTED: 'message-drawer-contact-request-accepted',\n CONTACT_REQUEST_DECLINED: 'message-drawer-contact-request-declined',\n CONVERSATION_CREATED: 'message-drawer-conversation-created',\n CONVERSATION_NEW_LAST_MESSAGE: 'message-drawer-conversation-new-last-message',\n CONVERSATION_DELETED: 'message-drawer-conversation-deleted',\n CONVERSATION_READ: 'message-drawer-conversation-read',\n CONVERSATION_SET_FAVOURITE: 'message-drawer-conversation-set-favourite',\n CONVERSATION_SET_MUTED: 'message-drawer-conversation-set-muted',\n CONVERSATION_UNSET_FAVOURITE: 'message-drawer-conversation-unset-favourite',\n CONVERSATION_UNSET_MUTED: 'message-drawer-conversation-unset-muted',\n PREFERENCES_UPDATED: 'message-drawer-preferences-updated',\n READY: 'message-drawer-ready',\n ROUTE_CHANGED: 'message-drawer-route-change',\n SHOW: 'message-drawer-show',\n HIDE: 'message-drawer-hide',\n TOGGLE_VISIBILITY: 'message-drawer-toggle',\n SHOW_CONVERSATION: 'message-drawer-show-conversation',\n SHOW_SETTINGS: 'message-drawer-show-settings',\n };\n});\n"],"names":["define","CREATE_CONVERSATION_WITH_USER","CONTACT_BLOCKED","CONTACT_UNBLOCKED","CONTACT_ADDED","CONTACT_REMOVED","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","CONVERSATION_CREATED","CONVERSATION_NEW_LAST_MESSAGE","CONVERSATION_DELETED","CONVERSATION_READ","CONVERSATION_SET_FAVOURITE","CONVERSATION_SET_MUTED","CONVERSATION_UNSET_FAVOURITE","CONVERSATION_UNSET_MUTED","PREFERENCES_UPDATED","READY","ROUTE_CHANGED","SHOW","HIDE","TOGGLE_VISIBILITY","SHOW_CONVERSATION","SHOW_SETTINGS"],"mappings":";;;;;;;AAsBAA,4CAAO,IAAI,iBACA,CACHC,8BAA+B,+CAC/BC,gBAAiB,iCACjBC,kBAAmB,mCACnBC,cAAe,+BACfC,gBAAiB,iCACjBC,yBAA0B,0CAC1BC,yBAA0B,0CAC1BC,qBAAsB,sCACtBC,8BAA+B,+CAC/BC,qBAAsB,sCACtBC,kBAAmB,mCACnBC,2BAA4B,4CAC5BC,uBAAwB,wCACxBC,6BAA8B,8CAC9BC,yBAA0B,0CAC1BC,oBAAqB,qCACrBC,MAAO,uBACPC,cAAe,8BACfC,KAAM,sBACNC,KAAM,sBACNC,kBAAmB,wBACnBC,kBAAmB,mCACnBC,cAAe"}
|
@ -5,6 +5,6 @@
|
||||
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("core_message/message_drawer_helper",["core/pubsub","core_message/message_drawer_events"],(function(PubSub,MessageDrawerEvents){return{createConversationWithUser:function(args){PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER,args)},hide:function(){PubSub.publish(MessageDrawerEvents.HIDE)},show:function(){PubSub.publish(MessageDrawerEvents.SHOW)},showConversation:function(args){PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION,args)},showSettings:function(){PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS)}}}));
|
||||
define("core_message/message_drawer_helper",["core/pubsub","core_message/message_drawer_events"],(function(PubSub,MessageDrawerEvents){var drawerMarkedReady=!1,waitForDrawerToLoad=function(){return new Promise((function(resolve){drawerMarkedReady?resolve():PubSub.subscribe(MessageDrawerEvents.READY,resolve)}))};return{createConversationWithUser:function(args){waitForDrawerToLoad().then((function(){PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER,args)})).catch()},hide:function(){waitForDrawerToLoad().then((function(){PubSub.publish(MessageDrawerEvents.HIDE)})).catch()},show:function(){waitForDrawerToLoad().then((function(){PubSub.publish(MessageDrawerEvents.SHOW)})).catch()},showConversation:function(args){waitForDrawerToLoad().then((function(){PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION,args)})).catch()},showSettings:function(){waitForDrawerToLoad().then((function(){PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS)})).catch()},markDrawerReady:function(){drawerMarkedReady=!0,PubSub.publish(MessageDrawerEvents.READY)}}}));
|
||||
|
||||
//# sourceMappingURL=message_drawer_helper.min.js.map
|
@ -1 +1 @@
|
||||
{"version":3,"file":"message_drawer_helper.min.js","sources":["../src/message_drawer_helper.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Provides some helper functions to trigger actions in the message drawer.\n *\n * @module core_message/message_drawer_helper\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'core/pubsub',\n 'core_message/message_drawer_events'\n],\nfunction(\n PubSub,\n MessageDrawerEvents\n) {\n\n /**\n * Trigger an event to create a new conversation in the message drawer.\n *\n * @param {object} args\n * @param {Number} args.userId The user id to start a conversation.\n */\n var createConversationWithUser = function(args) {\n PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER, args);\n };\n\n /**\n * Trigger an event to hide the message drawer.\n */\n var hide = function() {\n PubSub.publish(MessageDrawerEvents.HIDE);\n };\n\n /**\n * Trigger an event to show the message drawer.\n */\n var show = function() {\n PubSub.publish(MessageDrawerEvents.SHOW);\n };\n\n /**\n * Trigger an event to show the given conversation.\n *\n * @param {object} args\n * @param {int} args.conversationId Id for the conversation to show.\n */\n var showConversation = function(args) {\n PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION, args);\n };\n\n /**\n * Trigger an event to show messaging settings.\n */\n var showSettings = function() {\n PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS);\n };\n\n return {\n createConversationWithUser: createConversationWithUser,\n hide: hide,\n show: show,\n showConversation: showConversation,\n showSettings: showSettings\n };\n});\n"],"names":["define","PubSub","MessageDrawerEvents","createConversationWithUser","args","publish","CREATE_CONVERSATION_WITH_USER","hide","HIDE","show","SHOW","showConversation","SHOW_CONVERSATION","showSettings","SHOW_SETTINGS"],"mappings":";;;;;;;AAsBAA,4CACA,CACI,cACA,uCAEJ,SACIC,OACAC,2BA4CO,CACHC,2BApC6B,SAASC,MACtCH,OAAOI,QAAQH,oBAAoBI,8BAA+BF,OAoClEG,KA9BO,WACPN,OAAOI,QAAQH,oBAAoBM,OA8BnCC,KAxBO,WACPR,OAAOI,QAAQH,oBAAoBQ,OAwBnCC,iBAfmB,SAASP,MAC5BH,OAAOI,QAAQH,oBAAoBU,kBAAmBR,OAetDS,aATe,WACfZ,OAAOI,QAAQH,oBAAoBY"}
|
||||
{"version":3,"file":"message_drawer_helper.min.js","sources":["../src/message_drawer_helper.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Provides some helper functions to trigger actions in the message drawer.\n *\n * @module core_message/message_drawer_helper\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'core/pubsub',\n 'core_message/message_drawer_events'\n],\nfunction(\n PubSub,\n MessageDrawerEvents\n) {\n\n /** @property {boolean} Whether the drawer is ready or not */\n var drawerMarkedReady = false;\n\n /**\n * Trigger an event to create a new conversation in the message drawer.\n *\n * @param {object} args\n * @param {Number} args.userId The user id to start a conversation.\n */\n var createConversationWithUser = function(args) {\n waitForDrawerToLoad().then(function () {\n PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER, args);\n return;\n }).catch();\n };\n\n /**\n * Trigger an event to hide the message drawer.\n */\n var hide = function() {\n waitForDrawerToLoad().then(function () {\n PubSub.publish(MessageDrawerEvents.HIDE);\n return;\n }).catch();\n };\n\n /**\n * Trigger an event to show the message drawer.\n */\n var show = function() {\n waitForDrawerToLoad().then(function () {\n PubSub.publish(MessageDrawerEvents.SHOW);\n return;\n }).catch();\n };\n\n /**\n * Trigger an event to show the given conversation.\n *\n * @param {object} args\n * @param {int} args.conversationId Id for the conversation to show.\n */\n var showConversation = function(args) {\n waitForDrawerToLoad().then(function () {\n PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION, args);\n return;\n }).catch();\n };\n\n /**\n * Trigger an event to show messaging settings.\n */\n var showSettings = function() {\n waitForDrawerToLoad().then(function() {\n PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS);\n return;\n }).catch();\n };\n\n /**\n * Helper to wait for the drawer to be ready before performing an action.\n *\n * @returns {Promise<void>}\n */\n var waitForDrawerToLoad = function() {\n return new Promise(function(resolve) {\n if (drawerMarkedReady) {\n resolve();\n } else {\n PubSub.subscribe(MessageDrawerEvents.READY, resolve);\n }\n });\n };\n\n /**\n * Helper to allow the drawer to mark itself as ready.\n */\n var markDrawerReady = function() {\n drawerMarkedReady = true;\n PubSub.publish(MessageDrawerEvents.READY);\n };\n\n return {\n createConversationWithUser: createConversationWithUser,\n hide: hide,\n show: show,\n showConversation: showConversation,\n showSettings: showSettings,\n markDrawerReady: markDrawerReady,\n };\n});\n"],"names":["define","PubSub","MessageDrawerEvents","drawerMarkedReady","waitForDrawerToLoad","Promise","resolve","subscribe","READY","createConversationWithUser","args","then","publish","CREATE_CONVERSATION_WITH_USER","catch","hide","HIDE","show","SHOW","showConversation","SHOW_CONVERSATION","showSettings","SHOW_SETTINGS","markDrawerReady"],"mappings":";;;;;;;AAsBAA,4CACA,CACI,cACA,uCAEJ,SACIC,OACAC,yBAIIC,mBAAoB,EA+DpBC,oBAAsB,kBACf,IAAIC,SAAQ,SAASC,SACpBH,kBACAG,UAEAL,OAAOM,UAAUL,oBAAoBM,MAAOF,mBAajD,CACHG,2BA1E6B,SAASC,MACtCN,sBAAsBO,MAAK,WACvBV,OAAOW,QAAQV,oBAAoBW,8BAA+BH,SAEnEI,SAuEHC,KAjEO,WACPX,sBAAsBO,MAAK,WACvBV,OAAOW,QAAQV,oBAAoBc,SAEpCF,SA8DHG,KAxDO,WACPb,sBAAsBO,MAAK,WACvBV,OAAOW,QAAQV,oBAAoBgB,SAEpCJ,SAqDHK,iBA5CmB,SAAST,MAC5BN,sBAAsBO,MAAK,WACvBV,OAAOW,QAAQV,oBAAoBkB,kBAAmBV,SAEvDI,SAyCHO,aAnCe,WACfjB,sBAAsBO,MAAK,WACvBV,OAAOW,QAAQV,oBAAoBoB,kBAEpCR,SAgCHS,gBAXkB,WAClBpB,mBAAoB,EACpBF,OAAOW,QAAQV,oBAAoBM"}
|
@ -35,6 +35,7 @@ define(
|
||||
'core_message/message_drawer_router',
|
||||
'core_message/message_drawer_routes',
|
||||
'core_message/message_drawer_events',
|
||||
'core_message/message_drawer_helper',
|
||||
'core/pending',
|
||||
'core/drawer',
|
||||
],
|
||||
@ -52,6 +53,7 @@ function(
|
||||
Router,
|
||||
Routes,
|
||||
Events,
|
||||
Helper,
|
||||
Pending,
|
||||
Drawer
|
||||
) {
|
||||
@ -353,6 +355,9 @@ function(
|
||||
Router.go.apply(null, routeParams);
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the drawer as ready.
|
||||
Helper.markDrawerReady();
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -38,6 +38,7 @@ define([], function() {
|
||||
CONVERSATION_UNSET_FAVOURITE: 'message-drawer-conversation-unset-favourite',
|
||||
CONVERSATION_UNSET_MUTED: 'message-drawer-conversation-unset-muted',
|
||||
PREFERENCES_UPDATED: 'message-drawer-preferences-updated',
|
||||
READY: 'message-drawer-ready',
|
||||
ROUTE_CHANGED: 'message-drawer-route-change',
|
||||
SHOW: 'message-drawer-show',
|
||||
HIDE: 'message-drawer-hide',
|
||||
|
@ -30,6 +30,9 @@ function(
|
||||
MessageDrawerEvents
|
||||
) {
|
||||
|
||||
/** @property {boolean} Whether the drawer is ready or not */
|
||||
var drawerMarkedReady = false;
|
||||
|
||||
/**
|
||||
* Trigger an event to create a new conversation in the message drawer.
|
||||
*
|
||||
@ -37,21 +40,30 @@ function(
|
||||
* @param {Number} args.userId The user id to start a conversation.
|
||||
*/
|
||||
var createConversationWithUser = function(args) {
|
||||
PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER, args);
|
||||
waitForDrawerToLoad().then(function () {
|
||||
PubSub.publish(MessageDrawerEvents.CREATE_CONVERSATION_WITH_USER, args);
|
||||
return;
|
||||
}).catch();
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event to hide the message drawer.
|
||||
*/
|
||||
var hide = function() {
|
||||
PubSub.publish(MessageDrawerEvents.HIDE);
|
||||
waitForDrawerToLoad().then(function () {
|
||||
PubSub.publish(MessageDrawerEvents.HIDE);
|
||||
return;
|
||||
}).catch();
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event to show the message drawer.
|
||||
*/
|
||||
var show = function() {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW);
|
||||
waitForDrawerToLoad().then(function () {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW);
|
||||
return;
|
||||
}).catch();
|
||||
};
|
||||
|
||||
/**
|
||||
@ -61,14 +73,43 @@ function(
|
||||
* @param {int} args.conversationId Id for the conversation to show.
|
||||
*/
|
||||
var showConversation = function(args) {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION, args);
|
||||
waitForDrawerToLoad().then(function () {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW_CONVERSATION, args);
|
||||
return;
|
||||
}).catch();
|
||||
};
|
||||
|
||||
/**
|
||||
* Trigger an event to show messaging settings.
|
||||
*/
|
||||
var showSettings = function() {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS);
|
||||
waitForDrawerToLoad().then(function() {
|
||||
PubSub.publish(MessageDrawerEvents.SHOW_SETTINGS);
|
||||
return;
|
||||
}).catch();
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to wait for the drawer to be ready before performing an action.
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
var waitForDrawerToLoad = function() {
|
||||
return new Promise(function(resolve) {
|
||||
if (drawerMarkedReady) {
|
||||
resolve();
|
||||
} else {
|
||||
PubSub.subscribe(MessageDrawerEvents.READY, resolve);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to allow the drawer to mark itself as ready.
|
||||
*/
|
||||
var markDrawerReady = function() {
|
||||
drawerMarkedReady = true;
|
||||
PubSub.publish(MessageDrawerEvents.READY);
|
||||
};
|
||||
|
||||
return {
|
||||
@ -76,6 +117,7 @@ function(
|
||||
hide: hide,
|
||||
show: show,
|
||||
showConversation: showConversation,
|
||||
showSettings: showSettings
|
||||
showSettings: showSettings,
|
||||
markDrawerReady: markDrawerReady,
|
||||
};
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user