diff --git a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java index b165343f..c134ed48 100644 --- a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java +++ b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java @@ -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"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index aa864ebc..a1a04172 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -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 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; } diff --git a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java index c60deaca..7bac27a4 100644 --- a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java +++ b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java @@ -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; }