Skip to content

Commit

Permalink
feat: add chat.message.getMessage api (#227)
Browse files Browse the repository at this point in the history
* 添加api: getMessage

* 更改异常信息、检查消息是否存在
  • Loading branch information
eya46 authored May 9, 2024
1 parent 8fbc090 commit 34a380e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
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

0 comments on commit 34a380e

Please sign in to comment.