Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 6446de9

Browse files
committed
feat: 增加消息撤回限时与相关翻译
1 parent bf0f4e2 commit 6446de9

3 files changed

Lines changed: 27 additions & 0 deletions

File tree

locales/en-US/translation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"k3b4422dc": "This user is not a temporary user",
3+
"k429851b9": "No operation authority",
4+
"k42cdd273": "Username already exists!",
5+
"k45c8d1bf": "Claimed user does not exist",
6+
"k719464e0": "This message has been recall",
7+
"k89bf46fc": "Unable to recall messages from {{minutes}} minutes ago",
8+
"ka8b712f7": "Email already exists!",
29
"kb32d3d62": "Anonymous",
10+
"kb5971793": "Username or email is empty",
11+
"kb8be9969": "Recall failed, no permission",
312
"ke9fabda8": "Token Invalid"
413
}

locales/zh-CN/translation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"k3b4422dc": "该用户不是临时用户",
3+
"k429851b9": "没有操作权限",
4+
"k42cdd273": "用户名已存在!",
5+
"k45c8d1bf": "认领用户不存在",
6+
"k719464e0": "该消息已被撤回",
7+
"k89bf46fc": "无法撤回 {{minutes}} 分钟前的消息",
8+
"ka8b712f7": "邮箱已存在!",
29
"kb32d3d62": "匿名用户",
10+
"kb5971793": "用户名或邮箱为空",
11+
"kb8be9969": "撤回失败, 没有权限",
312
"ke9fabda8": "Token不合规"
413
}

services/chat/message.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import moment from 'moment';
12
import { Types } from 'mongoose';
23
import { NoPermissionError } from '../../lib/errors';
34
import type { TcDbService } from '../../mixins/db.mixin';
@@ -106,6 +107,14 @@ class MessageService extends TcService {
106107
throw new Error(t('该消息已被撤回'));
107108
}
108109

110+
// 消息撤回限时
111+
if (
112+
moment().valueOf() - moment(message.createdAt).valueOf() >
113+
15 * 60 * 1000
114+
) {
115+
throw new Error(t('无法撤回 {{minutes}} 分钟前的消息', { minutes: 15 }));
116+
}
117+
109118
let allowToRecall = false;
110119

111120
//#region 撤回权限检查

0 commit comments

Comments
 (0)