Skip to content

Commit 738eb75

Browse files
committed
feat: add invite code usage limit for every invite code
1 parent 518d12b commit 738eb75

File tree

12 files changed

+344
-18
lines changed

12 files changed

+344
-18
lines changed

client/shared/i18n/langs/en-US/translation.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"k1ea9f5ff": "Verified",
3333
"k206eff71": "Nickname can not be blank",
3434
"k21ee7a1f": "Roles",
35+
"k226a52c3": "Invite settings modified successfully",
3536
"k22856100": "Not found",
3637
"k22ffe5e9": "Allow to manage users",
3738
"k2317a90c": "Clear Inbox",
@@ -41,6 +42,7 @@
4142
"k249e23b9": "E-mail format is incorrect",
4243
"k24ccd723": "Refresh now",
4344
"k250e392c": "System is busy, please try again later",
45+
"k263bff41": "Edit invite link",
4446
"k267cc491": "Me",
4547
"k2a1422d2": "Configuration",
4648
"k2a8031e": "Homepage",
@@ -87,6 +89,7 @@
8789
"k41064134": "DM",
8890
"k416e301a": "An exception occurred, Socket creation failed",
8991
"k419da0ef": "Message explanation",
92+
"k41a0bacf": "12 hours",
9093
"k4231ab36": "Performance statistics",
9194
"k42a98418": "File Service",
9295
"k4539164b": "The OTP code is 6 digits",
@@ -97,8 +100,10 @@
97100
"k48a38bc1": "Group not found",
98101
"k49721de0": "Reset Password",
99102
"k4a573576": "Unable to modify the display name of the Everyone permission group",
103+
"k4c6cd28": "6 hours",
100104
"k4cda3b42": "30 minutes",
101105
"k4d32a754": "Group Name",
106+
"k4e456fee": "50 uses",
102107
"k4f672109": "Failed to load global configuration",
103108
"k4f69cbc9": "Forget Password",
104109
"k50504f9e": "Upload picture to converse",
@@ -156,6 +161,7 @@
156161
"k6fc3abcd": "Enter now",
157162
"k705ca774": "Hide member full name",
158163
"k70751578": "Jump to converse",
164+
"k70b73a14": "1 use",
159165
"k7173d09e": "Account",
160166
"k736edc2f": "Old and new passwords do not match",
161167
"k73d9fc70": "Allow members to view admin channels",
@@ -171,6 +177,7 @@
171177
"k78102887": "Member Count",
172178
"k78e52ed0": "Accept",
173179
"k79304fa9": "Nickname changed successfully",
180+
"k795c9a6e": "5 uses",
174181
"k7a89720": "Open in new window",
175182
"k7c232f9e": "Panel",
176183
"k7cf4e7ff": "Message deleted successfully",
@@ -180,6 +187,7 @@
180187
"k7f0c746d": "Operation successful",
181188
"k7fc7e508": "Dark Mode",
182189
"k814bdc7a": "Is not a valid JSON string",
190+
"k8157b129": "25 uses",
183191
"k81662255": "Create invitation code",
184192
"k821ff85a": "Common",
185193
"k8266bcf2": "New password",
@@ -191,6 +199,7 @@
191199
"k87a609ad": "Please do not install plugins from unknown sources, it may steal your personal information in Tailchat",
192200
"k87dd7754": "Mention (@) your message will appear here",
193201
"k887e1f4b": "Copy plain text succeeded",
202+
"k8990744f": "Maximum number of uses",
194203
"k89df1d1e": "The network is abnormal",
195204
"k8abdba5c": "Has been sent",
196205
"k8acbe00": "Current service available",
@@ -220,6 +229,8 @@
220229
"k9fc409ec": "Install Succeed",
221230
"ka01a00eb": "System language",
222231
"ka0451c97": "Cancel",
232+
"ka0be0bd9": "Allow members to edit invite links",
233+
"ka0ccce44": "100 uses",
223234
"ka29e9508": "Send Image",
224235
"ka2c48894": "Customize your group",
225236
"ka2ed2b61": "Are you sure you want to do this?",
@@ -238,6 +249,7 @@
238249
"ka697d1d8": "Password modify complete",
239250
"ka7907771": "Save Successful",
240251
"ka7ecc377": "Unpin",
252+
"ka820940c": "Never",
241253
"ka9481f95": "Creator",
242254
"kaa040a8e": "Default Group",
243255
"kaa7d786e": "Create Converse",
@@ -254,6 +266,7 @@
254266
"kaf403ef0": "Light Mode",
255267
"kaf51d834": "Reset to default",
256268
"kb030fbd1": "Member List",
269+
"kb0584341": "Usage Count",
257270
"kb07659b0": "Repeat password",
258271
"kb123dbb9": "Your personal unique identifier",
259272
"kb12cc88f": "Unmute",
@@ -279,6 +292,7 @@
279292
"kbef193d": "Invitation link copied to clipboard",
280293
"kbef5b92e": "Copy Link",
281294
"kc14b2ea3": "Back",
295+
"kc161f3a6": "1 hour",
282296
"kc1afdd08": "Don't worry, you can make changes anytime after this",
283297
"kc1bfb977": "Login {{serverName}}",
284298
"kc2d30ab7": "Plugin Name",
@@ -338,6 +352,7 @@
338352
"ke17b2c87": "Do not upload pictures that violate local laws and regulations",
339353
"ke187440d": "Panel type cannot be empty",
340354
"ke2431c67": "Plugin render function does not exist",
355+
"ke3a77a77": "Unlimited",
341356
"ke3d797fd": "Drop files to send into current converse",
342357
"ke59ffe49": "Muted, there are {{remain}} left",
343358
"ke6da074f": "The message was withdrawn successfully",
@@ -395,5 +410,6 @@
395410
"kfc07c0a4": "Here is the beginning of all messages, please feel free to speak up.",
396411
"kfc0ccc0e": "It can be modified at any time in the user settings later",
397412
"kfd340bbc": "Manage members",
398-
"kfe731dfc": "Action"
413+
"kfe731dfc": "Action",
414+
"kfe9c1c6c": "10 uses"
399415
}

