diff --git a/server/models/group/group.ts b/server/models/group/group.ts index d3f475aa..e2968658 100644 --- a/server/models/group/group.ts +++ b/server/models/group/group.ts @@ -52,8 +52,16 @@ export class GroupPanel { @prop() parentId?: string; // 父节点id + /** + * 面板类型: + * 0 文本频道 + * 1 面板分组 + * 2 插件 + * + * Reference: https://discord.com/developers/docs/resources/channel#channel-object-channel-types + */ @prop() - type: number; // 面板类型: Reference: https://discord.com/developers/docs/resources/channel#channel-object-channel-types + type: number; @prop() provider?: string; // 面板提供者,为插件的标识,仅面板类型为插件时有效 diff --git a/server/packages/sdk/src/services/lib/call.ts b/server/packages/sdk/src/services/lib/call.ts index a989747f..5e0467bd 100644 --- a/server/packages/sdk/src/services/lib/call.ts +++ b/server/packages/sdk/src/services/lib/call.ts @@ -8,6 +8,15 @@ import { export function call(ctx: TcContext) { return { + /** + * 加入socketio房间 + */ + async joinSocketIORoom(roomIds: string[], userId?: string) { + await ctx.call('gateway.joinRoom', { + roomIds, + userId, + }); + }, /** * 发送系统消息 * 如果为群组消息则需要增加groupId @@ -72,7 +81,7 @@ export function call(ctx: TcContext) { /** * 获取群组信息 */ - async getGroupInfo(groupId: string): Promise { + async getGroupInfo(groupId: string): Promise { return await ctx.call('group.getGroupInfo', { groupId, }); diff --git a/server/services/core/chat/converse.service.ts b/server/services/core/chat/converse.service.ts index f9fc3cb8..3f16828d 100644 --- a/server/services/core/chat/converse.service.ts +++ b/server/services/core/chat/converse.service.ts @@ -70,10 +70,7 @@ class ConverseService extends TcService { const roomId = String(converse._id); await Promise.all( participantList.map((memberId) => - ctx.call('gateway.joinRoom', { - roomIds: [roomId], - userId: memberId, - }) + call(ctx).joinSocketIORoom([roomId], memberId) ) ); @@ -144,10 +141,7 @@ class ConverseService extends TcService { await Promise.all( memberIds.map((uid) => - ctx.call('gateway.joinRoom', { - roomIds: [String(converseId)], - userId: uid, - }) + call(ctx).joinSocketIORoom([String(converseId)], uid) ) ); @@ -233,9 +227,11 @@ class ConverseService extends TcService { panelIds: string[]; }>('group.getJoinedGroupAndPanelIds'); - await ctx.call('gateway.joinRoom', { - roomIds: [...dmConverseIds, ...groupIds, ...panelIds], - }); + await call(ctx).joinSocketIORoom([ + ...dmConverseIds, + ...groupIds, + ...panelIds, + ]); return { dmConverseIds, diff --git a/server/services/core/group/group.service.ts b/server/services/core/group/group.service.ts index 36426ac0..f7d96be4 100644 --- a/server/services/core/group/group.service.ts +++ b/server/services/core/group/group.service.ts @@ -225,10 +225,10 @@ class GroupService extends TcService { const textPanelIds = this.getGroupTextPanelIds(group); - await ctx.call('gateway.joinRoom', { - roomIds: [String(group._id), ...textPanelIds], - userId, - }); + await call(ctx).joinSocketIORoom( + [String(group._id), ...textPanelIds], + userId + ); return this.transformDocuments(ctx, {}, group); } @@ -411,10 +411,11 @@ class GroupService extends TcService { this.unicastNotify(ctx, userId, 'add', group); const textPanelIds = this.getGroupTextPanelIds(group); - await ctx.call('gateway.joinRoom', { - roomIds: [String(group._id), ...textPanelIds], - userId, - }); + + await call(ctx).joinSocketIORoom( + [String(group._id), ...textPanelIds], + userId + ); return group; } @@ -591,6 +592,8 @@ class GroupService extends TcService { throw new NoPermissionError(t('没有操作权限')); } + const panelId = String(new Types.ObjectId()); + const group = await this.adapter.model .findOneAndUpdate( { @@ -599,7 +602,7 @@ class GroupService extends TcService { { $push: { panels: { - id: String(new Types.ObjectId()), + id: panelId, name, type, parentId, @@ -615,6 +618,17 @@ class GroupService extends TcService { ) .exec(); + if (type === 0) { + /** + * 如果为文本面板 + * 则所有群组成员加入房间 + */ + const groupInfo = await call(ctx).getGroupInfo(groupId); + (groupInfo?.members ?? []).map((m) => + call(ctx).joinSocketIORoom([panelId], m.userId) + ); + } + this.notifyGroupInfoUpdate(ctx, group); }