From 5bb8ab3d956548a1abea04702abcbecafa927f9b Mon Sep 17 00:00:00 2001 From: "heavyrain.lee" Date: Sat, 29 Jun 2019 11:26:33 +0800 Subject: [PATCH] update --- .../imhandler/SetGroupManagerHandler.java | 35 +++++++++++++++++++ .../persistence/MemoryMessagesStore.java | 34 ++++++++++++++++++ .../java/io/moquette/spi/IMessagesStore.java | 1 + .../src/main/java/win/liyufan/im/IMTopic.java | 2 +- .../GroupNotificationBinaryContent.java | 6 ++++ .../cn/wildfirechat/proto/ProtoConstants.java | 2 ++ 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 broker/src/main/java/io/moquette/imhandler/SetGroupManagerHandler.java diff --git a/broker/src/main/java/io/moquette/imhandler/SetGroupManagerHandler.java b/broker/src/main/java/io/moquette/imhandler/SetGroupManagerHandler.java new file mode 100644 index 00000000..2899d433 --- /dev/null +++ b/broker/src/main/java/io/moquette/imhandler/SetGroupManagerHandler.java @@ -0,0 +1,35 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package io.moquette.imhandler; + +import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.GroupNotificationBinaryContent; +import cn.wildfirechat.proto.WFCMessage; +import io.moquette.spi.impl.Qos1PublishHandler; +import io.netty.buffer.ByteBuf; +import win.liyufan.im.IMTopic; + +import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS; + +@Handler(IMTopic.SetGroupManagerTopic) +public class SetGroupManagerHandler extends GroupHandler { + @Override + public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.SetGroupManagerRequest request, Qos1PublishHandler.IMCallback callback) { + ErrorCode errorCode = m_messagesStore.setGroupManager(fromUser, request.getGroupId(), request.getType(), request.getUserIdList(), isAdmin); + if (errorCode == ERROR_CODE_SUCCESS) { + if (request.hasNotifyContent() && request.getNotifyContent().getType() > 0) { + sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), request.getNotifyContent()); + } else { + WFCMessage.MessageContent content = new GroupNotificationBinaryContent(request.getGroupId(), fromUser, request.getType() + "", request.getUserIdList()).getSetGroupManagerNotifyContent(); + sendGroupNotification(fromUser, request.getGroupId(), request.getToLineList(), content); + } + } + return errorCode; + } +} diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 7012a590..1b9955ec 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -973,6 +973,40 @@ public class MemoryMessagesStore implements IMessagesStore { return ErrorCode.ERROR_CODE_SUCCESS; } + @Override + public ErrorCode setGroupManager(String operator, String groupId, int type, List userList, boolean isAdmin) { + HazelcastInstance hzInstance = m_Server.getHazelcastInstance(); + IMap mIMap = hzInstance.getMap(GROUPS_MAP); + + + WFCMessage.GroupInfo groupInfo = mIMap.get(groupId); + + if (groupInfo == null) { + return ErrorCode.ERROR_CODE_NOT_EXIST; + } + + if (!isAdmin && (groupInfo.getType() == ProtoConstants.GroupType.GroupType_Restricted || groupInfo.getType() == ProtoConstants.GroupType.GroupType_Normal) + && (groupInfo.getOwner() == null || !groupInfo.getOwner().equals(operator))) { + return ErrorCode.ERROR_CODE_NOT_RIGHT; + } + + long updateDt = System.currentTimeMillis(); + MultiMap groupMembers = hzInstance.getMultiMap(GROUP_MEMBERS); + Collection members = groupMembers.get(groupId); + for (WFCMessage.GroupMember member : members) { + if (userList.contains(member.getMemberId())) { + groupMembers.remove(groupId, member); + member = member.toBuilder().setType(ProtoConstants.GroupMemberType.GroupMemberType_Manager).setUpdateDt(updateDt).build(); + databaseStore.persistGroupMember(groupId, Arrays.asList(member)); + groupMembers.put(groupId, member); +// userList.remove(member.getMemberId()); + } + } + + mIMap.put(groupId, groupInfo.toBuilder().setUpdateDt(updateDt).setMemberUpdateDt(updateDt).build()); + return ErrorCode.ERROR_CODE_SUCCESS; + } + @Override public boolean isMemberInGroup(String memberId, String groupId) { HazelcastInstance hzInstance = m_Server.getHazelcastInstance(); diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 88f8717d..46d1f62c 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -113,6 +113,7 @@ public interface IMessagesStore { WFCMessage.GroupInfo getGroupInfo(String groupId); ErrorCode getGroupMembers(String groupId, long maxDt, List members); ErrorCode transferGroup(String operator, String groupId, String newOwner, boolean isAdmin); + ErrorCode setGroupManager(String operator, String groupId, int type, List userList, boolean isAdmin); boolean isMemberInGroup(String member, String groupId); ErrorCode canSendMessageInGroup(String member, String groupId); diff --git a/broker/src/main/java/win/liyufan/im/IMTopic.java b/broker/src/main/java/win/liyufan/im/IMTopic.java index dd9bc3a9..c89f7ad1 100755 --- a/broker/src/main/java/win/liyufan/im/IMTopic.java +++ b/broker/src/main/java/win/liyufan/im/IMTopic.java @@ -30,7 +30,7 @@ public interface IMTopic { String GetGroupInfoTopic = "GPGI"; String GetGroupMemberTopic = "GPGM"; String TransferGroupTopic = "GTG"; - + String SetGroupManagerTopic = "GSM"; String GetUserInfoTopic = "UPUI"; String ModifyMyInfoTopic = "MMI"; diff --git a/common/src/main/java/cn.wildfirechat.pojos/GroupNotificationBinaryContent.java b/common/src/main/java/cn.wildfirechat.pojos/GroupNotificationBinaryContent.java index 073a7d70..8ad45e8b 100644 --- a/common/src/main/java/cn.wildfirechat.pojos/GroupNotificationBinaryContent.java +++ b/common/src/main/java/cn.wildfirechat.pojos/GroupNotificationBinaryContent.java @@ -141,4 +141,10 @@ public class GroupNotificationBinaryContent { return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE); } + public WFCMessage.MessageContent getSetGroupManagerNotifyContent() { + return getGroupNotifyContent(ProtoConstants.MESSAGE_CONTENT_TYPE_SET_MANAGER); + } + + + } diff --git a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java index 3a20caed..c341d949 100644 --- a/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java +++ b/common/src/main/java/cn/wildfirechat/proto/ProtoConstants.java @@ -146,5 +146,7 @@ public class ProtoConstants { public static final int MESSAGE_CONTENT_TYPE_CHANGE_JOINTYPE = 114; public static final int MESSAGE_CONTENT_TYPE_CHANGE_PRIVATECHAT = 115; public static final int MESSAGE_CONTENT_TYPE_CHANGE_SEARCHABLE = 116; + + public static final int MESSAGE_CONTENT_TYPE_SET_MANAGER = 117; }