@builder6/rooms 0.11.1 → 0.11.3
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/README.md +55 -4
- package/dist/rooms/app.controller.d.ts +3 -1
- package/dist/rooms/app.controller.js +14 -7
- package/dist/rooms/app.controller.js.map +1 -1
- package/dist/rooms/dtos/room_members.dto.d.ts +1 -0
- package/dist/rooms/dtos/room_members.dto.js +4 -0
- package/dist/rooms/dtos/room_members.dto.js.map +1 -1
- package/dist/rooms/emailNotification.service.js +3 -3
- package/dist/rooms/emailNotification.service.js.map +1 -1
- package/dist/rooms/rooms.controller.d.ts +1 -1
- package/dist/rooms/rooms.controller.js +4 -5
- package/dist/rooms/rooms.controller.js.map +1 -1
- package/dist/rooms/rooms.service.d.ts +10 -3
- package/dist/rooms/rooms.service.js +49 -31
- package/dist/rooms/rooms.service.js.map +1 -1
- package/package.json +7 -7
- package/src/rooms/app.controller.ts +12 -6
- package/src/rooms/dtos/room_members.dto.ts +3 -0
- package/src/rooms/emailNotification.service.tsx +3 -32
- package/src/rooms/rooms.controller.ts +2 -7
- package/src/rooms/rooms.service.ts +60 -46
- package/yarn-error.log +17218 -0
|
@@ -11,6 +11,7 @@ import { Response } from 'express';
|
|
|
11
11
|
import { ConfigService } from '@nestjs/config';
|
|
12
12
|
import { AuthGuard } from '@builder6/core';
|
|
13
13
|
import { PagesService } from '@builder6/pages';
|
|
14
|
+
import { RoomsService } from './rooms.service';
|
|
14
15
|
|
|
15
16
|
// 兼容 Steedos OpenAPI v1 格式的 api
|
|
16
17
|
@Controller('b6/rooms/')
|
|
@@ -18,6 +19,7 @@ import { PagesService } from '@builder6/pages';
|
|
|
18
19
|
export class RoomsAppController {
|
|
19
20
|
constructor(
|
|
20
21
|
private readonly pagesService: PagesService,
|
|
22
|
+
private readonly roomsService: RoomsService,
|
|
21
23
|
private configService: ConfigService,
|
|
22
24
|
) {}
|
|
23
25
|
|
|
@@ -29,20 +31,24 @@ export class RoomsAppController {
|
|
|
29
31
|
@Res() res: Response,
|
|
30
32
|
) {
|
|
31
33
|
const user = req['user'];
|
|
32
|
-
const
|
|
34
|
+
const room = await this.roomsService.resolveRoomInfo({ roomId });
|
|
35
|
+
const roomName = room?.name || roomId;
|
|
33
36
|
try {
|
|
34
37
|
const schema = {
|
|
35
38
|
type: 'page',
|
|
39
|
+
title: roomName,
|
|
40
|
+
regions: ['body', 'toolbar', 'header'],
|
|
36
41
|
toolbar: [
|
|
37
42
|
{
|
|
38
43
|
type: 'rooms-provider',
|
|
39
44
|
baseUrl: '',
|
|
40
|
-
body:
|
|
41
|
-
|
|
45
|
+
body: {
|
|
46
|
+
type: 'wrapper',
|
|
47
|
+
className: 'p-4',
|
|
48
|
+
body: {
|
|
42
49
|
type: 'rooms-inbox-popover',
|
|
43
|
-
className: 'flex flex-col m-3 gap-3',
|
|
44
50
|
},
|
|
45
|
-
|
|
51
|
+
},
|
|
46
52
|
},
|
|
47
53
|
],
|
|
48
54
|
body: [
|
|
@@ -62,7 +68,7 @@ export class RoomsAppController {
|
|
|
62
68
|
const data = {};
|
|
63
69
|
const env = {
|
|
64
70
|
assetUrls: [
|
|
65
|
-
`https://unpkg.com/@steedos-widgets/liveblocks@6.3.12-beta.
|
|
71
|
+
`https://unpkg.com/@steedos-widgets/liveblocks@6.3.12-beta.6/dist/assets.json`,
|
|
66
72
|
],
|
|
67
73
|
};
|
|
68
74
|
const rendered = await this.pagesService.renderAmis(
|
|
@@ -60,10 +60,10 @@ export class EmailNotificationService {
|
|
|
60
60
|
return await this.roomsService.resolveUsers({ userIds });
|
|
61
61
|
},
|
|
62
62
|
resolveRoomInfo: async ({ roomId }) => {
|
|
63
|
-
const
|
|
64
|
-
|
|
63
|
+
const room = await this.roomsService.resolveRoomInfo({
|
|
64
|
+
roomId,
|
|
65
65
|
});
|
|
66
|
-
return
|
|
66
|
+
return room;
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
69
|
);
|
|
@@ -83,35 +83,6 @@ export class EmailNotificationService {
|
|
|
83
83
|
let email;
|
|
84
84
|
let subject;
|
|
85
85
|
|
|
86
|
-
// switch (emailData.type) {
|
|
87
|
-
// case 'unreadMention': {
|
|
88
|
-
// email = (
|
|
89
|
-
// <div>
|
|
90
|
-
// <div>
|
|
91
|
-
// @{emailData.comment.author.id} at {emailData.comment.createdAt}
|
|
92
|
-
// </div>
|
|
93
|
-
// <div>{emailData.comment.reactBody}</div>
|
|
94
|
-
// </div>
|
|
95
|
-
// );
|
|
96
|
-
// break;
|
|
97
|
-
// }
|
|
98
|
-
|
|
99
|
-
// case 'unreadReplies': {
|
|
100
|
-
// email = (
|
|
101
|
-
// <div>
|
|
102
|
-
// {emailData.comments.map((comment) => (
|
|
103
|
-
// <div key={comment.id}>
|
|
104
|
-
// <div>
|
|
105
|
-
// @{comment.author.id} at {comment.createdAt}
|
|
106
|
-
// </div>
|
|
107
|
-
// <div>{comment.reactBody}</div>
|
|
108
|
-
// </div>
|
|
109
|
-
// ))}
|
|
110
|
-
// </div>
|
|
111
|
-
// );
|
|
112
|
-
// break;
|
|
113
|
-
// }
|
|
114
|
-
// }
|
|
115
86
|
switch (emailData.type) {
|
|
116
87
|
// Handle unread replies use case
|
|
117
88
|
case 'unreadReplies': {
|
|
@@ -68,14 +68,9 @@ export class RoomsController {
|
|
|
68
68
|
async searchUsers(
|
|
69
69
|
@Req() req: Request,
|
|
70
70
|
@Query('keyword') keyword: string,
|
|
71
|
-
@Query('roomdId') roomdId: string,
|
|
72
71
|
) {
|
|
73
72
|
const spaceId = req['jwt'].sid;
|
|
74
|
-
const users = await this.roomsService.searchUsers(
|
|
75
|
-
spaceId,
|
|
76
|
-
keyword,
|
|
77
|
-
roomdId,
|
|
78
|
-
);
|
|
73
|
+
const users = await this.roomsService.searchUsers(spaceId, keyword);
|
|
79
74
|
return users;
|
|
80
75
|
}
|
|
81
76
|
|
|
@@ -85,7 +80,7 @@ export class RoomsController {
|
|
|
85
80
|
if (typeof roomIds === 'string') {
|
|
86
81
|
roomIds = [roomIds];
|
|
87
82
|
}
|
|
88
|
-
const rooms = await this.roomsService.
|
|
83
|
+
const rooms = await this.roomsService.resolveRoomsInfo({ roomIds });
|
|
89
84
|
return rooms;
|
|
90
85
|
}
|
|
91
86
|
|
|
@@ -94,10 +94,14 @@ export class RoomsService {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// 如果当前用户不在 room 中,创建一个 room member
|
|
97
98
|
let member = await this.getRoomMember(roomId, userId);
|
|
98
99
|
if (!member) {
|
|
99
|
-
member = await this.createRoomMember(
|
|
100
|
+
member = await this.createRoomMember({
|
|
100
101
|
userId,
|
|
102
|
+
roomId,
|
|
103
|
+
notifications: room.defaultNotifications,
|
|
104
|
+
scopes: room.defaultScopes,
|
|
101
105
|
});
|
|
102
106
|
}
|
|
103
107
|
|
|
@@ -149,18 +153,21 @@ export class RoomsService {
|
|
|
149
153
|
}
|
|
150
154
|
|
|
151
155
|
// 按照 email, name, username 搜索用户, 返回 userId 数组
|
|
152
|
-
async searchUsers(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const spaceUsers = await this.mongodbService.find('space_users', {
|
|
156
|
+
async searchUsers(spaceId: string, keyword: string): Promise<string[]> {
|
|
157
|
+
if (!keyword) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const query: any = {
|
|
158
161
|
space: spaceId,
|
|
159
162
|
$or: [
|
|
160
163
|
{ username: { $regex: keyword, $options: 'i' } },
|
|
161
164
|
{ email: { $regex: keyword, $options: 'i' } },
|
|
162
165
|
{ name: { $regex: keyword, $options: 'i' } },
|
|
163
166
|
],
|
|
167
|
+
};
|
|
168
|
+
// 最多返回5行
|
|
169
|
+
const spaceUsers = await this.mongodbService.find('space_users', query, {
|
|
170
|
+
limit: 5,
|
|
164
171
|
});
|
|
165
172
|
|
|
166
173
|
return spaceUsers.map((spaceUser) => spaceUser.user as string);
|
|
@@ -537,26 +544,24 @@ export class RoomsService {
|
|
|
537
544
|
// 循环 members,执行 createRoomMember,并保存到 result.members
|
|
538
545
|
room.members = [];
|
|
539
546
|
for (const member of members) {
|
|
540
|
-
const newMember = await this.createRoomMember(
|
|
547
|
+
const newMember = await this.createRoomMember({
|
|
548
|
+
notifications: room.defaultNotifications,
|
|
549
|
+
scopes: room.defaultScopes,
|
|
550
|
+
...member,
|
|
551
|
+
});
|
|
541
552
|
room.members.push(newMember);
|
|
542
553
|
}
|
|
543
554
|
|
|
544
555
|
return room;
|
|
545
556
|
}
|
|
546
557
|
|
|
547
|
-
async createRoomMember(
|
|
548
|
-
const {
|
|
549
|
-
_id,
|
|
550
|
-
userId,
|
|
551
|
-
roles = [],
|
|
552
|
-
notifications = room.defaultNotifications,
|
|
553
|
-
scopes = room.defaultScopes,
|
|
554
|
-
} = member;
|
|
558
|
+
async createRoomMember(member: RoomMemberDTO) {
|
|
559
|
+
const { _id, userId, roomId, roles = [], notifications, scopes } = member;
|
|
555
560
|
const newMember = {
|
|
556
561
|
_id,
|
|
557
562
|
userId,
|
|
558
563
|
roles,
|
|
559
|
-
roomId
|
|
564
|
+
roomId,
|
|
560
565
|
notifications,
|
|
561
566
|
scopes,
|
|
562
567
|
createdAt: new Date().toISOString(),
|
|
@@ -613,40 +618,49 @@ export class RoomsService {
|
|
|
613
618
|
return rooms;
|
|
614
619
|
}
|
|
615
620
|
|
|
616
|
-
async
|
|
621
|
+
async resolveRoomsInfo({ roomIds }: { roomIds: string[] }) {
|
|
617
622
|
const result = [];
|
|
618
623
|
for (const roomId of roomIds) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
624
|
+
const room = await this.resolveRoomInfo({ roomId });
|
|
625
|
+
result.push(room);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return result;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async resolveRoomInfo({ roomId }: { roomId: string }) {
|
|
632
|
+
if (
|
|
633
|
+
roomId &&
|
|
634
|
+
roomId.split(':').length === 3 &&
|
|
635
|
+
roomId.split(':')[0] === 'objects'
|
|
636
|
+
) {
|
|
637
|
+
const [, objectName, recordId] = roomId.split(':');
|
|
638
|
+
const record = await this.mongodbService.findOne(
|
|
639
|
+
objectName,
|
|
640
|
+
{
|
|
641
|
+
_id: recordId,
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
projection: {
|
|
645
|
+
name: 1,
|
|
634
646
|
},
|
|
635
|
-
|
|
647
|
+
},
|
|
648
|
+
);
|
|
636
649
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
650
|
+
return {
|
|
651
|
+
id: roomId,
|
|
652
|
+
name: record ? record.name : roomId,
|
|
653
|
+
url: record
|
|
654
|
+
? `${process.env.B6_ROOT_URL}/app/-/${objectName}/view/${recordId}`
|
|
655
|
+
: null,
|
|
656
|
+
};
|
|
657
|
+
} else {
|
|
658
|
+
return {
|
|
659
|
+
id: roomId,
|
|
660
|
+
name: roomId,
|
|
661
|
+
url: `${process.env.B6_HOST}/b6/rooms/${roomId}`,
|
|
662
|
+
};
|
|
648
663
|
}
|
|
649
|
-
return result;
|
|
650
664
|
}
|
|
651
665
|
|
|
652
666
|
async getInboxNotification({ inboxNotificationId, userId }) {
|