feat: add message.searchMessage api

pull/147/merge
moonrailgun 1 year ago
parent b3015401b2
commit 235389b394

@ -13,6 +13,7 @@
"k313eb9b3": "User does not exist, please check your username",
"k3b35c0b0": "No permission to create invitation codes",
"k3b4422dc": "This user is not a temporary user",
"k3b44c0a": "Messages cannot be searched if you are not a member of the group",
"k3d0d56b": "Invalid group invitation: group id is empty",
"k4241451e": "Not member of this group",
"k429851b9": "No operation authority",

@ -13,6 +13,7 @@
"k313eb9b3": "用户不存在, 请检查您的用户名",
"k3b35c0b0": "没有创建邀请码权限",
"k3b4422dc": "该用户不是临时用户",
"k3b44c0a": "不是群组成员无法搜索消息",
"k3d0d56b": "群组邀请失效: 群组id为空",
"k4241451e": "不是该群组成员",
"k429851b9": "没有操作权限",

@ -64,6 +64,13 @@ class MessageService extends TcService {
messageId: 'string',
},
});
this.registerAction('searchMessage', this.searchMessage, {
params: {
groupId: { type: 'string', optional: true },
converseId: 'string',
text: 'string',
},
});
this.registerAction(
'fetchConverseLastMessages',
this.fetchConverseLastMessages,
@ -368,6 +375,38 @@ class MessageService extends TcService {
return true;
}
/**
*
*/
async searchMessage(
ctx: TcContext<{ groupId?: string; converseId: string; text: string }>
) {
const { groupId, converseId, text } = ctx.params;
const userId = ctx.meta.userId;
const t = ctx.meta.t;
if (groupId) {
const groupInfo = await call(ctx).getGroupInfo(groupId);
if (!groupInfo.members.map((m) => m.userId).includes(userId)) {
throw new Error(t('不是群组成员无法搜索消息'));
}
}
const messages = this.adapter.model
.find({
groupId: groupId ?? null,
converseId,
content: {
$regex: text,
},
})
.sort({ _id: -1 })
.limit(10)
.maxTimeMS(5 * 1000); // 超过5s的查询直接放弃
return messages;
}
/**
* idid
*/

Loading…
Cancel
Save