From c3b9b9fccf1d10c8aa30b3501fb92d7f35020087 Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Wed, 3 Aug 2022 12:19:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=A4=E7=BB=84=E6=B7=BB=E5=8A=A0=E6=88=90?= =?UTF-8?q?=E5=91=98=E6=97=B6=EF=BC=8C=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8=E7=BE=A4=E7=BB=84=E6=88=90?= =?UTF-8?q?=E5=91=98=EF=BC=8C=20fix=20issue=20#501?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/MemoryMessagesStore.java | 44 ++++++++++++------- .../cn/wildfirechat/common/ErrorCode.java | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 378c0454f..88461975f 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -1300,11 +1300,31 @@ public ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupI } } + MultiMap groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS); + Collection members = groupMembers.get(groupId); + if (members == null || members.size() == 0) { + members = loadGroupMemberFromDB(hzInstance, groupId); + } + + ArrayList existMemberIds = new ArrayList<>(); + for (WFCMessage.GroupMember member : members) { + if (member.getType() != GroupMemberType_Removed) { + existMemberIds.add(member.getMemberId()); + } + } + long updateDt = System.currentTimeMillis(); List tmp = new ArrayList<>(); - ArrayList newInviteUsers = new ArrayList<>(); + int newMemberCount = 0; for (WFCMessage.GroupMember member : memberList) { + if (existMemberIds.contains(member.getMemberId()) && member.getType() != GroupMemberType_Removed) { + if(!isAdmin) + continue; + } else { + newMemberCount++; + } + WFCMessage.GroupMember.Builder builder = member.toBuilder(); builder.setUpdateDt(updateDt).setCreateDt(updateDt); if (member.getMemberId().equals(groupInfo.getOwner())) { @@ -1324,29 +1344,23 @@ public ErrorCode addGroupMembers(String operator, boolean isAdmin, String groupI } member = builder.build(); tmp.add(member); - newInviteUsers.add(member.getMemberId()); updateDt++; } memberList = tmp; - MultiMap groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS); - Collection members = groupMembers.get(groupId); - if (members == null || members.size() == 0) { - members = loadGroupMemberFromDB(hzInstance, groupId); - } - - if (maxCount != Integer.MAX_VALUE) { - int existCount = 0; - for (WFCMessage.GroupMember member : members) { - if (member.getType() != GroupMemberType_Removed) { - existCount++; - } + if (memberList.size() == 0) { + if (!isAdmin) { + return ErrorCode.ERROR_CODE_ALREADY_IN_GROUP; + } else { + return ErrorCode.ERROR_CODE_SUCCESS; } - if (existCount + newInviteUsers.size() > maxCount) { + } else { + if (existMemberIds.size() + newMemberCount > maxCount) { return ErrorCode.ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT; } } + databaseStore.persistGroupMember(groupId, memberList, true); databaseStore.updateGroupMemberCountDt(groupId); diff --git a/common/src/main/java/cn/wildfirechat/common/ErrorCode.java b/common/src/main/java/cn/wildfirechat/common/ErrorCode.java index d8c291373..393cd0f65 100755 --- a/common/src/main/java/cn/wildfirechat/common/ErrorCode.java +++ b/common/src/main/java/cn/wildfirechat/common/ErrorCode.java @@ -29,6 +29,7 @@ public enum ErrorCode { //Group error ERROR_CODE_GROUP_ALREADY_EXIST(11, "group already exist"), + ERROR_CODE_ALREADY_IN_GROUP(12, "member already in group"), //user error ERROR_CODE_FRIEND_ALREADY_REQUEST(16, "already send request"),