From 5c3e40152ddd9576cb56a88447aad69527a5db4f Mon Sep 17 00:00:00 2001 From: Justin Reynolds Date: Mon, 5 Aug 2019 15:19:16 -0500 Subject: [PATCH 1/3] Support for custom packages & room templates --- app/callbacks/lib/callbacks.js | 5 ++-- app/custom/client/index.js | 0 app/custom/css/index.js | 0 app/custom/index.js | 8 ++++++ app/custom/server/index.js | 0 .../client/public/stylesheets/discussion.css | 4 +++ .../hooks/propagateDiscussionMetadata.js | 28 +++++++++++++------ app/ui-utils/client/lib/RoomManager.js | 4 +-- app/ui-utils/client/lib/openRoom.js | 2 +- app/ui-utils/client/lib/readMessages.js | 7 +++++ client/importPackages.js | 1 + client/importsCss.js | 2 +- server/importPackages.js | 1 + 13 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 app/custom/client/index.js create mode 100644 app/custom/css/index.js create mode 100644 app/custom/index.js create mode 100644 app/custom/server/index.js diff --git a/app/callbacks/lib/callbacks.js b/app/callbacks/lib/callbacks.js index 193b6be06ed6..71591975bb13 100644 --- a/app/callbacks/lib/callbacks.js +++ b/app/callbacks/lib/callbacks.js @@ -59,8 +59,8 @@ const combinedCallbacks = new Map(); this.combinedCallbacks = combinedCallbacks; /* * 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/css/index.js b/app/custom/css/index.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/custom/index.js b/app/custom/index.js new file mode 100644 index 000000000000..a67eca871efb --- /dev/null +++ b/app/custom/index.js @@ -0,0 +1,8 @@ +import { Meteor } from 'meteor/meteor'; + +if (Meteor.isClient) { + module.exports = require('./client/index.js'); +} +if (Meteor.isServer) { + module.exports = require('./server/index.js'); +} 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/client/public/stylesheets/discussion.css b/app/discussion/client/public/stylesheets/discussion.css index 93c6d4e8e20f..53e55b895401 100644 --- a/app/discussion/client/public/stylesheets/discussion.css +++ b/app/discussion/client/public/stylesheets/discussion.css @@ -3,6 +3,10 @@ padding: 0.5rem 0; align-items: center; + + & .rc-button { + white-space: nowrap; + } } .discussion-reply-lm { 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 30bcda015e99..3c872e4605db 100644 --- a/app/ui-utils/client/lib/RoomManager.js +++ b/app/ui-utils/client/lib/RoomManager.js @@ -105,7 +105,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; @@ -116,7 +116,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 e3dc202a5170..2127fa0ab1e0 100644 --- a/app/ui-utils/client/lib/openRoom.js +++ b/app/ui-utils/client/lib/openRoom.js @@ -82,7 +82,7 @@ export const openRoom = function(type, name) { return; } - 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/app/ui-utils/client/lib/readMessages.js b/app/ui-utils/client/lib/readMessages.js index aa288db73d60..8cd8941c7c4a 100644 --- a/app/ui-utils/client/lib/readMessages.js +++ b/app/ui-utils/client/lib/readMessages.js @@ -73,6 +73,13 @@ export const readMessage = new class extends EventEmitter { return; } + // If no messages exist on the screen, don't mark the unread as read + const message = $('.message'); + if (message.length <= 0) { + if (this.debug) { console.log('readMessage -> readNow canceled, no messages found on screen for rid:', rid); } + return; + } + // Only read messages if user saw the first unread message const unreadMark = $('.message.first-unread'); if (unreadMark.length > 0) { diff --git a/client/importPackages.js b/client/importPackages.js index e26dde77f6f7..fd4ad84c8eff 100644 --- a/client/importPackages.js +++ b/client/importPackages.js @@ -109,3 +109,4 @@ import '../app/ui-cached-collection'; import '../app/action-links'; import '../app/reactions/client'; import '../app/livechat/client'; +import '../app/custom'; diff --git a/client/importsCss.js b/client/importsCss.js index d723973c6a22..310d9d313563 100644 --- a/client/importsCss.js +++ b/client/importsCss.js @@ -1,4 +1,3 @@ - import '../app/chatpal-search/client/style.css'; import '../app/theme/client/main.css'; import '../app/theme/client/vendor/photoswipe.css'; @@ -39,3 +38,4 @@ import '../app/ui-vrecord/client/vrecord.css'; import '../app/videobridge/client/stylesheets/video.less'; import '../app/wordpress/client/wordpress-login-button.css'; import '../app/katex/katex.min.css'; +import '../app/custom/css/index'; diff --git a/server/importPackages.js b/server/importPackages.js index 35d4dbac90ea..3084ba224bbd 100644 --- a/server/importPackages.js +++ b/server/importPackages.js @@ -118,3 +118,4 @@ import '../app/ui-utils'; import '../app/action-links'; import '../app/reactions/server'; import '../app/livechat/server'; +import '../app/custom'; From c7299bc6ea43ab7226daba63ba1ecbb20f00b426 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 30 May 2020 14:40:53 -0300 Subject: [PATCH 2/3] Remove common index file --- app/custom/index.js | 8 -------- client/importPackages.js | 2 +- server/importPackages.js | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 app/custom/index.js diff --git a/app/custom/index.js b/app/custom/index.js deleted file mode 100644 index a67eca871efb..000000000000 --- a/app/custom/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -if (Meteor.isClient) { - module.exports = require('./client/index.js'); -} -if (Meteor.isServer) { - module.exports = require('./server/index.js'); -} diff --git a/client/importPackages.js b/client/importPackages.js index c7f1978bac3e..115a1d35665f 100644 --- a/client/importPackages.js +++ b/client/importPackages.js @@ -107,4 +107,4 @@ import '../app/reactions/client'; import '../app/livechat/client'; import '../app/meteor-autocomplete/client'; import '../app/theme/client'; -import '../app/custom'; +import '../app/custom/client'; diff --git a/server/importPackages.js b/server/importPackages.js index ecd802a5b10d..bf5a117a6dd3 100644 --- a/server/importPackages.js +++ b/server/importPackages.js @@ -112,4 +112,4 @@ import '../app/ui-utils'; import '../app/action-links/server'; import '../app/reactions/server'; import '../app/livechat/server'; -import '../app/custom'; +import '../app/custom/server'; From 2f694b45430a422f30fe85476c2a06318353ccc3 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 30 May 2020 14:42:57 -0300 Subject: [PATCH 3/3] Remove unecessary changes --- app/discussion/client/public/stylesheets/discussion.css | 4 ---- app/ui-utils/client/lib/readMessages.js | 7 ------- 2 files changed, 11 deletions(-) diff --git a/app/discussion/client/public/stylesheets/discussion.css b/app/discussion/client/public/stylesheets/discussion.css index 53e55b895401..93c6d4e8e20f 100644 --- a/app/discussion/client/public/stylesheets/discussion.css +++ b/app/discussion/client/public/stylesheets/discussion.css @@ -3,10 +3,6 @@ padding: 0.5rem 0; align-items: center; - - & .rc-button { - white-space: nowrap; - } } .discussion-reply-lm { diff --git a/app/ui-utils/client/lib/readMessages.js b/app/ui-utils/client/lib/readMessages.js index 5fde1cf63033..1afcd5d979d6 100644 --- a/app/ui-utils/client/lib/readMessages.js +++ b/app/ui-utils/client/lib/readMessages.js @@ -49,13 +49,6 @@ export const readMessage = new class extends EventEmitter { return; } - // If no messages exist on the screen, don't mark the unread as read - const message = $('.message'); - if (message.length <= 0) { - if (this.debug) { console.log('readMessage -> readNow canceled, no messages found on screen for rid:', rid); } - return; - } - // Only read messages if user saw the first unread message const unreadMark = $('.message.first-unread'); if (unreadMark.length > 0) {