|
|
@@ -6,6 +6,7 @@ import ( |
|
|
|
"gim/internal/business/comm/utils" |
|
|
|
"gim/internal/logic/domain/message/repo" |
|
|
|
"gim/internal/logic/proxy" |
|
|
|
"gim/pkg/db" |
|
|
|
"gim/pkg/gerrors" |
|
|
|
"gim/pkg/grpclib" |
|
|
|
"gim/pkg/pb" |
|
|
@@ -66,13 +67,20 @@ func (*friendService) DeleteFriend(ctx context.Context, userId, friendId int64) |
|
|
|
|
|
|
|
// AddFriend 添加好友 |
|
|
|
func (*friendService) AddFriend(ctx context.Context, userId, friendId int64, remarks, description string) error { |
|
|
|
masterId, _ := grpclib.GetCtxMasterId(ctx) |
|
|
|
isAutoAddFriends := svc.SysCfgGet(masterId, "is_auto_add_friends") |
|
|
|
|
|
|
|
friend, err := FriendRepo.Get(userId, friendId) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if friend != nil { |
|
|
|
if friend.Status == FriendStatusApply { |
|
|
|
return nil |
|
|
|
if isAutoAddFriends != "1" { |
|
|
|
return nil |
|
|
|
} |
|
|
|
//TODO::防止第一次加好友失败 |
|
|
|
db.DB.Where("user_id = ? and friend_id = ?", userId, friendId).Delete(&friend) |
|
|
|
} |
|
|
|
if friend.Status == FriendStatusAgree { |
|
|
|
return gerrors.ErrAlreadyIsFriend |
|
|
@@ -108,9 +116,6 @@ func (*friendService) AddFriend(ctx context.Context, userId, friendId int64, rem |
|
|
|
} |
|
|
|
|
|
|
|
//TODO::判断是否需要`自动添加好友` |
|
|
|
masterId, _ := grpclib.GetCtxMasterId(ctx) |
|
|
|
isAutoAddFriends := svc.SysCfgGet(masterId, "is_auto_add_friends") |
|
|
|
|
|
|
|
//if isAutoAddFriends == "1" && resp.User.IsAutoAddedFriends == 1 { |
|
|
|
if isAutoAddFriends == "1" { |
|
|
|
respFriend, err := rpc.GetBusinessIntClient().GetUser(ctx, &pb.GetUserReq{UserId: friendId}) |
|
|
|