diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index a6d11e67..36f128c3 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -170,6 +170,10 @@ robot.callback_with_sender_info false ## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息 robot.callback_with_target_info false +## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。 +## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。 +robot.mention_external_robot true + ## 频道回调信息是否带上用户clientId和平台类型。 channel.callback_with_client_info false diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ReplyMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ReplyMessageAction.java index a6ff64bb..f604b0f1 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ReplyMessageAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/ReplyMessageAction.java @@ -55,6 +55,15 @@ public class ReplyMessageAction extends RobotAction { errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT; } else if(System.currentTimeMillis() - message.getServerTimestamp() > 15*60*1000) { errorCode = ErrorCode.ERROR_CODE_RECALL_TIME_EXPIRED; + } else if(!messagesStore.isRobotMentionExternalRobot()) { + if(message.getConversation().getType() != ProtoConstants.ConversationType.ConversationType_Group) { + errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT; + } else { + WFCMessage.GroupMember member = messagesStore.getGroupMember(message.getConversation().getTarget(), robot.getUid()); + if(member == null || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Removed) { + errorCode = ErrorCode.ERROR_CODE_NOT_IMPLEMENT; + } + } } if(errorCode != null) { diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 853472c7..791b274d 100755 --- a/broker/src/main/java/io/moquette/BrokerConstants.java +++ b/broker/src/main/java/io/moquette/BrokerConstants.java @@ -173,6 +173,8 @@ public final class BrokerConstants { 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"; + public static final String ROBOT_Mention_External_Robot = "robot.mention_external_robot"; + public static final String CHANNEL_Callback_With_Client_Info = "channel.callback_with_client_info"; public static final String CHANNEL_Callback_With_Sender_Info = "channel.callback_with_sender_info"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 47ce864f..78539005 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -213,6 +213,7 @@ public class MemoryMessagesStore implements IMessagesStore { private boolean mRobotCallbackWithClientInfo = false; private boolean mRobotCallbackWithSenderInfo = false; private boolean mRobotCallbackWithTargetInfo = false; + private boolean mRobotMentionExternalRobot = false; private boolean mChannelCallbackWithClientInfo = false; private boolean mChannelCallbackWithSenderInfo = false; @@ -646,6 +647,9 @@ public class MemoryMessagesStore implements IMessagesStore { try { mRobotCallbackWithTargetInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Callback_With_Target_Info, "false")); } catch (Exception e) {} + try { + mRobotMentionExternalRobot = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.ROBOT_Mention_External_Robot, "false")); + } catch (Exception e) {} try { mChannelCallbackWithClientInfo = Boolean.parseBoolean(server.getConfig().getProperty(BrokerConstants.CHANNEL_Callback_With_Client_Info, "false")); @@ -741,7 +745,7 @@ public class MemoryMessagesStore implements IMessagesStore { int type = message.getConversation().getType(); int pullType = ProtoConstants.PullType.Pull_Normal; - if (type == ProtoConstants.ConversationType.ConversationType_Private) { + if (mRobotMentionExternalRobot && type == ProtoConstants.ConversationType.ConversationType_Private) { if(message.getConversation().getTarget().contains("|")) { String[] ss = message.getConversation().getTarget().split("\\|"); notifyReceivers.add(ss[0]); @@ -761,7 +765,7 @@ public class MemoryMessagesStore implements IMessagesStore { notifyReceivers.add(message.getConversation().getTarget()); } } - if (message.getContent().getMentionedTargetCount() > 0) { + if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) { for (String mentioned : message.getContent().getMentionedTargetList()) { if (!notifyReceivers.contains(mentioned)) { WFCMessage.User user = getUserInfo(mentioned); @@ -799,7 +803,7 @@ public class MemoryMessagesStore implements IMessagesStore { } } } - if (message.getContent().getMentionedTargetCount() > 0) { + if (mRobotMentionExternalRobot && message.getContent().getMentionedTargetCount() > 0) { for (String mentioned : message.getContent().getMentionedTargetList()) { if (!notifyReceivers.contains(mentioned)) { WFCMessage.User user = getUserInfo(mentioned); @@ -4922,6 +4926,11 @@ public class MemoryMessagesStore implements IMessagesStore { return mRobotCallbackWithTargetInfo; } + @Override + public boolean isRobotMentionExternalRobot() { + return mRobotMentionExternalRobot; + } + @Override public boolean isChannelCallbackWithClientInfo() { return mChannelCallbackWithClientInfo; diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 5af7270f..4ad51f07 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -254,6 +254,7 @@ public interface IMessagesStore { boolean isRobotCallbackWithClientInfo(); boolean isRobotCallbackWithSenderInfo(); boolean isRobotCallbackWithTargetInfo(); + boolean isRobotMentionExternalRobot(); boolean isChannelCallbackWithClientInfo(); boolean isChannelCallbackWithSenderInfo(); diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index e5e7e919..fe91b7f8 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -167,6 +167,10 @@ robot.callback_with_sender_info false ## 机器人回调信息是否带上目标的信息,单聊时是对方用户信息,群聊时是群组信息,频道时是频道信息 robot.callback_with_target_info false +## 是否允许@会话外的机器人。如果为true,单聊或者群聊时,可以@不在会话中的机器人。当机器人收到消息后,可以回复消息。 +## 如果为false,不能@不在会话中的机器人。机器人不在会话中时,也不能回复消息。 +robot.mention_external_robot true + ## 频道回调信息是否带上用户clientId和平台类型。 channel.callback_with_client_info false