关注加好友
This commit is contained in:
parent
8575e93a5b
commit
5d50c4d1ab
@ -1,18 +1,35 @@
|
||||
package com.red.circle.other.app.command.user;
|
||||
|
||||
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
|
||||
import com.red.circle.external.inner.endpoint.message.ImGroupClient;
|
||||
import com.red.circle.external.inner.model.cmd.message.GroupUnbanCmd;
|
||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||
import com.red.circle.framework.core.response.CommonErrorCode;
|
||||
import com.red.circle.mq.rocket.business.producer.TaskMqMessage;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.domain.gateway.user.ability.UserRelationsCalculatorGateway;
|
||||
import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator;
|
||||
import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator.CounterEnum;
|
||||
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile;
|
||||
import com.red.circle.other.infra.database.mongo.service.live.RoomProfileManagerService;
|
||||
import com.red.circle.other.infra.database.mongo.service.live.RoomUserBlacklistService;
|
||||
import com.red.circle.other.infra.database.mongo.service.user.friend.FriendsApplyListService;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.RelationshipFriend;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.RelationshipFriendService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.ShieldBlackService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.UserSubscriptionService;
|
||||
import com.red.circle.other.inner.asserts.user.UserRelationErrorCode;
|
||||
import com.red.circle.tool.core.date.TimestampUtils;
|
||||
import com.red.circle.tool.core.text.StringUtils;
|
||||
import com.red.circle.other.inner.asserts.user.UserErrorCode;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户关系订阅.
|
||||
*
|
||||
@ -25,6 +42,11 @@ public class UserSupportRelationFollowOrCancelCmdExe {
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final UserSubscriptionService userSubscriptionService;
|
||||
private final UserRelationsCalculatorGateway userRelationsCalculatorGateway;
|
||||
private final ImGroupClient imGroupClient;
|
||||
private final ShieldBlackService shieldBlackService;
|
||||
private final RoomUserBlacklistService roomUserBlacklistService;
|
||||
private final RoomProfileManagerService roomProfileManagerService;
|
||||
private final RelationshipFriendService relationshipFriendService;
|
||||
|
||||
public Boolean execute(AppUserIdCmd cmd) {
|
||||
// 不可操作自己
|
||||
@ -52,9 +74,62 @@ public class UserSupportRelationFollowOrCancelCmdExe {
|
||||
.setIncr(Boolean.TRUE)
|
||||
.setType(CounterEnum.SUBSCRIPTION)
|
||||
);
|
||||
|
||||
Long userId = cmd.requiredReqUserId();
|
||||
Long subUserId = cmd.getUserId();
|
||||
boolean mutual = userSubscriptionService.checkSubscription(subUserId, userId);
|
||||
|
||||
// 如果是相互关注 则自动加为好友
|
||||
if (mutual) {
|
||||
try {
|
||||
relationshipFriendService
|
||||
.saveBatch(createRelationshipFriend(cmd.requiredReqUserId(), subUserId));
|
||||
userRelationsCalculatorGateway.process(
|
||||
new UserRelationsCalculator()
|
||||
.setUserId(cmd.requiredReqUserId())
|
||||
.setSubUserId(subUserId)
|
||||
.setIncr(Boolean.TRUE)
|
||||
.setType(CounterEnum.FRIEND)
|
||||
);
|
||||
} catch (DuplicateKeyException ignore) {
|
||||
// 已经是好友
|
||||
ResponseAssert.failure(UserRelationErrorCode.ALREADY_FRIENDS);
|
||||
}
|
||||
// 将自己从对方的房间黑名单移除
|
||||
shieldBlackService.removeShieldBlackBothSides(cmd.requiredReqUserId(), subUserId);
|
||||
|
||||
RoomProfile roomProfile = roomProfileManagerService.getProfileByUserId(subUserId);
|
||||
if (Objects.nonNull(roomProfile)) {
|
||||
|
||||
Boolean status = ResponseAssert.requiredSuccess(
|
||||
imGroupClient.unBanGroupMember(new GroupUnbanCmd()
|
||||
.setGroupId(Objects.toString(roomProfile.getRoomAccount()))
|
||||
.setUserId(cmd.requiredReqUserId())
|
||||
)
|
||||
);
|
||||
if (Objects.equals(status, Boolean.TRUE)) {
|
||||
roomUserBlacklistService.removeBlack(roomProfile.getId(), cmd.requiredReqUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private List<RelationshipFriend> createRelationshipFriend(Long userId, Long applyUserId) {
|
||||
return Arrays.asList(newRelationshipFriend(userId, applyUserId),
|
||||
newRelationshipFriend(applyUserId, userId));
|
||||
}
|
||||
|
||||
private RelationshipFriend newRelationshipFriend(Long userId, Long applyUserId) {
|
||||
RelationshipFriend relationshipFriend = new RelationshipFriend()
|
||||
.setUserId(userId)
|
||||
.setFriendUserId(applyUserId);
|
||||
relationshipFriend.setCreateTime(TimestampUtils.now());
|
||||
relationshipFriend.setUpdateTime(TimestampUtils.now());
|
||||
return relationshipFriend;
|
||||
}
|
||||
|
||||
|
||||
private Boolean cancelSubscription(AppUserIdCmd cmd) {
|
||||
if (!userSubscriptionService.remove(cmd.requiredReqUserId(), cmd.getUserId())) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user