From 2958958b000c3dd3c012816e9d5dc75cf75d176f Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 30 Nov 2022 23:01:28 +0800 Subject: [PATCH] update --- .../logic/domain/friend/friend_service.go | 28 +++++++++++++------ test/tcp_conn/main.go | 4 +-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/logic/domain/friend/friend_service.go b/internal/logic/domain/friend/friend_service.go index 227892a..a971c2d 100644 --- a/internal/logic/domain/friend/friend_service.go +++ b/internal/logic/domain/friend/friend_service.go @@ -122,15 +122,25 @@ func (*friendService) AgreeAddFriend(ctx context.Context, userId, friendId int64 return err } - now := time.Now() - err = FriendRepo.Save(&Friend{ - UserId: userId, - FriendId: friendId, - Remarks: remarks, - Status: FriendStatusAgree, - CreateTime: now, - UpdateTime: now, - }) + newFriend, err := FriendRepo.Get(friendId, userId) + if newFriend != nil && newFriend.Status != FriendStatusAgree { + newFriend.Status = FriendStatusAgree + err = FriendRepo.Save(newFriend) + if err != nil { + return err + } + } else { + now := time.Now() + err = FriendRepo.Save(&Friend{ + UserId: userId, + FriendId: friendId, + Remarks: remarks, + Status: FriendStatusAgree, + CreateTime: now, + UpdateTime: now, + }) + } + if err != nil { return err } diff --git a/test/tcp_conn/main.go b/test/tcp_conn/main.go index a6e93d3..5fb6176 100644 --- a/test/tcp_conn/main.go +++ b/test/tcp_conn/main.go @@ -67,7 +67,7 @@ func (c *TcpClient) Output(pt pb.PackageType, requestId int64, message proto.Mes func (c *TcpClient) Start() { //connect, err := net.Dial("tcp", "111.229.238.28:8080") - connect, err := net.Dial("tcp", "im-tcp-connect.izhyin.com:8001") + connect, err := net.Dial("tcp", "im-tcp-connect.zhiyingos.com:8001") if err != nil { log.Println(err) return @@ -87,7 +87,7 @@ func (c *TcpClient) SignIn() { signIn := pb.SignInInput{ UserId: c.UserId, DeviceId: c.DeviceId, - Token: "JNSTQKMVVIEBWQWEILZXIZJILHBUWHUUNWPLZYDF", + Token: "KGDPGQAQDEXXFXFLPMHDWHJEDYTOVCSGIZNILPRP", } c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn) }