client/shared/i18n/langs/zh-CN/translation.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"k1ea9f5ff": "已认证",
3333
"k206eff71": "昵称不能为空",
3434
"k21ee7a1f": "身份组",
35+
"k226a52c3": "邀请设置修改成功",
3536
"k22856100": "未找到",
3637
"k22ffe5e9": "允许管理用户",
3738
"k2317a90c": "清空收件箱",
@@ -41,6 +42,7 @@
4142
"k249e23b9": "邮箱格式不正确",
4243
"k24ccd723": "立即刷新",
4344
"k250e392c": "系统忙, 请稍后再试",
45+
"k263bff41": "编辑邀请链接",
4446
"k267cc491": "",
4547
"k2a1422d2": "配置",
4648
"k2a8031e": "个人主页",
@@ -87,6 +89,7 @@
8789
"k41064134": "私信",
8890
"k416e301a": "出现异常, Socket 创建失败",
8991
"k419da0ef": "消息解释",
92+
"k41a0bacf": "12小时",
9093
"k4231ab36": "性能统计",
9194
"k42a98418": "文件服务",
9295
"k4539164b": "校验码为6位",
@@ -97,8 +100,10 @@
97100
"k48a38bc1": "群组不存在",
98101
"k49721de0": "重设密码",
99102
"k4a573576": "无法修改所有人权限组的显示名称",
103+
"k4c6cd28": "6小时",
100104
"k4cda3b42": "30分钟",
101105
"k4d32a754": "群组名称",
106+
"k4e456fee": "50次使用",
102107
"k4f672109": "全局配置加载失败",
103108
"k4f69cbc9": "忘记密码",
104109
"k50504f9e": "上传图片到会话",
@@ -156,6 +161,7 @@
156161
"k6fc3abcd": "立即进入",
157162
"k705ca774": "隐藏成员完整名称",
158163
"k70751578": "跳转到会话",
164+
"k70b73a14": "1次使用",
159165
"k7173d09e": "账户信息",
160166
"k736edc2f": "新旧密码不匹配",
161167
"k73d9fc70": "允许成员查看管理频道",
@@ -171,6 +177,7 @@
171177
"k78102887": "成员数",
172178
"k78e52ed0": "接受",
173179
"k79304fa9": "修改昵称成功",
180+
"k795c9a6e": "5次使用",
174181
"k7a89720": "在新窗口打开",
175182
"k7c232f9e": "面板",
176183
"k7cf4e7ff": "消息删除成功",
@@ -180,6 +187,7 @@
180187
"k7f0c746d": "操作成功",
181188
"k7fc7e508": "暗黑模式",
182189
"k814bdc7a": "不是一个合法的JSON字符串",
190+
"k8157b129": "25次使用",
183191
"k81662255": "创建邀请码",
184192
"k821ff85a": "通用",
185193
"k8266bcf2": "新密码",
@@ -191,6 +199,7 @@
191199
"k87a609ad": "请不要安装不明来源的插件,这可能会盗取你在 Tailchat 的个人信息",
192200
"k87dd7754": "提及(@)您的消息会在这里出现哦",
193201
"k887e1f4b": "复制纯文本成功",
202+
"k8990744f": "最大使用次数",
194203
"k89df1d1e": "网络出现异常",
195204
"k8abdba5c": "已发送",
196205
"k8acbe00": "当前服务可用",
@@ -220,6 +229,8 @@
220229
"k9fc409ec": "安装成功",
221230
"ka01a00eb": "系统语言",
222231
"ka0451c97": "取消",
232+
"ka0be0bd9": "允许成员编辑邀请链接",
233+
"ka0ccce44": "100次使用",
223234
"ka29e9508": "发送图片",
224235
"ka2c48894": "自定义你的群组",
225236
"ka2ed2b61": "确认要进行该操作么?",
@@ -238,6 +249,7 @@
238249
"ka697d1d8": "密码修改成功",
239250
"ka7907771": "保存成功",
240251
"ka7ecc377": "Unpin",
252+
"ka820940c": "永不",
241253
"ka9481f95": "创建者",
242254
"kaa040a8e": "默认群组",
243255
"kaa7d786e": "创建会话",
@@ -254,6 +266,7 @@
254266
"kaf403ef0": "亮色模式",
255267
"kaf51d834": "重置为默认值",
256268
"kb030fbd1": "成员列表",
269+
"kb0584341": "使用次数",
257270
"kb07659b0": "重复密码",
258271
"kb123dbb9": "您的个人唯一标识",
259272
"kb12cc88f": "取消免打扰",
@@ -279,6 +292,7 @@
279292
"kbef193d": "邀请链接已复制到剪切板",
280293
"kbef5b92e": "复制链接",
281294
"kc14b2ea3": "返回",
295+
"kc161f3a6": "1小时",
282296
"kc1afdd08": "不要担心, 在此之后你可以随时进行变更",
283297
"kc1bfb977": "登录 {{serverName}}",
284298
"kc2d30ab7": "插件名",
@@ -338,6 +352,7 @@
338352
"ke17b2c87": "请勿上传违反当地法律法规的图片",
339353
"ke187440d": "面板类型不能为空",
340354
"ke2431c67": "插件渲染函数不存在",
355+
"ke3a77a77": "无限制",
341356
"ke3d797fd": "拖放文件以发送到当前会话",
342357
"ke59ffe49": "禁言中, 还剩 {{remain}}",
343358
"ke6da074f": "消息撤回成功",
@@ -395,5 +410,6 @@
395410
"kfc07c0a4": "这里是所有消息的开始,请畅所欲言。",
396411
"kfc0ccc0e": "后续在用户设置中可以随时修改",
397412
"kfd340bbc": "管理成员",
398-
"kfe731dfc": "操作"
413+
"kfe731dfc": "操作",
414+
"kfe9c1c6c": "10次使用"
399415
}

