diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 9c9eb1b2..c387db88 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -126,6 +126,12 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 ## 离线用户推送过期天数,0是永不过期,建议配置为7天。 message.push_expired_days 7 +## 当会话静音/全局静音/PC在线静音时,普通消息都不会有推送,如果有某些消息类型需要此时保持推送,可以配置到这里。此配置对消息免打扰时段无效。 +## 此配置只影响远程推送,需要客户端处理客户端在线且在后台收到此消息的处理,需要针对这些消息类型加上本地通知。 +## 强制推送消息的MessagePayload中pushContent和pushData至少要存在一个才可以推送。 +## 消息类型以英文逗号分割。 +message.force_push_types 401,402 + ## 群发消息(包括server api群发和全局频道群发)时,目标用户是否来自于t_user表。如果使用野火托管用户信息,请设置为true,否则设置为false。 message.broadcast.target_from_user_table true diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 29648be8..9f4a302b 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -155,6 +155,7 @@ public final class BrokerConstants { public static final String MESSAGE_NO_Forward_Admin_Message = "message.no_forward_admin_message"; public static final String MESSAGE_Push_Expired_Days = "message.push_expired_days"; + public static final String MESSAGE_Force_Push_Types = "message.force_push_types"; public static final String MESSAGE_Forward_With_Client_Info = "message.forward_with_client_info"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 326cf955..5ca44a8e 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -155,6 +155,7 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean mFriendRobotAutoAccept = true; private long mPushExpiredTimes = 604800000L; + private Set mForcePushTypes = new HashSet<>(); private boolean mMultiPlatformNotification = false; private boolean mMobileDefaultSilentWhenPCOnline = true; @@ -257,6 +258,20 @@ public class MemoryMessagesStore implements IMessagesStore { e.printStackTrace(); } + try { + String forcePushTypes = m_Server.getConfig().getProperty(BrokerConstants.MESSAGE_Force_Push_Types); + if(!StringUtil.isNullOrEmptyAfterTrim(forcePushTypes)) { + forcePushTypes = forcePushTypes.replace(",", ","); + for (String s : forcePushTypes.split(",")) { + int type = Integer.parseInt(s.trim()); + if(type > 0) { + mForcePushTypes.add(type); + } + } + } + } catch (Exception e) { + } + try { mMultiPlatformNotification = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.SERVER_MULTI_PLATFROM_NOTIFICATION, "false")); } catch (Exception e) { @@ -4613,6 +4628,11 @@ public class MemoryMessagesStore implements IMessagesStore { return mPushExpiredTimes; } + @Override + public Set getForcePushTypes() { + return mForcePushTypes; + } + @Override public List getClientForbiddenSendTypes() { return mForbiddenClientSendTypes; diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index c6f94ccf..1656ea3b 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -247,6 +247,7 @@ public interface IMessagesStore { boolean isRobotAutoAcceptFriendRequest(); long getPushExpiredTimes(); + Set getForcePushTypes(); List getClientForbiddenSendTypes(); List getBlackListExceptionTypes(); 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 16dae2dd..77d527cf 100755 --- a/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java +++ b/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java @@ -21,7 +21,6 @@ import cn.wildfirechat.pojos.OutputMessageData; import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.WFCMessage; import cn.wildfirechat.push.PushServer; -import com.google.gson.Gson; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.util.StringUtil; import cn.wildfirechat.pojos.OutputNotifyChannelSubscribeStatus; @@ -271,6 +270,7 @@ public class MessagesPublisher { boolean isVoipSilent; boolean isNoDisturb; boolean isConvSilent = false; + boolean isForcePush = false; if (pullType == ProtoConstants.PullType.Pull_ChatRoom) { isSilent = true; isConvSilent = true; @@ -289,6 +289,11 @@ public class MessagesPublisher { conversation = WFCMessage.Conversation.newBuilder().setType(conversationType).setLine(line).setTarget(target).build(); } + if(m_messagesStore.getForcePushTypes().contains(messageContentType)) { + LOG.info("The message type {} force push", messageContentType); + isForcePush = true; + } + if (m_messagesStore.getUserConversationSilent(user, conversation)) { LOG.info("The conversation {}-{}-{} is slient", conversation.getType(), conversation.getTarget(), conversation.getLine()); isConvSilent = true; @@ -369,17 +374,17 @@ public class MessagesPublisher { continue; } - if (isConvSilent && !isVoip) { + if (isConvSilent && !isVoip && !isForcePush) { LOG.info("Silent of user or conversation"); continue; } - if (isSilent && !isVoip) { + if (isSilent && !isVoip && !isForcePush) { LOG.info("Silent of user"); continue; } - if(isVoip && isVoipSilent) { + if(isVoip && isVoipSilent && !isForcePush) { LOG.info("voip silent of user"); continue; } diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 5edeef73..14a7f33f 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -124,6 +124,12 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411 ## 离线用户推送过期天数,0是永不过期,建议配置为7天。 message.push_expired_days 7 +## 当会话静音/全局静音/PC在线静音时,普通消息都不会有推送,如果有某些消息类型需要此时保持推送,可以配置到这里。此配置对消息免打扰时段无效。 +## 此配置只影响远程推送,需要客户端处理客户端在线且在后台收到此消息的处理,需要针对这些消息类型加上本地通知。 +## 强制推送消息的MessagePayload中pushContent和pushData至少要存在一个才可以推送。 +## 消息类型以英文逗号分割。 +message.force_push_types 401,402 + ## 群发消息(包括server api群发和全局频道群发)时,目标用户是否来自于t_user表。如果使用野火托管用户信息,请设置为true,否则设置为false。 message.broadcast.target_from_user_table true