禁止私聊添加对机器人/管理员/物联网设备的例外

This commit is contained in:
imhao183
2020-01-04 14:35:34 +08:00
committed by heavyrain.lee
parent 1dbf431e4d
commit 41d326d40f
3 changed files with 18 additions and 1 deletions
@@ -191,7 +191,7 @@ public class DatabaseStore {
}
sql += " and _type <> 2"; //can search normal user(0) and robot(1), can not search things
sql += " and _type <> 2"; //can search normal user(0) and robot(1) and admin(100), can not search things
if (searchType == SearchUserType_Name_Mobile || searchType == SearchUserType_Name || searchType == SearchUserType_Mobile) {
sql += " limit 1";
@@ -22,6 +22,7 @@ import cn.wildfirechat.proto.WFCMessage;
import com.google.protobuf.ByteString;
import com.hazelcast.core.*;
import com.hazelcast.util.StringUtil;
import com.xiaoleilu.hutool.system.UserInfo;
import com.xiaoleilu.loServer.model.FriendData;
import cn.wildfirechat.pojos.InputOutputUserBlockStatus;
import cn.wildfirechat.common.ErrorCode;
@@ -1684,6 +1685,20 @@ public class MemoryMessagesStore implements IMessagesStore {
}
if (mDisableStrangerChat) {
//在禁止私聊时,允许机器人,物联网设备及管理员进行私聊。
IMap<String, WFCMessage.User> mUserMap = hzInstance.getMap(USERS);
WFCMessage.User target = mUserMap.get(targetUser);
if (target != null && target.getType() != ProtoConstants.UserType.UserType_Normal) {
return ErrorCode.ERROR_CODE_SUCCESS;
}
target = mUserMap.get(fromUser);
if (target != null && target.getType() != ProtoConstants.UserType.UserType_Normal) {
return ErrorCode.ERROR_CODE_SUCCESS;
}
//admin的usertype为3,所以不需要hardcode为admin添加例外
// if (targetUser.equals("admin") || fromUser.equals("admin")) {
// return ErrorCode.ERROR_CODE_SUCCESS;
// }
return ErrorCode.ERROR_CODE_NOT_RIGHT;
}
@@ -125,6 +125,8 @@ public class ProtoConstants {
int UserType_Normal = 0;
int UserType_Robot = 1;
int UserType_Device = 2;
int UserType_Admin = 3;
int UserType_Super_Admin = 100;
}