mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 11:06:43 +08:00
Error code standardization
This commit is contained in:
parent
467d44adc6
commit
026649f875
@ -1,4 +1,4 @@
|
||||
package utils
|
||||
package convert
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
@ -34,14 +34,14 @@ func NewPBFriend(friendInfo *sdk.FriendInfo) *PBFriend {
|
||||
return &PBFriend{FriendInfo: friendInfo}
|
||||
}
|
||||
|
||||
func (db *DBFriend) convert() (*sdk.FriendInfo, error) {
|
||||
func (db *DBFriend) Convert() (*sdk.FriendInfo, error) {
|
||||
pbFriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
||||
utils.CopyStructFields(pbFriend, db)
|
||||
user, err := getUsersInfo([]string{db.FriendUserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
CopyStructFields(pbFriend.FriendUser, user[0])
|
||||
utils.CopyStructFields(pbFriend.FriendUser, user[0])
|
||||
pbFriend.CreateTime = db.CreateTime.Unix()
|
||||
|
||||
pbFriend.FriendUser.CreateTime = db.CreateTime.Unix()
|
||||
@ -50,9 +50,9 @@ func (db *DBFriend) convert() (*sdk.FriendInfo, error) {
|
||||
|
||||
func (pb *PBFriend) Convert() (*relation.Friend, error) {
|
||||
dbFriend := &relation.Friend{}
|
||||
CopyStructFields(dbFriend, pb)
|
||||
utils.CopyStructFields(dbFriend, pb)
|
||||
dbFriend.FriendUserID = pb.FriendUser.UserID
|
||||
dbFriend.CreateTime = UnixSecondToTime(pb.CreateTime)
|
||||
dbFriend.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||
return dbFriend, nil
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ func (pb *PBBlack) Convert() (*relation.Black, error) {
|
||||
func (db *DBBlack) Convert() (*sdk.BlackInfo, error) {
|
||||
pbBlack := &sdk.BlackInfo{}
|
||||
utils.CopyStructFields(pbBlack, db)
|
||||
pbBlack.CreateTime = uint32(db.CreateTime.Unix())
|
||||
pbBlack.CreateTime = db.CreateTime.Unix()
|
||||
user, err := getUsersInfo([]string{db.BlockUserID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -248,8 +248,8 @@ func (pb *PBGroupRequest) Convert() (*relation.GroupRequest, error) {
|
||||
func (db *DBGroupRequest) Convert() (*sdk.GroupRequest, error) {
|
||||
dst := &sdk.GroupRequest{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
dst.ReqTime = uint32(db.ReqTime.Unix())
|
||||
dst.HandleTime = uint32(db.HandledTime.Unix())
|
||||
dst.ReqTime = db.ReqTime.Unix()
|
||||
dst.HandleTime = db.HandledTime.Unix()
|
||||
return dst, nil
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
// process Friend application
|
||||
func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.RespondFriendApplyReq) (*pbFriend.RespondFriendApplyResp, error) {
|
||||
resp := &pbFriend.RespondFriendApplyResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.ToUserID); err != nil {
|
||||
if err := check.Access(ctx, req.ToUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
friendRequest := relation.FriendRequest{FromUserID: req.FromUserID, ToUserID: req.ToUserID, HandleMsg: req.HandleMsg, HandleResult: req.HandleResult}
|
||||
@ -206,7 +206,7 @@ func (s *friendServer) RespondFriendApply(ctx context.Context, req *pbFriend.Res
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.DeleteFriendResp, error) {
|
||||
resp := &pbFriend.DeleteFriendResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
|
||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.FriendInterface.Delete(ctx, req.OwnerUserID, req.FriendUserID); err != nil {
|
||||
@ -218,7 +218,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri
|
||||
|
||||
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFriendRemarkReq) (*pbFriend.SetFriendRemarkResp, error) {
|
||||
resp := &pbFriend.SetFriendRemarkResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
|
||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.FriendInterface.UpdateRemark(ctx, req.OwnerUserID, req.FriendUserID, req.Remark); err != nil {
|
||||
@ -228,25 +228,25 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlackReq) (*pbFriend.RemoveBlackResp, error) {
|
||||
resp := &pbFriend.RemoveBlacklistResp{}
|
||||
func (s *friendServer) RemoveBlack(ctx context.Context, req *pbFriend.RemoveBlackReq) (*pbFriend.RemoveBlackResp, error) {
|
||||
resp := &pbFriend.RemoveBlackResp{}
|
||||
//Parse token, to find current user information
|
||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
if err := check.Access(ctx, req.OwnerUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.BlackInterface.Delete(ctx, []*relation.Black{{OwnerUserID: req.FromUserID, BlockUserID: req.ToUserID}}); err != nil {
|
||||
if err := s.BlackInterface.Delete(ctx, []*relation.Black{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chat.BlackDeletedNotification(req)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||
resp := &pbFriend.GetFriendListResp{}
|
||||
if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil {
|
||||
func (s *friendServer) GetFriends(ctx context.Context, req *pbFriend.GetFriendsReq) (*pbFriend.GetFriendsResp, error) {
|
||||
resp := &pbFriend.GetFriendsResp{}
|
||||
if err := check.Access(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
friends, err := s.FriendInterface.FindOwnerUserID(ctx, req.FromUserID)
|
||||
friends, err := s.FriendInterface.FindOwnerFriends(ctx, req.UserID, req.Pagination.PageNumber, req.Pagination.ShowNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -254,7 +254,7 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
||||
for _, f := range friends {
|
||||
userIDList = append(userIDList, f.FriendUserID)
|
||||
}
|
||||
users, err := GetUsersInfo(ctx, userIDList)
|
||||
users, err := check.GetUsersInfo(ctx, userIDList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -263,9 +263,12 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
||||
userMap[user.UserID] = users[i]
|
||||
}
|
||||
for _, friendUser := range friends {
|
||||
friendUserInfo := sdkws.FriendInfo{FriendUser: userMap[friendUser.FriendUserID]}
|
||||
utils.CopyStructFields(&friendUserInfo, friendUser)
|
||||
resp.FriendInfoList = append(resp.FriendInfoList, &friendUserInfo)
|
||||
|
||||
friendUserInfo, err := (utils.NewDBFriend(friendUser)).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.FriendsInfo = append(resp.FriendsInfo, friendUserInfo)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ type FriendInterface interface {
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error)
|
||||
FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error)
|
||||
//获取ownerUserID的好友列表
|
||||
FindOwnerFriends(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
//friendUserID在哪些人的好友列表中
|
||||
FindInWhoseFriends(ctx context.Context, friendUserID string, pageNumber, showNumber int32) (friends []*relation.Friend, err error)
|
||||
Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error)
|
||||
FindUserState(ctx context.Context, userID1, userID2 string) (friends []*relation.Friend, err error)
|
||||
}
|
||||
@ -70,6 +72,7 @@ type FriendDatabaseInterface interface {
|
||||
UpdateByMap(ctx context.Context, ownerUserID string, args map[string]interface{}) (err error)
|
||||
Update(ctx context.Context, friends []*relation.Friend) (err error)
|
||||
UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error)
|
||||
|
||||
FindOwnerUserID(ctx context.Context, ownerUserID string) (friends []*relation.Friend, err error)
|
||||
FindFriendUserID(ctx context.Context, friendUserID string) (friends []*relation.Friend, err error)
|
||||
Take(ctx context.Context, ownerUserID, friendUserID string) (friend *relation.Friend, err error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user