From 3e90315b75869bc67880fc3bf970c1792cdd7bc1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 24 Mar 2024 10:11:45 +0800 Subject: [PATCH] 1 --- database/frienddb_new.sql | 2 ++ server/imserver_new/friend/friendmgr.go | 28 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/database/frienddb_new.sql b/database/frienddb_new.sql index cc3e8872..4ebdbb74 100644 --- a/database/frienddb_new.sql +++ b/database/frienddb_new.sql @@ -41,7 +41,9 @@ CREATE TABLE `t_friend_relationship` ( `idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id1` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号1', `account_id2` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号2', + `add_time` int(11) NOT NULL DEFAULT '0' COMMENT '成为好友时间', `deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除', + `del_time` int(11) NOT NULL DEFAULT '0' COMMENT '删除时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index 770ca255..6a91a327 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -8,15 +8,15 @@ import ( ) type friendMgr struct { - friendHash map[string]*map[string]int32 - blackHash map[string]*map[string]int32 - byBlackHash map[string]*map[string]int32 + friendHash map[string]map[string]int32 + blackHash map[string]map[string]int32 + byBlackHash map[string]map[string]int32 } func (this *friendMgr) Init() { - this.friendHash = make(map[string]*map[string]int32) - this.blackHash = make(map[string]*map[string]int32) - this.byBlackHash = make(map[string]*map[string]int32) + this.friendHash = make(map[string]map[string]int32) + this.blackHash = make(map[string]map[string]int32) + this.byBlackHash = make(map[string]map[string]int32) this.loadFromDB() } @@ -42,11 +42,15 @@ func (this *friendMgr) loadFriendships() { } for ds.Next() { idx := q5.ToInt64(ds.GetByName("idx")) + accountId1 := ds.GetByName("account_id1") + accountId2 := ds.GetByName("account_id2") + addTime := q5.ToInt32(ds.GetByName("add_time")) if idx > lastIdx { lastIdx = idx } else { panic(fmt.Sprintf("friendMgr.loadFriendships idxerror:%s %s", idx, lastIdx)) } + this.addFriendShip(accountId1, accountId2, addTime) } if ds.NumOfReaded() <= 0 { done = true @@ -124,7 +128,7 @@ func (this *friendMgr) GetBlackList(accountId string) []string { func (this *friendMgr) getFriends(accountId string) *map[string]int32 { if friends, ok := this.friendHash[accountId]; ok { - return friends + return &friends } return nil } @@ -156,3 +160,13 @@ func (this *friendMgr) AsyncAddBlack(senderId string, targetId string, cb func(i func (this *friendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) { } + +func (this *friendMgr) addFriendShip(accountId1 string, accountId2 string, addTime int32) { + { + friends := this.getFriends(accountId1) + if friends != nil { + this.friendHash[accountId1] = make(map[string]int32) + friends = this.getFriends(accountId1) + } + } +}