Skip to content

Commit

Permalink
feat(admin): allow to delete private message
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Oct 10, 2023
1 parent d7e8a9d commit 915ed01
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions server/services/core/chat/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,22 +345,27 @@ class MessageService extends TcService {
throw new DataNotFoundError(t('该消息未找到'));
}

const converseId = String(message.converseId);
const groupId = message.groupId;
if (!groupId) {
throw new Error(t('无法删除私人信息'));
}

const [hasPermission] = await call(ctx).checkUserPermissions(
String(groupId),
userId,
[PERMISSION.core.deleteMessage]
);

if (!hasPermission) {
throw new NoPermissionError(t('没有删除权限')); // 仅管理员允许删除
// 私人会话
if (userId !== SYSTEM_USERID) {
// 如果是私人发起的, 则直接抛出异常
throw new Error(t('无法删除私人信息'));
}
} else {
// 群组会话, 进行权限校验
const [hasPermission] = await call(ctx).checkUserPermissions(
String(groupId),
userId,
[PERMISSION.core.deleteMessage]
);

if (!hasPermission) {
throw new NoPermissionError(t('没有删除权限')); // 仅管理员允许删除
}
}

const converseId = String(message.converseId);
await this.adapter.removeById(messageId); // TODO: 考虑是否要改为软删除

this.roomcastNotify(ctx, converseId, 'delete', { converseId, messageId });
Expand Down

0 comments on commit 915ed01

Please sign in to comment.