The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/packages/rocketchat-lib/server/functions/addUserToRoom.js

46 lines
1.1 KiB

RocketChat.addUserToRoom = function(rid, user, inviter, silenced) {
const now = new Date();
const room = RocketChat.models.Rooms.findOneById(rid);
// Check if user is already in room
const subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);
if (subscription) {
return;
}
Enhance outgoing webhooks and add history (#5823) * Convert the majority of the integrations package to JavaScript * Move the trigger handler to it's own class * Start trying to generalize integration items * Yay, additional events trigger outgoing webhooks * Silence codacy and fix eslint problems. * Started work on user created event for outgoing integrations * Finish the outgoing integration work on the user created event. * Add user join and leave room events for outgoing webhooks * Add fields to the rest api integration creation and clean up the processWebhookMessage * Add the HTTP to the incoming webhook context * Don't check for property on result if it isn't there. Closes #4175, #5762, and #5896. * Add archive room and file upload events for the webhooks * Disable integrations when the user to run/post as gets deleted. * Try to fix the tests failing due to the requird events property * Add history of integration which get fired * Add the missing file for the IntegrationHistory * Fix deleting users being broke due to my code * Add the outgoing webhook integration history viewing page along with v1 rest api to retrieve it * Integration history replays are now enabled along with advanced settings * Work on the advanced settings and enable paging on the integration history * Enable i18n for the history and advanced settings * Update the wording on the word placement * Move migration to be 88 now. * Add missing translations for the webhooks * Fix en.i18n.json identation * Fix integrations.html indentation * Fix more identations * Fix identation of integrationsOutgoing.html
9 years ago
if (room.t === 'c' || room.t === 'p') {
RocketChat.callbacks.run('beforeJoinRoom', user, room);
}
const muted = room.ro && !RocketChat.authz.hasPermission(user._id, 'post-readonly');
RocketChat.models.Rooms.addUsernameById(rid, user.username, muted);
RocketChat.models.Subscriptions.createWithRoomAndUser(room, user, {
ts: now,
open: true,
alert: true,
unread: 1
});
if (!silenced) {
if (inviter) {
RocketChat.models.Messages.createUserAddedWithRoomIdAndUser(rid, user, {
ts: now,
u: {
_id: inviter._id,
username: inviter.username
}
});
} else {
RocketChat.models.Messages.createUserJoinWithRoomIdAndUser(rid, user, { ts: now });
}
}
Enhance outgoing webhooks and add history (#5823) * Convert the majority of the integrations package to JavaScript * Move the trigger handler to it's own class * Start trying to generalize integration items * Yay, additional events trigger outgoing webhooks * Silence codacy and fix eslint problems. * Started work on user created event for outgoing integrations * Finish the outgoing integration work on the user created event. * Add user join and leave room events for outgoing webhooks * Add fields to the rest api integration creation and clean up the processWebhookMessage * Add the HTTP to the incoming webhook context * Don't check for property on result if it isn't there. Closes #4175, #5762, and #5896. * Add archive room and file upload events for the webhooks * Disable integrations when the user to run/post as gets deleted. * Try to fix the tests failing due to the requird events property * Add history of integration which get fired * Add the missing file for the IntegrationHistory * Fix deleting users being broke due to my code * Add the outgoing webhook integration history viewing page along with v1 rest api to retrieve it * Integration history replays are now enabled along with advanced settings * Work on the advanced settings and enable paging on the integration history * Enable i18n for the history and advanced settings * Update the wording on the word placement * Move migration to be 88 now. * Add missing translations for the webhooks * Fix en.i18n.json identation * Fix integrations.html indentation * Fix more identations * Fix identation of integrationsOutgoing.html
9 years ago
if (room.t === 'c' || room.t === 'p') {
Meteor.defer(function() {
RocketChat.callbacks.run('afterJoinRoom', user, room);
});
}
return true;
};