Skip to content

Commit 7a0e697

Browse files
author
auterium
committed
Add basic support for teams
1 parent ac16e93 commit 7a0e697

File tree

35 files changed

+124
-83
lines changed

35 files changed

+124
-83
lines changed

client/startup/unread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Meteor.startup(function() {
3939
}
4040
}
4141

42-
if (RoomManager.openedRooms[subscription.t + subscription.name]) {
42+
if (RoomManager.openedRooms[subscription.t + subscription.team + '/' + subscription.name]) {
4343
readMessage.refreshUnreadMark(subscription.rid);
4444
}
4545
}

packages/rocketchat-api/server/v1/channels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function findChannelByIdOrName({ params, checkedArchived = true, returnUsernames
1515
if (params.roomId) {
1616
room = RocketChat.models.Rooms.findOneById(params.roomId, { fields });
1717
} else if (params.roomName) {
18-
room = RocketChat.models.Rooms.findOneByName(params.roomName, { fields });
18+
room = RocketChat.models.Rooms.findOneByName(params.roomName, params.team, { fields });
1919
}
2020

2121
if (!room || room.t !== 'c') {

packages/rocketchat-api/server/v1/groups.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ function findPrivateGroupByIdOrName({ params, userId, checkedArchived = true })
99
let roomSub;
1010
if (params.roomId) {
1111
roomSub = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(params.roomId, userId);
12-
} else if (params.roomName) {
13-
roomSub = RocketChat.models.Subscriptions.findOneByRoomNameAndUserId(params.roomName, userId);
12+
} else if (params.roomName && params.team) {
13+
// Add team
14+
roomSub = RocketChat.models.Subscriptions.findOneByRoomNameAndUserId(params.team, params.roomName, userId);
1415
}
1516

1617
if (!roomSub || roomSub.t !== 'p') {
@@ -118,6 +119,10 @@ RocketChat.API.v1.addRoute('groups.create', { authRequired: true }, {
118119
return RocketChat.API.v1.failure('Body param "name" is required');
119120
}
120121

122+
if (!this.bodyParams.team) {
123+
return RocketChat.API.v1.failure('Body param "team" is required');
124+
}
125+
121126
if (this.bodyParams.members && !_.isArray(this.bodyParams.members)) {
122127
return RocketChat.API.v1.failure('Body param "members" must be an array if provided');
123128
}
@@ -132,8 +137,9 @@ RocketChat.API.v1.addRoute('groups.create', { authRequired: true }, {
132137
}
133138

134139
let id;
140+
const { name, team, members, customFields } = this.bodyParams;
135141
Meteor.runAsUser(this.userId, () => {
136-
id = Meteor.call('createPrivateGroup', this.bodyParams.name, this.bodyParams.members ? this.bodyParams.members : [], readOnly, this.bodyParams.customFields);
142+
id = Meteor.call('createPrivateGroup', name, members || [], readOnly, customFields, { team });
137143
});
138144

139145
return RocketChat.API.v1.success({

packages/rocketchat-api/server/v1/im.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function findDirectMessageRoom(params, user) {
88
const room = RocketChat.getRoomByNameOrIdWithOptionToJoin({
99
currentUserId: user._id,
1010
nameOrId: params.username || params.roomId,
11-
type: 'd'
11+
type: 'd',
12+
team: params.team
1213
});
1314

1415
if (!room || room.t !== 'd') {

packages/rocketchat-apps/server/bridges/rooms.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class AppRoomBridge {
99
console.log(`The App ${ appId } is creating a new room.`, room);
1010

1111
const rcRoom = this.orch.getConverters().get('rooms').convertAppRoom(room);
12+
const params = [rcRoom.usernames];
1213
let method;
1314

1415
switch (room.type) {
@@ -17,14 +18,16 @@ export class AppRoomBridge {
1718
break;
1819
case RoomType.PRIVATE_GROUP:
1920
method = 'createPrivateGroup';
21+
// params.push(team)
22+
throw new Error('Team not set');
2023
break;
2124
default:
2225
throw new Error('Only channels and private groups can be created.');
2326
}
2427

2528
let rid;
2629
Meteor.runAsUser(room.creator.id, () => {
27-
const info = Meteor.call(method, rcRoom.usernames);
30+
const info = Meteor.call(method, ...params);
2831
rid = info.rid;
2932
});
3033

packages/rocketchat-channel-settings/client/startup/trackSettingsChange.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ Meteor.startup(function() {
44
if (msg.t === 'room_changed_privacy') {
55
if (Session.get('openedRoom') === msg.rid) {
66
const type = FlowRouter.current().route.name === 'channel' ? 'c' : 'p';
7-
RoomManager.close(type + FlowRouter.getParam('name'));
7+
RoomManager.close(type + FlowRouter.getParam('team') + '/' + FlowRouter.getParam('name'));
88

99
const subscription = ChatSubscription.findOne({ rid: msg.rid });
1010
const route = subscription.t === 'c' ? 'channel' : 'group';
11-
FlowRouter.go(route, { name: subscription.name }, FlowRouter.current().queryParams);
11+
FlowRouter.go(route, { name: subscription.name, team: subscription.team }, FlowRouter.current().queryParams);
1212
}
1313
}
1414
});
@@ -24,7 +24,7 @@ Meteor.startup(function() {
2424
if (Session.get('openedRoom') === msg.rid) {
2525
const room = ChatRoom.findOne(msg.rid);
2626
if (room.name !== FlowRouter.getParam('name')) {
27-
RoomManager.close(room.t + FlowRouter.getParam('name'));
27+
RoomManager.close(room.t + FlowRouter.getParam('team') + '/' + FlowRouter.getParam('name'));
2828
RocketChat.roomTypes.openRouteLink(room.t, room, FlowRouter.current().queryParams);
2929
}
3030
}

packages/rocketchat-channel-settings/server/functions/saveRoomName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RocketChat.saveRoomName = function(rid, displayName, user, sendMessage = true) {
1010
return;
1111
}
1212

13-
const slugifiedRoomName = RocketChat.getValidRoomName(displayName, rid);
13+
const slugifiedRoomName = RocketChat.getValidRoomName(displayName, team, rid);
1414

1515
const update = RocketChat.models.Rooms.setNameById(rid, slugifiedRoomName, displayName) && RocketChat.models.Subscriptions.updateNameAndAlertByRoomId(rid, slugifiedRoomName, displayName);
1616

packages/rocketchat-error-handler/server/lib/RocketChat.ErrorHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class ErrorHandler {
3636
};
3737
}
3838

39-
getRoomId(roomName) {
39+
getRoomId(roomName, team) {
4040
roomName = roomName.replace('#');
41-
const room = RocketChat.models.Rooms.findOneByName(roomName, { fields: { _id: 1, t: 1 } });
41+
const room = RocketChat.models.Rooms.findOneByName(roomName, team, { fields: { _id: 1, t: 1 } });
4242
if (room && (room.t === 'c' || room.t === 'p')) {
4343
return room._id;
4444
} else {

packages/rocketchat-integrations/server/processWebhookMessage.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import s from 'underscore.string';
44
this.processWebhookMessage = function(messageObj, user, defaultValues = { channel: '', alias: '', avatar: '', emoji: '' }, mustBeJoined = false) {
55
const sentData = [];
66
const channels = [].concat(messageObj.channel || messageObj.roomId || defaultValues.channel);
7+
const team = messageObj.team;
78

89
for (const channel of channels) {
910
const channelType = channel[0];
@@ -13,22 +14,22 @@ this.processWebhookMessage = function(messageObj, user, defaultValues = { channe
1314

1415
switch (channelType) {
1516
case '#':
16-
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, joinChannel: true });
17+
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, team, nameOrId: channelValue, joinChannel: true });
1718
break;
1819
case '@':
19-
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, type: 'd' });
20+
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, team, nameOrId: channelValue, type: 'd' });
2021
break;
2122
default:
2223
channelValue = channelType + channelValue;
2324

2425
//Try to find the room by id or name if they didn't include the prefix.
25-
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, joinChannel: true, errorOnEmpty: false });
26+
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, team, nameOrId: channelValue, joinChannel: true, errorOnEmpty: false });
2627
if (room) {
2728
break;
2829
}
2930

3031
//We didn't get a room, let's try finding direct messages
31-
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, nameOrId: channelValue, type: 'd', tryDirectByUserIdOnly: true });
32+
room = RocketChat.getRoomByNameOrIdWithOptionToJoin({ currentUserId: user._id, team, nameOrId: channelValue, type: 'd', tryDirectByUserIdOnly: true });
3233
if (room) {
3334
break;
3435
}

packages/rocketchat-lib/client/lib/cachedCollection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class CachedCollection {
331331
this.log('record received', t, record);
332332
if (t === 'removed') {
333333
this.collection.remove(record._id);
334-
RoomManager.close(record.t+record.name);
334+
RoomManager.close(record.t + record.team + '/' + record.name);
335335
} else {
336336
delete record.$loki;
337337
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));

0 commit comments

Comments
 (0)