From 2fdf11006d8b5ff1502d6b7ff3fcd55b3dadf5cb Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Tue, 12 Oct 2021 07:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=8C=E6=96=B9=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E5=8A=A0=E5=A5=BD=E5=8F=8B=E5=90=8E=EF=BC=8C=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E6=96=B9=E6=8E=A5=E5=8F=97=E5=90=8E=EF=BC=8C=E5=8F=A6?= =?UTF-8?q?=E5=A4=96=E4=B8=80=E6=96=B9=E6=97=A0=E6=B3=95=E6=8E=A5=E5=8F=97?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imhandler/HandleFriendRequestHandler.java | 5 +++++ .../moquette/persistence/MemoryMessagesStore.java | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/broker/src/main/java/io/moquette/imhandler/HandleFriendRequestHandler.java b/broker/src/main/java/io/moquette/imhandler/HandleFriendRequestHandler.java index 220d61151..7673bf7e0 100644 --- a/broker/src/main/java/io/moquette/imhandler/HandleFriendRequestHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/HandleFriendRequestHandler.java @@ -19,6 +19,7 @@ import win.liyufan.im.IMTopic; import win.liyufan.im.MessageShardingUtil; +import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_ALREADY_FRIENDS; import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS; @Handler(IMTopic.HandleFriendRequestTopic) @@ -86,6 +87,10 @@ public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, bo publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, heads[1]); } } + if(errorCode == ERROR_CODE_ALREADY_FRIENDS) { + errorCode = ERROR_CODE_SUCCESS; + } + 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 bf45269cb..f8f82ad61 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -2856,7 +2856,7 @@ public ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] he public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin) { HazelcastInstance hzInstance = m_Server.getHazelcastInstance(); - + boolean alreadyFriend = false; if(!isAdmin && request.getStatus() == ProtoConstants.FriendRequestStatus.RequestStatus_Accepted) { MultiMap friendsMap = hzInstance.getMultiMap(USER_FRIENDS); @@ -2868,10 +2868,9 @@ public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendReque for (FriendData fd : friends) { if (fd.getFriendUid().equals(request.getTargetUid())) { if (fd.getState() == 0) { - return ErrorCode.ERROR_CODE_ALREADY_FRIENDS; - } else { - break; + alreadyFriend = true; } + break; } } } @@ -2950,7 +2949,7 @@ public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendReque } if (existRequest != null) { - if (mFriendRequestExpiration > 0 && System.currentTimeMillis() - existRequest.getUpdateDt() > mFriendRequestExpiration) { + if (!alreadyFriend && mFriendRequestExpiration > 0 && System.currentTimeMillis() - existRequest.getUpdateDt() > mFriendRequestExpiration) { return ErrorCode.ERROR_CODE_FRIEND_REQUEST_EXPIRED; } else { existRequest = existRequest.toBuilder().setStatus(request.getStatus()).setUpdateDt(System.currentTimeMillis()).build(); @@ -2976,7 +2975,7 @@ public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendReque } } - if(request.getStatus() == ProtoConstants.FriendRequestStatus.RequestStatus_Accepted){ + if(!alreadyFriend && request.getStatus() == ProtoConstants.FriendRequestStatus.RequestStatus_Accepted){ MultiMap friendsMap = hzInstance.getMultiMap(USER_FRIENDS); FriendData friendData1 = new FriendData(userId, request.getTargetUid(), "", request.getExtra(), 0, 0, System.currentTimeMillis()); databaseStore.persistOrUpdateFriendData(friendData1); @@ -2997,6 +2996,9 @@ public ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendReque callbackRelationEvent(userId, request.getTargetUid(), 0, "1"); } + if(alreadyFriend) { + return ErrorCode.ERROR_CODE_ALREADY_FRIENDS; + } return ErrorCode.ERROR_CODE_SUCCESS; } } else {