From 73ac2c5d80db9cea6d144ed77c6809693fbfec76 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Thu, 11 May 2023 16:44:00 +0800 Subject: [PATCH] update --- internal/business/api/business_ext.go | 2 +- internal/business/comm/md/app_redis_key.go | 2 +- internal/logic/domain/friend/friend_service.go | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/business/api/business_ext.go b/internal/business/api/business_ext.go index 1596fb8..0987c5c 100644 --- a/internal/business/api/business_ext.go +++ b/internal/business/api/business_ext.go @@ -66,7 +66,7 @@ func (s *BusinessExtServer) IsFriends(ctx context.Context, req *pb.IsFriendsReq) return nil, err } var isFriend = int64(1) - if friend == nil { + if friend == nil || friend.Status == friend2.FriendStatusApply { isFriend = 2 } diff --git a/internal/business/comm/md/app_redis_key.go b/internal/business/comm/md/app_redis_key.go index 9e4cd58..0edc29a 100644 --- a/internal/business/comm/md/app_redis_key.go +++ b/internal/business/comm/md/app_redis_key.go @@ -4,5 +4,5 @@ package md const ( AppCfgCacheKey = "%s:gim_cfg_cache:%s" // 占位符: masterId, key的第一个字母 AppUserPushForJgCacheKey = "%s:gim_user_push_for_jg_cache:%s" // 占位符: masterId, key的第一个字母 - CfgCacheTime = 86400 + CfgCacheTime = 0.5 * 60 * 60 ) diff --git a/internal/logic/domain/friend/friend_service.go b/internal/logic/domain/friend/friend_service.go index 8bc52d6..6fb363f 100644 --- a/internal/logic/domain/friend/friend_service.go +++ b/internal/logic/domain/friend/friend_service.go @@ -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})