From 8e3100e5b79be920fb42148336e89aefb6295528 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Tue, 10 Oct 2023 21:53:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=85=81=E8=AE=B8=E7=BE=A4=E4=B8=BB=E5=92=8C?= =?UTF-8?q?=E7=BE=A4=E7=AE=A1=E7=90=86=E5=91=98=E4=B8=8D=E5=8F=97=E9=99=90?= =?UTF-8?q?=E5=88=B6=E6=92=A4=E5=9B=9E=E8=87=AA=E5=B7=B1=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 6 ++++ .../java/io/moquette/BrokerConstants.java | 2 ++ .../persistence/MemoryMessagesStore.java | 36 ++++++++++++++++++- .../src/main/resources/wildfirechat.conf | 6 ++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index ead437b5d..fae5b6aa7 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -169,6 +169,12 @@ chatroom.rejoin_when_active true ## 当一个聊天室不存在时,如果有用户加入就自动创建 chatroom.create_when_not_exist true +## 是否允许群主不受限制地撤回自己发送的消息。false可以${message.recall_time_limit}撤回自己的消息;true可以撤回任意时间自己的消息。默认为true。 +group.allow_owner_recall_self_msg true + +## 是否允许群管理员不受限制地撤回自己发送的消息。false可以${message.recall_time_limit}撤回自己的消息;true可以撤回任意时间自己的消息。默认为false。 +group.allow_manager_recall_self_msg false + ## 是否允许客户端发送操作群的自定义群通知消息 group.allow_client_custom_operation_notification true diff --git a/broker/src/main/java/io/moquette/BrokerConstants.java b/broker/src/main/java/io/moquette/BrokerConstants.java index 89c93f0d9..0162bb02c 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 CHATROOM_Create_When_Not_Exist = "chatroom.create_when_not_exist"; + public static final String GROUP_Allow_Owner_Recall_Self_Msg = "group.allow_owner_recall_self_msg"; + public static final String GROUP_Allow_Manager_Recall_Self_Msg = "group.allow_manager_recall_self_msg"; public static final String GROUP_Allow_Client_Custom_Operation_Notification = "group.allow_client_custom_operation_notification"; public static final String GROUP_Allow_Robot_Custom_Operation_Notification = "group.allow_robot_custom_operation_notificatio"; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 1c521b161..9554c4ef3 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -180,6 +180,8 @@ protected boolean removeEldestEntry(Map.Entry eldest) { private String mChannelInfoUpdateCallback; private String mChatroomInfoUpdateCallback; private String mChatroomMemberUpdateCallback; + private boolean mGroupAllowOwnerRecallSelfMsg = false; + private boolean mGroupAllowManagerRecallSelfMsg = false; private boolean mGroupAllowClientCustomOperationNotification; private boolean mGroupAllowRobotCustomOperationNotification; private int mGroupVisibleQuitKickoffNotification; @@ -468,6 +470,17 @@ protected boolean removeEldestEntry(Map.Entry eldest) { } + try { + mGroupAllowOwnerRecallSelfMsg = Boolean.parseBoolean(server.getConfig().getProperty(GROUP_Allow_Owner_Recall_Self_Msg, "true")); + } catch (Exception e) { + + } + try { + mGroupAllowManagerRecallSelfMsg = Boolean.parseBoolean(server.getConfig().getProperty(GROUP_Allow_Manager_Recall_Self_Msg, "false")); + } catch (Exception e) { + + } + try { mGroupAllowClientCustomOperationNotification = Boolean.parseBoolean(server.getConfig().getProperty(GROUP_Allow_Client_Custom_Operation_Notification)); } catch (Exception e) { @@ -2232,7 +2245,28 @@ public ErrorCode recallMessage(long messageUid, String operatorId, String client return ErrorCode.ERROR_CODE_RECALL_TIME_EXPIRED; } if (operatorId.equals(groupInfo.getOwner())) { - canRecall = true; + if(operatorId.equals(message.getFromUser())) { + if(mGroupAllowOwnerRecallSelfMsg) { + canRecall = true; + } + } else { + canRecall = true; + } + } else { + if(message.getFromUser().equals(operatorId) && mGroupAllowManagerRecallSelfMsg) { + MultiMap groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS); + Collection members = groupMembers.get(message.getConversation().getTarget()); + if (members == null || members.size() == 0) { + members = loadGroupMemberFromDB(hzInstance, message.getConversation().getTarget()); + } + for (WFCMessage.GroupMember member : members) { + if (member.getMemberId().equals(operatorId)) { + if (member.getType() == GroupMemberType_Manager || member.getType() == ProtoConstants.GroupMemberType.GroupMemberType_Owner) { + canRecall = true; + } + } + } + } } if(!canRecall && !message.getFromUser().equals(operatorId)) { diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index ce68aff67..4453aab48 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -167,6 +167,12 @@ chatroom.rejoin_when_active true ## 当一个聊天室不存在时,如果有用户加入就自动创建 chatroom.create_when_not_exist true +## 是否允许群主不受限制地撤回自己发送的消息。false可以${message.recall_time_limit}撤回自己的消息;true可以撤回任意时间自己的消息。默认为true。 +group.allow_owner_recall_self_msg true + +## 是否允许群管理员不受限制地撤回自己发送的消息。false可以${message.recall_time_limit}撤回自己的消息;true可以撤回任意时间自己的消息。默认为false。 +group.allow_manager_recall_self_msg false + ## 是否允许客户端发送操作群的自定义群通知消息 group.allow_client_custom_operation_notification true