From 594103e06bded017a424026c8a2ed72407cfddab Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Sat, 2 Dec 2023 23:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=B9=BF=E6=92=AD=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E7=BB=99=E6=9C=AA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 3 +++ broker/src/main/java/io/moquette/BrokerConstants.java | 3 +++ .../java/io/moquette/persistence/DatabaseStore.java | 11 +++++++---- .../io/moquette/persistence/MemoryMessagesStore.java | 11 ++++++++++- distribution/src/main/resources/wildfirechat.conf | 3 +++ 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 95081f84..526b9a30 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -126,6 +126,9 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 ## 离线用户推送过期天数,0是永不过期,建议配置为7天。 message.push_expired_days 7 +## 群发消息(包括server api群发和全局频道群发)时,目标用户是否来自于t_user表。如果使用野火托管用户信息,请设置为true,否则设置为false。 +message.broadcast.target_from_user_table true + ## 消息转发功能开启时,开关是否不转发server api接口消息。 ## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。 message.no_forward_admin_message false diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 630b2f93..f3ac43e6 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -156,6 +156,9 @@ public final class BrokerConstants { public static final String MESSAGE_Push_Expired_Days = "message.push_expired_days"; public static final String MESSAGE_Forward_With_Client_Info = "message.forward_with_client_info"; + + public static final String BROADCAST_Target_From_User_Table = "message.broadcast.target_from_user_table"; + public static final String ROBOT_Callback_With_Client_Info = "robot.callback_with_client_info"; public static final String CHANNEL_Callback_With_Client_Info = "channel.callback_with_client_info"; diff --git a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java index b24fc5b4..ebc50dcf 100644 --- a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java +++ b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java @@ -3000,17 +3000,20 @@ public class DatabaseStore { return outList; } - Set getAllEnds() { + Set getAllEnds(boolean fromUserTable) { Connection connection = null; PreparedStatement statement = null; ResultSet rs = null; try { connection = DBUtil.getConnection(); - String sql = "select distinct(`_uid`) from t_user_session where `_deleted` = 0"; + String sql; + if(fromUserTable) { + sql = "select distinct(`_uid`) from t_user_session"; + } else { + sql = "select distinct(`_uid`) from t_user where `_deleted` = 0 and `_type` <> 1 and `_type` <> 2"; + } statement = connection.prepareStatement(sql); - - rs = statement.executeQuery(); Set out = new HashSet<>(); while (rs.next()) { diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 713d6ba2..60d96175 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -192,6 +192,8 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean keepDisplayNameWhenDestroyUser = true; private String mRecallForwardUrl = null; + private boolean mBroadcastTargetFromUserTable = false; + private boolean mForwardMessageWithClientInfo = false; private boolean mRobotCallbackWithClientInfo = false; private boolean mChannelCallbackWithClientInfo = false; @@ -560,6 +562,13 @@ public class MemoryMessagesStore implements IMessagesStore { } catch (Exception e) { } + + try { + mBroadcastTargetFromUserTable = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.BROADCAST_Target_From_User_Table, "false")); + } catch (Exception e) { + + } + try { mRobotCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Callback_With_Client_Info, "false")); } catch (Exception e) { @@ -748,7 +757,7 @@ public class MemoryMessagesStore implements IMessagesStore { @Override public Set getAllEnds() { - return databaseStore.getAllEnds(); + return databaseStore.getAllEnds(mBroadcastTargetFromUserTable); } @Override public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) { diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index e1f75767..e47d958b 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -124,6 +124,9 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 ## 离线用户推送过期天数,0是永不过期,建议配置为7天。 message.push_expired_days 7 +## 群发消息(包括server api群发和全局频道群发)时,目标用户是否来自于t_user表。如果使用野火托管用户信息,请设置为true,否则设置为false。 +message.broadcast.target_from_user_table true + ## 消息转发功能开启时,开关是否不转发server api接口消息。 ## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。 message.no_forward_admin_message false