From 088f770c79ca605568b6635192c943b4b88446df Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 22 Mar 2024 12:02:39 +0800 Subject: [PATCH] 1 --- server/imserver_new/friend/friendmgr.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index 1c81a987..fe46e030 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -31,11 +31,7 @@ func (this *FriendMgr) IsFriend(accountId1 string, accountId2 string) bool { } func (this *FriendMgr) HasFriend(accountId string) bool { - myFriends := this.getFriends(accountId) - if myFriends != nil { - return len(*myFriends) > 0 - } - return false + return this.GetFriendNum(accountId) > 0 } func (this *FriendMgr) GetFriendNum(accountId string) int32 { @@ -46,6 +42,17 @@ func (this *FriendMgr) GetFriendNum(accountId string) int32 { return 0 } +func (this *FriendMgr) TraverseFriend(accountId string, cb func(string, int32) bool) { + myFriends := this.getFriends(accountId) + if myFriends != nil { + for a, t := range *myFriends { + if !cb(a, t) { + break + } + } + } +} + func (this *FriendMgr) getFriends(accountId string) *map[string]int32 { if friends, ok := this.friendHash[accountId]; ok { return friends