Skip to content

Commit

Permalink
[IMPROVE] Make the implementation of custom code easier by having pla…
Browse files Browse the repository at this point in the history
…ceholders for a custom folder (#15106)
  • Loading branch information
justinr1234 authored May 30, 2020
1 parent ae90799 commit 53c4ecf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/callbacks/lib/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const combinedCallbacks = new Map();

/*
* Callback priorities
* @enum {CallbackPriority}
*/

callbacks.priority = {
HIGH: -1000,
MEDIUM: 0,
Expand All @@ -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,
Expand Down
Empty file added app/custom/client/index.js
Empty file.
Empty file added app/custom/server/index.js
Empty file.
28 changes: 19 additions & 9 deletions app/discussion/server/hooks/propagateDiscussionMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
4 changes: 2 additions & 2 deletions app/ui-utils/client/lib/RoomManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion app/ui-utils/client/lib/openRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions client/importPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions server/importPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 53c4ecf

Please sign in to comment.