@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.
Files changed (112) hide show
  1. package/dist/emails/UnreadMention.d.ts +9 -0
  2. package/dist/emails/UnreadMention.js +54 -0
  3. package/dist/emails/UnreadMention.js.map +1 -0
  4. package/dist/emails/UnreadReplies.d.ts +9 -0
  5. package/dist/emails/UnreadReplies.js +68 -0
  6. package/dist/emails/UnreadReplies.js.map +1 -0
  7. package/dist/emails/_components/comment.d.ts +1 -0
  8. package/dist/emails/_components/comment.js +32 -0
  9. package/dist/emails/_components/comment.js.map +1 -0
  10. package/dist/emails/_components/header.d.ts +2 -0
  11. package/dist/emails/_components/header.js +15 -0
  12. package/dist/emails/_components/header.js.map +1 -0
  13. package/dist/emails/_components/headline.d.ts +5 -0
  14. package/dist/emails/_components/headline.js +17 -0
  15. package/dist/emails/_components/headline.js.map +1 -0
  16. package/dist/emails/_components/layout.d.ts +5 -0
  17. package/dist/emails/_components/layout.js +24 -0
  18. package/dist/emails/_components/layout.js.map +1 -0
  19. package/dist/emails/_lib/types.d.ts +9 -0
  20. package/dist/emails/_lib/types.js +3 -0
  21. package/dist/emails/_lib/types.js.map +1 -0
  22. package/dist/emails/_styles/colors.d.ts +2 -0
  23. package/dist/emails/_styles/colors.js +7 -0
  24. package/dist/emails/_styles/colors.js.map +1 -0
  25. package/dist/emails/_utils/cn.d.ts +2 -0
  26. package/dist/emails/_utils/cn.js +10 -0
  27. package/dist/emails/_utils/cn.js.map +1 -0
  28. package/dist/emails/_utils/comments.d.ts +7 -0
  29. package/dist/emails/_utils/comments.js +29 -0
  30. package/dist/emails/_utils/comments.js.map +1 -0
  31. package/dist/emails/_utils/getProps.d.ts +1 -0
  32. package/dist/emails/_utils/getProps.js +11 -0
  33. package/dist/emails/_utils/getProps.js.map +1 -0
  34. package/dist/rooms/app.controller.d.ts +3 -1
  35. package/dist/rooms/app.controller.js +61 -46
  36. package/dist/rooms/app.controller.js.map +1 -1
  37. package/dist/rooms/emailNotification.service.d.ts +17 -0
  38. package/dist/rooms/emailNotification.service.js +113 -0
  39. package/dist/rooms/emailNotification.service.js.map +1 -0
  40. package/dist/rooms/emails/comment-body.d.ts +44 -0
  41. package/dist/rooms/emails/comment-body.js +138 -0
  42. package/dist/rooms/emails/comment-body.js.map +1 -0
  43. package/dist/rooms/emails/comment-with-body.d.ts +6 -0
  44. package/dist/rooms/emails/comment-with-body.js +17 -0
  45. package/dist/rooms/emails/comment-with-body.js.map +1 -0
  46. package/dist/rooms/emails/index.d.ts +4 -0
  47. package/dist/rooms/emails/index.js +7 -0
  48. package/dist/rooms/emails/index.js.map +1 -0
  49. package/dist/rooms/emails/lib/batch-users-resolver.d.ts +9 -0
  50. package/dist/rooms/emails/lib/batch-users-resolver.js +67 -0
  51. package/dist/rooms/emails/lib/batch-users-resolver.js.map +1 -0
  52. package/dist/rooms/emails/lib/css-properties.d.ts +3 -0
  53. package/dist/rooms/emails/lib/css-properties.js +96 -0
  54. package/dist/rooms/emails/lib/css-properties.js.map +1 -0
  55. package/dist/rooms/emails/lib/warning.d.ts +1 -0
  56. package/dist/rooms/emails/lib/warning.js +20 -0
  57. package/dist/rooms/emails/lib/warning.js.map +1 -0
  58. package/dist/rooms/emails/thread-notification.d.ts +90 -0
  59. package/dist/rooms/emails/thread-notification.js +297 -0
  60. package/dist/rooms/emails/thread-notification.js.map +1 -0
  61. package/dist/rooms/globals/augmentation.d.ts +0 -5
  62. package/dist/rooms/lib/utils.js +21 -10
  63. package/dist/rooms/lib/utils.js.map +1 -1
  64. package/dist/rooms/liveblocks.service.d.ts +16 -0
  65. package/dist/rooms/liveblocks.service.js +54 -0
  66. package/dist/rooms/liveblocks.service.js.map +1 -0
  67. package/dist/rooms/notifications.service.d.ts +4 -0
  68. package/dist/rooms/notifications.service.js +107 -80
  69. package/dist/rooms/notifications.service.js.map +1 -1
  70. package/dist/rooms/rooms.controller.d.ts +6 -4
  71. package/dist/rooms/rooms.controller.js +323 -244
  72. package/dist/rooms/rooms.controller.js.map +1 -1
  73. package/dist/rooms/rooms.gateway.js +132 -109
  74. package/dist/rooms/rooms.gateway.js.map +1 -1
  75. package/dist/rooms/rooms.guard.js +31 -19
  76. package/dist/rooms/rooms.guard.js.map +1 -1
  77. package/dist/rooms/rooms.module.js +12 -3
  78. package/dist/rooms/rooms.module.js.map +1 -1
  79. package/dist/rooms/rooms.moleculer.js +85 -66
  80. package/dist/rooms/rooms.moleculer.js.map +1 -1
  81. package/dist/rooms/rooms.service.d.ts +17 -4
  82. package/dist/rooms/rooms.service.js +408 -340
  83. package/dist/rooms/rooms.service.js.map +1 -1
  84. package/package.json +18 -6
  85. package/src/emails/UnreadMention.tsx +76 -0
  86. package/src/emails/UnreadReplies.tsx +106 -0
  87. package/src/emails/_components/comment.tsx +70 -0
  88. package/src/emails/_components/header.tsx +27 -0
  89. package/src/emails/_components/headline.tsx +20 -0
  90. package/src/emails/_components/layout.tsx +45 -0
  91. package/src/emails/_lib/types.ts +10 -0
  92. package/src/emails/_styles/colors.ts +7 -0
  93. package/src/emails/_utils/cn.ts +6 -0
  94. package/src/emails/_utils/comments.ts +61 -0
  95. package/src/emails/_utils/getProps.ts +7 -0
  96. package/src/rooms/app.controller.ts +7 -2
  97. package/src/rooms/emailNotification.service.tsx +152 -0
  98. package/src/rooms/emails/comment-body.tsx +342 -0
  99. package/src/rooms/emails/comment-with-body.ts +24 -0
  100. package/src/rooms/emails/index.ts +25 -0
  101. package/src/rooms/emails/lib/batch-users-resolver.ts +120 -0
  102. package/src/rooms/emails/lib/css-properties.ts +123 -0
  103. package/src/rooms/emails/lib/warning.ts +25 -0
  104. package/src/rooms/emails/thread-notification.tsx +583 -0
  105. package/src/rooms/globals/augmentation.ts +8 -8
  106. package/src/rooms/liveblocks.service.ts +25 -0
  107. package/src/rooms/notifications.service.ts +22 -10
  108. package/src/rooms/rooms.controller.ts +24 -5
  109. package/src/rooms/rooms.module.ts +11 -2
  110. package/src/rooms/rooms.service.ts +35 -20
  111. package/tsconfig.json +2 -0
  112. 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
