diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 90b36a87..915b67f5 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -56,6 +56,8 @@ type PlayerMgr interface { type FriendMgr interface { IsFriend(string, string) bool + GetFriendList(string) []string + AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) } type Guild interface { diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index 7a0ae30e..e6722f48 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -1,6 +1,7 @@ package friend import ( + "q5" ) type FriendMgr struct { @@ -56,9 +57,25 @@ func (this *FriendMgr) TraverseFriend(accountId string, cb func(string, int32) b } } +func (this *FriendMgr) GetFriendList(accountId string) []string { + friendList := []string{} + this.TraverseFriend( + accountId, + func (friendId string, addTime int32) bool { + ele := q5.NewSliceElement(&friendList) + *ele = friendId + return true + }) + return friendList +} + func (this *FriendMgr) getFriends(accountId string) *map[string]int32 { if friends, ok := this.friendHash[accountId]; ok { return friends } return nil } + +func (this *FriendMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) { + +} diff --git a/server/imserver_new/player/player.go b/server/imserver_new/player/player.go index 29ce2c01..bc4a4fb9 100644 --- a/server/imserver_new/player/player.go +++ b/server/imserver_new/player/player.go @@ -91,9 +91,53 @@ func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUser } func (this *player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) { + GetFriendMgr().AsyncGetApplyList( + 0, + this.GetAccountId(), + func (errCode int32, errMsg string, sinceId int64, accountIds []string) { + rspMsg := new(cs.SMListPendingFriendRequest) + if errCode != 0 { + this.SendMsg(rspMsg.Err(1, "internal server error")) + return + } + GetCacheMgr().AsyncGetUsers( + accountIds, + func (errCode int32, errMsg string) { + if errCode != 0 { + this.SendMsg(rspMsg.Err(1, "internal server error")) + return + } + for _, accountId := range(accountIds) { + userProfile := GetCacheMgr().GetUserProfile(accountId) + if userProfile != nil { + ele := q5.NewSliceElement(&rspMsg.Users) + userProfile.FillMFUser(*ele) + } + } + this.SendMsg(rspMsg) + }) + }) } func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) { + friendList := GetFriendMgr().GetFriendList(this.GetAccountId()) + GetCacheMgr().AsyncGetUsers( + friendList, + func (errCode int32, errMsg string) { + rspMsg := new(cs.SMListFriend) + if errCode != 0 { + this.SendMsg(rspMsg.Err(1, "internal server error")) + return + } + for _, accountId := range(friendList) { + userProfile := GetCacheMgr().GetUserProfile(accountId) + if userProfile != nil { + ele := q5.NewSliceElement(&rspMsg.Users) + userProfile.FillMFUser(*ele) + } + } + this.SendMsg(rspMsg) + }) } func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {