Skip to content

Commit

Permalink
解决广播没有发送消息给未登录用户的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrian2012 committed Dec 2, 2023
1 parent 90e8997 commit 594103e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions broker/config/wildfirechat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions broker/src/main/java/io/moquette/BrokerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
11 changes: 7 additions & 4 deletions broker/src/main/java/io/moquette/persistence/DatabaseStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3000,17 +3000,20 @@ List<WFCMessage.User> getAllUsers(int count, int offset) {
return outList;
}

Set<String> getAllEnds() {
Set<String> 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<String> out = new HashSet<>();
while (rs.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ protected boolean removeEldestEntry(Map.Entry<String, Long> eldest) {
private boolean keepDisplayNameWhenDestroyUser = true;
private String mRecallForwardUrl = null;

private boolean mBroadcastTargetFromUserTable = false;

private boolean mForwardMessageWithClientInfo = false;
private boolean mRobotCallbackWithClientInfo = false;
private boolean mChannelCallbackWithClientInfo = false;
Expand Down Expand Up @@ -560,6 +562,13 @@ protected boolean removeEldestEntry(Map.Entry<String, Long> eldest) {
} 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) {
Expand Down Expand Up @@ -748,7 +757,7 @@ public int getNotifyReceivers(String fromUser, WFCMessage.Message.Builder messag

@Override
public Set<String> getAllEnds() {
return databaseStore.getAllEnds();
return databaseStore.getAllEnds(mBroadcastTargetFromUserTable);
}
@Override
public WFCMessage.PullMessageResult fetchMessage(String user, String exceptClientId, long fromMessageId, int pullType) {
Expand Down
3 changes: 3 additions & 0 deletions distribution/src/main/resources/wildfirechat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 594103e

Please sign in to comment.