Add 注释

This commit is contained in:
殷勇 2023-08-18 13:20:32 +08:00
parent 8e225ed25e
commit e2cc00bdd7

View File

@ -18,11 +18,11 @@ const (
type FriendsMgr struct { type FriendsMgr struct {
cs.MsgHandlerImpl cs.MsgHandlerImpl
users map[string]*User users map[string]*User // AccountId -> 用户
searchCaches map[string]SearchCache searchCaches map[string]SearchCache // SearchKeyword -> 好友搜索结果 []*User
friendships map[string][]*Friendship friendships map[string][]*Friendship // AccountId -> 好友关系列表 []*Friendship
pendingReqs map[string]map[string]bool pendingReqs map[string]map[string]bool // AccountId -> 等待请求列表 map[targetAccount]true
blockedUser map[string][]string blockedUser map[string][]string // AccountId -> 黑名单列表 []AccountIds
} }
type SearchCache struct { type SearchCache struct {
@ -75,7 +75,7 @@ func (fm *FriendsMgr) unInit() {
// 2. Struct Data Persist to DB // 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 { if user, ok := fm.users[accountId]; ok {
return user return user
} }
@ -94,7 +94,7 @@ func (fm *FriendsMgr) searchUsers(keyword string) []*User {
} }
maxUsers := 20 maxUsers := 20
var listFriend []*User listFriend := make([]*User, 0, maxUsers)
lowercaseQuery := strings.ToLower(keyword) lowercaseQuery := strings.ToLower(keyword)
for _, u := range fm.users { for _, u := range fm.users {
if strings.Contains(strings.ToLower(u.Username), lowercaseQuery) { 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 { func (fm *FriendsMgr) findBlockedUserIndex(Account1Id, Account2Id string) int {
for i, blockedAccountId := range fm.blockedUser[AccountId1] { if fm.blockedUser[Account1Id] != nil {
if blockedAccountId == AccountId2 { for i, blockedAccountId := range fm.blockedUser[Account1Id] {
return i if blockedAccountId == Account2Id {
return i
}
} }
} }
return -1 return -1
} }