@builder6/rooms 0.10.7 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/emails/UnreadMention.d.ts +9 -0
- package/dist/emails/UnreadMention.js +54 -0
- package/dist/emails/UnreadMention.js.map +1 -0
- package/dist/emails/UnreadReplies.d.ts +9 -0
- package/dist/emails/UnreadReplies.js +68 -0
- package/dist/emails/UnreadReplies.js.map +1 -0
- package/dist/emails/_components/comment.d.ts +1 -0
- package/dist/emails/_components/comment.js +32 -0
- package/dist/emails/_components/comment.js.map +1 -0
- package/dist/emails/_components/header.d.ts +2 -0
- package/dist/emails/_components/header.js +15 -0
- package/dist/emails/_components/header.js.map +1 -0
- package/dist/emails/_components/headline.d.ts +5 -0
- package/dist/emails/_components/headline.js +17 -0
- package/dist/emails/_components/headline.js.map +1 -0
- package/dist/emails/_components/layout.d.ts +5 -0
- package/dist/emails/_components/layout.js +24 -0
- package/dist/emails/_components/layout.js.map +1 -0
- package/dist/emails/_lib/types.d.ts +9 -0
- package/dist/emails/_lib/types.js +3 -0
- package/dist/emails/_lib/types.js.map +1 -0
- package/dist/emails/_styles/colors.d.ts +2 -0
- package/dist/emails/_styles/colors.js +7 -0
- package/dist/emails/_styles/colors.js.map +1 -0
- package/dist/emails/_utils/cn.d.ts +2 -0
- package/dist/emails/_utils/cn.js +10 -0
- package/dist/emails/_utils/cn.js.map +1 -0
- package/dist/emails/_utils/comments.d.ts +7 -0
- package/dist/emails/_utils/comments.js +29 -0
- package/dist/emails/_utils/comments.js.map +1 -0
- package/dist/emails/_utils/getProps.d.ts +1 -0
- package/dist/emails/_utils/getProps.js +11 -0
- package/dist/emails/_utils/getProps.js.map +1 -0
- package/dist/rooms/app.controller.d.ts +3 -1
- package/dist/rooms/app.controller.js +61 -46
- package/dist/rooms/app.controller.js.map +1 -1
- package/dist/rooms/emailNotification.service.d.ts +17 -0
- package/dist/rooms/emailNotification.service.js +113 -0
- package/dist/rooms/emailNotification.service.js.map +1 -0
- package/dist/rooms/emails/comment-body.d.ts +44 -0
- package/dist/rooms/emails/comment-body.js +138 -0
- package/dist/rooms/emails/comment-body.js.map +1 -0
- package/dist/rooms/emails/comment-with-body.d.ts +6 -0
- package/dist/rooms/emails/comment-with-body.js +17 -0
- package/dist/rooms/emails/comment-with-body.js.map +1 -0
- package/dist/rooms/emails/index.d.ts +4 -0
- package/dist/rooms/emails/index.js +7 -0
- package/dist/rooms/emails/index.js.map +1 -0
- package/dist/rooms/emails/lib/batch-users-resolver.d.ts +9 -0
- package/dist/rooms/emails/lib/batch-users-resolver.js +67 -0
- package/dist/rooms/emails/lib/batch-users-resolver.js.map +1 -0
- package/dist/rooms/emails/lib/css-properties.d.ts +3 -0
- package/dist/rooms/emails/lib/css-properties.js +96 -0
- package/dist/rooms/emails/lib/css-properties.js.map +1 -0
- package/dist/rooms/emails/lib/warning.d.ts +1 -0
- package/dist/rooms/emails/lib/warning.js +20 -0
- package/dist/rooms/emails/lib/warning.js.map +1 -0
- package/dist/rooms/emails/thread-notification.d.ts +90 -0
- package/dist/rooms/emails/thread-notification.js +297 -0
- package/dist/rooms/emails/thread-notification.js.map +1 -0
- package/dist/rooms/globals/augmentation.d.ts +0 -5
- package/dist/rooms/lib/utils.js +21 -10
- package/dist/rooms/lib/utils.js.map +1 -1
- package/dist/rooms/liveblocks.service.d.ts +16 -0
- package/dist/rooms/liveblocks.service.js +54 -0
- package/dist/rooms/liveblocks.service.js.map +1 -0
- package/dist/rooms/notifications.service.d.ts +4 -0
- package/dist/rooms/notifications.service.js +107 -80
- package/dist/rooms/notifications.service.js.map +1 -1
- package/dist/rooms/rooms.controller.d.ts +6 -4
- package/dist/rooms/rooms.controller.js +323 -244
- package/dist/rooms/rooms.controller.js.map +1 -1
- package/dist/rooms/rooms.gateway.js +132 -109
- package/dist/rooms/rooms.gateway.js.map +1 -1
- package/dist/rooms/rooms.guard.js +31 -19
- package/dist/rooms/rooms.guard.js.map +1 -1
- package/dist/rooms/rooms.module.js +12 -3
- package/dist/rooms/rooms.module.js.map +1 -1
- package/dist/rooms/rooms.moleculer.js +85 -66
- package/dist/rooms/rooms.moleculer.js.map +1 -1
- package/dist/rooms/rooms.service.d.ts +17 -4
- package/dist/rooms/rooms.service.js +408 -340
- package/dist/rooms/rooms.service.js.map +1 -1
- package/package.json +18 -6
- package/src/emails/UnreadMention.tsx +76 -0
- package/src/emails/UnreadReplies.tsx +106 -0
- package/src/emails/_components/comment.tsx +70 -0
- package/src/emails/_components/header.tsx +27 -0
- package/src/emails/_components/headline.tsx +20 -0
- package/src/emails/_components/layout.tsx +45 -0
- package/src/emails/_lib/types.ts +10 -0
- package/src/emails/_styles/colors.ts +7 -0
- package/src/emails/_utils/cn.ts +6 -0
- package/src/emails/_utils/comments.ts +61 -0
- package/src/emails/_utils/getProps.ts +7 -0
- package/src/rooms/app.controller.ts +7 -2
- package/src/rooms/emailNotification.service.tsx +152 -0
- package/src/rooms/emails/comment-body.tsx +342 -0
- package/src/rooms/emails/comment-with-body.ts +24 -0
- package/src/rooms/emails/index.ts +25 -0
- package/src/rooms/emails/lib/batch-users-resolver.ts +120 -0
- package/src/rooms/emails/lib/css-properties.ts +123 -0
- package/src/rooms/emails/lib/warning.ts +25 -0
- package/src/rooms/emails/thread-notification.tsx +583 -0
- package/src/rooms/globals/augmentation.ts +8 -8
- package/src/rooms/liveblocks.service.ts +25 -0
- package/src/rooms/notifications.service.ts +22 -10
- package/src/rooms/rooms.controller.ts +24 -5
- package/src/rooms/rooms.module.ts +11 -2
- package/src/rooms/rooms.service.ts +35 -20
- package/tsconfig.json +2 -0
- package/yarn-error.log +17218 -0
|
@@ -8,6 +8,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
11
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
21
|
exports.RoomsService = exports.CommentBodyInlineType = exports.CommentType = void 0;
|
|
13
22
|
const core_1 = require("@builder6/core");
|
|
@@ -17,6 +26,7 @@ const rooms_dto_1 = require("./dtos/rooms.dto");
|
|
|
17
26
|
const lodash_1 = require("lodash");
|
|
18
27
|
const notifications_service_1 = require("./notifications.service");
|
|
19
28
|
const uuid_1 = require("uuid");
|
|
29
|
+
const emailNotification_service_1 = require("./emailNotification.service");
|
|
20
30
|
var CommentType;
|
|
21
31
|
(function (CommentType) {
|
|
22
32
|
CommentType["Paragraph"] = "paragraph";
|
|
@@ -27,399 +37,457 @@ var CommentBodyInlineType;
|
|
|
27
37
|
CommentBodyInlineType["Link"] = "link";
|
|
28
38
|
})(CommentBodyInlineType = exports.CommentBodyInlineType || (exports.CommentBodyInlineType = {}));
|
|
29
39
|
let RoomsService = class RoomsService {
|
|
30
|
-
constructor(mongodbService, jwtService, notificationsService) {
|
|
40
|
+
constructor(mongodbService, jwtService, notificationsService, emailNotificationService) {
|
|
31
41
|
this.mongodbService = mongodbService;
|
|
32
42
|
this.jwtService = jwtService;
|
|
33
43
|
this.notificationsService = notificationsService;
|
|
44
|
+
this.emailNotificationService = emailNotificationService;
|
|
34
45
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
getToken({ spaceId, userId, perms, }) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const payload = {
|
|
49
|
+
k: 'acc',
|
|
50
|
+
pid: spaceId,
|
|
51
|
+
sid: spaceId,
|
|
52
|
+
uid: userId,
|
|
53
|
+
mcpr: 10,
|
|
54
|
+
perms: perms,
|
|
55
|
+
jti: 'S4EMiESTDe6k',
|
|
56
|
+
};
|
|
57
|
+
const token = yield this.jwtService.signAsync(payload);
|
|
58
|
+
return { token };
|
|
59
|
+
});
|
|
47
60
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
room
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
getRoomToken({ roomId, spaceId, userId, readonly = false, }) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
let room = yield this.getRoom(roomId);
|
|
64
|
+
if (!room) {
|
|
65
|
+
room = yield this.createRoom({
|
|
66
|
+
_id: roomId,
|
|
67
|
+
name: 'Room ' + roomId,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
let member = yield this.getRoomMember(roomId, userId);
|
|
71
|
+
if (!member) {
|
|
72
|
+
member = yield this.createRoomMember(room, {
|
|
73
|
+
userId,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const scopes = readonly ? rooms_dto_1.READ_ACCESS : member.scopes;
|
|
77
|
+
const perms = {
|
|
78
|
+
[roomId]: scopes,
|
|
79
|
+
};
|
|
80
|
+
return yield this.getToken({
|
|
81
|
+
spaceId,
|
|
59
82
|
userId,
|
|
83
|
+
perms,
|
|
60
84
|
});
|
|
61
|
-
}
|
|
62
|
-
const scopes = readonly ? rooms_dto_1.READ_ACCESS : member.scopes;
|
|
63
|
-
const perms = {
|
|
64
|
-
[roomId]: scopes,
|
|
65
|
-
};
|
|
66
|
-
return await this.getToken({
|
|
67
|
-
spaceId,
|
|
68
|
-
userId,
|
|
69
|
-
perms,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
async getAttachmentById(attachmentId) {
|
|
73
|
-
const attachment = await this.mongodbService.findOne('cfs.files.filerecord', {
|
|
74
|
-
_id: attachmentId,
|
|
75
85
|
});
|
|
76
|
-
return {
|
|
77
|
-
id: attachmentId,
|
|
78
|
-
mimeType: attachment.original.type,
|
|
79
|
-
name: attachment.original.name,
|
|
80
|
-
size: attachment.original.size,
|
|
81
|
-
type: 'attachment',
|
|
82
|
-
};
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const users = [];
|
|
89
|
-
for (const userId of userIds) {
|
|
90
|
-
const user = await this.mongodbService.findOne('users', {
|
|
91
|
-
_id: userId,
|
|
87
|
+
getAttachmentById(attachmentId) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const attachment = yield this.mongodbService.findOne('cfs.files.filerecord', {
|
|
90
|
+
_id: attachmentId,
|
|
92
91
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
return {
|
|
93
|
+
id: attachmentId,
|
|
94
|
+
mimeType: attachment.original.type,
|
|
95
|
+
name: attachment.original.name,
|
|
96
|
+
size: attachment.original.size,
|
|
97
|
+
type: 'attachment',
|
|
98
|
+
};
|
|
99
|
+
});
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
resolveUsers({ userIds }) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const users = [];
|
|
104
|
+
for (const userId of userIds) {
|
|
105
|
+
const user = yield this.mongodbService.findOne('users', {
|
|
106
|
+
_id: userId,
|
|
107
|
+
});
|
|
108
|
+
users.push({
|
|
109
|
+
name: user ? user.name : 'Unknown',
|
|
110
|
+
avatar: `${process.env.B6_HOST}/api/v6/users/${userId}/avatar`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return users;
|
|
108
114
|
});
|
|
109
|
-
return spaceUsers.map((spaceUser) => spaceUser.user);
|
|
110
115
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
searchUsers(spaceId, keyword, roomId) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const spaceUsers = yield this.mongodbService.find('space_users', {
|
|
119
|
+
space: spaceId,
|
|
120
|
+
$or: [
|
|
121
|
+
{ username: { $regex: keyword, $options: 'i' } },
|
|
122
|
+
{ email: { $regex: keyword, $options: 'i' } },
|
|
123
|
+
{ name: { $regex: keyword, $options: 'i' } },
|
|
124
|
+
],
|
|
125
|
+
});
|
|
126
|
+
return spaceUsers.map((spaceUser) => spaceUser.user);
|
|
115
127
|
});
|
|
116
|
-
if (!thread) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
const comments = await this.getComments(roomId, threadId);
|
|
120
|
-
thread.comments = comments;
|
|
121
|
-
return thread;
|
|
122
128
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
getThread({ roomId, threadId }) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
const thread = yield this.mongodbService.findOne('b6_threads', {
|
|
132
|
+
roomId: roomId,
|
|
133
|
+
_id: threadId,
|
|
134
|
+
});
|
|
135
|
+
if (!thread) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const comments = yield this.getComments(roomId, threadId);
|
|
131
139
|
thread.comments = comments;
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
return thread;
|
|
141
|
+
});
|
|
134
142
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
getThreads(roomId, since) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const queryOptions = { roomId: roomId };
|
|
146
|
+
if (since) {
|
|
147
|
+
queryOptions.updatedAt = { $gt: since };
|
|
148
|
+
}
|
|
149
|
+
const threads = yield this.mongodbService.find('b6_threads', queryOptions);
|
|
150
|
+
for (const thread of threads) {
|
|
151
|
+
const comments = yield this.getComments(roomId, thread.id);
|
|
152
|
+
thread.comments = comments;
|
|
153
|
+
}
|
|
154
|
+
return threads;
|
|
155
|
+
});
|
|
145
156
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
getThreadsByIds(notifications) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const threadPromises = [];
|
|
160
|
+
for (let i = 0; i < notifications.length; i++) {
|
|
161
|
+
const notification = notifications[i];
|
|
162
|
+
threadPromises.push(this.getThread({
|
|
163
|
+
roomId: notification.roomId,
|
|
164
|
+
threadId: notification.threadId,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
if (threadPromises.length > 0) {
|
|
168
|
+
return Promise.all(threadPromises);
|
|
169
|
+
}
|
|
170
|
+
return [];
|
|
150
171
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
}
|
|
173
|
+
getComments(roomId, threadId) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const comments = yield this.mongodbService.find('b6_comments', {
|
|
176
|
+
roomId: roomId,
|
|
177
|
+
threadId: threadId,
|
|
178
|
+
});
|
|
179
|
+
for (const comment of comments) {
|
|
180
|
+
comment.attachments = [];
|
|
181
|
+
for (const attachmentId of comment.attachmentIds) {
|
|
182
|
+
const attachment = yield this.getAttachmentById(attachmentId);
|
|
183
|
+
comment.attachments.push(attachment);
|
|
184
|
+
}
|
|
156
185
|
}
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
return comments;
|
|
187
|
+
});
|
|
159
188
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
createThread({ id, comment, metadata, resolved = false, roomId, userId, }) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
const newThread = {
|
|
192
|
+
createdAt: new Date().toISOString(),
|
|
193
|
+
updatedAt: new Date().toISOString(),
|
|
194
|
+
_id: id,
|
|
195
|
+
id,
|
|
196
|
+
resolved,
|
|
197
|
+
metadata,
|
|
198
|
+
type: 'thread',
|
|
199
|
+
roomId,
|
|
200
|
+
userId,
|
|
201
|
+
};
|
|
202
|
+
const result = yield this.mongodbService.insertOne('b6_threads', newThread);
|
|
203
|
+
const newComment = yield this.createComment({
|
|
204
|
+
id: comment.id,
|
|
205
|
+
attachmentIds: comment.attachmentIds,
|
|
206
|
+
body: comment.body,
|
|
207
|
+
roomId,
|
|
208
|
+
threadId: id,
|
|
209
|
+
userId,
|
|
210
|
+
});
|
|
211
|
+
result.comments = [newComment];
|
|
212
|
+
return result;
|
|
180
213
|
});
|
|
181
|
-
result.comments = [newComment];
|
|
182
|
-
return result;
|
|
183
214
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
updatedAt: new Date().toISOString(),
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return result;
|
|
215
|
+
updateThread(threadId, thread) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
const newThread = Object.assign({ updatedAt: new Date().toISOString() }, thread);
|
|
218
|
+
const result = yield this.mongodbService.findOneAndUpdate('b6_threads', { _id: threadId }, newThread);
|
|
219
|
+
return result;
|
|
220
|
+
});
|
|
191
221
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const { content } = body;
|
|
212
|
-
let notificationsPromises;
|
|
213
|
-
let createRoomMentionPromises;
|
|
214
|
-
const mentionUsers = [];
|
|
215
|
-
for (const message of content) {
|
|
216
|
-
if (message.type === CommentType.Paragraph) {
|
|
217
|
-
message.children
|
|
218
|
-
.filter((child) => child?.type === CommentBodyInlineType.Mention)
|
|
219
|
-
.forEach((child) => mentionUsers.push(child.id));
|
|
222
|
+
createComment({ id, attachmentIds, body, roomId, threadId, userId, }) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const newComment = {
|
|
225
|
+
createdAt: new Date().toISOString(),
|
|
226
|
+
_id: id,
|
|
227
|
+
id,
|
|
228
|
+
reactions: [],
|
|
229
|
+
roomId,
|
|
230
|
+
threadId,
|
|
231
|
+
userId,
|
|
232
|
+
type: 'comment',
|
|
233
|
+
attachmentIds,
|
|
234
|
+
body,
|
|
235
|
+
};
|
|
236
|
+
const result = yield this.mongodbService.insertOne('b6_comments', newComment);
|
|
237
|
+
result.attachments = [];
|
|
238
|
+
for (const attachmentId of attachmentIds) {
|
|
239
|
+
const attachment = yield this.getAttachmentById(attachmentId);
|
|
240
|
+
result.attachments.push(attachment);
|
|
220
241
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
const { content } = body;
|
|
243
|
+
let notificationsPromises;
|
|
244
|
+
let createRoomMentionPromises;
|
|
245
|
+
const mentionUsers = [];
|
|
246
|
+
for (const message of content) {
|
|
247
|
+
if (message.type === CommentType.Paragraph) {
|
|
248
|
+
message.children
|
|
249
|
+
.filter((child) => (child === null || child === void 0 ? void 0 : child.type) === CommentBodyInlineType.Mention)
|
|
250
|
+
.forEach((child) => mentionUsers.push(child.id));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (mentionUsers && mentionUsers.length > 0) {
|
|
254
|
+
const uniqUsers = (0, lodash_1.uniq)(mentionUsers);
|
|
255
|
+
notificationsPromises = uniqUsers.map((mentionedUserId) => __awaiter(this, void 0, void 0, function* () {
|
|
256
|
+
const _id = (0, uuid_1.v4)();
|
|
257
|
+
const notification = yield this.notificationsService.createInboxNotification({
|
|
258
|
+
_id,
|
|
259
|
+
userId: mentionedUserId,
|
|
260
|
+
kind: 'thread',
|
|
261
|
+
notifiedAt: new Date(),
|
|
262
|
+
readAt: null,
|
|
263
|
+
roomId,
|
|
264
|
+
threadId,
|
|
265
|
+
});
|
|
266
|
+
yield this.emailNotificationService.sendThreadNotificationEmail({
|
|
267
|
+
roomId,
|
|
268
|
+
threadId,
|
|
269
|
+
userId: mentionedUserId,
|
|
270
|
+
fromUserId: userId,
|
|
271
|
+
inboxNotificationId: notification._id,
|
|
272
|
+
});
|
|
273
|
+
}));
|
|
274
|
+
createRoomMentionPromises = uniqUsers.map((mentionedUserId) => {
|
|
275
|
+
return this.notificationsService.createRoomMention({
|
|
276
|
+
userId: mentionedUserId,
|
|
277
|
+
roomId,
|
|
278
|
+
fromUserId: userId,
|
|
279
|
+
});
|
|
241
280
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
async updateComment(commentId, { attachmentIds, body, userId }) {
|
|
250
|
-
const newComment = {
|
|
251
|
-
updatedAt: new Date().toISOString(),
|
|
252
|
-
type: 'comment',
|
|
253
|
-
attachmentIds,
|
|
254
|
-
body,
|
|
255
|
-
userId,
|
|
256
|
-
};
|
|
257
|
-
const result = (await this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, newComment));
|
|
258
|
-
result.attachments = [];
|
|
259
|
-
for (const attachmentId of attachmentIds) {
|
|
260
|
-
const attachment = await this.getAttachmentById(attachmentId);
|
|
261
|
-
result.attachments.push(attachment);
|
|
262
|
-
}
|
|
263
|
-
delete result['_id'];
|
|
264
|
-
delete result['attachmentIds'];
|
|
265
|
-
return result;
|
|
281
|
+
yield Promise.all([].concat(notificationsPromises, createRoomMentionPromises));
|
|
282
|
+
}
|
|
283
|
+
delete result['_id'];
|
|
284
|
+
delete result['attachmentIds'];
|
|
285
|
+
return result;
|
|
286
|
+
});
|
|
266
287
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
288
|
+
updateComment(commentId, { attachmentIds, body, userId }) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
const newComment = {
|
|
291
|
+
updatedAt: new Date().toISOString(),
|
|
292
|
+
type: 'comment',
|
|
293
|
+
attachmentIds,
|
|
294
|
+
body,
|
|
295
|
+
userId,
|
|
296
|
+
};
|
|
297
|
+
const result = (yield this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, newComment));
|
|
298
|
+
result.attachments = [];
|
|
299
|
+
for (const attachmentId of attachmentIds) {
|
|
300
|
+
const attachment = yield this.getAttachmentById(attachmentId);
|
|
301
|
+
result.attachments.push(attachment);
|
|
302
|
+
}
|
|
303
|
+
delete result['_id'];
|
|
304
|
+
delete result['attachmentIds'];
|
|
305
|
+
return result;
|
|
270
306
|
});
|
|
271
|
-
return result;
|
|
272
307
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
308
|
+
deleteComment(commentId) {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
const result = yield this.mongodbService.deleteOne('b6_comments', {
|
|
311
|
+
_id: commentId,
|
|
312
|
+
});
|
|
313
|
+
return result;
|
|
276
314
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (!
|
|
284
|
-
|
|
315
|
+
}
|
|
316
|
+
createReaction(commentId, { userId, emoji }) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
+
const comment = yield this.mongodbService.findOne('b6_comments', {
|
|
319
|
+
_id: commentId,
|
|
320
|
+
});
|
|
321
|
+
if (!comment) {
|
|
322
|
+
throw new Error('Comment not found');
|
|
323
|
+
}
|
|
324
|
+
let reaction = comment.reactions.find((reaction) => reaction.emoji === emoji);
|
|
325
|
+
if (reaction) {
|
|
326
|
+
const userExists = reaction.users.some((user) => user.id === userId);
|
|
327
|
+
if (!userExists) {
|
|
328
|
+
reaction.users.push({ id: userId });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
reaction = {
|
|
333
|
+
emoji,
|
|
334
|
+
createdAt: new Date().toISOString(),
|
|
335
|
+
users: [{ id: userId }],
|
|
336
|
+
};
|
|
337
|
+
comment.reactions.push(reaction);
|
|
285
338
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
reaction = {
|
|
339
|
+
yield this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, comment);
|
|
340
|
+
return {
|
|
289
341
|
emoji,
|
|
290
|
-
createdAt:
|
|
291
|
-
|
|
342
|
+
createdAt: reaction.createdAt,
|
|
343
|
+
userId,
|
|
292
344
|
};
|
|
293
|
-
comment.reactions.push(reaction);
|
|
294
|
-
}
|
|
295
|
-
await this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, comment);
|
|
296
|
-
return {
|
|
297
|
-
emoji,
|
|
298
|
-
createdAt: reaction.createdAt,
|
|
299
|
-
userId,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
async deleteReaction(commentId, { userId, emoji }) {
|
|
303
|
-
const comment = await this.mongodbService.findOne('b6_comments', {
|
|
304
|
-
_id: commentId,
|
|
305
345
|
});
|
|
306
|
-
if (!comment) {
|
|
307
|
-
throw new Error('Comment not found');
|
|
308
|
-
}
|
|
309
|
-
const reaction = comment.reactions.find((reaction) => reaction.emoji === emoji);
|
|
310
|
-
if (!reaction) {
|
|
311
|
-
throw new Error('Reaction not found');
|
|
312
|
-
}
|
|
313
|
-
reaction.users = reaction.users.filter((user) => user.id !== userId);
|
|
314
|
-
comment.reactions = comment.reactions.filter((reaction) => reaction.users.length > 0);
|
|
315
|
-
await this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, comment);
|
|
316
|
-
return null;
|
|
317
346
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
return room;
|
|
347
|
+
deleteReaction(commentId, { userId, emoji }) {
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
const comment = yield this.mongodbService.findOne('b6_comments', {
|
|
350
|
+
_id: commentId,
|
|
351
|
+
});
|
|
352
|
+
if (!comment) {
|
|
353
|
+
throw new Error('Comment not found');
|
|
354
|
+
}
|
|
355
|
+
const reaction = comment.reactions.find((reaction) => reaction.emoji === emoji);
|
|
356
|
+
if (!reaction) {
|
|
357
|
+
throw new Error('Reaction not found');
|
|
358
|
+
}
|
|
359
|
+
reaction.users = reaction.users.filter((user) => user.id !== userId);
|
|
360
|
+
comment.reactions = comment.reactions.filter((reaction) => reaction.users.length > 0);
|
|
361
|
+
yield this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, comment);
|
|
362
|
+
return null;
|
|
363
|
+
});
|
|
336
364
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
365
|
+
createRoom({ _id, name, description = '', membershipType = 'standard', members = [], defaultNotifications = ['replies', 'mentions'], defaultScopes = ['room:write'], }) {
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
const newRoom = {
|
|
368
|
+
createdAt: new Date().toISOString(),
|
|
369
|
+
updatedAt: new Date().toISOString(),
|
|
370
|
+
_id,
|
|
371
|
+
name,
|
|
372
|
+
description,
|
|
373
|
+
membershipType,
|
|
374
|
+
defaultNotifications,
|
|
375
|
+
defaultScopes,
|
|
376
|
+
};
|
|
377
|
+
const room = yield this.mongodbService.insertOne('b6_rooms', newRoom);
|
|
378
|
+
room.members = [];
|
|
379
|
+
for (const member of members) {
|
|
380
|
+
const newMember = yield this.createRoomMember(room, member);
|
|
381
|
+
room.members.push(newMember);
|
|
382
|
+
}
|
|
383
|
+
return room;
|
|
384
|
+
});
|
|
350
385
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
_id
|
|
386
|
+
createRoomMember(room, member) {
|
|
387
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
388
|
+
const { _id, userId, roles = [], notifications = room.defaultNotifications, scopes = room.defaultScopes, } = member;
|
|
389
|
+
const newMember = {
|
|
390
|
+
_id,
|
|
391
|
+
userId,
|
|
392
|
+
roles,
|
|
393
|
+
roomId: room._id,
|
|
394
|
+
notifications,
|
|
395
|
+
scopes,
|
|
396
|
+
createdAt: new Date().toISOString(),
|
|
397
|
+
};
|
|
398
|
+
const result = yield this.mongodbService.insertOne('b6_room_members', newMember);
|
|
399
|
+
return result;
|
|
354
400
|
});
|
|
355
|
-
if (!room) {
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
room.members = await this.getRoomMembers(roomId);
|
|
359
|
-
return room;
|
|
360
401
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
402
|
+
getRoom(roomId) {
|
|
403
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
404
|
+
const room = yield this.mongodbService.findOne('b6_rooms', {
|
|
405
|
+
_id: roomId,
|
|
406
|
+
});
|
|
407
|
+
if (!room) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
room.members = yield this.getRoomMembers(roomId);
|
|
411
|
+
return room;
|
|
364
412
|
});
|
|
365
|
-
return members;
|
|
366
413
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
414
|
+
getRoomMembers(roomId) {
|
|
415
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
416
|
+
const members = yield this.mongodbService.find('b6_room_members', {
|
|
417
|
+
roomId,
|
|
418
|
+
});
|
|
419
|
+
return members;
|
|
371
420
|
});
|
|
372
|
-
return member;
|
|
373
421
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
422
|
+
getRoomMember(roomId, userId) {
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
+
const member = yield this.mongodbService.findOne('b6_room_members', {
|
|
425
|
+
roomId,
|
|
426
|
+
userId,
|
|
427
|
+
});
|
|
428
|
+
return member;
|
|
377
429
|
});
|
|
378
|
-
const rooms = [];
|
|
379
|
-
for (const roomMember of roomMembers) {
|
|
380
|
-
const room = await this.getRoom(roomMember.roomId);
|
|
381
|
-
rooms.push(room);
|
|
382
|
-
}
|
|
383
|
-
return rooms;
|
|
384
430
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
const [, objectName, recordId] = roomId.split(':');
|
|
395
|
-
const record = await this.mongodbService.findOne(objectName, {
|
|
396
|
-
_id: recordId,
|
|
397
|
-
}, {
|
|
398
|
-
projection: {
|
|
399
|
-
name: 1,
|
|
400
|
-
},
|
|
401
|
-
});
|
|
402
|
-
result.push({
|
|
403
|
-
id: roomId,
|
|
404
|
-
name: record ? record.name : roomId,
|
|
405
|
-
url: record ? `/b6/steedos/${objectName}/${recordId}` : null,
|
|
406
|
-
});
|
|
431
|
+
getMyRooms(userId) {
|
|
432
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
433
|
+
const roomMembers = yield this.mongodbService.find('b6_room_members', {
|
|
434
|
+
userId,
|
|
435
|
+
});
|
|
436
|
+
const rooms = [];
|
|
437
|
+
for (const roomMember of roomMembers) {
|
|
438
|
+
const room = yield this.getRoom(roomMember.roomId);
|
|
439
|
+
rooms.push(room);
|
|
407
440
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
441
|
+
return rooms;
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
resolveRoomInfo({ roomIds }) {
|
|
445
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
const result = [];
|
|
447
|
+
for (const roomId of roomIds) {
|
|
448
|
+
if (roomId &&
|
|
449
|
+
roomId.split(':').length === 3 &&
|
|
450
|
+
roomId.split(':')[0] === 'objects') {
|
|
451
|
+
const [, objectName, recordId] = roomId.split(':');
|
|
452
|
+
const record = yield this.mongodbService.findOne(objectName, {
|
|
453
|
+
_id: recordId,
|
|
454
|
+
}, {
|
|
455
|
+
projection: {
|
|
456
|
+
name: 1,
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
result.push({
|
|
460
|
+
id: roomId,
|
|
461
|
+
name: record ? record.name : roomId,
|
|
462
|
+
url: record ? `${process.env.B6_HOST}/b6/rooms/${roomId}` : null,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
result.push({
|
|
467
|
+
id: roomId,
|
|
468
|
+
name: roomId,
|
|
469
|
+
});
|
|
470
|
+
}
|
|
413
471
|
}
|
|
414
|
-
|
|
415
|
-
|
|
472
|
+
return result;
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
getInboxNotification({ inboxNotificationId, userId }) {
|
|
476
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
477
|
+
const notification = yield this.notificationsService.getInboxNotification({
|
|
478
|
+
inboxNotificationId,
|
|
479
|
+
userId,
|
|
480
|
+
});
|
|
481
|
+
return notification;
|
|
482
|
+
});
|
|
416
483
|
}
|
|
417
484
|
};
|
|
418
485
|
RoomsService = __decorate([
|
|
419
486
|
(0, common_1.Injectable)(),
|
|
420
487
|
__metadata("design:paramtypes", [core_1.MongodbService,
|
|
421
488
|
jwt_1.JwtService,
|
|
422
|
-
notifications_service_1.NotificationsService
|
|
489
|
+
notifications_service_1.NotificationsService,
|
|
490
|
+
emailNotification_service_1.EmailNotificationService])
|
|
423
491
|
], RoomsService);
|
|
424
492
|
exports.RoomsService = RoomsService;
|
|
425
493
|
//# sourceMappingURL=rooms.service.js.map
|