diff --git a/app/callbacks/lib/callbacks.js b/app/callbacks/lib/callbacks.js index d602e0384203..93a7e8d04d58 100644 --- a/app/callbacks/lib/callbacks.js +++ b/app/callbacks/lib/callbacks.js @@ -59,8 +59,8 @@ const combinedCallbacks = new Map(); /* * Callback priorities +* @enum {CallbackPriority} */ - callbacks.priority = { HIGH: -1000, MEDIUM: 0, @@ -73,8 +73,9 @@ const getHooks = (hookName) => callbacks[hookName] || []; * Add a callback function to a hook * @param {String} hook - The name of the hook * @param {Function} callback - The callback function +* @param {CallbackPriority} priority - The callback run priority (order) +* @param {String} id - Human friendly name for this callback */ - callbacks.add = function( hook, callback, diff --git a/app/custom/client/index.js b/app/custom/client/index.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/custom/server/index.js b/app/custom/server/index.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/discussion/server/hooks/propagateDiscussionMetadata.js b/app/discussion/server/hooks/propagateDiscussionMetadata.js index 902965ca23e4..271b19221160 100644 --- a/app/discussion/server/hooks/propagateDiscussionMetadata.js +++ b/app/discussion/server/hooks/propagateDiscussionMetadata.js @@ -23,15 +23,25 @@ callbacks.add('afterDeleteMessage', function(message, { _id, prid } = {}) { return message; }, callbacks.priority.LOW, 'PropagateDiscussionMetadata'); -callbacks.add('afterDeleteRoom', (rid) => Rooms.find({ prid: rid }, { fields: { _id: 1 } }).forEach(({ _id }) => deleteRoom(_id)), 'DeleteDiscussionChain'); +callbacks.add('afterDeleteRoom', (rid) => { + Rooms.find({ prid: rid }, { fields: { _id: 1 } }).forEach(({ _id }) => deleteRoom(_id)); + return rid; +}, callbacks.priority.LOW, 'DeleteDiscussionChain'); // TODO discussions define new fields -callbacks.add('afterRoomNameChange', ({ rid, name, oldName }) => Rooms.update({ prid: rid, ...oldName && { topic: oldName } }, { $set: { topic: name } }, { multi: true }), 'updateTopicDiscussion'); +callbacks.add('afterRoomNameChange', (roomConfig) => { + const { rid, name, oldName } = roomConfig; + Rooms.update({ prid: rid, ...oldName && { topic: oldName } }, { $set: { topic: name } }, { multi: true }); + return roomConfig; +}, callbacks.priority.LOW, 'updateTopicDiscussion'); -callbacks.add('afterDeleteRoom', (drid) => Messages.update({ drid }, { - $unset: { - dcount: 1, - dlm: 1, - drid: 1, - }, -}), 'CleanDiscussionMessage'); +callbacks.add('afterDeleteRoom', (drid) => { + Messages.update({ drid }, { + $unset: { + dcount: 1, + dlm: 1, + drid: 1, + }, + }); + return drid; +}, callbacks.priority.LOW, 'CleanDiscussionMessage'); diff --git a/app/ui-utils/client/lib/RoomManager.js b/app/ui-utils/client/lib/RoomManager.js index 84eff4b04a38..43a478adee19 100644 --- a/app/ui-utils/client/lib/RoomManager.js +++ b/app/ui-utils/client/lib/RoomManager.js @@ -114,7 +114,7 @@ export const RoomManager = new function() { return Object.keys(openedRooms).map((typeName) => openedRooms[typeName]).find((openedRoom) => openedRoom.rid === rid); } - getDomOfRoom(typeName, rid) { + getDomOfRoom(typeName, rid, templateName) { const room = openedRooms[typeName]; if (room == null) { return; @@ -125,7 +125,7 @@ export const RoomManager = new function() { room.dom.classList.add('room-container'); const contentAsFunc = (content) => () => content; - room.template = Blaze._TemplateWith({ _id: rid }, contentAsFunc(Template.room)); + room.template = Blaze._TemplateWith({ _id: rid }, contentAsFunc(Template[templateName || 'room'])); Blaze.render(room.template, room.dom); // , nextNode, parentView } diff --git a/app/ui-utils/client/lib/openRoom.js b/app/ui-utils/client/lib/openRoom.js index 54252661781d..71b35a397d0c 100644 --- a/app/ui-utils/client/lib/openRoom.js +++ b/app/ui-utils/client/lib/openRoom.js @@ -84,7 +84,7 @@ export const openRoom = async function(type, name) { return FlowRouter.go('direct', { rid: room._id }, FlowRouter.current().queryParams); } - const roomDom = RoomManager.getDomOfRoom(type + name, room._id); + const roomDom = RoomManager.getDomOfRoom(type + name, room._id, roomTypes.getConfig(type).mainTemplate); const mainNode = replaceCenterDomBy(roomDom); if (mainNode) { diff --git a/client/importPackages.js b/client/importPackages.js index 7d95bc6f83e7..115a1d35665f 100644 --- a/client/importPackages.js +++ b/client/importPackages.js @@ -107,3 +107,4 @@ import '../app/reactions/client'; import '../app/livechat/client'; import '../app/meteor-autocomplete/client'; import '../app/theme/client'; +import '../app/custom/client'; diff --git a/server/importPackages.js b/server/importPackages.js index aa56233f2bf5..bf5a117a6dd3 100644 --- a/server/importPackages.js +++ b/server/importPackages.js @@ -112,3 +112,4 @@ import '../app/ui-utils'; import '../app/action-links/server'; import '../app/reactions/server'; import '../app/livechat/server'; +import '../app/custom/server';