@builder6/rooms 0.10.8 → 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 +5 -3
  71. package/dist/rooms/rooms.controller.js +321 -243
  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 +10 -1
  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 -7
  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 +22 -4
  109. package/src/rooms/rooms.module.ts +10 -1
  110. package/src/rooms/rooms.service.ts +35 -20
  111. package/tsconfig.json +2 -0
  112. package/yarn-error.log +17218 -0
@@ -2,6 +2,7 @@ import { AuthGuard } from '@builder6/core';
2
2
  import { FilesService } from '@builder6/files';
3
3
  import { RoomsService } from './rooms.service';
4
4
  import { omit, uniqBy } from 'lodash';
5
+ import { ApiBody } from '@nestjs/swagger';
5
6
  import {
6
7
  Controller,
7
8
  Get,
@@ -22,8 +23,8 @@ import * as rawBody from 'raw-body';
22
23
  import { Request } from 'express';
23
24
  import { RoomsGateway } from './rooms.gateway';
24
25
  import { ServerMsgCode } from './protocol/ServerMsg';
25
- import { READ_ACCESS } from './dtos/rooms.dto';
26
26
  import { NotificationsService } from './notifications.service';
27
+ import { EmailNotificationService } from './emailNotification.service';
27
28
 
28
29
  @Controller('v2/c/')
29
30
  export class RoomsController {
@@ -33,6 +34,7 @@ export class RoomsController {
33
34
  private jwtService: JwtService,
34
35
  private roomsGateway: RoomsGateway,
35
36
  private notificationsService: NotificationsService,
37
+ private emailNotificationService: EmailNotificationService,
36
38
  ) {}
37
39
 
38
40
  @UseGuards(AuthGuard)
@@ -54,7 +56,10 @@ export class RoomsController {
54
56
  @UseGuards(RoomsGuard)
55
57
  @Get('users')
56
58
  async getUsers(@Query('userIds') userIds: string | string[]) {
57
- const users = await this.roomsService.getUsers(userIds);
59
+ if (typeof userIds === 'string') {
60
+ userIds = [userIds];
61
+ }
62
+ const users = await this.roomsService.resolveUsers({ userIds });
58
63
  return users;
59
64
  }
60
65
 
@@ -77,7 +82,10 @@ export class RoomsController {
77
82
  @UseGuards(RoomsGuard)
78
83
  @Get('rooms')
79
84
  async getRooms(@Query('roomIds') roomIds: string | string[]) {
80
- const rooms = await this.roomsService.getRooms(roomIds);
85
+ if (typeof roomIds === 'string') {
86
+ roomIds = [roomIds];
87
+ }
88
+ const rooms = await this.roomsService.resolveRoomInfo({ roomIds });
81
89
  return rooms;
82
90
  }
83
91
 
@@ -176,7 +184,7 @@ export class RoomsController {
176
184
  @Param('roomId') roomId: string,
177
185
  @Param('threadId') threadId: string,
178
186
  ) {
179
- const thread = await this.roomsService.getThread(roomId, threadId);
187
+ const thread = await this.roomsService.getThread({ roomId, threadId });
180
188
  const inboxNotifications =
181
189
  await this.notificationsService.findNotifications({
182
190
  userId: req['jwt'].uid,
@@ -519,4 +527,14 @@ export class RoomsController {
519
527
  });
520
528
  return {};
521
529
  }
530
+
531
+ @Post('email')
532
+ @ApiBody({
533
+ schema: {
534
+ type: 'object',
535
+ },
536
+ })
537
+ async sendEmail(@Body() body: object) {
538
+ this.emailNotificationService.sendThreadNotificationEmail(body as any);
539
+ }
522
540
  }
@@ -10,12 +10,15 @@ import { PagesModule } from '@builder6/pages';
10
10
  import { NotificationsService } from './notifications.service';
11
11
  import { RoomsAppController } from './app.controller';
12
12
  import { RoomsMoleculer } from './rooms.moleculer';
13
+ import { EmailNotificationService } from './emailNotification.service';
14
+ import { EmailModule } from '@builder6/email';
13
15
 
14
16
  /* 按照 liveblocks.io 规范实现的API */
15
17
  @Module({
16
18
  imports: [
17
19
  AuthModule,
18
20
  MongodbModule,
21
+ EmailModule,
19
22
  FilesModule,
20
23
  PagesModule,
21
24
  JwtModule.register({
@@ -24,6 +27,12 @@ import { RoomsMoleculer } from './rooms.moleculer';
24
27
  }),
25
28
  ],
26
29
  controllers: [RoomsAppController, RoomsController],
27
- providers: [RoomsService, RoomsGateway, NotificationsService, RoomsMoleculer],
30
+ providers: [
31
+ RoomsService,
32
+ RoomsGateway,
33
+ NotificationsService,
34
+ EmailNotificationService,
35
+ RoomsMoleculer,
36
+ ],
28
37
  })
29
38
  export class RoomsModule {}
@@ -7,6 +7,7 @@ import { uniq } from 'lodash';
7
7
  import { NotificationsService } from './notifications.service';
8
8
  import { v4 as uuidv4 } from 'uuid';
9
9
  import { CommentBody, CommentBodyMention } from './protocol/Comments';
10
+ import { EmailNotificationService } from './emailNotification.service';
10
11
 
11
12
  export interface CreateThreadParams {
12
13
  id?: string;
@@ -49,6 +50,7 @@ export class RoomsService {
49
50
  private mongodbService: MongodbService,
50
51
  private jwtService: JwtService,
51
52
  private notificationsService: NotificationsService,
53
+ private emailNotificationService: EmailNotificationService,
52
54
  ) {}
53
55
 
54
56
  async getToken({
@@ -115,7 +117,6 @@ export class RoomsService {
115
117
  async getAttachmentById(attachmentId: string): Promise<Attachment> {
116
118
  // 模拟从数据库获取附件
117
119
  // 实际实现中应替换为数据库查询
118
-
119
120
  const attachment = await this.mongodbService.findOne(
120
121
  'cfs.files.filerecord',
121
122
  {
@@ -131,10 +132,7 @@ export class RoomsService {
131
132
  };
132
133
  }
133
134
 
134
- async getUsers(userIds: string | string[]) {
135
- if (typeof userIds === 'string') {
136
- userIds = [userIds];
137
- }
135
+ async resolveUsers({ userIds }: { userIds: string[] }) {
138
136
  const users = [];
139
137
 
140
138
  for (const userId of userIds) {
@@ -143,7 +141,7 @@ export class RoomsService {
143
141
  });
144
142
  users.push({
145
143
  name: user ? user.name : 'Unknown',
146
- avatar: '/api/v6/users/' + userId + '/avatar',
144
+ avatar: `${process.env.B6_HOST}/api/v6/users/${userId}/avatar`,
147
145
  });
148
146
  }
149
147
 
@@ -168,7 +166,7 @@ export class RoomsService {
168
166
  return spaceUsers.map((spaceUser) => spaceUser.user as string);
169
167
  }
170
168
 
171
- async getThread(roomId: string, threadId: string) {
169
+ async getThread({ roomId, threadId }: { roomId: string; threadId: string }) {
172
170
  const thread = await this.mongodbService.findOne('b6_threads', {
173
171
  roomId: roomId,
174
172
  _id: threadId,
@@ -212,7 +210,10 @@ export class RoomsService {
212
210
  for (let i = 0; i < notifications.length; i++) {
213
211
  const notification = notifications[i];
214
212
  threadPromises.push(
215
- this.getThread(notification.roomId, notification.threadId),
213
+ this.getThread({
214
+ roomId: notification.roomId,
215
+ threadId: notification.threadId,
216
+ }),
216
217
  );
217
218
  }
218
219
  if (threadPromises.length > 0) {
@@ -336,16 +337,25 @@ export class RoomsService {
336
337
  }
337
338
  if (mentionUsers && mentionUsers.length > 0) {
338
339
  const uniqUsers = uniq(mentionUsers);
339
- notificationsPromises = uniqUsers.map((mentionedUserId) => {
340
+ notificationsPromises = uniqUsers.map(async (mentionedUserId) => {
340
341
  const _id = uuidv4();
341
- return this.notificationsService.createInboxNotification({
342
- _id,
343
- userId: mentionedUserId,
344
- kind: 'thread',
345
- notifiedAt: new Date(),
346
- readAt: null,
342
+ const notification =
343
+ await this.notificationsService.createInboxNotification({
344
+ _id,
345
+ userId: mentionedUserId,
346
+ kind: 'thread',
347
+ notifiedAt: new Date(),
348
+ readAt: null,
349
+ roomId,
350
+ threadId,
351
+ });
352
+
353
+ await this.emailNotificationService.sendThreadNotificationEmail({
347
354
  roomId,
348
355
  threadId,
356
+ userId: mentionedUserId,
357
+ fromUserId: userId,
358
+ inboxNotificationId: notification._id,
349
359
  });
350
360
  });
351
361
  createRoomMentionPromises = uniqUsers.map((mentionedUserId) => {
@@ -603,10 +613,7 @@ export class RoomsService {
603
613
  return rooms;
604
614
  }
605
615
 
606
- async getRooms(roomIds: string[] | string) {
607
- if (typeof roomIds === 'string') {
608
- roomIds = [roomIds];
609
- }
616
+ async resolveRoomInfo({ roomIds }: { roomIds: string[] }) {
610
617
  const result = [];
611
618
  for (const roomId of roomIds) {
612
619
  if (
@@ -630,7 +637,7 @@ export class RoomsService {
630
637
  result.push({
631
638
  id: roomId,
632
639
  name: record ? record.name : roomId,
633
- url: record ? `/b6/steedos/${objectName}/${recordId}` : null,
640
+ url: record ? `${process.env.B6_HOST}/b6/rooms/${roomId}` : null,
634
641
  });
635
642
  } else {
636
643
  result.push({
@@ -641,4 +648,12 @@ export class RoomsService {
641
648
  }
642
649
  return result;
643
650
  }
651
+
652
+ async getInboxNotification({ inboxNotificationId, userId }) {
653
+ const notification = await this.notificationsService.getInboxNotification({
654
+ inboxNotificationId,
655
+ userId,
656
+ });
657
+ return notification;
658
+ }
644
659
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
+ "jsx": "react",
5
+ "target": "es6",
4
6
  "outDir": "./dist",
5
7
  "rootDir": "./src"
6
8
  },