feat: add the multi converse strategy, create a multi converse without reusing past converse

feat/group-preview
moonrailgun 2 years ago
parent f6c2f6fced
commit edc076f430

@ -48,6 +48,7 @@
"kbb1ef795": "Verification failed, OTP has expired",
"kbb96754b": "Group OP not allowed to be kicked out",
"kbe05914c": "{{user}} invited {{others}} to join the session",
"kbf66da60": "The number of members is abnormal, and the converse cannot be created",
"kc1e668f5": "Not allowed to kick yourself out",
"kc4b77045": "{{nickname}} join this group with invite code from {{creator}}",
"kcb07c88f": "Personal message subscription created, subscribeId: {{subscribeId}}",

@ -48,6 +48,7 @@
"kbb1ef795": "校验失败, OTP已过期",
"kbb96754b": "不允许踢出群组OP",
"kbe05914c": "{{user}} 邀请 {{others}} 加入会话",
"kbf66da60": "成员数异常,无法创建会话",
"kc1e668f5": "不允许踢出自己",
"kc4b77045": "{{nickname}} 通过 {{creator}} 的邀请码加入群组",
"kcb07c88f": "个人消息订阅已创建, subscribeId: {{subscribeId}}",

@ -16,6 +16,7 @@ import { User } from '../user/user';
const converseType = [
'DM', // 私信
'Multi', // 多人会话
'Group', // 群组
] as const;
@ -39,7 +40,7 @@ export class Converse extends TimeStamps implements Base {
enum: converseType,
type: () => String,
})
type!: typeof converseType[number];
type!: (typeof converseType)[number];
/**
*
@ -58,6 +59,7 @@ export class Converse extends TimeStamps implements Base {
const converse = await this.findOne({
members: {
$all: [...members],
$size: members.length,
},
});

@ -57,13 +57,29 @@ class ConverseService extends TcService {
const participantList = _.uniq([userId, ...memberIds]);
let converse = await this.adapter.model.findConverseWithMembers(
participantList
);
if (converse === null) {
// 创建新的会话
converse = await this.adapter.insert({
type: 'DM',
if (participantList.length < 2) {
throw new Error(t('成员数异常,无法创建会话'));
}
let converse: ConverseDocument;
if (participantList.length === 2) {
// 私信会话
converse = await this.adapter.model.findConverseWithMembers(
participantList
);
if (converse === null) {
// 创建新的会话
converse = await this.adapter.model.create({
type: 'DM',
members: participantList.map((id) => new Types.ObjectId(id)),
});
}
}
if (participantList.length > 2) {
// 多人会话
converse = await this.adapter.model.create({
type: 'Multi',
members: participantList.map((id) => new Types.ObjectId(id)),
});
}

Loading…
Cancel
Save