From cf968c0b4c9c505e1817431b8b67e98de5c8d02b Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 11:41:20 +0800 Subject: [PATCH 01/17] friend --- internal/api/auth.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/api/auth.go b/internal/api/auth.go index 5e1b8ad0c..76920259a 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -2,6 +2,7 @@ package api import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/internal/api/a2r" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" From 7fd9a8427108aeac8d94544ffe2348fee88de191 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:12:32 +0800 Subject: [PATCH 02/17] error --- config/config.yaml | 2 +- pkg/common/config/config.go | 1 + pkg/common/db/controller/friend.go | 2 ++ pkg/common/mw/rpc_server_interceptor.go | 46 ++++++++++++++----------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 47d7e5409..d801d1811 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -162,7 +162,7 @@ log: #日志级别 6表示全都打印,测试阶段建议设置为6 remainLogLevel: -1 stderr: true - + withStack: false elasticSearchSwitch: false elasticSearchAddr: [ 127.0.0.1:9201 ] elasticSearchUser: "" diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 114b36b2d..75dfc60aa 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -187,6 +187,7 @@ type config struct { RemainRotationCount uint `yaml:"remainRotationCount"` RemainLogLevel int `yaml:"remainLogLevel"` Stderr bool `yaml:"stderr"` + WithStack bool `yaml:"withStack"` ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"` ElasticSearchAddr []string `yaml:"elasticSearchAddr"` ElasticSearchUser string `yaml:"elasticSearchUser"` diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index b85a4fb34..f2ede2e8e 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" @@ -74,6 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { + log.ZDebug(ctx, "AddFriendRequest err:%v", err.Error(), "err", err, "unwrap", errors.Unwrap(err)) return err } //无错误 则更新 diff --git a/pkg/common/mw/rpc_server_interceptor.go b/pkg/common/mw/rpc_server_interceptor.go index cb4df6dc6..ca6af8f7d 100644 --- a/pkg/common/mw/rpc_server_interceptor.go +++ b/pkg/common/mw/rpc_server_interceptor.go @@ -3,6 +3,12 @@ package mw import ( "context" "fmt" + "math" + "runtime" + "runtime/debug" + "strings" + + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" @@ -12,10 +18,6 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" - "math" - "runtime" - "runtime/debug" - "strings" ) const OperationID = "operationID" @@ -87,23 +89,25 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary } grpcStatus := status.New(codes.Code(code), codeErr.Msg()) var errInfo *errinfo.ErrorInfo - if unwrap != err { - sti, ok := err.(interface{ StackTrace() errors.StackTrace }) - if ok { - log.ZWarn(ctx, "rpc server resp", err, "funcName", funcName, "unwrap", unwrap.Error(), "stack", fmt.Sprintf("%+v", err)) - if fs := sti.StackTrace(); len(fs) > 0 { - pc := uintptr(fs[0]) - fn := runtime.FuncForPC(pc) - file, line := fn.FileLine(pc) - errInfo = &errinfo.ErrorInfo{ - Path: file, - Line: uint32(line), - Name: fn.Name(), - Cause: unwrap.Error(), - Warp: nil, - } - if arr := strings.Split(err.Error(), ": "); len(arr) > 1 { - errInfo.Warp = arr[:len(arr)-1] + if config.Config.Log.WithStack { + if unwrap != err { + sti, ok := err.(interface{ StackTrace() errors.StackTrace }) + if ok { + log.ZWarn(ctx, "rpc server resp", err, "funcName", funcName, "unwrap", unwrap.Error(), "stack", fmt.Sprintf("%+v", err)) + if fs := sti.StackTrace(); len(fs) > 0 { + pc := uintptr(fs[0]) + fn := runtime.FuncForPC(pc) + file, line := fn.FileLine(pc) + errInfo = &errinfo.ErrorInfo{ + Path: file, + Line: uint32(line), + Name: fn.Name(), + Cause: unwrap.Error(), + Warp: nil, + } + if arr := strings.Split(err.Error(), ": "); len(arr) > 1 { + errInfo.Warp = arr[:len(arr)-1] + } } } } From 553606d2a869840618973c97e414c13977c40a2f Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:18:33 +0800 Subject: [PATCH 03/17] err --- pkg/common/db/controller/friend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index f2ede2e8e..0f8662b36 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -75,7 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { - log.ZDebug(ctx, "AddFriendRequest err:%v", err.Error(), "err", err, "unwrap", errors.Unwrap(err)) + log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", errors.Unwrap(err)) return err } //无错误 则更新 From 9716d478bd442da3c5fe3c44c7e91241d53b4294 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:23:49 +0800 Subject: [PATCH 04/17] freind --- pkg/common/db/controller/friend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 0f8662b36..a413d3b59 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -75,7 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { - log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", errors.Unwrap(err)) + log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", errors.Unwrap(err), "unwrap", errors.Unwrap(err)) return err } //无错误 则更新 From 506a417b0bfc3302d44aaf6cd034651c4ce18ea5 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:29:19 +0800 Subject: [PATCH 05/17] err --- pkg/common/db/controller/friend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index a413d3b59..230423d9d 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -75,7 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { - log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", errors.Unwrap(err), "unwrap", errors.Unwrap(err)) + log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err, "unwrap", errors.Unwrap(err)) return err } //无错误 则更新 From 1921e5b0303d66c9e8315c5dbff7fc7893f5d3f0 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:32:26 +0800 Subject: [PATCH 06/17] err --- pkg/common/db/controller/friend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 230423d9d..f9fc857d4 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -75,7 +75,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { - log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err, "unwrap", errors.Unwrap(err)) + log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err.Error(), "unwrap", errors.Unwrap(err).Error()) return err } //无错误 则更新 From befd5c8636a1151b1704e3c3fdca38795197c2fb Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:36:26 +0800 Subject: [PATCH 07/17] err --- pkg/common/db/controller/friend.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index f9fc857d4..cfa4de233 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -74,7 +74,8 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse return f.tx.Transaction(func(tx any) error { _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 - if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { + if err != nil && errs.Unwrap(err) != gorm.ErrRecordNotFound { + // errors.Unwrap() log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err.Error(), "unwrap", errors.Unwrap(err).Error()) return err } From 91e2f3caeb9f5a4f27a940b329d8bfcd5218bd71 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 12:41:04 +0800 Subject: [PATCH 08/17] err --- pkg/common/db/controller/friend.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index cfa4de233..f9fc857d4 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -74,8 +74,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse return f.tx.Transaction(func(tx any) error { _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 - if err != nil && errs.Unwrap(err) != gorm.ErrRecordNotFound { - // errors.Unwrap() + if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err.Error(), "unwrap", errors.Unwrap(err).Error()) return err } From 40da937c4c7eb9826fdab7d4e9665548ad697bfa Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 13:44:30 +0800 Subject: [PATCH 09/17] friend --- pkg/common/db/controller/friend.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index f9fc857d4..09a150239 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -2,12 +2,11 @@ package controller import ( "context" - "errors" + "time" "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" @@ -74,8 +73,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse return f.tx.Transaction(func(tx any) error { _, err := f.friendRequest.NewTx(tx).Take(ctx, fromUserID, toUserID) //有db错误 - if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound { - log.ZDebug(ctx, "AddFriendRequest err", "bool", errors.Unwrap(err) != gorm.ErrRecordNotFound, "err", err.Error(), "unwrap", errors.Unwrap(err).Error()) + if err != nil && errs.Unwrap(err) != gorm.ErrRecordNotFound { return err } //无错误 则更新 @@ -91,7 +89,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse return nil } //gorm.ErrRecordNotFound 错误,则新增 - if err := f.friendRequest.NewTx(tx).Create(ctx, []*relation.FriendRequestModel{{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex}}); err != nil { + if err := f.friendRequest.NewTx(tx).Create(ctx, []*relation.FriendRequestModel{{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex, CreateTime: time.Now()}}); err != nil { return err } return nil From a765160ee3fd4d2400d96ad1476079286d9ee4c4 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 14:19:53 +0800 Subject: [PATCH 10/17] friend --- pkg/common/db/controller/friend.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 09a150239..4bb857a45 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -89,7 +89,7 @@ func (f *friendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse return nil } //gorm.ErrRecordNotFound 错误,则新增 - if err := f.friendRequest.NewTx(tx).Create(ctx, []*relation.FriendRequestModel{{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex, CreateTime: time.Now()}}); err != nil { + if err := f.friendRequest.NewTx(tx).Create(ctx, []*relation.FriendRequestModel{{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex, CreateTime: time.Now(), HandleTime: time.Unix(0, 0)}}); err != nil { return err } return nil From 40333d62e373e7fdaed212d01fdc08908eb98d1a Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 14:59:32 +0800 Subject: [PATCH 11/17] friend --- pkg/common/db/controller/friend.go | 4 ++-- pkg/common/db/relation/friend_request_model.go | 4 ++-- pkg/common/db/table/relation/friend_request.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 4bb857a45..77cc7d5d3 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -142,7 +142,7 @@ func (f *friendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest return err } friendRequest.HandleResult = constant.FriendResponseRefuse - err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest}) + err = f.friendRequest.Update(ctx, friendRequest) if err != nil { return err } @@ -158,7 +158,7 @@ func (f *friendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest * } friendRequest.HandlerUserID = friendRequest.FromUserID friendRequest.HandleResult = constant.FriendResponseAgree - err = f.friendRequest.NewTx(tx).Update(ctx, []*relation.FriendRequestModel{friendRequest}) + err = f.friendRequest.NewTx(tx).Update(ctx, friendRequest) if err != nil { return err } diff --git a/pkg/common/db/relation/friend_request_model.go b/pkg/common/db/relation/friend_request_model.go index 5efb0bddd..bc04b27f8 100644 --- a/pkg/common/db/relation/friend_request_model.go +++ b/pkg/common/db/relation/friend_request_model.go @@ -36,8 +36,8 @@ func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, formUserID string, } // 更新多条记录 (非零值) -func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*relation.FriendRequestModel) (err error) { - return utils.Wrap(f.db(ctx).Updates(&friendRequests).Error, "") +func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests *relation.FriendRequestModel) (err error) { + return utils.Wrap(f.db(ctx).Updates(friendRequests).Error, "") } // 获取来指定用户的好友申请 未找到 不返回错误 diff --git a/pkg/common/db/table/relation/friend_request.go b/pkg/common/db/table/relation/friend_request.go index 559b67bb2..998a76719 100644 --- a/pkg/common/db/table/relation/friend_request.go +++ b/pkg/common/db/table/relation/friend_request.go @@ -31,7 +31,7 @@ type FriendRequestModelInterface interface { // 更新零值 UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}) (err error) // 更新多条记录 (非零值) - Update(ctx context.Context, friendRequests []*FriendRequestModel) (err error) + Update(ctx context.Context, friendRequests *FriendRequestModel) (err error) // 获取来指定用户的好友申请 未找到 不返回错误 Find(ctx context.Context, fromUserID, toUserID string) (friendRequest *FriendRequestModel, err error) Take(ctx context.Context, fromUserID, toUserID string) (friendRequest *FriendRequestModel, err error) From c8fd03a6933ab4bb7e6ee7b099446a29223a297f Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 15:04:01 +0800 Subject: [PATCH 12/17] friend --- pkg/common/db/relation/friend_request_model.go | 10 +++++----- pkg/common/db/table/relation/friend_request.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/common/db/relation/friend_request_model.go b/pkg/common/db/relation/friend_request_model.go index bc04b27f8..9cb30ecbf 100644 --- a/pkg/common/db/relation/friend_request_model.go +++ b/pkg/common/db/relation/friend_request_model.go @@ -31,13 +31,13 @@ func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID str } // 更新零值 -func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}) (err error) { - return utils.Wrap(f.db(ctx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? AND to_user_id =?", formUserID, toUserID).Updates(args).Error, "") +func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, fromUserID string, toUserID string, args map[string]interface{}) (err error) { + return utils.Wrap(f.db(ctx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? AND to_user_id =?", fromUserID, toUserID).Updates(args).Error, "") } -// 更新多条记录 (非零值) -func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests *relation.FriendRequestModel) (err error) { - return utils.Wrap(f.db(ctx).Updates(friendRequests).Error, "") +// 更新记录 (非零值) +func (f *FriendRequestGorm) Update(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) { + return utils.Wrap(f.db(ctx).Where("from_user_id = ? AND to_user_id =?", friendRequest.FromUserID, friendRequest.ToUserID).Updates(friendRequest).Error, "") } // 获取来指定用户的好友申请 未找到 不返回错误 diff --git a/pkg/common/db/table/relation/friend_request.go b/pkg/common/db/table/relation/friend_request.go index 998a76719..b14ecb2c2 100644 --- a/pkg/common/db/table/relation/friend_request.go +++ b/pkg/common/db/table/relation/friend_request.go @@ -31,7 +31,7 @@ type FriendRequestModelInterface interface { // 更新零值 UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}) (err error) // 更新多条记录 (非零值) - Update(ctx context.Context, friendRequests *FriendRequestModel) (err error) + Update(ctx context.Context, friendRequest *FriendRequestModel) (err error) // 获取来指定用户的好友申请 未找到 不返回错误 Find(ctx context.Context, fromUserID, toUserID string) (friendRequest *FriendRequestModel, err error) Take(ctx context.Context, fromUserID, toUserID string) (friendRequest *FriendRequestModel, err error) From 2f8c65f9303e4faaccb5235c0450060f818fd1b1 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 15:17:40 +0800 Subject: [PATCH 13/17] friend --- internal/rpc/friend/friend.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 6d519a3d5..a44b949a4 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/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" @@ -195,7 +196,12 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p if err := s.userCheck.Access(ctx, req.UserID); err != nil { return nil, err } - friendRequests, total, err := s.FriendDatabase.PageFriendRequestFromMe(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) + var pageNumber, showNumber int32 + if req.Pagination != nil { + pageNumber = req.Pagination.PageNumber + showNumber = req.Pagination.ShowNumber + } + friendRequests, total, err := s.FriendDatabase.PageFriendRequestFromMe(ctx, req.UserID, pageNumber, showNumber) if err != nil { return nil, err } From 19f535472152371071a0093056b50dacb2a6d833 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 15:24:07 +0800 Subject: [PATCH 14/17] page --- internal/rpc/friend/friend.go | 12 +++++------- pkg/utils/page.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 pkg/utils/page.go diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index a44b949a4..a55443b16 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -178,7 +178,8 @@ func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbf if err := s.userCheck.Access(ctx, req.UserID); err != nil { return nil, err } - friendRequests, total, err := s.FriendDatabase.PageFriendRequestToMe(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) + pageNumber, showNumber := utils.GetPage(req.Pagination) + friendRequests, total, err := s.FriendDatabase.PageFriendRequestToMe(ctx, req.UserID, pageNumber, showNumber) if err != nil { return nil, err } @@ -196,11 +197,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *p if err := s.userCheck.Access(ctx, req.UserID); err != nil { return nil, err } - var pageNumber, showNumber int32 - if req.Pagination != nil { - pageNumber = req.Pagination.PageNumber - showNumber = req.Pagination.ShowNumber - } + pageNumber, showNumber := utils.GetPage(req.Pagination) friendRequests, total, err := s.FriendDatabase.PageFriendRequestFromMe(ctx, req.UserID, pageNumber, showNumber) if err != nil { return nil, err @@ -228,7 +225,8 @@ func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbfriend.G if err := s.userCheck.Access(ctx, req.UserID); err != nil { return nil, err } - friends, total, err := s.FriendDatabase.PageOwnerFriends(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber) + pageNumber, showNumber := utils.GetPage(req.Pagination) + friends, total, err := s.FriendDatabase.PageOwnerFriends(ctx, req.UserID, pageNumber, showNumber) if err != nil { return nil, err } diff --git a/pkg/utils/page.go b/pkg/utils/page.go new file mode 100644 index 000000000..61942a5d7 --- /dev/null +++ b/pkg/utils/page.go @@ -0,0 +1,10 @@ +package utils + +import "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" + +func GetPage(pagination *sdkws.RequestPagination) (pageNumber, showNumber int32) { + if pagination != nil { + return pagination.PageNumber, pagination.ShowNumber + } + return +} From 04347bcc0d4b238e037d97b4ac7336bbf9976762 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 15:48:48 +0800 Subject: [PATCH 15/17] friend --- pkg/rpcclient/convert/convert.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/rpcclient/convert/convert.go b/pkg/rpcclient/convert/convert.go index a37fa322b..2aabfc030 100644 --- a/pkg/rpcclient/convert/convert.go +++ b/pkg/rpcclient/convert/convert.go @@ -2,13 +2,14 @@ package convert import ( "context" + "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" sdk "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check" utils2 "github.com/OpenIMSDK/Open-IM-Server/pkg/utils" utils "github.com/OpenIMSDK/open_utils" - "time" ) type DBFriend struct { @@ -110,6 +111,9 @@ func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation if len(friendRequests) > 0 { userIDs = append(userIDs, friendRequests[0].FromUserID) } + for _, v := range friendRequests { + userIDs = append(userIDs, v.ToUserID) + } users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true) if err != nil { return nil, err From c9fd33681288e35ee9ef3106a71c8dc2f8064aaf Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 15:54:54 +0800 Subject: [PATCH 16/17] friend --- pkg/rpcclient/convert/convert.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/rpcclient/convert/convert.go b/pkg/rpcclient/convert/convert.go index 2aabfc030..f7d059c21 100644 --- a/pkg/rpcclient/convert/convert.go +++ b/pkg/rpcclient/convert/convert.go @@ -126,8 +126,8 @@ func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation pbFriendRequest.ToNickname = users[v.ToUserID].Nickname pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL pbFriendRequest.ToGender = users[v.ToUserID].Gender - pbFriendRequest.CreateTime = db.CreateTime.Unix() - pbFriendRequest.HandleTime = db.HandleTime.Unix() + pbFriendRequest.CreateTime = v.CreateTime.Unix() + pbFriendRequest.HandleTime = v.HandleTime.Unix() PBFriendRequests = append(PBFriendRequests, pbFriendRequest) } return From 7c8c809fb85392b7f4c713b4f029e9b558c5dcfe Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 17 Mar 2023 16:01:56 +0800 Subject: [PATCH 17/17] errcode --- pkg/common/db/controller/friend.go | 2 ++ pkg/rpcclient/convert/convert.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pkg/common/db/controller/friend.go b/pkg/common/db/controller/friend.go index 77cc7d5d3..553e52d17 100644 --- a/pkg/common/db/controller/friend.go +++ b/pkg/common/db/controller/friend.go @@ -142,6 +142,7 @@ func (f *friendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest return err } friendRequest.HandleResult = constant.FriendResponseRefuse + friendRequest.HandleTime = time.Now() err = f.friendRequest.Update(ctx, friendRequest) if err != nil { return err @@ -158,6 +159,7 @@ func (f *friendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest * } friendRequest.HandlerUserID = friendRequest.FromUserID friendRequest.HandleResult = constant.FriendResponseAgree + friendRequest.HandleTime = time.Now() err = f.friendRequest.NewTx(tx).Update(ctx, friendRequest) if err != nil { return err diff --git a/pkg/rpcclient/convert/convert.go b/pkg/rpcclient/convert/convert.go index f7d059c21..41c340a6b 100644 --- a/pkg/rpcclient/convert/convert.go +++ b/pkg/rpcclient/convert/convert.go @@ -120,14 +120,17 @@ func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation } for _, v := range friendRequests { pbFriendRequest := &sdk.FriendRequest{} + pbFriendRequest.FromUserID = users[v.FromUserID].UserID pbFriendRequest.FromNickname = users[v.FromUserID].Nickname pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL pbFriendRequest.FromGender = users[v.FromUserID].Gender + pbFriendRequest.ToUserID = users[v.ToUserID].UserID pbFriendRequest.ToNickname = users[v.ToUserID].Nickname pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL pbFriendRequest.ToGender = users[v.ToUserID].Gender pbFriendRequest.CreateTime = v.CreateTime.Unix() pbFriendRequest.HandleTime = v.HandleTime.Unix() + pbFriendRequest.HandlerUserID = v.HandlerUserID PBFriendRequests = append(PBFriendRequests, pbFriendRequest) } return