client/shared/model/group.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export interface GroupInvite {
9797
groupId: string;
9898
creator: string;
9999
expiredAt?: string;
100+
usage: number;
101+
usageLimit?: number;
100102
}
101103

102104
/**
@@ -267,6 +269,27 @@ export async function createGroupInviteCode(
267269
return data;
268270
}
269271

272+
/**
273+
* 编辑群组邀请链接
274+
* @param groupId 群组ID
275+
* @param code 邀请码
276+
* @param expiredAt 过期时间,是一个时间戳,单位ms,为undefined则为不限制
277+
* @param usageLimit 最大使用次数,为undefined则不限制
278+
*/
279+
export async function editGroupInvite(
280+
groupId: string,
281+
code: string,
282+
expiredAt?: number,
283+
usageLimit?: number
284+
) {
285+
await request.post('/api/group/invite/editGroupInvite', {
286+
groupId,
287+
code,
288+
expiredAt,
289+
usageLimit,
290+
});
291+
}
292+
270293
/**
271294
* 获取群组所有邀请码
272295
* @param groupId 群组ID

client/shared/utils/role-helper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const PERMISSION = {
3838
message: 'core.message',
3939
invite: 'core.invite',
4040
unlimitedInvite: 'core.unlimitedInvite',
41+
editInvite: 'core.editInvite',
4142
groupDetail: 'core.groupDetail',
4243
groupConfig: 'core.groupConfig',
4344
manageUser: 'core.manageUser',
@@ -68,6 +69,13 @@ export const getPermissionList = (): PermissionItemType[] => [
6869
default: false,
6970
required: [PERMISSION.core.invite],
7071
},
72+
{
73+
key: PERMISSION.core.editInvite,
74+
title: t('编辑邀请链接'),
75+
desc: t('允许成员编辑邀请链接'),
76+
default: false,
77+
required: [PERMISSION.core.unlimitedInvite],
78+
},
7179
{
7280
key: PERMISSION.core.groupDetail,
7381
title: t('查看群组详情'),

client/web/src/components/modals/CreateGroupInvite/CreateInviteCode.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { InviteCodeExpiredAt } from '@/components/InviteCodeExpiredAt';
2+
import { closeModal, openModal } from '@/components/Modal';
23
import { generateInviteCodeUrl } from '@/utils/url-helper';
3-
import { Menu, Typography, Dropdown, MenuProps } from 'antd';
4+
import { Menu, Typography, Dropdown, MenuProps, Button } from 'antd';
45
import React, { useState } from 'react';
56
import {
67
useAsyncRequest,
@@ -9,7 +10,10 @@ import {
910
GroupInvite,
1011
PERMISSION,
1112
useHasGroupPermission,
13+
useEvent,
14+
showToasts,
1215
} from 'tailchat-shared';
16+
import { EditGroupInvite } from '../EditGroupInvite';
1317
import styles from './CreateInviteCode.module.less';
1418

1519
enum InviteCodeType {
@@ -38,6 +42,23 @@ export const CreateInviteCode: React.FC<CreateInviteCodeProps> = React.memo(
3842
PERMISSION.core.unlimitedInvite,
3943
]);
4044

45+
const handleEditGroupInvite = useEvent(() => {
46+
if (!createdInvite) {
47+
return;
48+
}
49+
50+
const key = openModal(
51+
<EditGroupInvite
52+
groupId={groupId}
53+
code={createdInvite.code}
54+
onEditSuccess={() => {
55+
showToasts(t('邀请设置修改成功'), 'success');
56+
closeModal(key);
57+
}}
58+
/>
59+
);
60+
});
61+
4162
const menu: MenuProps = {
4263
items: [
4364
{
@@ -62,6 +83,9 @@ export const CreateInviteCode: React.FC<CreateInviteCodeProps> = React.memo(
6283
</Typography.Title>
6384
<p className="text-gray-500 text-sm">
6485
<InviteCodeExpiredAt invite={createdInvite} />
86+
<Button type="link" size="small" onClick={handleEditGroupInvite}>
87+
{t('编辑')}
88+
</Button>
6589
</p>
6690
</div>
6791
) : (

0 commit comments

Comments
 (0)