File tree Expand file tree Collapse file tree 4 files changed +28
-8
lines changed Expand file tree Collapse file tree 4 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 48
48
"kbb1ef795" : " Verification failed, OTP has expired" ,
49
49
"kbb96754b" : " Group OP not allowed to be kicked out" ,
50
50
"kbe05914c" : " {{user}} invited {{others}} to join the session" ,
51
+ "kbf66da60" : " The number of members is abnormal, and the converse cannot be created" ,
51
52
"kc1e668f5" : " Not allowed to kick yourself out" ,
52
53
"kc4b77045" : " {{nickname}} join this group with invite code from {{creator}}" ,
53
54
"kcb07c88f" : " Personal message subscription created, subscribeId: {{subscribeId}}" ,
Original file line number Diff line number Diff line change 48
48
"kbb1ef795" : " 校验失败, OTP已过期" ,
49
49
"kbb96754b" : " 不允许踢出群组OP" ,
50
50
"kbe05914c" : " {{user}} 邀请 {{others}} 加入会话" ,
51
+ "kbf66da60" : " 成员数异常,无法创建会话" ,
51
52
"kc1e668f5" : " 不允许踢出自己" ,
52
53
"kc4b77045" : " {{nickname}} 通过 {{creator}} 的邀请码加入群组" ,
53
54
"kcb07c88f" : " 个人消息订阅已创建, subscribeId: {{subscribeId}}" ,
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import { User } from '../user/user';
16
16
17
17
const converseType = [
18
18
'DM' , // 私信
19
+ 'Multi' , // 多人会话
19
20
'Group' , // 群组
20
21
] as const ;
21
22
@@ -39,7 +40,7 @@ export class Converse extends TimeStamps implements Base {
39
40
enum : converseType ,
40
41
type : ( ) => String ,
41
42
} )
42
- type ! : typeof converseType [ number ] ;
43
+ type ! : ( typeof converseType ) [ number ] ;
43
44
44
45
/**
45
46
* 会话参与者
@@ -58,6 +59,7 @@ export class Converse extends TimeStamps implements Base {
58
59
const converse = await this . findOne ( {
59
60
members : {
60
61
$all : [ ...members ] ,
62
+ $size : members . length ,
61
63
} ,
62
64
} ) ;
63
65
Original file line number Diff line number Diff line change @@ -57,13 +57,29 @@ class ConverseService extends TcService {
57
57
58
58
const participantList = _ . uniq ( [ userId , ...memberIds ] ) ;
59
59
60
- let converse = await this . adapter . model . findConverseWithMembers (
61
- participantList
62
- ) ;
63
- if ( converse === null ) {
64
- // 创建新的会话
65
- converse = await this . adapter . insert ( {
66
- type : 'DM' ,
60
+ if ( participantList . length < 2 ) {
61
+ throw new Error ( t ( '成员数异常,无法创建会话' ) ) ;
62
+ }
63
+
64
+ let converse : ConverseDocument ;
65
+ if ( participantList . length === 2 ) {
66
+ // 私信会话
67
+ converse = await this . adapter . model . findConverseWithMembers (
68
+ participantList
69
+ ) ;
70
+ if ( converse === null ) {
71
+ // 创建新的会话
72
+ converse = await this . adapter . model . create ( {
73
+ type : 'DM' ,
74
+ members : participantList . map ( ( id ) => new Types . ObjectId ( id ) ) ,
75
+ } ) ;
76
+ }
77
+ }
78
+
79
+ if ( participantList . length > 2 ) {
80
+ // 多人会话
81
+ converse = await this . adapter . model . create ( {
82
+ type : 'Multi' ,
67
83
members : participantList . map ( ( id ) => new Types . ObjectId ( id ) ) ,
68
84
} ) ;
69
85
}
You can’t perform that action at this time.
0 commit comments