From bf52a00304004e22c4172e492c9e1c55743a8364 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Sat, 12 Apr 2025 14:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=85=81=E8=AE=B8=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BB=99=E8=A2=AB=E5=B0=81=E7=A6=81=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 3 +++ .../src/main/java/io/moquette/BrokerConstants.java | 2 ++ .../io/moquette/imhandler/SendMessageHandler.java | 12 +++++++++--- distribution/src/main/resources/wildfirechat.conf | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index c3dacb8d..f35fd231 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -158,6 +158,9 @@ message.forward_with_sender_info false ## 消息转发功能开启时,转发信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息 message.forward_with_target_info false +## 允许发送单聊消息给被封禁用户 +message.allow_send_to_forbidden_user false + ## 机器人回调信息是否带上用户clientId和平台类型。 robot.callback_with_client_info false diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index d0b6390d..10069337 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -168,6 +168,8 @@ public final class BrokerConstants { public static final String BROADCAST_Target_From_User_Table = "message.broadcast.target_from_user_table"; + public static final String MESSAGES_ALLOW_SEND_TO_FORBIDDEN_USER = "message.allow_send_to_forbidden_user"; + public static final String ROBOT_Callback_With_Client_Info = "robot.callback_with_client_info"; public static final String ROBOT_Callback_With_Sender_Info = "robot.callback_with_sender_info"; public static final String ROBOT_Callback_With_Target_Info = "robot.callback_with_target_info"; diff --git a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java index 7db17960..4a65ddc8 100644 --- a/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/SendMessageHandler.java @@ -39,6 +39,7 @@ public class SendMessageHandler extends IMHandler { private int mBlacklistStrategy = 0; //黑名单中时,0失败,1吞掉。 private boolean mBlacklistAllowSend2Black = true; private boolean mNoForwardAdminMessage = false; + private boolean mAllowSend2ForbiddenUser = false; private String mRemoteSensitiveServerUrl = null; private Set mRemoteSensitiveMessageTypes; @@ -101,6 +102,9 @@ public class SendMessageHandler extends IMHandler { Utility.printExecption(LOG, e); } + try { + mAllowSend2ForbiddenUser = Boolean.parseBoolean(mServer.getConfig().getProperty(BrokerConstants.MESSAGES_ALLOW_SEND_TO_FORBIDDEN_USER, "false")); + } catch (Exception e) {} } private void parseTypes(Collection collection, String types) { @@ -170,9 +174,11 @@ public class SendMessageHandler extends IMHandler { } } - userStatus = m_messagesStore.getUserStatus(message.getConversation().getTarget()); - if (userStatus == ProtoConstants.UserStatus.Forbidden) { - return ErrorCode.ERROR_CODE_USER_FORBIDDEN; + if (!mAllowSend2ForbiddenUser) { + userStatus = m_messagesStore.getUserStatus(message.getConversation().getTarget()); + if (userStatus == ProtoConstants.UserStatus.Forbidden) { + return ErrorCode.ERROR_CODE_USER_FORBIDDEN; + } } } diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 52d734c7..2dd1f2ab 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -153,6 +153,9 @@ message.forward_with_sender_info false ## 消息转发功能开启时,转发信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息 message.forward_with_target_info false +## 允许发送单聊消息给被封禁用户 +message.allow_send_to_forbidden_user false + ## 机器人回调信息是否带上用户clientId和平台类型。 robot.callback_with_client_info false