diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java index 3b689812..af7b5cab 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/ProcessCpApplyCmd.java @@ -106,7 +106,7 @@ public class ProcessCpApplyCmd { cmd.requireReqSysOrigin(), relationType); } - sendAutoRejectedNotices(autoRefuseWaitAppliesAfterAgree(cpApply, relationType)); + autoRefuseWaitAppliesAfterAgree(cpApply, relationType); cpRelationshipCacheService.remove(Arrays.asList(cpApply.getSendApplyUserId(), cpApply.getAcceptApplyUserId())); cpRelationBroadcastMqClient.publish(cmd.requireReqSysOrigin(), cpApply.getId(), @@ -126,24 +126,12 @@ public class ProcessCpApplyCmd { imMessageClient.sendCustomMessage(agree ? CpRelationC2cNoticeUtils.buildAccepted(cpApply, senderProfile, acceptProfile) : CpRelationC2cNoticeUtils.buildRejected(cpApply, senderProfile, acceptProfile)); - imMessageClient.sendCustomMessage(agree - ? CpRelationC2cNoticeUtils.buildAcceptedToAcceptUser(cpApply, senderProfile, - acceptProfile) - : CpRelationC2cNoticeUtils.buildRejectedToAcceptUser(cpApply, senderProfile, - acceptProfile)); } catch (Exception ex) { log.warn("[CP] send process c2c notice failed, applyId={}, agree={}, reason={}", cpApply.getId(), agree, ex.getMessage(), ex); } } - private void sendAutoRejectedNotices(List refusedApplies) { - if (Objects.isNull(refusedApplies) || refusedApplies.isEmpty()) { - return; - } - refusedApplies.forEach(apply -> sendProcessNotice(apply, false)); - } - private List autoRefuseWaitAppliesAfterAgree(CpApply cpApply, String relationType) { Map refusedApplyMap = new LinkedHashMap<>(); addRefusedApplies(refusedApplyMap, diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java index 18cb6dc9..cf86681c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/SendCpApplyCmdExe.java @@ -185,6 +185,9 @@ public class SendCpApplyCmdExe { CpRelationshipType relationType, String title) { imMessageClient.sendCustomMessage(CpRelationC2cNoticeUtils.buildInvitePending(sendUserId, acceptUserId, applyId, userProfile, acceptUserProfile, isReconcile, relationType, title)); + imMessageClient.sendCustomMessage(CpRelationC2cNoticeUtils.buildInvitePendingToSendUser( + sendUserId, acceptUserId, applyId, userProfile, acceptUserProfile, isReconcile, relationType, + title)); } private BigDecimal normalizeApplyConsumeGold(BigDecimal applyConsumeGold) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationC2cNoticeUtils.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationC2cNoticeUtils.java index ede089f9..22e11280 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationC2cNoticeUtils.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/common/cp/CpRelationC2cNoticeUtils.java @@ -25,6 +25,20 @@ public final class CpRelationC2cNoticeUtils { public static CustomC2cMsgBodyCmd buildInvitePending(Long fromUserId, Long toUserId, Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile, boolean isReconcile, CpRelationshipType relationType, String title) { + return buildInvitePendingMessage(fromUserId, toUserId, applyId, senderProfile, acceptProfile, + isReconcile, relationType, title); + } + + public static CustomC2cMsgBodyCmd buildInvitePendingToSendUser(Long sendUserId, Long acceptUserId, + Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile, + boolean isReconcile, CpRelationshipType relationType, String title) { + return buildInvitePendingMessage(acceptUserId, sendUserId, applyId, senderProfile, + acceptProfile, isReconcile, relationType, title); + } + + private static CustomC2cMsgBodyCmd buildInvitePendingMessage(Long fromUserId, Long toUserId, + Long applyId, UserProfileDTO senderProfile, UserProfileDTO acceptProfile, + boolean isReconcile, CpRelationshipType relationType, String title) { Map content = senderContent(senderProfile); content.put("applyType", isReconcile ? "RECONCILE" : "APPLY"); content.put("relationType", relationType.name()); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java index 5de85c44..d97acfc3 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/listener/user/CpApplyListener.java @@ -76,8 +76,6 @@ public class CpApplyListener implements MessageListener { } imMessageClient.sendCustomMessage( CpRelationC2cNoticeUtils.buildExpiredToAcceptUser(cpApply, senderProfile, acceptProfile)); - imMessageClient.sendCustomMessage( - CpRelationC2cNoticeUtils.buildExpiredToSendUser(cpApply, senderProfile, acceptProfile)); } catch (Exception ex) { log.warn("[CP] send expired c2c notice failed, applyId={}, reason={}", cpApply.getId(), ex.getMessage(), ex); diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/ProcessCpApplyCmdTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/ProcessCpApplyCmdTest.java index 85754241..f732b9af 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/ProcessCpApplyCmdTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/command/user/ProcessCpApplyCmdTest.java @@ -40,8 +40,8 @@ class ProcessCpApplyCmdTest { nullable(Long.class), eq("LIKEI"), eq("BROTHER")); verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L, "BROTHER"); - assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0, - "RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER"); } @Test @@ -54,8 +54,8 @@ class ProcessCpApplyCmdTest { nullable(Long.class), eq("LIKEI"), eq("SISTERS")); verify(fixture.cpRelationBroadcastMqClient).publish("LIKEI", 3001L, 1001L, 2001L, "SISTERS"); - assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0, - "RELATION_ESTABLISHED", "ACCEPTED", true, "SISTERS", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "SISTERS"); } @Test @@ -64,8 +64,8 @@ class ProcessCpApplyCmdTest { fixture.exe.execute(processCmd(false)); - assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0, - "RELATION_REJECTED", "REJECTED", false, "CP", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_REJECTED", "REJECTED", false, "CP"); } @Test @@ -85,7 +85,7 @@ class ProcessCpApplyCmdTest { } @Test - void agreeApplyShouldRejectOtherWaitAppliesBetweenSameUsers() { + void agreeApplyShouldAutoRefuseOtherWaitAppliesBetweenSameUsersWithoutRejectedIm() { Fixture fixture = new Fixture("CP"); when(fixture.cpApplyService.refuseOtherWaitAppliesBetweenUsers(3001L, 1001L, 2001L)) .thenReturn(List.of(apply(3002L, "BROTHER"), apply(3003L, "SISTERS"))); @@ -93,13 +93,8 @@ class ProcessCpApplyCmdTest { fixture.exe.execute(processCmd(true)); verify(fixture.cpApplyService).refuseOtherWaitAppliesBetweenUsers(3001L, 1001L, 2001L); - List messages = fixture.sentCustomMessages(6); - assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false, - "BROTHER", 3002L, 1001L, 2001L); - assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false, - "SISTERS", 3003L, 1001L, 2001L); - assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true, - "CP", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "CP"); } @Test @@ -118,17 +113,8 @@ class ProcessCpApplyCmdTest { fixture.exe.execute(processCmd(true)); - List messages = fixture.sentCustomMessages(10); - assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false, - "BROTHER", 3002L, 1001L, 2001L); - assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false, - "SISTERS", 3003L, 1001L, 2001L); - assertProcessMessagesToBothUsers(messages, 4, "RELATION_REJECTED", "REJECTED", false, - "CP", 3004L, 1001L, 4001L); - assertProcessMessagesToBothUsers(messages, 6, "RELATION_REJECTED", "REJECTED", false, - "CP", 3005L, 1001L, 4002L); - assertProcessMessagesToBothUsers(messages, 8, "RELATION_ESTABLISHED", "ACCEPTED", true, - "CP", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "CP"); } @Test @@ -145,13 +131,8 @@ class ProcessCpApplyCmdTest { fixture.exe.execute(processCmd(true)); - List messages = fixture.sentCustomMessages(6); - assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false, - "CP", 3002L, 1001L, 4001L); - assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false, - "CP", 3003L, 1001L, 4002L); - assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true, - "CP", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "CP"); } @Test @@ -164,8 +145,8 @@ class ProcessCpApplyCmdTest { verify(fixture.cpApplyService, never()).refuseWaitAppliesByUserAndRelation( any(Long.class), eq(1001L), eq("BROTHER")); - assertProcessMessagesToBothUsers(fixture.sentCustomMessages(2), 0, - "RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER"); } @Test @@ -182,13 +163,8 @@ class ProcessCpApplyCmdTest { fixture.exe.execute(processCmd(true)); - List messages = fixture.sentCustomMessages(6); - assertProcessMessagesToBothUsers(messages, 0, "RELATION_REJECTED", "REJECTED", false, - "BROTHER", 3002L, 1001L, 4001L); - assertProcessMessagesToBothUsers(messages, 2, "RELATION_REJECTED", "REJECTED", false, - "BROTHER", 3003L, 1001L, 4002L); - assertProcessMessagesToBothUsers(messages, 4, "RELATION_ESTABLISHED", "ACCEPTED", true, - "BROTHER", 3001L, 1001L, 2001L); + assertProcessMessage(fixture.sentCustomMessage(), + "RELATION_ESTABLISHED", "ACCEPTED", true, "BROTHER"); } private static ProcessApplyCmd processCmd(boolean agree) { @@ -251,15 +227,6 @@ class ProcessCpApplyCmdTest { .contains("\"relationType\":\"" + relationType + "\"")); } - private static void assertProcessMessagesToBothUsers(List messages, - int startIndex, String action, String status, Boolean agree, String relationType, - Long applyId, Long sendUserId, Long acceptUserId) { - assertProcessMessage(messages.get(startIndex), action, status, agree, relationType, applyId, - String.valueOf(acceptUserId), String.valueOf(sendUserId)); - assertProcessMessage(messages.get(startIndex + 1), action, status, agree, relationType, - applyId, String.valueOf(sendUserId), String.valueOf(acceptUserId)); - } - private static class Fixture { private final CpApplyService cpApplyService = mock(CpApplyService.class); @@ -306,13 +273,6 @@ class ProcessCpApplyCmdTest { return captor.getValue(); } - private List sentCustomMessages(int count) { - ArgumentCaptor captor = ArgumentCaptor.forClass( - CustomC2cMsgBodyCmd.class); - verify(imMessageClient, org.mockito.Mockito.times(count)).sendCustomMessage(captor.capture()); - return captor.getAllValues(); - } - private static UserProfile profile(Long userId) { UserProfile userProfile = new UserProfile(); userProfile.setId(userId); diff --git a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java index 9a57aea3..a421907b 100644 --- a/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java +++ b/rc-service/rc-service-other/other-application/src/test/java/com/red/circle/other/app/listener/user/CpApplyListenerTest.java @@ -31,7 +31,7 @@ import org.mockito.ArgumentCaptor; class CpApplyListenerTest { @Test - void waitApplyExpiredShouldSendC2cMessageToBothUsers() { + void waitApplyExpiredShouldSendOneC2cMessageToConversation() { CpApplyService cpApplyService = mock(CpApplyService.class); ImMessageClient imMessageClient = mock(ImMessageClient.class); UserProfileGateway userProfileGateway = mock(UserProfileGateway.class); @@ -66,10 +66,9 @@ class CpApplyListenerTest { ArgumentCaptor captor = ArgumentCaptor.forClass( CustomC2cMsgBodyCmd.class); - verify(imMessageClient, org.mockito.Mockito.times(2)).sendCustomMessage(captor.capture()); + verify(imMessageClient).sendCustomMessage(captor.capture()); List messages = captor.getAllValues(); assertExpiredMessage(messages.get(0), "1001", "2001"); - assertExpiredMessage(messages.get(1), "2001", "1001"); verify(cpApplyService).changeStatusById(3001L, CpApplyStatus.EXPIRE); }