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/client/shared/model/group.ts

471 lines
8.9 KiB
TypeScript

import { request } from '../api/request';
export enum GroupPanelType {
TEXT = 0,
GROUP = 1,
PLUGIN = 2,
}
export const groupConfigNames = [
// 隐藏群组成员标识位
'hideGroupMemberDiscriminator',
] as const;
export type GroupConfigNames = typeof groupConfigNames[number];
export interface GroupMember {
roles: string[]; // 角色组
userId: string;
/**
* xxx
*/
muteUntil?: string;
}
/**
*
*/
export type GroupPanelFeature =
| 'subscribe' // 订阅事件变更状态用于加入socket.io群组
| 'ack'; // 是否包含已读未读检查,如果包含的话需要同时开启 subscribe 特性
export interface GroupPanel {
/**
*
*/
id: string;
/**
*
*/
name: string;
parentId?: string;
type: GroupPanelType;
provider?: string; // 面板提供者
pluginPanelName?: string; // 插件面板名
meta?: Record<string, unknown>;
}
export interface GroupRole {
_id: string;
/**
*
*/
name: string;
/**
* ,
*/
permissions: string[];
}
export interface GroupInfo {
_id: string;
name: string;
avatar?: string;
owner: string;
members: GroupMember[];
panels: GroupPanel[];
roles: GroupRole[];
config?: Partial<Record<GroupConfigNames, any>>;
/**
*
*
*/
fallbackPermissions: string[];
/**
* Id
*/
pinnedPanelId?: string;
}
/**
* 访
*/
export interface GroupBasicInfo {
name: string;
avatar?: string;
owner: string;
memberCount: number;
}
export interface GroupInvite {
code: string;
groupId: string;
creator: string;
expiredAt?: string;
}
/**
*
*/
export function getGroupConfigWithInfo(
groupInfo: GroupInfo | null | undefined
): {
hideGroupMemberDiscriminator: boolean;
[key: string]: unknown;
} {
const config = groupInfo?.config ?? {};
return {
...config,
hideGroupMemberDiscriminator: config.hideGroupMemberDiscriminator ?? false,
};
}
/**
*
* @param name
* @param panels
*/
export async function createGroup(
name: string,
panels: GroupPanel[]
): Promise<GroupInfo> {
const { data } = await request.post('/api/group/createGroup', {
name,
panels,
});
return data;
}
/**
*
*/
export async function getGroupBasicInfo(
groupId: string
): Promise<GroupBasicInfo | null> {
const { data } = await request.get('/api/group/getGroupBasicInfo', {
params: {
groupId,
},
});
return data;
}
/**
*
* @param groupId ID
* @param fieldName
* @param fieldValue
*/
type AllowedModifyField =
| 'name'
| 'avatar'
| 'panels'
| 'roles'
| 'fallbackPermissions';
export async function modifyGroupField(
groupId: string,
fieldName: AllowedModifyField,
fieldValue: unknown
) {
await request.post('/api/group/updateGroupField', {
groupId,
fieldName,
fieldValue,
});
}
/**
*
* @param groupId ID
* @param configName
* @param configValue
*/
export async function modifyGroupConfig(
groupId: string,
configName: GroupConfigNames,
configValue: unknown
) {
await request.post('/api/group/updateGroupConfig', {
groupId,
configName,
configValue,
});
}
/**
* 退()
* socket退
* @param groupId ID
*/
export async function quitGroup(groupId: string) {
await request.post('/api/group/quitGroup', {
groupId,
});
}
/**
*
* @param groupId ID
*/
export async function isMember(groupId: string): Promise<boolean> {
const { data } = await request.post('/api/group/isMember', {
groupId,
});
return data;
}
/**
*
* @param groupId ID
* @param memberIds
* @param roles
*/
export async function appendGroupMemberRoles(
groupId: string,
memberIds: string[],
roles: string[]
) {
await request.post('/api/group/appendGroupMemberRoles', {
groupId,
memberIds,
roles,
});
}
/**
*
* @param groupId ID
* @param memberIds
* @param roles
*/
export async function removeGroupMemberRoles(
groupId: string,
memberIds: string[],
roles: string[]
) {
await request.post('/api/group/removeGroupMemberRoles', {
groupId,
memberIds,
roles,
});
}
/**
*
* 7
* @param groupId id
*/
export async function createGroupInviteCode(
groupId: string,
inviteType: 'normal' | 'permanent'
): Promise<GroupInvite> {
const { data } = await request.post('/api/group/invite/createGroupInvite', {
groupId,
inviteType,
});
return data;
}
/**
*
* @param groupId ID
*/
export async function getAllGroupInviteCode(
groupId: string
): Promise<GroupInvite[]> {
const { data } = await request.get(
'/api/group/invite/getAllGroupInviteCode',
{
params: {
groupId,
},
}
);
return data;
}
/**
*
* @param inviteCode
*/
export async function findGroupInviteByCode(
inviteCode: string
): Promise<GroupInvite | null> {
const { data } = await request.get('/api/group/invite/findInviteByCode', {
params: {
code: inviteCode,
},
});
return data;
}
/**
* 使
*
*/
export async function applyGroupInvite(inviteCode: string): Promise<void> {
await request.post('/api/group/invite/applyInvite', {
code: inviteCode,
});
}
/**
*
*/
export async function deleteGroupInvite(
groupId: string,
inviteId: string
): Promise<void> {
await request.post('/api/group/invite/deleteInvite', {
groupId,
inviteId,
});
}
/**
*
*/
export async function createGroupPanel(
groupId: string,
options: {
name: string;
type: number;
parentId?: string;
provider?: string;
pluginPanelName?: string;
meta?: Record<string, unknown>;
}
) {
await request.post('/api/group/createGroupPanel', {
...options,
groupId,
});
}
/**
*
*/
export async function modifyGroupPanel(
groupId: string,
panelId: string,
options: {
name: string;
type: number;
parentId?: string;
provider?: string;
pluginPanelName?: string;
meta?: Record<string, unknown>;
}
) {
await request.post('/api/group/modifyGroupPanel', {
...options,
groupId,
panelId,
});
}
/**
*
* @param groupId Id
* @param panelId Id
*/
export async function deleteGroupPanel(groupId: string, panelId: string) {
await request.post('/api/group/deleteGroupPanel', {
groupId,
panelId,
});
}
/**
*
* @param groupId id
* @param roleName
* @param permissions
*/
export async function createGroupRole(
groupId: string,
roleName: string,
permissions: string[]
) {
await request.post('/api/group/createGroupRole', {
groupId,
roleName,
permissions,
});
}
/**
*
* @param groupId Id
* @param roleId Id
*/
export async function deleteGroupRole(groupId: string, roleId: string) {
await request.post('/api/group/deleteGroupRole', {
groupId,
roleId,
});
}
/**
*
* @param groupId Id
* @param roleId Id
* @param roleName
*/
export async function updateGroupRoleName(
groupId: string,
roleId: string,
roleName: string
) {
await request.post('/api/group/updateGroupRoleName', {
groupId,
roleId,
roleName,
});
}
/**
*
* @param groupId Id
* @param roleId Id
* @param permissions
*/
export async function updateGroupRolePermission(
groupId: string,
roleId: string,
permissions: string[]
) {
await request.post('/api/group/updateGroupRolePermission', {
groupId,
roleId,
permissions,
});
}
/**
*
* @param groupId ID
* @param memberId ID
* @param muteMs xxx,
*/
export async function muteGroupMember(
groupId: string,
memberId: string,
muteMs: number
) {
await request.post('/api/group/muteGroupMember', {
groupId,
memberId,
muteMs,
});
}
/**
*
* @param groupId ID
* @param memberId ID
*/
export async function deleteGroupMember(groupId: string, memberId: string) {
await request.post('/api/group/deleteGroupMember', {
groupId,
memberId,
});
}