From e2cc00bdd795535c586c520d82714018310f7997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Fri, 18 Aug 2023 13:20:32 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/imserver/friendsmgr.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/server/imserver/friendsmgr.go b/server/imserver/friendsmgr.go index 2fc2d700..bce0169f 100644 --- a/server/imserver/friendsmgr.go +++ b/server/imserver/friendsmgr.go @@ -18,11 +18,11 @@ const ( type FriendsMgr struct { cs.MsgHandlerImpl - users map[string]*User - searchCaches map[string]SearchCache - friendships map[string][]*Friendship - pendingReqs map[string]map[string]bool - blockedUser map[string][]string + users map[string]*User // AccountId -> 用户 + searchCaches map[string]SearchCache // SearchKeyword -> 好友搜索结果 []*User + friendships map[string][]*Friendship // AccountId -> 好友关系列表 []*Friendship + pendingReqs map[string]map[string]bool // AccountId -> 等待请求列表 map[targetAccount]true + blockedUser map[string][]string // AccountId -> 黑名单列表 []AccountIds } type SearchCache struct { @@ -75,7 +75,7 @@ func (fm *FriendsMgr) unInit() { // 2. Struct Data Persist to DB } -func (fm *FriendsMgr) searchUserByAccountId(accountId string) *User { +func (fm *FriendsMgr) searchByAccountId(accountId string) *User { if user, ok := fm.users[accountId]; ok { return user } @@ -94,7 +94,7 @@ func (fm *FriendsMgr) searchUsers(keyword string) []*User { } maxUsers := 20 - var listFriend []*User + listFriend := make([]*User, 0, maxUsers) lowercaseQuery := strings.ToLower(keyword) for _, u := range fm.users { if strings.Contains(strings.ToLower(u.Username), lowercaseQuery) { @@ -422,11 +422,14 @@ func PrintUsers(str string, userList []*User) { } } -func (fm *FriendsMgr) findBlockedUserIndex(AccountId1, AccountId2 string) int { - for i, blockedAccountId := range fm.blockedUser[AccountId1] { - if blockedAccountId == AccountId2 { - return i +func (fm *FriendsMgr) findBlockedUserIndex(Account1Id, Account2Id string) int { + if fm.blockedUser[Account1Id] != nil { + for i, blockedAccountId := range fm.blockedUser[Account1Id] { + if blockedAccountId == Account2Id { + return i + } } } + return -1 }