mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 19:22:46 +08:00
Error code standardization
This commit is contained in:
parent
d59c4367fb
commit
0a2e55311c
4
go.mod
4
go.mod
@ -1,6 +1,6 @@
|
||||
module Open_IM
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
@ -49,7 +49,6 @@ require (
|
||||
go.mongodb.org/mongo-driver v1.8.3
|
||||
golang.org/x/image v0.3.0
|
||||
golang.org/x/net v0.5.0
|
||||
golang.org/x/tools v0.1.12
|
||||
google.golang.org/api v0.103.0
|
||||
google.golang.org/grpc v1.52.0
|
||||
google.golang.org/protobuf v1.28.1
|
||||
@ -157,6 +156,7 @@ require (
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
golang.org/x/tools v0.1.12 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
|
||||
|
@ -343,7 +343,7 @@ func (pb *PBUser) Convert() (*relation.UserModel, error) {
|
||||
dst := &relation.UserModel{}
|
||||
utils.CopyStructFields(dst, pb)
|
||||
dst.Birth = utils.UnixSecondToTime(pb.Birthday)
|
||||
dst.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
||||
dst.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq) (*pbFriend.GetBlacksResp, error) {
|
||||
resp := &pbFriend.GetBlacksResp{}
|
||||
func (s *friendServer) GetPaginationBlacks(ctx context.Context, req *pbFriend.GetPaginationBlacksReq) (resp *pbFriend.GetPaginationBlacksResp, err error) {
|
||||
resp = &pbFriend.GetPaginationBlacksResp{}
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -24,7 +24,6 @@ func (s *friendServer) GetBlacks(ctx context.Context, req *pbFriend.GetBlacksReq
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp.Total = int32(total)
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -128,22 +127,22 @@ func (s *friendServer) Run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {
|
||||
resp := &pbFriend.AddFriendResp{}
|
||||
// ok
|
||||
func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbFriend.ApplyToAddFriendReq) (resp *pbFriend.ApplyToAddFriendResp, err error) {
|
||||
resp = &pbFriend.ApplyToAddFriendResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := callbackBeforeAddFriendV1(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//检查toUserID fromUserID是否存在
|
||||
if req.ToUserID == req.FromUserID {
|
||||
return nil, constant.ErrCanNotAddYourself.Wrap()
|
||||
}
|
||||
if _, err := check.GetUsersInfo(ctx, req.ToUserID, req.FromUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//from是否在to的好友列表里面
|
||||
err, in1, in2 := s.FriendInterface.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
||||
in1, in2, err := s.FriendInterface.CheckIn(ctx, req.FromUserID, req.ToUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -153,34 +152,36 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
if err = s.FriendInterface.AddFriendRequest(ctx, req.FromUserID, req.ToUserID, req.ReqMsg, req.Ex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationNotification(ctx, req)
|
||||
chat.FriendApplicationAddNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriends(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
resp := &pbFriend.ImportFriendResp{}
|
||||
// ok
|
||||
func (s *friendServer) ImportFriends(ctx context.Context, req *pbFriend.ImportFriendReq) (resp *pbFriend.ImportFriendResp, err error) {
|
||||
resp = &pbFriend.ImportFriendResp{}
|
||||
if err := token_verify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := check.GetUsersInfo(ctx, req.OwnerUserID); err != nil {
|
||||
if _, err := check.GetUsersInfo(ctx, req.OwnerUserID, req.FriendUserIDs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var friends []*relation2.FriendModel
|
||||
for _, userID := range utils.RemoveDuplicateElement(req.FriendUserIDs) {
|
||||
friends = append(friends, &relation2.FriendModel{OwnerUserID: userID, FriendUserID: req.OwnerUserID, AddSource: constant.BecomeFriendByImport, OperatorUserID: tracelog.GetOpUserID(ctx)})
|
||||
if utils.Contain(req.FriendUserIDs, req.OwnerUserID) {
|
||||
return nil, constant.ErrCanNotAddYourself.Wrap()
|
||||
}
|
||||
if len(friends) > 0 {
|
||||
if err := s.FriendInterface.BecomeFriend(ctx, friends); err != nil {
|
||||
if utils.Duplicate(req.FriendUserIDs) {
|
||||
return nil, constant.ErrArgs.Wrap("friend userID repeated")
|
||||
}
|
||||
|
||||
if err := s.FriendInterface.BecomeFriends(ctx, req.OwnerUserID, req.FriendUserIDs, constant.BecomeFriendByImport, tracelog.GetOpUserID(ctx)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// process Friend application
|
||||
func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.RespondFriendApplyReq) (*pbFriend.RespondFriendApplyResp, error) {
|
||||
resp := &pbFriend.RespondFriendApplyResp{}
|
||||
// ok
|
||||
func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.RespondFriendApplyReq) (resp *pbFriend.RespondFriendApplyResp, err error) {
|
||||
resp = &pbFriend.RespondFriendApplyResp{}
|
||||
if err := check.Access(ctx, req.ToUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -190,7 +191,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationApprovedNotification(ctx, req)
|
||||
chat.FriendApplicationAgreedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
if req.HandleResult == constant.FriendResponseRefuse {
|
||||
@ -198,29 +199,39 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendApplicationRejectedNotification(ctx, req)
|
||||
chat.FriendApplicationRefusedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
return nil, constant.ErrArgs.Wrap("req.HandleResult != -1/1")
|
||||
}
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.DeleteFriendResp, error) {
|
||||
resp := &pbFriend.DeleteFriendResp{}
|
||||
// ok
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (resp *pbFriend.DeleteFriendResp, err error) {
|
||||
resp = &pbFriend.DeleteFriendResp{}
|
||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, req.FriendUserID); err != nil {
|
||||
_, err = s.FindFriends(ctx, req.OwnerUserID, []string{req.FriendUserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, []string{req.FriendUserID}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.FriendDeletedNotification(ctx, req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFriendRemarkReq) (*pbFriend.SetFriendRemarkResp, error) {
|
||||
resp := &pbFriend.SetFriendRemarkResp{}
|
||||
// ok
|
||||
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFriendRemarkReq) (resp *pbFriend.SetFriendRemarkResp, err error) {
|
||||
resp = &pbFriend.SetFriendRemarkResp{}
|
||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = s.FindFriends(ctx, req.OwnerUserID, []string{req.FriendUserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -228,8 +239,9 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriends(ctx context.Context, req *pbFriend.GetFriendsReq) (*pbFriend.GetFriendsResp, error) {
|
||||
resp := &pbFriend.GetFriendsResp{}
|
||||
// ok
|
||||
func (s *friendServer) GetDesignatedFriendsReq(ctx context.Context, req *pbFriend.GetDesignatedFriendsReq) (resp *pbFriend.GetDesignatedFriendsResp, err error) {
|
||||
resp = &pbFriend.GetDesignatedFriendsResp{}
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -237,18 +249,6 @@ func (s *friendServer) GetFriends(ctx context.Context, req *pbFriend.GetFriendsR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userIDList := make([]string, 0, len(friends))
|
||||
for _, f := range friends {
|
||||
userIDList = append(userIDList, f.FriendUserID)
|
||||
}
|
||||
users, err := check.GetUsersInfo(ctx, userIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userMap := make(map[string]*sdkws.UserInfo)
|
||||
for i, user := range users {
|
||||
userMap[user.UserID] = users[i]
|
||||
}
|
||||
resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(friends)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -257,9 +257,9 @@ func (s *friendServer) GetFriends(ctx context.Context, req *pbFriend.GetFriendsR
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 获取接收到的好友申请(即别人主动申请的)
|
||||
func (s *friendServer) GetToFriendsApply(ctx context.Context, req *pbFriend.GetToFriendsApplyReq) (*pbFriend.GetToFriendsApplyResp, error) {
|
||||
resp := &pbFriend.GetToFriendsApplyResp{}
|
||||
// ok 获取接收到的好友申请(即别人主动申请的)
|
||||
func (s *friendServer) GetPaginationFriendsApplyTo(ctx context.Context, req *pbFriend.GetPaginationFriendsApplyToReq) (resp *pbFriend.GetPaginationFriendsApplyToResp, err error) {
|
||||
resp = &pbFriend.GetPaginationFriendsApplyToResp{}
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -275,9 +275,9 @@ func (s *friendServer) GetToFriendsApply(ctx context.Context, req *pbFriend.GetT
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 获取主动发出去的好友申请列表
|
||||
func (s *friendServer) GetFromFriendsApply(ctx context.Context, req *pbFriend.GetFromFriendsApplyReq) (*pbFriend.GetFromFriendsApplyResp, error) {
|
||||
resp := &pbFriend.GetFromFriendsApplyResp{}
|
||||
// ok 获取主动发出去的好友申请列表
|
||||
func (s *friendServer) GetPaginationFriendsApplyFrom(ctx context.Context, req *pbFriend.GetPaginationFriendsApplyFromReq) (resp *pbFriend.GetPaginationFriendsApplyFromResp, err error) {
|
||||
resp = &pbFriend.GetPaginationFriendsApplyFromResp{}
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -293,26 +293,28 @@ func (s *friendServer) GetFromFriendsApply(ctx context.Context, req *pbFriend.Ge
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
resp := &pbFriend.IsFriendResp{}
|
||||
err, in1, in2 := s.FriendInterface.CheckIn(ctx, req.UserID1, req.UserID2)
|
||||
// ok
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (resp *pbFriend.IsFriendResp, err error) {
|
||||
resp = &pbFriend.IsFriendResp{}
|
||||
resp.InUser1Friends, resp.InUser2Friends, err = s.FriendInterface.CheckIn(ctx, req.UserID1, req.UserID2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.InUser1Friends = in1
|
||||
resp.InUser2Friends = in2
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendsInfoResp, error) {
|
||||
resp := pbFriend.GetFriendsInfoResp{}
|
||||
// ok
|
||||
func (s *friendServer) GetPaginationFriends(ctx context.Context, req *pbFriend.GetPaginationFriendsReq) (resp *pbFriend.GetPaginationFriendsResp, err error) {
|
||||
resp = &pbFriend.GetPaginationFriendsResp{}
|
||||
if utils.Duplicate(req.FriendUserIDs) {
|
||||
return nil, constant.ErrArgs.Wrap("friend userID repeated")
|
||||
}
|
||||
friends, err := s.FriendInterface.FindFriends(ctx, req.OwnerUserID, req.FriendUserIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(friends)
|
||||
if err != nil {
|
||||
if resp.FriendsInfo, err = (*convert.DBFriend)(nil).DB2PB(friends); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -91,14 +91,14 @@ func friendNotification(operationID, fromUserID, toUserID string, contentType in
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func FriendApplicationNotification(ctx context.Context, req *pbFriend.AddFriendReq) {
|
||||
func FriendApplicationAddNotification(ctx context.Context, req *pbFriend.AddFriendReq) {
|
||||
FriendApplicationTips := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.ToUserID
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
}
|
||||
|
||||
func FriendApplicationApprovedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
func FriendApplicationAgreedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
@ -106,7 +106,7 @@ func FriendApplicationApprovedNotification(ctx context.Context, req *pbFriend.Re
|
||||
friendNotification(tracelog.GetOperationID(ctx), req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendApplicationRejectedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
func FriendApplicationRefusedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
"Open_IM/pkg/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
@ -167,6 +168,7 @@ func (s *userServer) SyncJoinedGroupMemberNickname(ctx context.Context, userID s
|
||||
}
|
||||
}
|
||||
|
||||
// ok
|
||||
func (s *userServer) GetUsersInfo(ctx context.Context, req *pbUser.GetUsersInfoReq) (*pbUser.GetUsersInfoResp, error) {
|
||||
resp := &pbUser.GetUsersInfoResp{}
|
||||
users, err := s.Find(ctx, req.UserIDs)
|
||||
@ -228,21 +230,24 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) {
|
||||
resp := pbUser.SetGlobalRecvMessageOptResp{}
|
||||
func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (resp *pbUser.SetGlobalRecvMessageOptResp, err error) {
|
||||
resp = &pbUser.SetGlobalRecvMessageOptResp{}
|
||||
|
||||
if _, err := s.Find(ctx, []string{req.UserID}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["global_recv_msg_opt"] = req.GlobalRecvMsgOpt
|
||||
err := s.UpdateByMap(ctx, req.UserID, m)
|
||||
if err != nil {
|
||||
if err := s.UpdateByMap(ctx, req.UserID, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
|
||||
return &resp, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
resp := pbUser.AccountCheckResp{}
|
||||
err := token_verify.CheckAdmin(ctx)
|
||||
func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (resp *pbUser.AccountCheckResp, err error) {
|
||||
resp = &pbUser.AccountCheckResp{}
|
||||
err = token_verify.CheckAdmin(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -250,24 +255,23 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uidList := make([]string, 0)
|
||||
userIDs := make(map[string]interface{}, 0)
|
||||
for _, v := range user {
|
||||
uidList = append(uidList, v.UserID)
|
||||
userIDs[v.UserID] = nil
|
||||
}
|
||||
var r []*pbUser.AccountCheckRespSingleUserStatus
|
||||
for _, v := range req.CheckUserIDs {
|
||||
temp := new(pbUser.AccountCheckRespSingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp := &pbUser.AccountCheckRespSingleUserStatus{UserID: v}
|
||||
if _, ok := userIDs[v]; ok {
|
||||
temp.AccountStatus = constant.Registered
|
||||
} else {
|
||||
temp.AccountStatus = constant.UnRegistered
|
||||
}
|
||||
r = append(r, temp)
|
||||
resp.Results = append(resp.Results, temp)
|
||||
}
|
||||
return &resp, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// todo
|
||||
func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pbUser.GetUsersResp, error) {
|
||||
resp := pbUser.GetUsersResp{}
|
||||
var err error
|
||||
@ -286,7 +290,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
|
||||
if req.UserName != "" {
|
||||
usersDB, total, err := s.GetByName(ctx, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
usersDB, total, err := s.GetByName(ctx, req.UserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -300,7 +304,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
}
|
||||
return &resp, nil
|
||||
} else if req.Content != "" {
|
||||
usersDB, total, err := s.GetByNameAndID(ctx, req.UserName, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
usersDB, total, err := s.GetByNameAndID(ctx, req.UserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -315,7 +319,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
usersDB, total, err := s.Get(ctx, req.Pagination.ShowNumber, req.Pagination.PageNumber)
|
||||
usersDB, total, err := s.Get(ctx, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -332,18 +336,22 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) UserRegister(ctx context.Context, req *pbUser.UserRegisterReq) (*pbUser.UserRegisterResp, error) {
|
||||
resp := pbUser.UserRegisterResp{}
|
||||
func (s *userServer) UserRegister(ctx context.Context, req *pbUser.UserRegisterReq) (resp *pbUser.UserRegisterResp, err error) {
|
||||
resp = &pbUser.UserRegisterResp{}
|
||||
if utils.DuplicateAny(req.Users, func(e *server_api_params.UserInfo) string { return e.UserID }) {
|
||||
return nil, constant.ErrArgs.Wrap("userID repeated")
|
||||
}
|
||||
userIDs := make([]string, 0)
|
||||
for _, v := range req.Users {
|
||||
userIDs = append(userIDs, v.UserID)
|
||||
}
|
||||
|
||||
exist, err := s.IsExist(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if exist {
|
||||
return nil, constant.ErrRegisteredAlready.Wrap("exist")
|
||||
return nil, constant.ErrRegisteredAlready.Wrap("userID exist in db")
|
||||
}
|
||||
users, err := (*convert.PBUser)(nil).PB2DB(req.Users)
|
||||
if err != nil {
|
||||
@ -353,5 +361,5 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbUser.UserRegisterR
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -301,9 +301,7 @@ const (
|
||||
)
|
||||
const (
|
||||
BecomeFriendByImport = 1 //管理员导入
|
||||
BecomeFriendByMyApply = 2 //自己主动申请添加
|
||||
BecomeFriendByPeerApply = 3 //对方主动申请添加
|
||||
BecomeFriendByApply = 4 //申请添加
|
||||
BecomeFriendByApply = 2 //申请添加
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -18,6 +18,7 @@ var (
|
||||
|
||||
ErrRelationshipAlready = &ErrInfo{RelationshipAlreadyError, "RelationshipAlreadyError", ""}
|
||||
ErrNotRelationshipYet = &ErrInfo{NotRelationshipYetError, "NotRelationshipYetError", ""}
|
||||
ErrCanNotAddYourself = &ErrInfo{CanNotAddYourselfError, "CanNotAddYourselfError", ""}
|
||||
|
||||
ErrOnlyOneOwner = &ErrInfo{OnlyOneOwnerError, "OnlyOneOwnerError", ""}
|
||||
ErrInGroupAlready = &ErrInfo{InGroupAlreadyError, "InGroupAlreadyError", ""}
|
||||
@ -90,6 +91,7 @@ const (
|
||||
const (
|
||||
RelationshipAlreadyError = 92001 //已经是好友关系(或者黑名单)
|
||||
NotRelationshipYetError = 92002 //不是好友关系(或者黑名单)
|
||||
CanNotAddYourselfError = 92003 //不能添加自己为好友
|
||||
)
|
||||
|
||||
// 群组错误码
|
||||
|
@ -6,33 +6,34 @@ import (
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type FriendInterface interface {
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
CheckIn(ctx context.Context, user1, user2 string) (inUser1Friends bool, inUser2Friends bool, err error)
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
// 增加或者更新好友申请 如果之前有记录则更新,没有记录则新增
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, friends []*relation.FriendModel, revFriends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
// (1)先判断是否在好友表 (在不在都不返回错误) (2)对于不在好友列表的 插入即可
|
||||
BecomeFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, addSource int32, OperatorUserID string) (err error)
|
||||
// 拒绝好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)修改申请记录 已拒绝
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
// 同意好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)检查是否好友(不返回错误) (3) 不是好友则建立双向好友关系 (4)修改申请记录 已同意
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
// 删除好友 外部判断是否好友关系
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error)
|
||||
// 更新好友备注 零值也支持
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
// 获取ownerUserID的好友列表 无结果不返回错误
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
// friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
// 获取我发出去的好友申请 无结果不返回错误
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
// 获取我收到的的好友申请 无结果不返回错误
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在也返回错误
|
||||
// 获取某人指定好友的信息 如果有一个不存在也返回错误
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ func NewFriendController(db *gorm.DB) *FriendController {
|
||||
return &FriendController{database: NewFriendDatabase(db)}
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
func (f *FriendController) CheckIn(ctx context.Context, user1, user2 string) (inUser1Friends bool, inUser2Friends bool, err error) {
|
||||
return f.database.CheckIn(ctx, user1, user2)
|
||||
}
|
||||
@ -55,8 +56,8 @@ func (f *FriendController) AddFriendRequest(ctx context.Context, fromUserID, toU
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendController) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error) {
|
||||
return f.database.BecomeFriend(ctx, ownerUserID, friends)
|
||||
func (f *FriendController) BecomeFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, addSource int32, OperatorUserID string) (err error) {
|
||||
return f.database.BecomeFriends(ctx, ownerUserID, friendUserIDs, addSource, OperatorUserID)
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
@ -70,7 +71,7 @@ func (f *FriendController) AgreeFriendRequest(ctx context.Context, friendRequest
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
func (f *FriendController) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||
func (f *FriendController) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
return f.database.Delete(ctx, ownerUserID, friendUserIDs)
|
||||
}
|
||||
|
||||
@ -102,33 +103,32 @@ func (f *FriendController) FindFriendRequestToMe(ctx context.Context, userID str
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
func (f *FriendController) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error) {
|
||||
return f.database.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
|
||||
}
|
||||
|
||||
type FriendDatabaseInterface interface {
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
CheckIn(ctx context.Context, user1, user2 string) (inUser1Friends bool, inUser2Friends bool, err error)
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
// 增加或者更新好友申请
|
||||
AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error)
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error)
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
// 先判断是否在好友表,如果在则不插入
|
||||
BecomeFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, addSource int32, OperatorUserID string) (err error)
|
||||
// 拒绝好友申请
|
||||
RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
// 同意好友申请
|
||||
AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error)
|
||||
// Delete 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error)
|
||||
// UpdateRemark 更新好友备注
|
||||
// 删除好友
|
||||
Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error)
|
||||
// 更新好友备注
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
// 获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
// friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error)
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
// 获取我发出去的好友申请
|
||||
FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
// 获取我收到的的好友申请
|
||||
FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error)
|
||||
// FindFriends 获取某人指定好友的信息
|
||||
// 获取某人指定好友的信息
|
||||
FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error)
|
||||
}
|
||||
|
||||
@ -141,9 +141,12 @@ func NewFriendDatabase(db *gorm.DB) *FriendDatabase {
|
||||
return &FriendDatabase{friend: relation1.NewFriendGorm(db), friendRequest: relation1.NewFriendRequestGorm(db)}
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
// ok 检查user2是否在user1的好友列表中(inUser1Friends==true) 检查user1是否在user2的好友列表中(inUser2Friends==true)
|
||||
func (f *FriendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Friends bool, inUser2Friends bool, err error) {
|
||||
friends, err := f.friend.FindUserState(ctx, userID1, userID2)
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
for _, v := range friends {
|
||||
if v.OwnerUserID == userID1 && v.FriendUserID == userID2 {
|
||||
inUser1Friends = true
|
||||
@ -155,14 +158,16 @@ func (f *FriendDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (
|
||||
return
|
||||
}
|
||||
|
||||
// AddFriendRequest 增加或者更新好友申请
|
||||
// 增加或者更新好友申请 如果之前有记录则更新,没有记录则新增
|
||||
func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUserID string, reqMsg string, ex string) (err error) {
|
||||
return f.friendRequest.DB.Transaction(func(tx *gorm.DB) error {
|
||||
fq, err := f.friendRequest.Find(ctx, fromUserID, toUserID, tx)
|
||||
if err != nil {
|
||||
_, err := f.friendRequest.Take(ctx, fromUserID, toUserID, tx)
|
||||
//有db错误
|
||||
if err != nil && errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
if fq != nil { //
|
||||
//无错误 则更新
|
||||
if err == nil {
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["handle_result"] = 0
|
||||
m["handle_msg"] = ""
|
||||
@ -171,44 +176,45 @@ func (f *FriendDatabase) AddFriendRequest(ctx context.Context, fromUserID, toUse
|
||||
if err := f.friendRequest.UpdateByMap(ctx, fromUserID, toUserID, m, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
//gorm.ErrRecordNotFound 错误,则新增
|
||||
if err := f.friendRequest.Create(ctx, []*relation.FriendRequestModel{&relation.FriendRequestModel{FromUserID: fromUserID, ToUserID: toUserID, ReqMsg: reqMsg, Ex: ex}}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// BecomeFriend 先判断是否在好友表,如果在则不插入
|
||||
func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, friends []*relation.FriendModel) (err error) {
|
||||
// (1)先判断是否在好友表 (在不在都不返回错误) (2)对于不在好友列表的 插入即可
|
||||
func (f *FriendDatabase) BecomeFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, addSource int32, OperatorUserID string) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
friendUserIDs := make([]string, 0, len(friends))
|
||||
for _, v := range friends {
|
||||
friendUserIDs = append(friendUserIDs, v.FriendUserID)
|
||||
}
|
||||
fs1, err := f.friend.FindFriends(ctx, ownerUserID, friendUserIDs, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fs1 = append(fs1, friends...)
|
||||
for _, v := range friendUserIDs {
|
||||
fs1 = append(fs1, &relation.FriendModel{OwnerUserID: ownerUserID, FriendUserID: v, AddSource: addSource, OperatorUserID: OperatorUserID})
|
||||
}
|
||||
fs11 := utils.DistinctAny(fs1, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
return e.FriendUserID
|
||||
})
|
||||
|
||||
err = f.friend.Create(ctx, fs11, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fs2, err := f.friend.FindReversalFriends(ctx, ownerUserID, friendUserIDs, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range friends {
|
||||
fs2 = append(fs2, &relation.FriendModel{OwnerUserID: v.FriendUserID, FriendUserID: ownerUserID})
|
||||
for _, v := range friendUserIDs {
|
||||
fs2 = append(fs2, &relation.FriendModel{OwnerUserID: v, FriendUserID: ownerUserID, AddSource: addSource, OperatorUserID: OperatorUserID})
|
||||
}
|
||||
fs22 := utils.DistinctAny(fs2, func(e *relation.FriendModel) string {
|
||||
return utils.UniqueJoin(e.OwnerUserID, e.FriendUserID)
|
||||
return e.OwnerUserID
|
||||
})
|
||||
err = f.friend.Create(ctx, fs22, tx)
|
||||
if err != nil {
|
||||
@ -218,8 +224,12 @@ func (f *FriendDatabase) BecomeFriend(ctx context.Context, ownerUserID string, f
|
||||
})
|
||||
}
|
||||
|
||||
// RefuseFriendRequest 拒绝好友申请
|
||||
// 拒绝好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)修改申请记录 已拒绝
|
||||
func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
_, err = f.friendRequest.Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
friendRequest.HandleResult = constant.FriendResponseRefuse
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest})
|
||||
if err != nil {
|
||||
@ -228,79 +238,90 @@ func (f *FriendDatabase) RefuseFriendRequest(ctx context.Context, friendRequest
|
||||
return nil
|
||||
}
|
||||
|
||||
// AgreeFriendRequest 同意好友申请
|
||||
// 同意好友申请 (1)检查是否有申请记录且为未处理状态 (没有记录返回错误) (2)检查是否好友(不返回错误) (3) 不是好友则建立双向好友关系 (4)修改申请记录 已同意
|
||||
func (f *FriendDatabase) AgreeFriendRequest(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return f.friend.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//先find 找出重复的 去掉重复的
|
||||
fs1, err := f.friend.FindFriends(ctx, friendRequest.FromUserID, []string{friendRequest.ToUserID}, tx)
|
||||
_, err = f.friendRequest.Take(ctx, friendRequest.FromUserID, friendRequest.ToUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(fs1) == 0 {
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.FromUserID,
|
||||
FriendUserID: friendRequest.ToUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
AddSource: constant.BecomeFriendByApply,
|
||||
}}, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fs2, err := f.friend.FindReversalFriends(ctx, friendRequest.ToUserID, []string{friendRequest.FromUserID}, tx)
|
||||
if len(fs2) == 0 {
|
||||
err = f.friend.Create(ctx, []*relation.FriendModel{
|
||||
&relation.FriendModel{
|
||||
OwnerUserID: friendRequest.ToUserID,
|
||||
FriendUserID: friendRequest.FromUserID,
|
||||
OperatorUserID: friendRequest.ToUserID,
|
||||
AddSource: constant.BecomeFriendByApply,
|
||||
}}, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
friendRequest.HandlerUserID = friendRequest.FromUserID
|
||||
friendRequest.HandleResult = constant.FriendResponseAgree
|
||||
err = f.friendRequest.Update(ctx, []*relation.FriendRequestModel{friendRequest}, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ownerUserID := friendRequest.FromUserID
|
||||
friendUserIDs := []string{friendRequest.ToUserID}
|
||||
addSource := int32(constant.BecomeFriendByApply)
|
||||
OperatorUserID := friendRequest.FromUserID
|
||||
//先find 找出重复的 去掉重复的
|
||||
fs1, err := f.friend.FindFriends(ctx, ownerUserID, friendUserIDs, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range friendUserIDs {
|
||||
fs1 = append(fs1, &relation.FriendModel{OwnerUserID: ownerUserID, FriendUserID: v, AddSource: addSource, OperatorUserID: OperatorUserID})
|
||||
}
|
||||
fs11 := utils.DistinctAny(fs1, func(e *relation.FriendModel) string {
|
||||
return e.FriendUserID
|
||||
})
|
||||
|
||||
err = f.friend.Create(ctx, fs11, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fs2, err := f.friend.FindReversalFriends(ctx, ownerUserID, friendUserIDs, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range friendUserIDs {
|
||||
fs2 = append(fs2, &relation.FriendModel{OwnerUserID: v, FriendUserID: ownerUserID, AddSource: addSource, OperatorUserID: OperatorUserID})
|
||||
}
|
||||
fs22 := utils.DistinctAny(fs2, func(e *relation.FriendModel) string {
|
||||
return e.OwnerUserID
|
||||
})
|
||||
err = f.friend.Create(ctx, fs22, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除好友
|
||||
func (f *FriendDatabase) Delete(ctx context.Context, ownerUserID string, friendUserID string) (err error) {
|
||||
return f.friend.Delete(ctx, ownerUserID, friendUserID)
|
||||
// 删除好友 外部判断是否好友关系
|
||||
func (f *FriendDatabase) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
return f.friend.Delete(ctx, ownerUserID, friendUserIDs)
|
||||
}
|
||||
|
||||
// UpdateRemark 更新好友备注
|
||||
// 更新好友备注 零值也支持
|
||||
func (f *FriendDatabase) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
return f.friend.UpdateRemark(ctx, ownerUserID, friendUserID, remark)
|
||||
}
|
||||
|
||||
// FindOwnerFriends 获取ownerUserID的好友列表
|
||||
// 获取ownerUserID的好友列表 无结果不返回错误
|
||||
func (f *FriendDatabase) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindOwnerFriends(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindInWhoseFriends friendUserID在哪些人的好友列表中
|
||||
// friendUserID在哪些人的好友列表中
|
||||
func (f *FriendDatabase) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.FriendModel, total int64, err error) {
|
||||
return f.friend.FindInWhoseFriends(ctx, friendUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestFromMe 获取我发出去的好友申请
|
||||
// 获取我发出去的好友申请 无结果不返回错误
|
||||
func (f *FriendDatabase) FindFriendRequestFromMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindFromUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriendRequestToMe 获取我收到的的好友申请
|
||||
// 获取我收到的的好友申请 无结果不返回错误
|
||||
func (f *FriendDatabase) FindFriendRequestToMe(ctx context.Context, userID string, pageNumber, showNumber int32) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
return f.friendRequest.FindToUserID(ctx, userID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// FindFriends 获取某人指定好友的信息 如果有一个不存在,也返回错误
|
||||
// 获取某人指定好友的信息 如果有好友不存在,也返回错误
|
||||
func (f *FriendDatabase) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string) (friends []*relation.FriendModel, err error) {
|
||||
friends, err = f.friend.FindFriends(ctx, ownerUserID, friendUserIDs)
|
||||
if err != nil {
|
||||
|
@ -9,20 +9,16 @@ import (
|
||||
)
|
||||
|
||||
type UserInterface interface {
|
||||
//获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
//获取指定用户的信息 如有userID未找到 也返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error)
|
||||
//插入
|
||||
Create(ctx context.Context, users []*relation2.UserModel) error
|
||||
//更新
|
||||
//插入多条 外部保证userID 不重复 且在db中不存在
|
||||
Create(ctx context.Context, users []*relation2.UserModel) (err error)
|
||||
//更新(非零值) 外部保证userID存在
|
||||
Update(ctx context.Context, users []*relation2.UserModel) (err error)
|
||||
//更新带零值的
|
||||
//更新(零值) 外部保证userID存在
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
//通过名字搜索
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//通过名字和id搜索
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//获取,如果没找到,不不返回错误
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//获取,如果没找到,不返回错误
|
||||
Get(ctx context.Context, pageNumber, showNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
//userIDs是否存在 只要有一个存在就为true
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
@ -45,20 +41,12 @@ func (u *UserController) UpdateByMap(ctx context.Context, userID string, args ma
|
||||
return u.database.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
|
||||
func (u *UserController) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.Get(ctx, showNumber, pageNumber)
|
||||
func (u *UserController) Get(ctx context.Context, pageNumber, showNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.database.Get(ctx, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (u *UserController) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
||||
return u.IsExist(ctx, userIDs)
|
||||
return u.database.IsExist(ctx, userIDs)
|
||||
}
|
||||
func NewUserController(db *gorm.DB) *UserController {
|
||||
controller := &UserController{database: newUserDatabase(db)}
|
||||
@ -70,27 +58,25 @@ type UserDatabaseInterface interface {
|
||||
Create(ctx context.Context, users []*relation2.UserModel) error
|
||||
Update(ctx context.Context, users []*relation2.UserModel) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
Get(ctx context.Context, pageNumber, showNumber int32) (users []*relation2.UserModel, count int64, err error)
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
|
||||
type UserDatabase struct {
|
||||
sqlDB *relation.UserGorm
|
||||
user *relation.UserGorm
|
||||
}
|
||||
|
||||
func newUserDatabase(db *gorm.DB) *UserDatabase {
|
||||
sqlDB := relation.NewUserGorm(db)
|
||||
database := &UserDatabase{
|
||||
sqlDB: sqlDB,
|
||||
user: sqlDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
|
||||
// 获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
// 获取指定用户的信息 如有userID未找到 也返回错误
|
||||
func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*relation2.UserModel, err error) {
|
||||
users, err = u.sqlDB.Find(ctx, userIDs)
|
||||
users, err = u.user.Find(ctx, userIDs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -100,33 +86,31 @@ func (u *UserDatabase) Find(ctx context.Context, userIDs []string) (users []*rel
|
||||
return
|
||||
}
|
||||
|
||||
// 插入多条 外部保证userID 不重复 且在db中不存在
|
||||
func (u *UserDatabase) Create(ctx context.Context, users []*relation2.UserModel) (err error) {
|
||||
return u.sqlDB.Create(ctx, users)
|
||||
return u.user.Create(ctx, users)
|
||||
}
|
||||
|
||||
// 更新(非零值) 外部保证userID存在
|
||||
func (u *UserDatabase) Update(ctx context.Context, users []*relation2.UserModel) (err error) {
|
||||
return u.sqlDB.Update(ctx, users)
|
||||
return u.user.Update(ctx, users)
|
||||
}
|
||||
|
||||
// 更新(零值) 外部保证userID存在
|
||||
func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return u.sqlDB.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
func (u *UserDatabase) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.GetByName(ctx, userName, showNumber, pageNumber)
|
||||
}
|
||||
func (u *UserDatabase) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.GetByNameAndID(ctx, content, showNumber, pageNumber)
|
||||
return u.user.UpdateByMap(ctx, userID, args)
|
||||
}
|
||||
|
||||
// 获取,如果没找到,不返回错误
|
||||
func (u *UserDatabase) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation2.UserModel, count int64, err error) {
|
||||
return u.sqlDB.Get(ctx, showNumber, pageNumber)
|
||||
return u.user.Get(ctx, showNumber, pageNumber)
|
||||
}
|
||||
|
||||
// userIDs是否存在 只要有一个存在就为true
|
||||
func (u *UserDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
||||
users, err := u.sqlDB.Find(ctx, userIDs)
|
||||
users, err := u.user.Find(ctx, userIDs)
|
||||
if err != nil {
|
||||
return
|
||||
return false, err
|
||||
}
|
||||
if len(users) > 0 {
|
||||
return true, nil
|
||||
|
@ -30,105 +30,106 @@ type FriendUser struct {
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
// 插入多条记录
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&table.FriendModel{}).Create(&friends).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserIDs string) (err error) {
|
||||
// 删除ownerUserID指定的好友
|
||||
func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs)
|
||||
}()
|
||||
err = utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserIDs).Delete(&table.FriendModel{}).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Where("owner_user_id = ? AND friend_user_id in ( ?)", ownerUserID, friendUserIDs).Delete(&relation.FriendModel{}).Error, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error) {
|
||||
// 更新ownerUserID单个好友信息 更新零值
|
||||
func (f *FriendGorm) UpdateByMap(ctx context.Context, ownerUserID string, friendUserID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "args", args)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Where("owner_user_id = ? AND friend_user_id = ? ", ownerUserID, friendUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
// 更新好友信息的非零值
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*relation.FriendModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friends", friends)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Updates(&friends).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
// 更新好友备注(也支持零值 )
|
||||
func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "remark", remark)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
if remark != "" {
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Where("owner_user_id = ? and friend_user_id = ?", ownerUserID, friendUserID).Update("remark", remark).Error, "")
|
||||
}
|
||||
m := make(map[string]interface{}, 1)
|
||||
m["remark"] = ""
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Updates(m).Error, "")
|
||||
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.FriendModel, err error) {
|
||||
// 获取单个好友信息,如没找到 返回错误
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string, tx ...*gorm.DB) (friend *relation.FriendModel, err error) {
|
||||
friend = &relation.FriendModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", *friend)
|
||||
return friend, utils.Wrap(getDBConn(f.DB, tx).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
// 查找好友关系,如果是双向关系,则都返回
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID1", userID1, "userID2", userID2, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ?", ownerUserID).Find(&friends).Error, "")
|
||||
return friends, utils.Wrap(getDBConn(f.DB, tx).Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("friend_user_id = ?", friendUserID).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.FriendModel, err error) {
|
||||
friend = &table.FriendModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "friendUserID", friendUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("owner_user_id = ? and friend_user_id", ownerUserID, friendUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendGorm) FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "userID1", userID1, "userID2", userID2)
|
||||
}()
|
||||
return friends, utils.Wrap(f.DB.Model(&table.FriendModel{}).Where("(owner_user_id = ? and friend_user_id = ?) or (owner_user_id = ? and friend_user_id = ?)", userID1, userID2, userID2, userID1).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 获取 owner的好友列表 如果不存在也不返回错误
|
||||
// 获取 owner指定的好友列表 如果有friendUserIDs不存在,也不返回错误
|
||||
func (f *FriendGorm) FindFriends(ctx context.Context, ownerUserID string, friendUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserIDs", friendUserIDs, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "friendUserIDs", friendUserIDs, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(getDBConn(f.DB, tx).Where("owner_user_id = ? AND friend_user_id in (?)", ownerUserID, friendUserIDs).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID 如果不存在也不返回错误
|
||||
// 获取哪些人添加了friendUserID 如果有ownerUserIDs不存在,也不返回错误
|
||||
func (f *FriendGorm) FindReversalFriends(ctx context.Context, friendUserID string, ownerUserIDs []string, tx ...*gorm.DB) (friends []*relation.FriendModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friendUserID", friendUserID, "ownerUserIDs", ownerUserIDs, "friends", friends)
|
||||
}()
|
||||
return friends, utils.Wrap(getDBConn(f.DB, tx).Where("friend_user_id = ? AND owner_user_id in (?)", friendUserID, ownerUserIDs).Find(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 获取ownerUserID好友列表 支持翻页
|
||||
func (f *FriendGorm) FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "ownerUserID", ownerUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "ownerUserID", ownerUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
err = getDBConn(f.DB, tx).Model(f).Where("owner_user_id = ? ", ownerUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Where("owner_user_id = ? ", ownerUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(f).Where("owner_user_id = ? ", ownerUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Where("owner_user_id = ? ", ownerUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID 支持翻页
|
||||
func (f *FriendGorm) FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendUserID", friendUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friendUserID", friendUserID, "pageNumber", pageNumber, "showNumber", showNumber, "friends", friends, "total", total)
|
||||
}()
|
||||
err = getDBConn(f.DB, tx).Model(f).Where("friend_user_id = ? ", friendUserID).Count(&total).Error
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendModel{}).Where("friend_user_id = ? ", friendUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(f).Where("friend_user_id = ? ", friendUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Where("friend_user_id = ? ", friendUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
return
|
||||
}
|
||||
|
@ -20,68 +20,80 @@ type FriendRequestGorm struct {
|
||||
DB *gorm.DB `gorm:"-"`
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friends []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
// 插入多条记录
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friendRequests []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friendRequests", friendRequests)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Create(&friends).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Create(&friendRequests).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
// 删除记录
|
||||
func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "fromUserID", fromUserID, "toUserID", toUserID)
|
||||
}()
|
||||
return utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id = ?", fromUserID, toUserID).Delete(&relation.FriendRequestModel{}).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Where("from_user_id = ? AND to_user_id = ?", fromUserID, toUserID).Delete(&relation.FriendRequestModel{}).Error, "")
|
||||
}
|
||||
|
||||
// 更新零值
|
||||
func (f *FriendRequestGorm) UpdateByMap(ctx context.Context, formUserID string, toUserID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "formUserID", formUserID, "toUserID", toUserID, "args", args)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "formUserID", formUserID, "toUserID", toUserID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? AND to_user_id ", formUserID, toUserID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
// 更新多条记录 (非零值)
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequests []*relation.FriendRequestModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "friendRequests", friendRequests)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "friendRequests", friendRequests)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Updates(&friendRequests).Error, "")
|
||||
return utils.Wrap(getDBConn(f.DB, tx).Updates(&friendRequests).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string) (friend *relation.FriendRequestModel, err error) {
|
||||
friend = &relation.FriendRequestModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
return friend, utils.Wrap(f.DB.Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (friend *relation.FriendRequestModel, err error) {
|
||||
friend = &relation.FriendRequestModel{}
|
||||
defer tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "toUserID", toUserID, "friend", friend)
|
||||
return friend, utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Find(friend).Error, "")
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
// 获取来指定用户的好友申请 未找到 不返回错误
|
||||
func (f *FriendRequestGorm) Find(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (friendRequest *relation.FriendRequestModel, err error) {
|
||||
friendRequest = &relation.FriendRequestModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "toUserID", toUserID, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "fromUserID", fromUserID, "toUserID", toUserID, "friendRequest", *friendRequest)
|
||||
}()
|
||||
utils.Wrap(getDBConn(f.DB, tx).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Find(friendRequest).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) Take(ctx context.Context, fromUserID, toUserID string, tx ...*gorm.DB) (friendRequest *relation.FriendRequestModel, err error) {
|
||||
friendRequest = &relation.FriendRequestModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "fromUserID", fromUserID, "toUserID", toUserID, "friendRequest", *friendRequest)
|
||||
}()
|
||||
utils.Wrap(getDBConn(f.DB, tx).Where("from_user_id = ? and to_user_id", fromUserID, toUserID).Take(friendRequest).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
// 获取toUserID收到的好友申请列表
|
||||
func (f *FriendRequestGorm) FindToUserID(ctx context.Context, toUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friendRequests []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "toUserID", toUserID, "friendRequests", friendRequests)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Where("to_user_id = ? ", toUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friendRequests).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friends []*relation.FriendRequestModel, total int64, err error) {
|
||||
// 获取fromUserID发出去的好友申请列表
|
||||
func (f *FriendRequestGorm) FindFromUserID(ctx context.Context, fromUserID string, pageNumber, showNumber int32, tx ...*gorm.DB) (friendRequests []*relation.FriendRequestModel, total int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetSelfFuncName(), err, "fromUserID", fromUserID, "friends", friends)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "fromUserID", fromUserID, "friendRequests", friendRequests)
|
||||
}()
|
||||
|
||||
err = getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
}
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Model(&relation.FriendRequestModel{}).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friends).Error, "")
|
||||
err = utils.Wrap(getDBConn(f.DB, tx).Where("from_user_id = ? ", fromUserID).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&friendRequests).Error, "")
|
||||
return
|
||||
}
|
||||
|
@ -19,75 +19,84 @@ func NewUserGorm(db *gorm.DB) *UserGorm {
|
||||
return &user
|
||||
}
|
||||
|
||||
// 插入多条
|
||||
func (u *UserGorm) Create(ctx context.Context, users []*relation.UserModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Create(&users).Error, "")
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Create(&users).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
// 更新用户信息 零值
|
||||
func (u *UserGorm) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "args", args)
|
||||
}()
|
||||
return utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) Update(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||
// 更新多个用户信息 非零值
|
||||
func (u *UserGorm) Update(ctx context.Context, users []*relation.UserModel, tx ...*gorm.DB) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "users", users)
|
||||
}()
|
||||
return utils.Wrap(u.DB.Model(&relation.UserModel{}).Updates(&users).Error, "")
|
||||
return utils.Wrap(getDBConn(u.DB, tx).Updates(&users).Error, "")
|
||||
}
|
||||
|
||||
func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {
|
||||
// 获取指定用户信息 不存在,也不返回错误
|
||||
func (u *UserGorm) Find(ctx context.Context, userIDs []string, tx ...*gorm.DB) (users []*relation.UserModel, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users)
|
||||
}()
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
return users, err
|
||||
}
|
||||
|
||||
func (u *UserGorm) Take(ctx context.Context, userID string) (user *relation.UserModel, err error) {
|
||||
// 获取某个用户信息 不存在,则返回错误
|
||||
func (u *UserGorm) Take(ctx context.Context, userID string, tx ...*gorm.DB) (user *relation.UserModel, err error) {
|
||||
user = &relation.UserModel{}
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userID", userID, "user", *user)
|
||||
}()
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
return user, err
|
||||
}
|
||||
|
||||
func (u *UserGorm) GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
// 通过名字查找用户 不存在,不返回错误
|
||||
func (u *UserGorm) GetByName(ctx context.Context, userName string, pageNumber, showNumber int32, tx ...*gorm.DB) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userName", userName, "pageNumber", pageNumber, "showNumber", showNumber, "users", users, "count", count)
|
||||
}()
|
||||
err = u.DB.Model(&relation.UserModel{}).Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber * pageNumber)).Find(&users).Error
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error, "")
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
return
|
||||
}
|
||||
return users, count, utils.Wrap(u.DB.Model(&relation.UserModel{}).Where(" name like ? ", fmt.Sprintf("%%%s%%", userName)).Count(&count).Error, "")
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Where(" name like ?", fmt.Sprintf("%%%s%%", userName)).Limit(int(showNumber)).Offset(int(showNumber*pageNumber)).Find(&users).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UserGorm) GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
// 通过名字或userID查找用户 不存在,不返回错误
|
||||
func (u *UserGorm) GetByNameAndID(ctx context.Context, content string, pageNumber, showNumber int32, tx ...*gorm.DB) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "content", content, "showNumber", showNumber, "pageNumber", pageNumber, "users", users)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "content", content, "pageNumber", pageNumber, "showNumber", showNumber, "users", users, "count", count)
|
||||
}()
|
||||
db := u.DB.Model(&relation.UserModel{}).Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err := db.Model(&relation.UserModel{}).Count(&count).Error; err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
db := getDBConn(u.DB, tx).Model(&relation.UserModel{}).Where(" name like ? or user_id = ? ", fmt.Sprintf("%%%s%%", content), content)
|
||||
if err = db.Count(&count).Error; err != nil {
|
||||
return
|
||||
}
|
||||
err = utils.Wrap(db.Limit(int(showNumber)).Offset(int(showNumber*pageNumber)).Find(&users).Error, "")
|
||||
return
|
||||
}
|
||||
|
||||
func (u *UserGorm) Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||
// 获取用户信息 不存在,不返回错误
|
||||
func (u *UserGorm) Get(ctx context.Context, pageNumber, showNumber int32, tx ...*gorm.DB) (users []*relation.UserModel, count int64, err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "showNumber", showNumber, "pageNumber", pageNumber, "users", users, "count", count)
|
||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "pageNumber", pageNumber, "showNumber", showNumber, "users", users, "count", count)
|
||||
}()
|
||||
err = u.DB.Model(&relation.UserModel{}).Model(u).Count(&count).Error
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Model(&relation.UserModel{}).Count(&count).Error, "")
|
||||
if err != nil {
|
||||
return nil, 0, utils.Wrap(err, "")
|
||||
return
|
||||
}
|
||||
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&users).Error, "")
|
||||
err = utils.Wrap(getDBConn(u.DB, tx).Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Find(&users).Error, "")
|
||||
return
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ type FriendModel struct {
|
||||
OwnerUserID string `gorm:"column:owner_user_id;primary_key;size:64"`
|
||||
FriendUserID string `gorm:"column:friend_user_id;primary_key;size:64"`
|
||||
Remark string `gorm:"column:remark;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
CreateTime time.Time `gorm:"column:create_time;autoCreateTime"`
|
||||
AddSource int32 `gorm:"column:add_source"`
|
||||
OperatorUserID string `gorm:"column:operator_user_id;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
|
@ -9,7 +9,7 @@ type FriendRequestModel struct {
|
||||
ToUserID string `gorm:"column:to_user_id;primary_key;size:64"`
|
||||
HandleResult int32 `gorm:"column:handle_result"`
|
||||
ReqMsg string `gorm:"column:req_msg;size:255"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
CreateTime time.Time `gorm:"column:create_time; autoCreateTime"`
|
||||
HandlerUserID string `gorm:"column:handler_user_id;size:64"`
|
||||
HandleMsg string `gorm:"column:handle_msg;size:255"`
|
||||
HandleTime time.Time `gorm:"column:handle_time"`
|
||||
|
@ -11,11 +11,12 @@ type UserModel struct {
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
FaceURL string `gorm:"column:face_url;size:255"`
|
||||
Gender int32 `gorm:"column:gender"`
|
||||
AreaCode string `gorm:"column:area_code;size:8" json:"areaCode"`
|
||||
PhoneNumber string `gorm:"column:phone_number;size:32"`
|
||||
Birth time.Time `gorm:"column:birth"`
|
||||
Email string `gorm:"column:email;size:64"`
|
||||
Ex string `gorm:"column:ex;size:1024"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time; autoCreateTime"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,22 +3,22 @@ import "Open-IM-Server/pkg/proto/sdk_ws/ws.proto";
|
||||
option go_package = "Open_IM/pkg/proto/friend;friend";
|
||||
package friend;
|
||||
|
||||
message getFriendsInfoReq{
|
||||
message getPaginationFriendsReq{
|
||||
string ownerUserID = 1;
|
||||
repeated string friendUserIDs = 2;
|
||||
}
|
||||
message getFriendsInfoResp{
|
||||
message getPaginationFriendsResp{
|
||||
repeated server_api_params.FriendInfo friendsInfo = 1;
|
||||
}
|
||||
|
||||
|
||||
message addFriendReq{
|
||||
message applyToAddFriendReq{
|
||||
string fromUserID = 1;
|
||||
string toUserID = 2;
|
||||
string reqMsg = 3;
|
||||
string ex = 4;
|
||||
}
|
||||
message addFriendResp{
|
||||
message applyToAddFriendResp{
|
||||
}
|
||||
|
||||
|
||||
@ -31,22 +31,22 @@ message importFriendResp{
|
||||
}
|
||||
|
||||
|
||||
message getToFriendsApplyReq{
|
||||
message getPaginationFriendsApplyToReq{
|
||||
string userID = 1;
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
|
||||
}
|
||||
message getToFriendsApplyResp{
|
||||
message getPaginationFriendsApplyToResp{
|
||||
repeated server_api_params.FriendRequest FriendRequests = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
|
||||
message getFriendsReq{
|
||||
message getDesignatedFriendsReq{
|
||||
server_api_params.RequestPagination pagination = 1;
|
||||
string userID = 2;
|
||||
}
|
||||
message getFriendsResp{
|
||||
message getDesignatedFriendsResp{
|
||||
repeated server_api_params.FriendInfo FriendsInfo = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
@ -67,11 +67,11 @@ message removeBlackReq{
|
||||
message removeBlackResp{
|
||||
}
|
||||
|
||||
message getBlacksReq{
|
||||
message getPaginationBlacksReq{
|
||||
string userID = 1;
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
}
|
||||
message getBlacksResp{
|
||||
message getPaginationBlacksResp{
|
||||
repeated server_api_params.BlackInfo blacks= 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
@ -122,24 +122,22 @@ message setFriendRemarkReq{
|
||||
message setFriendRemarkResp{
|
||||
}
|
||||
|
||||
message getFromFriendsApplyReq{
|
||||
message getPaginationFriendsApplyFromReq{
|
||||
string userID = 1;
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
}
|
||||
message getFromFriendsApplyResp{
|
||||
message getPaginationFriendsApplyFromResp{
|
||||
repeated server_api_params.FriendRequest friendRequests = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
service friend{
|
||||
//申请加好友
|
||||
rpc addFriend(addFriendReq) returns(addFriendResp);
|
||||
rpc applyToAddFriend(applyToAddFriendReq) returns(applyToAddFriendResp);
|
||||
//获取收到的好友申请列表
|
||||
rpc getToFriendsApply(getToFriendsApplyReq) returns(getToFriendsApplyResp);
|
||||
rpc getPaginationFriendsApplyTo(getPaginationFriendsApplyToReq) returns(getPaginationFriendsApplyToResp);
|
||||
//获取主动发出去的好友申请列表
|
||||
rpc getFromFriendsApply(getFromFriendsApplyReq) returns(getFromFriendsApplyResp);
|
||||
//获取好友列表
|
||||
rpc getFriends(getFriendsReq) returns(getFriendsResp);
|
||||
rpc getPaginationFriendsApplyFrom(getPaginationFriendsApplyFromReq) returns(getPaginationFriendsApplyFromResp);
|
||||
//添加黑名单
|
||||
rpc addBlack(addBlackReq) returns(addBlackResp);
|
||||
//移除黑名单
|
||||
@ -149,7 +147,7 @@ service friend{
|
||||
//判断是否在黑名单中
|
||||
rpc isBlack(isBlackReq) returns(isBlackResp);
|
||||
//获取黑名单列表
|
||||
rpc getBlacks(getBlacksReq) returns(getBlacksResp);
|
||||
rpc getPaginationBlacks(getPaginationBlacksReq) returns(getPaginationBlacksResp);
|
||||
//删除好友
|
||||
rpc deleteFriend(deleteFriendReq) returns(deleteFriendResp);
|
||||
//对好友申请响应(同意或拒绝)
|
||||
@ -158,6 +156,8 @@ service friend{
|
||||
rpc setFriendRemark(setFriendRemarkReq) returns(setFriendRemarkResp);
|
||||
//导入好友关系
|
||||
rpc importFriends(importFriendReq) returns(importFriendResp);
|
||||
//获取指定好友信息
|
||||
rpc getFriendsInfo(getFriendsInfoReq) returns (getFriendsInfoResp);
|
||||
//翻页获取好友列表 无结果不返回错误
|
||||
rpc getDesignatedFriends(getDesignatedFriendsReq) returns(getDesignatedFriendsResp);
|
||||
//获取指定好友信息 有id不存在也返回错误
|
||||
rpc getPaginationFriends(getPaginationFriendsReq) returns (getPaginationFriendsResp);
|
||||
}
|
@ -114,9 +114,6 @@ message batchSetConversationsResp{
|
||||
|
||||
message getUsersReq {
|
||||
server_api_params.RequestPagination pagination = 2;
|
||||
string userName = 3;
|
||||
string userID = 4;
|
||||
string content = 5;
|
||||
}
|
||||
|
||||
message getUsersResp{
|
||||
@ -143,7 +140,7 @@ service user {
|
||||
//检查userID是否存在
|
||||
rpc accountCheck(accountCheckReq)returns(accountCheckResp);
|
||||
//翻页(或指定userID,昵称)拉取用户信息 全字段
|
||||
rpc getUsers(getUsersReq) returns (getUsersResp);
|
||||
rpc getPaginationUsers(getUsersReq) returns (getUsersResp);
|
||||
//用户注册
|
||||
rpc userRegister(userRegisterReq) returns (userRegisterResp);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user