You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/server/services/core/group/preview.service.ts

79 lines
1.8 KiB
TypeScript

import { TcService, TcContext, call } from 'tailchat-server-sdk';
class GroupPreviewService extends TcService {
get serviceName(): string {
return 'group.preview';
}
onInit(): void {
/**
* TODO: 这里的action都应当判断一下群组是否支持预览
*/
this.registerAction('joinGroupRooms', this.joinGroupRooms, {
params: {
groupId: 'string',
},
});
this.registerAction('leaveGroupRooms', this.leaveGroupRooms, {
params: {
groupId: 'string',
},
});
this.registerAction('getGroupInfo', this.getGroupInfo, {
params: {
groupId: 'string',
},
});
}
async joinGroupRooms(ctx: TcContext<{ groupId: string }>) {
const groupId = ctx.params.groupId;
const { textPanelIds, subscribeFeaturePanelIds } = await ctx.call<
{
textPanelIds: string[];
subscribeFeaturePanelIds: string[];
},
{ groupId: string }
>('group.getGroupSocketRooms', {
groupId,
});
await call(ctx).joinSocketIORoom([
groupId,
...textPanelIds,
...subscribeFeaturePanelIds,
]);
}
async leaveGroupRooms(ctx: TcContext<{ groupId: string }>) {
const groupId = ctx.params.groupId;
const { textPanelIds, subscribeFeaturePanelIds } = await ctx.call<
{
textPanelIds: string[];
subscribeFeaturePanelIds: string[];
},
{ groupId: string }
>('group.getGroupSocketRooms', {
groupId,
});
await call(ctx).leaveSocketIORoom([
groupId,
...textPanelIds,
...subscribeFeaturePanelIds,
]);
}
async getGroupInfo(ctx: TcContext<{ groupId: string }>) {
const groupId = ctx.params.groupId;
const groupInfo = await call(ctx).getGroupInfo(groupId);
return groupInfo;
}
}
export default GroupPreviewService;