From ea9c9a496be73d322054aea9591a6dd80481f0f5 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 11:02:54 +0800 Subject: [PATCH 1/2] friend --- internal/rpc/friend/friend.go | 4 ++-- pkg/common/db/controller/friend.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 0aeaccef0..ada168ec8 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -2,6 +2,7 @@ package friend import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/internal/common/check" "github.com/OpenIMSDK/Open-IM-Server/internal/common/convert" "github.com/OpenIMSDK/Open-IM-Server/internal/common/notification" @@ -46,7 +47,6 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error { // ok func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) (resp *pbfriend.ApplyToAddFriendResp, err error) { - resp = &pbfriend.ApplyToAddFriendResp{} if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil { return nil, err } @@ -70,7 +70,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply return nil, err } s.notification.FriendApplicationAddNotification(ctx, req) - return resp, nil + return &pbfriend.ApplyToAddFriendResp{}, nil } // ok diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index b85a4fb34..c1a2f6b49 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -7,6 +7,7 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" @@ -72,6 +73,7 @@ func (f *friendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) ( func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) { return f.tx.Transaction(func(tx any) error { _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) + log.ZError(ctx, "fr error", err) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { return err From 67e1faefd8e3326e154bca5e6bc3b3cc44c345c7 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 11:26:34 +0800 Subject: [PATCH 2/2] friend db --- pkg/common/config/config.go | 5 ++++- pkg/common/db/controller/friend.go | 2 -- pkg/common/db/relation/friend_request_model.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index ca56d77b5..114b36b2d 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -2,13 +2,15 @@ package config import ( "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "io/ioutil" "os" "path/filepath" "runtime" + "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" + _ "embed" + "gopkg.in/yaml.v3" ) @@ -189,6 +191,7 @@ type config struct { ElasticSearchAddr []string `yaml:"elasticSearchAddr"` ElasticSearchUser string `yaml:"elasticSearchUser"` ElasticSearchPassword string `yaml:"elasticSearchPassword"` + isJson bool `yaml:"isJson"` } ModuleName struct { LongConnSvrName string `yaml:"longConnSvrName"` diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index c1a2f6b49..b85a4fb34 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -7,7 +7,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" @@ -73,7 +72,6 @@ func (f *friendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) ( func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) { return f.tx.Transaction(func(tx any) error { _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) - log.ZError(ctx, "fr error", err) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { return err diff --git a/pkg/common/db/relation/friend_request_model.go b/pkg/common/db/relation/friend_request_model.go index 658a0c5ed..5efb0bddd 100644 --- a/pkg/common/db/relation/friend_request_model.go +++ b/pkg/common/db/relation/friend_request_model.go @@ -43,14 +43,14 @@ func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*relati // 获取来指定用户的好友申请 未找到 不返回错误 func (f *FriendRequestGorm) Find(ctx context.Context, fromUserID, toUserID string) (friendRequest *relation.FriendRequestModel, err error) { friendRequest = &relation.FriendRequestModel{} - utils.Wrap(f.db(ctx).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Find(friendRequest).Error, "") - return + err = utils.Wrap(f.db(ctx).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Find(friendRequest).Error, "") + return friendRequest, err } func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friendRequest *relation.FriendRequestModel, err error) { friendRequest = &relation.FriendRequestModel{} - utils.Wrap(f.db(ctx).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Take(friendRequest).Error, "") - return + err = utils.Wrap(f.db(ctx).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Take(friendRequest).Error, "") + return friendRequest, err } // 获取toUserID收到的好友申请列表