From 6b1f4e16867e3b38aa24f02202c8928527fb512d Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 28 Dec 2021 11:57:12 +0800 Subject: [PATCH] tidy code --- internal/rpc/friend/firend.go | 104 ++++++++---------- internal/rpc/group/group.go | 51 ++++----- .../im_mysql_model/friend_model.go | 2 +- .../im_mysql_model/friend_request_model.go | 19 +++- .../im_mysql_model/group_member_model.go | 2 +- pkg/proto/sdk_ws/ws.proto | 1 - 6 files changed, 85 insertions(+), 94 deletions(-) diff --git a/internal/rpc/friend/firend.go b/internal/rpc/friend/firend.go index ed0d4e5ff..eff77a572 100644 --- a/internal/rpc/friend/firend.go +++ b/internal/rpc/friend/firend.go @@ -111,7 +111,8 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String()) ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) if !ok { - log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) + return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } black := imdb.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID} @@ -120,7 +121,7 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error()) return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - log.NewInfo(req.CommID.OperationID, "InsertInToUserBlackList ok ", req.CommID.FromUserID, req.CommID.ToUserID) + log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID) chat.BlackAddedNotification(req) return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil } @@ -129,7 +130,8 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String()) ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) if !ok { - log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) + return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } //Cannot add non-existent users if _, err := imdb.GetUserByUserID(req.CommID.ToUserID); err != nil { @@ -142,7 +144,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq utils.CopyStructFields(&friendRequest, req.CommID) err := imdb.UpdateFriendApplication(&friendRequest) if err != nil { - log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error()) + log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest) return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } @@ -150,19 +152,20 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil } +//todo func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) { log.NewInfo(req.OperationID, "ImportFriend failed ", req.String()) var resp pbFriend.ImportFriendResp var c pbFriend.CommonResp if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) { - log.NewError(req.OperationID, "not authorized", req.OpUserID) + log.NewError(req.OperationID, "not authorized", req.OpUserID, config.Config.Manager.AppManagerUid) c.ErrCode = constant.ErrAccess.ErrCode c.ErrMsg = constant.ErrAccess.ErrMsg return &pbFriend.ImportFriendResp{CommonResp: &c, FailedFriendUserIDList: req.FriendUserIDList}, nil } if _, err := imdb.GetUserByUserID(req.FromUserID); err != nil { - log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID) + log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID) c.ErrCode = constant.ErrDB.ErrCode c.ErrMsg = "this user not exists,cant not add friend" return &pbFriend.ImportFriendResp{CommonResp: &c, FailedFriendUserIDList: req.FriendUserIDList}, nil @@ -209,8 +212,8 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.AddFriendResponseResp, error) { log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String()) - if !token_verify.CheckAccess(req.CommID.FromUserID, req.CommID.ToUserID) { - log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.FromUserID, req.CommID.ToUserID) + if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } @@ -221,45 +224,47 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF log.NewError(req.CommID.OperationID, "GetFriendApplicationByBothUserID failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - friendRequest.HandleResult = req.Flag - //Change friend request status flag + friendRequest.HandleTime = time.Now() + friendRequest.HandleMsg = req.HandleMsg + friendRequest.HandlerUserID = req.CommID.OpUserID err = imdb.UpdateFriendApplication(friendRequest) if err != nil { log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok") //Change the status of the friend request form if req.Flag == constant.FriendFlag { //Establish friendship after find friend relationship not exists - _, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID) + _, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID) if err == nil { - log.NewWarn(req.CommID.OperationID, "FindFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID) + log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID) } else { //Establish two single friendship - err = imdb.InsertToFriend(req.CommID.FromUserID, req.CommID.ToUserID, req.Flag) + toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID} + err = imdb.InsertToFriend(&toInsertFollow) if err != nil { - log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag) + log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } } - _, err = imdb.FindFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID) + _, err = imdb.GetFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID) if err == nil { log.NewWarn(req.CommID.OperationID, "FindFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID) - return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil } - err = imdb.InsertToFriend(req.CommID.ToUserID, req.CommID.FromUserID, req.Flag) + toInsertFollow := imdb.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID} + err = imdb.InsertToFriend(&toInsertFollow) if err != nil { - log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag) + log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID) } chat.FriendApplicationProcessedNotification(req) - chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID) + log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok") return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil } @@ -286,7 +291,7 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { - log.NewError(req.CommID.OperationID, "CheckAccess failed", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } @@ -304,13 +309,13 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl //Find black user information us, err := imdb.GetUserByUserID(blackUser.BlockUserID) if err != nil { - log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), blackUser.BlockUserID) + log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), blackUser.BlockUserID) continue } utils.CopyStructFields(&blackUserInfo, us) userInfoList = append(userInfoList, &blackUserInfo) } - log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok") + log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}) return &pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}, nil } @@ -318,13 +323,13 @@ func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFr log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String()) //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { - log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.SetFriendCommentResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } - err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.OpUserID, req.Remark) + err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark) if err != nil { - log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", err.Error(), req.CommID.FromUserID, req.CommID.OpUserID, req.Remark) + log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark) return &pbFriend.SetFriendCommentResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok") @@ -336,7 +341,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String()) //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { - log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } err := imdb.RemoveBlackList(req.CommID.FromUserID, req.CommID.ToUserID) @@ -345,7 +350,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } - log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok") + log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ") chat.BlackDeletedNotification(req) return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil } @@ -353,7 +358,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) { log.NewInfo("IsInBlackList args ", req.String()) if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { - log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } @@ -362,7 +367,7 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac if err == nil { isInBlacklist = true } - log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok") + log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist}) return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil } @@ -379,62 +384,45 @@ func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) } else { isFriend = false } - log.NewInfo("IsFriend rpc ok") + log.NewInfo("IsFriend rpc ok ", pbFriend.IsFriendResp{Response: isFriend}) return &pbFriend.IsFriendResp{Response: isFriend}, nil } func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) { log.NewInfo("GetFriendList args ", req.String()) - var userInfoList []*sdkws.FriendInfo - //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - friends, err := imdb.GetUserInfoFromFriend(req.CommID.FromUserID) + friends, err := imdb.GetFriendListByUserID(req.CommID.FromUserID) if err != nil { - log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed", err.Error(), req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed ", err.Error(), req.CommID.FromUserID) return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } + var userInfoList []*sdkws.FriendInfo for _, friendUser := range friends { + var friendUserInfo sdkws.FriendInfo - //find user is in blackList - // err = imdb.GetRelationshipFromBlackList(req.CommID.FromUserID, friendUser.FriendUserID) - //if err == nil { - // friendUserInfo.IsBlack = constant.BlackListFlag - //} else { - // friendUserInfo.IsBlack = 0 - //} - //Find user information - us, err := imdb.GetUserByUserID(friendUser.FriendUserID) - if err != nil { - log.NewError(req.CommID.OperationID, "FindUserByUID failed", err.Error(), friendUser.FriendUserID) - continue - } - utils.CopyStructFields(friendUserInfo.FriendUser, us) - friendUserInfo.Remark = friendUser.Remark - friendUserInfo.OwnerUserID = req.CommID.FromUserID - friendUserInfo.CreateTime = friendUser.CreateTime + utils.CopyStructFields(&friendUserInfo, friendUser) userInfoList = append(userInfoList, &friendUserInfo) } log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{FriendInfoList: userInfoList}) return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil } +//received func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) { log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String()) - //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - // Find the current user friend applications received ApplyUsersInfo, err := imdb.GetReceivedFriendsApplicationListByUserID(req.CommID.FromUserID) if err != nil { - log.NewError(req.CommID.OperationID, "FindFriendsApplyFromFriendReq ", err.Error(), req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "GetReceivedFriendsApplicationListByUserID ", err.Error(), req.CommID.FromUserID) return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } @@ -451,19 +439,19 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSelfApplyListReq) (*pbFriend.GetSelfApplyListResp, error) { log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String()) - var selfApplyOtherUserList []*sdkws.FriendRequest + //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - // Find the self add other userinfo usersInfo, err := imdb.GetSendFriendApplicationListByUserID(req.CommID.FromUserID) if err != nil { - log.NewError(req.CommID.OperationID, "FindSelfApplyFromFriendReq failed ", err.Error(), req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, "GetSendFriendApplicationListByUserID failed ", err.Error(), req.CommID.FromUserID) return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } + var selfApplyOtherUserList []*sdkws.FriendRequest for _, selfApplyOtherUserInfo := range usersInfo { var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo utils.CopyStructFields(&userInfo, selfApplyOtherUserInfo) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index cf36f01ad..53ab002d8 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -74,21 +74,22 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - var okUserIDList []string + //Time stamp + MD5 to generate group chat id groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10)) //to group - groupInfo := imdb.Group{} + groupInfo := imdb.Group{GroupID: groupId} utils.CopyStructFields(&groupInfo, req.GroupInfo) + groupInfo.CreatorUserID = req.OpUserID err := im_mysql_model.InsertIntoGroup(groupInfo) if err != nil { - log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupId, req.GroupInfo.GroupName, req.GroupInfo.Introduction, req.GroupInfo.Notification, req.GroupInfo.FaceUrl, req.GroupInfo.Ex, req.GroupInfo.GroupType) + log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupInfo) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } us, err := imdb.GetUserByUserID(req.OwnerUserID) if err != nil { - log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OwnerUserID) + log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } @@ -97,16 +98,15 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR utils.CopyStructFields(&groupMember, us) err = im_mysql_model.InsertIntoGroupMember(groupMember) if err != nil { - log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error()) + log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } err = db.DB.AddGroupMember(groupId, req.OwnerUserID) if err != nil { log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, req.OwnerUserID) - // return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil } - + var okUserIDList []string //to group member for _, user := range req.InitMemberList { us, err := im_mysql_model.GetUserByUserID(user.UserID) @@ -118,11 +118,14 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR log.NewError(req.OperationID, "only one owner, failed ", user) continue } + groupMember.RoleLevel = user.RoleLevel utils.CopyStructFields(&groupMember, us) err = im_mysql_model.InsertIntoGroupMember(groupMember) if err != nil { log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) + continue } + okUserIDList = append(okUserIDList, user.UserID) err = db.DB.AddGroupMember(groupId, user.UserID) if err != nil { @@ -140,6 +143,9 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR } chat.GroupCreatedNotification(req.OperationID, req.OpUserID, req.OwnerUserID, groupId, okUserIDList) utils.CopyStructFields(resp.GroupInfo, group) + resp.GroupInfo.MemberCount = uint32(imdb.GetGroupMemberNumByGroupID(groupId)) + resp.GroupInfo.OwnerUserID = req.OwnerUserID + log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String()) return resp, nil } @@ -167,6 +173,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo utils.CopyStructFields(&groupNode, group) groupNode.CreateTime = group.CreateTime groupNode.MemberCount = uint32(num) + groupNode.OwnerUserID = owner.UserID resp.GroupList = append(resp.GroupList, &groupNode) } else { log.NewError(req.OperationID, "check nil ", num, owner, err, group) @@ -174,8 +181,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo } log.NewDebug(req.OperationID, "joinedGroup ", groupNode) } - resp.ErrCode = 0 - log.NewInfo(req.OperationID, "GetJoinedGroupList return ", resp.String()) + log.NewInfo(req.OperationID, "GetJoinedGroupList rpc return ", resp.String()) return &resp, nil } @@ -187,8 +193,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(req.GroupID) - if err != nil || groupInfoFromMysql == nil { + _, err := imdb.GetGroupInfoByGroupID(req.GroupID) + if err != nil { log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", req.GroupID, err) return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } @@ -202,7 +208,6 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite resultNode.UserID = v resultNode.Result = 0 toUserInfo, err := imdb.GetUserByUserID(v) - if err != nil { log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), v) resultNode.Result = -1 @@ -244,7 +249,6 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) { log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String()) var resp pbGroup.GetGroupAllMemberResp - resp.ErrCode = 0 memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID) if err != nil { resp.ErrCode = constant.ErrDB.ErrCode @@ -252,35 +256,23 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed,", err.Error(), req.GroupID) return &resp, nil } - m := token_verify.IsMangerUserID(req.OpUserID) - in := false - if m { - in = true - } + for _, v := range memberList { var node open_im_sdk.GroupMemberFullInfo utils.CopyStructFields(node, v) resp.MemberList = append(resp.MemberList, &node) - if !m && req.OpUserID == v.UserID { - in = true - } - } - if !in { - } - resp.ErrCode = 0 + log.NewInfo(req.OperationID, "GetGroupAllMember rpc return ", resp.String()) return &resp, nil } func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGroupMemberListReq) (*pbGroup.GetGroupMemberListResp, error) { log.NewInfo(req.OperationID, "GetGroupMemberList, args ", req.String()) - var resp pbGroup.GetGroupMemberListResp - resp.ErrCode = 0 memberList, err := imdb.GetGroupMemberByGroupID(req.GroupID, req.Filter, req.NextSeq, 30) if err != nil { resp.ErrCode = constant.ErrDB.ErrCode - resp.ErrMsg = err.Error() + resp.ErrMsg = constant.ErrDB.ErrMsg log.NewError(req.OperationID, "GetGroupMemberByGroupId failed,", req.GroupID, req.Filter, req.NextSeq, 30) return &resp, nil } @@ -328,7 +320,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou } if flag != 1 { - log.NewError(req.OperationID, "failed, no access kick ") + log.NewError(req.OperationID, "failed, no access kick ", req.OpUserID) return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } @@ -369,7 +361,6 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou } } chat.MemberKickedNotification(req, okUserIDList) - resp.ErrCode = 0 log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String()) return &resp, nil } diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go index 0ef118f14..a5e6a5de2 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go @@ -33,7 +33,7 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*Friend, return &friend, err } -func GetUserInfoFromFriend(OwnerUserID string) ([]Friend, error) { +func GetFriendListByUserID(OwnerUserID string) ([]Friend, error) { dbConn, err := db.DB.MysqlDB.DefaultGormDB() if err != nil { return nil, err diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go index 735380d0b..dd8164521 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go @@ -44,14 +44,14 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, e return usersInfo, nil } -//reqId apply to add userId already -func GetFriendApplicationByBothUserID(FromUserId, ToUserID string) (*FriendRequest, error) { +//FromUserId apply to add ToUserID +func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*FriendRequest, error) { dbConn, err := db.DB.MysqlDB.DefaultGormDB() if err != nil { return nil, err } var friendRequest FriendRequest - err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", FromUserId, ToUserID).Find(&friendRequest).Error + err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Find(&friendRequest).Error if err != nil { return nil, err } @@ -63,9 +63,22 @@ func UpdateFriendApplication(friendRequest *FriendRequest) error { if err != nil { return err } + friendRequest.CreateTime = time.Now() err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error if err != nil { return err } return nil } + +func InsertFriendApplication(friendRequest *FriendRequest) error { + dbConn, err := db.DB.MysqlDB.DefaultGormDB() + if err != nil { + return err + } + err = dbConn.Table("friend_request").Create(friendRequest).Error + if err != nil { + return err + } + return nil +} diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go index 0f159abee..5845b5ef5 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go @@ -172,7 +172,7 @@ func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumbe var memberList []GroupMember var err error if filter >= 0 { - memberList, err = GetGroupMemberListByGroupIDAndFilter(groupID, filter) //sorted by join time + memberList, err = GetGroupMemberListByGroupIDAndRoleLevel(groupID, filter) //sorted by join time } else { memberList, err = GetGroupMemberListByGroupID(groupID) } diff --git a/pkg/proto/sdk_ws/ws.proto b/pkg/proto/sdk_ws/ws.proto index 1921ef694..60dfb0ee6 100644 --- a/pkg/proto/sdk_ws/ws.proto +++ b/pkg/proto/sdk_ws/ws.proto @@ -27,7 +27,6 @@ message GroupMemberFullInfo { int64 JoinTime = 4; string NickName = 5; string FaceUrl = 6; - string FriendRemark = 7; int32 AppMangerLevel = 8; //if >0 int32 JoinSource = 9; string OperatorUserID = 10;