feat: add feature disableAddFriend which can disable add friends

pull/105/head
moonrailgun 2 years ago
parent 2e489351c1
commit 36061f6b74

@ -45,6 +45,11 @@ export interface GlobalConfig {
*
*/
disablePluginStore?: boolean;
/**
*
*/
disableAddFriend?: boolean;
}
export function getGlobalConfig(): GlobalConfig {

@ -26,4 +26,5 @@ export const defaultGlobalConfig: GlobalConfig = {
disableGuestLogin: false,
disableCreateGroup: false,
disablePluginStore: false,
disableAddFriend: false,
};

@ -1,7 +1,7 @@
import React, { useCallback, useState } from 'react';
import { PillTabPane, PillTabs } from '@/components/PillTabs';
import { AddFriend } from './AddFriend';
import { t, useAppSelector } from 'tailchat-shared';
import { t, useAppSelector, useGlobalConfigStore } from 'tailchat-shared';
import { RequestSend } from './RequestSend';
import { RequestReceived } from './RequestReceived';
import { FriendList } from './FriendList';
@ -14,6 +14,9 @@ export const FriendPanel: React.FC = React.memo(() => {
const friendRequests = useAppSelector((state) => state.user.friendRequests);
const userId = useAppSelector((state) => state.user.info?._id);
const [activeKey, setActiveKey] = useState('1');
const disableAddFriend = useGlobalConfigStore(
(state) => state.disableAddFriend
);
const send = friendRequests.filter((item) => item.from === userId);
const received = friendRequests.filter((item) => item.to === userId);
@ -28,6 +31,9 @@ export const FriendPanel: React.FC = React.memo(() => {
<PillTabPane tab={t('全部')} key="1">
<FriendList onSwitchToAddFriend={handleSwitchToAddFriend} />
</PillTabPane>
{!disableAddFriend && (
<>
<PillTabPane
tab={
<Badge
@ -62,6 +68,8 @@ export const FriendPanel: React.FC = React.memo(() => {
>
<AddFriend />
</PillTabPane>
</>
)}
</PillTabs>
</div>
);

@ -17,7 +17,9 @@
"k429851b9": "No operation authority",
"k42cdd273": "Username already exists!",
"k45c8d1bf": "Claimed user does not exist",
"k493e44f1": "Can't add myself as a friend",
"k4fd701fe": "Email does not exist",
"k5191530a": "Cannot send duplicate friend requests",
"k590cb8b6": "Account does not exist",
"k5f7a33eb": "The server does not allow guests to login",
"k64a3c830": "User does not exist",
@ -32,6 +34,7 @@
"k986040de": "No group found",
"k9891f980": "{{nickname}} joined the group through the public community",
"k996e99cb": "This group is not a public group and cannot be joined directly",
"k9e276b5": "The administrator forbids the function of adding friends",
"ka3eb52f8": "Call ended, duration: {{num}} minutes",
"ka5b432c0": "Too frequent requests can share the same OTP within 10 minutes",
"ka8b712f7": "Email already exists!",
@ -53,6 +56,7 @@
"kd389d15d": "This message was not found",
"kd470bc32": "The robot service of this application has not been activated",
"ke050bc7a": "Username does not exist",
"ke0d53ced": "The other party is already your friend and cannot be added again",
"ke19c80a5": "User has no upload permission",
"ke5849544": "Wrong password",
"ke82b4383": "You cannot send messages because you are banned",

@ -17,7 +17,9 @@
"k429851b9": "没有操作权限",
"k42cdd273": "用户名已存在!",
"k45c8d1bf": "认领用户不存在",
"k493e44f1": "不能添加自己为好友",
"k4fd701fe": "邮箱不存在",
"k5191530a": "不能发送重复的好友请求",
"k590cb8b6": "账号不存在",
"k5f7a33eb": "服务器不允许游客登录",
"k64a3c830": "用户不存在",
@ -32,6 +34,7 @@
"k986040de": "没有找到群组",
"k9891f980": "{{nickname}} 通过公共社区加入群组",
"k996e99cb": "该群组并非公开群组, 无法直接加入",
"k9e276b5": "管理员禁止添加好友功能",
"ka3eb52f8": "通话已结束, 时长: {{num}}分钟",
"ka5b432c0": "过于频繁的请求10 分钟内可以共用同一OTP",
"ka8b712f7": "邮箱已存在!",
@ -53,6 +56,7 @@
"kd389d15d": "该消息未找到",
"kd470bc32": "该应用的机器人服务尚未开通",
"ke050bc7a": "用户名不存在",
"ke0d53ced": "对方已经是您的好友, 不能再次添加",
"ke19c80a5": "用户无上传权限",
"ke5849544": "密码错误",
"ke82b4383": "您因为被禁言无法发送消息",

@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/msgbyte/tailchat-server.git"
"url": "git+https://github.com/msgbyte/tailchat.git"
},
"keywords": [
"msgbyte",
@ -25,9 +25,9 @@
"author": "moonrailgun <moonrailgun@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/msgbyte/tailchat-server/issues"
"url": "https://github.com/msgbyte/tailchat/issues"
},
"homepage": "https://github.com/msgbyte/tailchat-server#readme",
"homepage": "https://github.com/msgbyte/tailchat#readme",
"devDependencies": {
"@types/jest": "^29.5.1",
"typescript": "^4.3.3"

@ -51,7 +51,8 @@ export const config = {
disableUserRegister: checkEnvTrusty(process.env.DISABLE_USER_REGISTER), // 是否关闭用户注册功能
disableGuestLogin: checkEnvTrusty(process.env.DISABLE_GUEST_LOGIN), // 是否关闭用户游客登录功能
disableCreateGroup: checkEnvTrusty(process.env.DISABLE_CREATE_GROUP), // 是否禁用用户创建群组功能
disablePluginStore: checkEnvTrusty(process.env.DISABLE_PLUGIN_STORE), // 是否禁用用户用户插件中心功能
disablePluginStore: checkEnvTrusty(process.env.DISABLE_PLUGIN_STORE), // 是否禁用用户插件中心功能
disableAddFriend: checkEnvTrusty(process.env.DISABLE_ADD_FRIEND), // 是否禁用用户添加好友功能
},
};

@ -184,7 +184,6 @@ class MessageService extends TcService {
const member = groupInfo.members.find((m) => String(m.userId) === userId);
if (member) {
// 因为有机器人,所以如果没有在成员列表中找到不报错
if (new Date(member.muteUntil).valueOf() > new Date().valueOf()) {
throw new Error(t('您因为被禁言无法发送消息'));
}

@ -83,6 +83,7 @@ class ConfigService extends TcService {
disableGuestLogin: config.feature.disableGuestLogin,
disableCreateGroup: config.feature.disableCreateGroup,
disablePluginStore: config.feature.disablePluginStore,
disableAddFriend: config.feature.disableAddFriend,
...persistConfig,
};
}

@ -5,6 +5,7 @@ import {
Errors,
DataNotFoundError,
NoPermissionError,
config,
} from 'tailchat-server-sdk';
import _ from 'lodash';
import type { FriendRequest } from '../../../models/user/friendRequest';
@ -47,11 +48,16 @@ class FriendService extends TcService {
*/
async add(ctx: TcContext<{ to: string; message?: string }>) {
const from = ctx.meta.userId;
const t = ctx.meta.t;
const { to, message } = ctx.params;
if (config.feature.disableAddFriend === true) {
throw new NoPermissionError(t('管理员禁止添加好友功能'));
}
if (from === to) {
throw new Errors.ValidationError('不能添加自己为好友');
throw new Errors.ValidationError(t('不能添加自己为好友'));
}
const exist = await this.adapter.findOne({
@ -59,12 +65,12 @@ class FriendService extends TcService {
to,
});
if (exist) {
throw new Errors.MoleculerError('不能发送重复的好友请求');
throw new Errors.MoleculerError(t('不能发送重复的好友请求'));
}
const isFriend = await ctx.call('friend.checkIsFriend', { targetId: to });
if (isFriend) {
throw new Error('对方已经是您的好友, 不能再次添加');
throw new Error(t('对方已经是您的好友, 不能再次添加'));
}
const doc = await this.adapter.insert({

Loading…
Cancel
Save