Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions server/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,24 @@
}
}
},
"/chat.message/getMessage": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"messageId": {
"type": "string"
}
}
}
}
}
}
}
},
"/chat.message/deleteMessage": {
"post": {
"requestBody": {
Expand Down
34 changes: 34 additions & 0 deletions server/services/core/chat/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class MessageService extends TcService {
messageId: 'string',
},
});
this.registerAction('getMessage', this.getMessage, {
params: {
messageId: 'string',
},
});
this.registerAction('deleteMessage', this.deleteMessage, {
params: {
messageId: 'string',
Expand Down Expand Up @@ -332,6 +337,35 @@ class MessageService extends TcService {
return json;
}

/**
* 获取消息
*/
async getMessage(ctx: TcContext<{ messageId: string }>) {
const { messageId } = ctx.params;
const { t, userId } = ctx.meta;
const message = await this.adapter.model.findById(messageId);
if (!message) {
throw new DataNotFoundError(t('该消息未找到'));
}
const converseId = String(message.converseId);
const groupId = message.groupId;
// 鉴权
if (!groupId) {
// 私人会话
const converseInfo = await call(ctx).getConverseInfo(converseId);
if (!converseInfo.members.map((m) => String(m)).includes(userId)) {
throw new NoPermissionError(t('没有当前会话权限'));
}
} else {
// 群组会话
const groupInfo = await call(ctx).getGroupInfo(String(groupId));
if (!groupInfo.members.map((m) => m.userId).includes(userId)) {
throw new NoPermissionError(t('没有当前会话权限'));
}
}
return message;
}

/**
* 删除消息
* 仅支持群组
Expand Down