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 {
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
}