diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 032e5627..1b593161 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -148,6 +148,10 @@ robot.callback_with_client_info false ## 频道回调信息是否带上用户clientId和平台类型。 channel.callback_with_client_info false +## 频道回调新方式,在新方式下,如果有callback地址就会总是回调客户端发送的消息(包括owner和订阅者)。automatic属性控制订阅者发送的消息是否发给owner, 0发,1不发。 +## 旧的方式是,automatic为0时,订阅者的消息发给owner,不转发消息到callback地址。为1时,把订阅者的消息转发给callback地址,不发给owner。 +channel.new_callback_feature true + ##禁止搜索用户 friend.disable_search false diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 9f4a302b..fb8b0cd7 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -163,6 +163,8 @@ public final class BrokerConstants { 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"; + public static final String CHANNEL_New_Callback_Feature = "channel.new_callback_feature"; + public static final String FRIEND_Disable_Search = "friend.disable_search"; public static final String FRIEND_Disable_NickName_Search = "friend.disable_nick_name_search"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index d6b112ca..6f29e068 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -203,6 +203,7 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean mForwardMessageWithClientInfo = false; private boolean mRobotCallbackWithClientInfo = false; private boolean mChannelCallbackWithClientInfo = false; + private boolean mChannelNewCallbackFeature = true; private Set mUserHideProperties = new HashSet<>(); @@ -602,8 +603,12 @@ public class MemoryMessagesStore implements IMessagesStore { try { mChannelCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_Callback_With_Client_Info, "false")); } catch (Exception e) { - } + try { + mChannelNewCallbackFeature = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_New_Callback_Feature, "true")); + } catch (Exception e) { + } + try { mRecallForwardUrl = server.getConfig().getProperty(BrokerConstants.MESSAGE_RecallMsg_Forward_Url); } catch (Exception e) { @@ -732,7 +737,7 @@ public class MemoryMessagesStore implements IMessagesStore { if (channelInfo != null) { if (channelInfo.getOwner().equals(fromUser)) { if(requestSourceType == ProtoConstants.RequestSourceType.Request_From_Channel - && channelInfo.getAutomatic() != 0) { + && channelInfo.getAutomatic() != 0 && !isChannelNewCallbackFeature()) { LOG.info("Channel api message not send to the owner when automatic"); } else { notifyReceivers.add(fromUser); @@ -762,7 +767,7 @@ public class MemoryMessagesStore implements IMessagesStore { } } else { notifyReceivers.add(fromUser); - if (channelInfo.getAutomatic() == 0) { + if (channelInfo.getAutomatic() == 0 || isChannelNewCallbackFeature()) { notifyReceivers.add(channelInfo.getOwner()); } else { LOG.info("Channel api message not send to the owner when automatic"); @@ -4645,6 +4650,11 @@ public class MemoryMessagesStore implements IMessagesStore { return mChannelCallbackWithClientInfo; } + @Override + public boolean isChannelNewCallbackFeature() { + return mChannelNewCallbackFeature; + } + @Override public boolean isRobotAutoAcceptFriendRequest() { return mFriendRobotAutoAccept; diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 1656ea3b..70892613 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -243,6 +243,7 @@ public interface IMessagesStore { boolean isForwardMessageWithClientInfo(); boolean isRobotCallbackWithClientInfo(); boolean isChannelCallbackWithClientInfo(); + boolean isChannelNewCallbackFeature(); boolean isRobotAutoAcceptFriendRequest(); diff --git a/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java b/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java index 77d527cf..92a82eb1 100755 --- a/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java +++ b/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java @@ -668,7 +668,15 @@ public class MessagesPublisher { public void publish2Receivers(WFCMessage.Message message, Set receivers, String exceptClientId, int pullType) { if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { WFCMessage.ChannelInfo channelInfo = m_messagesStore.getChannelInfo(message.getConversation().getTarget()); - if (channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback()) && channelInfo.getAutomatic() == 1 && !message.getFromUser().equals(channelInfo.getOwner())) { + + boolean forwardMsg; + if(m_messagesStore.isChannelNewCallbackFeature()) { + forwardMsg = channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback()) && !StringUtil.isNullOrEmpty(exceptClientId); + } else { + forwardMsg = channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback()) && channelInfo.getAutomatic() == 1 && !message.getFromUser().equals(channelInfo.getOwner()); + } + + if (forwardMsg) { OutputClient outputClient = null; if(m_messagesStore.isChannelCallbackWithClientInfo() && !StringUtil.isNullOrEmpty(exceptClientId)) { Session session = m_sessionsStore.getSession(exceptClientId); @@ -767,7 +775,10 @@ public class MessagesPublisher { } public void notifyChannelListenStatusChanged(WFCMessage.ChannelInfo channelInfo, String user, boolean listen) { - if (channelInfo == null || StringUtil.isNullOrEmpty(channelInfo.getCallback()) || channelInfo.getAutomatic() == 0) { + if (channelInfo == null || StringUtil.isNullOrEmpty(channelInfo.getCallback())) { + return; + } + if(!m_messagesStore.isChannelNewCallbackFeature() && channelInfo.getAutomatic() == 0) { return; } diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 779ae62f..8e66bd57 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -146,6 +146,10 @@ robot.callback_with_client_info false ## 频道回调信息是否带上用户clientId和平台类型。 channel.callback_with_client_info false +## 频道回调新方式,在新方式下,如果有callback地址就会总是回调客户端发送的消息(包括owner和订阅者)。automatic属性控制订阅者发送的消息是否发给owner, 0发,1不发。 +## 旧的方式是,automatic为0时,订阅者的消息发给owner,不转发消息到callback地址。为1时,把订阅者的消息转发给callback地址,不发给owner。 +channel.new_callback_feature true + ##禁止搜索用户 friend.disable_search false