修复在线好友
This commit is contained in:
parent
170c0ba6d9
commit
d99893e667
@ -462,6 +462,19 @@ var (
|
|||||||
MainType: string(comm.ModuleFriend),
|
MainType: string(comm.ModuleFriend),
|
||||||
SubType: friend.FriendSubTypeRandList,
|
SubType: friend.FriendSubTypeRandList,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
|
Print: func(rsp proto.Message) string {
|
||||||
|
var formatStr strings.Builder
|
||||||
|
if in, ok := rsp.(*pb.UserMessage); ok {
|
||||||
|
out := &pb.FriendRandlistResp{}
|
||||||
|
if !comm.ProtoUnmarshal(in, out) {
|
||||||
|
return errors.New("unmarshal err").Error()
|
||||||
|
}
|
||||||
|
for i, v := range out.List {
|
||||||
|
formatStr.WriteString(fmt.Sprintf("%d- %v\n", (i + 1), v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return formatStr.String()
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ff(comm.ModuleFriend, friend.FriendSubTypeList): {
|
ff(comm.ModuleFriend, friend.FriendSubTypeList): {
|
||||||
NavLabel: "好友列表",
|
NavLabel: "好友列表",
|
||||||
|
@ -13,61 +13,64 @@ func (this *apiComp) RandlistCheck(session comm.IUserSession, req *pb.FriendRand
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistReq) (code pb.ErrorCode, data proto.Message) {
|
func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
var (
|
|
||||||
self *pb.DBFriend
|
// 当前玩家好友数据
|
||||||
)
|
self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
|
||||||
//在线玩家
|
if self == nil {
|
||||||
|
code = pb.ErrorCode_FriendSelfNoData
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//在线玩家列表
|
||||||
cuList, err := this.moduleFriend.ModuleUser.UserOnlineList()
|
cuList, err := this.moduleFriend.ModuleUser.UserOnlineList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//过滤
|
||||||
|
var newList []*pb.CacheUser
|
||||||
|
for _, v := range cuList {
|
||||||
|
// 将自己从在线玩家中过滤掉
|
||||||
|
if v.Uid == session.GetUserId() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 将自己的好友从在线玩家中过滤掉
|
||||||
|
if _, ok := utils.Findx(self.FriendIds, v.Uid); ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newList = append(newList, v)
|
||||||
|
}
|
||||||
|
|
||||||
// 只随机选择5个在线玩家
|
// 只随机选择5个在线玩家
|
||||||
var randOnlineUsers []string
|
var randOnlineUsers []string
|
||||||
if len(cuList) > 5 {
|
if len(newList) > 5 {
|
||||||
randArr := utils.Numbers(0, len(cuList), 5)
|
randArr := utils.Numbers(0, len(newList), 5)
|
||||||
for _, v := range randArr {
|
for _, v := range randArr {
|
||||||
if cuList[v] != nil {
|
if newList[v] != nil {
|
||||||
randOnlineUsers = append(randOnlineUsers, cuList[v].Uid)
|
randOnlineUsers = append(randOnlineUsers, newList[v].Uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, v := range cuList {
|
for _, v := range newList {
|
||||||
randOnlineUsers = append(randOnlineUsers, v.Uid)
|
randOnlineUsers = append(randOnlineUsers, v.Uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 当前玩家好友数据
|
|
||||||
self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
|
|
||||||
if self == nil {
|
|
||||||
code = pb.ErrorCode_FriendSelfNoData
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var userList []*pb.FriendBase
|
var userList []*pb.FriendBase
|
||||||
|
|
||||||
for _, uid := range randOnlineUsers {
|
for _, uid := range randOnlineUsers {
|
||||||
// 将自己从在线玩家中过滤掉
|
|
||||||
if uid == session.GetUserId() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// 将自己的好友从在线玩家中过滤掉
|
|
||||||
if _, ok := utils.Findx(self.FriendIds, uid); ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断当前在线好友是否在自己的申请列表中,如果存在也过滤掉
|
|
||||||
target := this.moduleFriend.modelFriend.GetFriend(uid)
|
target := this.moduleFriend.modelFriend.GetFriend(uid)
|
||||||
if target == nil {
|
if target == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取在线好友的信息
|
// // 获取在线好友的信息
|
||||||
user := this.moduleFriend.ModuleUser.GetUser(uid)
|
// user := this.moduleFriend.ModuleUser.GetUser(uid)
|
||||||
if user == nil {
|
// if user == nil {
|
||||||
continue
|
// continue
|
||||||
}
|
// }
|
||||||
|
|
||||||
base := this.setDefaultFriendUserBaseInfo(uid)
|
base := this.setDefaultFriendUserBaseInfo(uid)
|
||||||
if base == nil {
|
if base == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user