- async getToken({ spaceId, userId, perms, }) {
36
- const payload = {
37
- k: 'acc',
38
- pid: spaceId,
39
- sid: spaceId,
40
- uid: userId,
41
- mcpr: 10,
42
- perms: perms,
43
- jti: 'S4EMiESTDe6k',
44
- };
45
- const token = await this.jwtService.signAsync(payload);
46
- return { token };
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
- async getRoomToken({ roomId, spaceId, userId, readonly = false, }) {
49
- let room = await this.getRoom(roomId);
50
- if (!room) {
51
- room = await this.createRoom({
52
- _id: roomId,
53
- name: 'Room ' + roomId,
54
- });
55
- }
56
- let member = await this.getRoomMember(roomId, userId);
57
- if (!member) {
58
- member = await this.createRoomMember(room, {
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
- async getUsers(userIds) {
85
- if (typeof userIds === 'string') {
86
- userIds = [userIds];
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
- users.push({
94
- name: user ? user.name : 'Unknown',
95
- avatar: '/api/v6/users/' + userId + '/avatar',
96
- });
97
- }
98
- return users;
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
- async searchUsers(spaceId, keyword, roomId) {
101
- const spaceUsers = await this.mongodbService.find('space_users', {
102
- space: spaceId,
103
- $or: [
104
- { username: { $regex: keyword, $options: 'i' } },
105
- { email: { $regex: keyword, $options: 'i' } },
106
- { name: { $regex: keyword, $options: 'i' } },
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
- async getThread(roomId, threadId) {
112
- const thread = await this.mongodbService.findOne('b6_threads', {
113
- roomId: roomId,
114
- _id: threadId,
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
- async getThreads(roomId, since) {
124
- const queryOptions = { roomId: roomId };
125
- if (since) {
126
- queryOptions.updatedAt = { $gt: since };
127
- }
128
- const threads = await this.mongodbService.find('b6_threads', queryOptions);
129
- for (const thread of threads) {
130
- const comments = await this.getComments(roomId, thread.id);
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
- return threads;
140
+ return thread;
141
+ });
134
142
  }
135
- async getThreadsByIds(notifications) {
136
- const threadPromises = [];
137
- for (let i = 0; i < notifications.length; i++) {
138
- const notification = notifications[i];
139
- threadPromises.push(this.getThread(notification.roomId, notification.threadId));
140
- }
141
- if (threadPromises.length > 0) {
142
- return Promise.all(threadPromises);
143
- }
144
- return [];
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
- async getComments(roomId, threadId) {
147
- const comments = await this.mongodbService.find('b6_comments', {
148
- roomId: roomId,
149
- threadId: threadId,
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
- for (const comment of comments) {
152
- comment.attachments = [];
153
- for (const attachmentId of comment.attachmentIds) {
154
- const attachment = await this.getAttachmentById(attachmentId);
155
- comment.attachments.push(attachment);
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
- return comments;
186
+ return comments;
187
+ });
159
188
  }
160
- async createThread({ id, comment, metadata, resolved = false, roomId, userId, }) {
161
- const newThread = {
162
- createdAt: new Date().toISOString(),
163
- updatedAt: new Date().toISOString(),
164
- _id: id,
165
- id,
166
- resolved,
167
- metadata,
168
- type: 'thread',
169
- roomId,
170
- userId,
171
- };
172
- const result = await this.mongodbService.insertOne('b6_threads', newThread);
173
- const newComment = await this.createComment({
174
- id: comment.id,
175
- attachmentIds: comment.attachmentIds,
176
- body: comment.body,
177
- roomId,
178
- threadId: id,
179
- userId,
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
- async updateThread(threadId, thread) {
185
- const newThread = {
186
- updatedAt: new Date().toISOString(),
187
- ...thread,
188
- };
189
- const result = await this.mongodbService.findOneAndUpdate('b6_threads', { _id: threadId }, newThread);
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
- async createComment({ id, attachmentIds, body, roomId, threadId, userId, }) {
193
- const newComment = {
194
- createdAt: new Date().toISOString(),
195
- _id: id,
196
- id,
197
- reactions: [],
198
- roomId,
199
- threadId,
200
- userId,
201
- type: 'comment',
202
- attachmentIds,
203
- body,
204
- };
205
- const result = await this.mongodbService.insertOne('b6_comments', newComment);
206
- result.attachments = [];
207
- for (const attachmentId of attachmentIds) {
208
- const attachment = await this.getAttachmentById(attachmentId);
209
- result.attachments.push(attachment);
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
- if (mentionUsers && mentionUsers.length > 0) {
223
- const uniqUsers = (0, lodash_1.uniq)(mentionUsers);
224
- notificationsPromises = uniqUsers.map((mentionedUserId) => {
225
- const _id = (0, uuid_1.v4)();
226
- return this.notificationsService.createInboxNotification({
227
- _id,
228
- userId: mentionedUserId,
229
- kind: 'thread',
230
- notifiedAt: new Date(),
231
- readAt: null,
232
- roomId,
233
- threadId,
234
- });
235
- });
236
- createRoomMentionPromises = uniqUsers.map((mentionedUserId) => {
237
- return this.notificationsService.createRoomMention({
238
- userId: mentionedUserId,
239
- roomId,
240
- fromUserId: userId,
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
- await Promise.all([].concat(notificationsPromises, createRoomMentionPromises));
244
- }
245
- delete result['_id'];
246
- delete result['attachmentIds'];
247
- return result;
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
- async deleteComment(commentId) {
268
- const result = await this.mongodbService.deleteOne('b6_comments', {
269
- _id: commentId,
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
- async createReaction(commentId, { userId, emoji }) {
274
- const comment = await this.mongodbService.findOne('b6_comments', {
275
- _id: commentId,
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
- if (!comment) {
278
- throw new Error('Comment not found');
279
- }
280
- let reaction = comment.reactions.find((reaction) => reaction.emoji === emoji);
281
- if (reaction) {
282
- const userExists = reaction.users.some((user) => user.id === userId);
283
- if (!userExists) {
284
- reaction.users.push({ id: userId });
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
- else {
288
- reaction = {
339
+ yield this.mongodbService.findOneAndUpdate('b6_comments', { _id: commentId }, comment);
340
+ return {
289
341
  emoji,
290
- createdAt: new Date().toISOString(),
291
- users: [{ id: userId }],
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
- async createRoom({ _id, name, description = '', membershipType = 'standard', members = [], defaultNotifications = ['replies', 'mentions'], defaultScopes = ['room:write'], }) {
319
- const newRoom = {
320
- createdAt: new Date().toISOString(),
321
- updatedAt: new Date().toISOString(),
322
- _id,
323
- name,
324
- description,
325
- membershipType,
326
- defaultNotifications,
327
- defaultScopes,
328
- };
329
- const room = await this.mongodbService.insertOne('b6_rooms', newRoom);
330
- room.members = [];
331
- for (const member of members) {
332
- const newMember = await this.createRoomMember(room, member);
333
- room.members.push(newMember);
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
- async createRoomMember(room, member) {
338
- const { _id, userId, roles = [], notifications = room.defaultNotifications, scopes = room.defaultScopes, } = member;
339
- const newMember = {
340
- _id,
341
- userId,
342
- roles,
343
- roomId: room._id,
344
- notifications,
345
- scopes,
346
- createdAt: new Date().toISOString(),
347
- };
348
- const result = await this.mongodbService.insertOne('b6_room_members', newMember);
349
- return result;
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
- async getRoom(roomId) {
352
- const room = await this.mongodbService.findOne('b6_rooms', {
353
- _id: roomId,
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
- async getRoomMembers(roomId) {
362
- const members = await this.mongodbService.find('b6_room_members', {
363
- roomId,
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
- async getRoomMember(roomId, userId) {
368
- const member = await this.mongodbService.findOne('b6_room_members', {
369
- roomId,
370
- userId,
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
- async getMyRooms(userId) {
375
- const roomMembers = await this.mongodbService.find('b6_room_members', {
376
- userId,
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
- async getRooms(roomIds) {
386
- if (typeof roomIds === 'string') {
387
- roomIds = [roomIds];
388
- }
389
- const result = [];
390
- for (const roomId of roomIds) {
391
- if (roomId &&
392
- roomId.split(':').length === 3 &&
393
- roomId.split(':')[0] === 'objects') {
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
- else {
409
- result.push({
410
- id: roomId,
411
- name: roomId,
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
- return result;
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