You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/friend/get_blacklist.go

56 lines
2.0 KiB

package friend
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
pbFriend "Open_IM/pkg/proto/friend"
"context"
)
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
log.Info(req.Token, req.OperationID, "rpc get blacklist is server,args=%s", req.String())
var (
userInfoList []*pbFriend.UserInfo
comment string
)
//Parse token, to find current user information
claims, err := token_verify.ParseToken(req.Token)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
return &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
}
blackListInfo, err := im_mysql_model.GetBlackListByUID(claims.UID)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s get blacklist failed", err.Error())
return &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrGetBlackList.ErrCode, ErrorMsg: constant.ErrGetBlackList.ErrMsg}, nil
}
for _, blackUser := range blackListInfo {
var blackUserInfo pbFriend.UserInfo
//Find black user information
us, err := im_mysql_model.FindUserByUID(blackUser.BlockId)
if err != nil {
log.Error(req.Token, req.OperationID, "err=%s search black list userInfo failed", err.Error())
continue
}
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, blackUser.BlockId)
if err == nil {
comment = friendShip.Comment
}
blackUserInfo.Uid = us.UID
blackUserInfo.Icon = us.Icon
blackUserInfo.Name = us.Name
blackUserInfo.Gender = us.Gender
blackUserInfo.Mobile = us.Mobile
blackUserInfo.Birth = us.Birth
blackUserInfo.Email = us.Email
blackUserInfo.Ex = us.Ex
blackUserInfo.Comment = comment
userInfoList = append(userInfoList, &blackUserInfo)
}
log.Info(req.Token, req.OperationID, "rpc get blacklist success return")
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
}