fix: 修复创建文本频道时无法立即监听会话的bug

pull/49/head
moonrailgun 3 years ago
parent 15a4571a08
commit f2bea54aa3

@ -52,8 +52,16 @@ export class GroupPanel {
@prop() @prop()
parentId?: string; // 父节点id parentId?: string; // 父节点id
/**
* :
* 0
* 1
* 2
*
* Reference: https://discord.com/developers/docs/resources/channel#channel-object-channel-types
*/
@prop() @prop()
type: number; // 面板类型: Reference: https://discord.com/developers/docs/resources/channel#channel-object-channel-types type: number;
@prop() @prop()
provider?: string; // 面板提供者,为插件的标识,仅面板类型为插件时有效 provider?: string; // 面板提供者,为插件的标识,仅面板类型为插件时有效

@ -8,6 +8,15 @@ import {
export function call(ctx: TcContext) { export function call(ctx: TcContext) {
return { return {
/**
* socketio
*/
async joinSocketIORoom(roomIds: string[], userId?: string) {
await ctx.call('gateway.joinRoom', {
roomIds,
userId,
});
},
/** /**
* *
* groupId * groupId
@ -72,7 +81,7 @@ export function call(ctx: TcContext) {
/** /**
* *
*/ */
async getGroupInfo(groupId: string): Promise<GroupStruct> { async getGroupInfo(groupId: string): Promise<GroupStruct | null> {
return await ctx.call('group.getGroupInfo', { return await ctx.call('group.getGroupInfo', {
groupId, groupId,
}); });

@ -70,10 +70,7 @@ class ConverseService extends TcService {
const roomId = String(converse._id); const roomId = String(converse._id);
await Promise.all( await Promise.all(
participantList.map((memberId) => participantList.map((memberId) =>
ctx.call('gateway.joinRoom', { call(ctx).joinSocketIORoom([roomId], memberId)
roomIds: [roomId],
userId: memberId,
})
) )
); );
@ -144,10 +141,7 @@ class ConverseService extends TcService {
await Promise.all( await Promise.all(
memberIds.map((uid) => memberIds.map((uid) =>
ctx.call('gateway.joinRoom', { call(ctx).joinSocketIORoom([String(converseId)], uid)
roomIds: [String(converseId)],
userId: uid,
})
) )
); );
@ -233,9 +227,11 @@ class ConverseService extends TcService {
panelIds: string[]; panelIds: string[];
}>('group.getJoinedGroupAndPanelIds'); }>('group.getJoinedGroupAndPanelIds');
await ctx.call('gateway.joinRoom', { await call(ctx).joinSocketIORoom([
roomIds: [...dmConverseIds, ...groupIds, ...panelIds], ...dmConverseIds,
}); ...groupIds,
...panelIds,
]);
return { return {
dmConverseIds, dmConverseIds,

@ -225,10 +225,10 @@ class GroupService extends TcService {
const textPanelIds = this.getGroupTextPanelIds(group); const textPanelIds = this.getGroupTextPanelIds(group);
await ctx.call('gateway.joinRoom', { await call(ctx).joinSocketIORoom(
roomIds: [String(group._id), ...textPanelIds], [String(group._id), ...textPanelIds],
userId, userId
}); );
return this.transformDocuments(ctx, {}, group); return this.transformDocuments(ctx, {}, group);
} }
@ -411,10 +411,11 @@ class GroupService extends TcService {
this.unicastNotify(ctx, userId, 'add', group); this.unicastNotify(ctx, userId, 'add', group);
const textPanelIds = this.getGroupTextPanelIds(group); const textPanelIds = this.getGroupTextPanelIds(group);
await ctx.call('gateway.joinRoom', {
roomIds: [String(group._id), ...textPanelIds], await call(ctx).joinSocketIORoom(
userId, [String(group._id), ...textPanelIds],
}); userId
);
return group; return group;
} }
@ -591,6 +592,8 @@ class GroupService extends TcService {
throw new NoPermissionError(t('没有操作权限')); throw new NoPermissionError(t('没有操作权限'));
} }
const panelId = String(new Types.ObjectId());
const group = await this.adapter.model const group = await this.adapter.model
.findOneAndUpdate( .findOneAndUpdate(
{ {
@ -599,7 +602,7 @@ class GroupService extends TcService {
{ {
$push: { $push: {
panels: { panels: {
id: String(new Types.ObjectId()), id: panelId,
name, name,
type, type,
parentId, parentId,
@ -615,6 +618,17 @@ class GroupService extends TcService {
) )
.exec(); .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); this.notifyGroupInfoUpdate(ctx, group);
} }

Loading…
Cancel
Save