This commit is contained in:
aozhiwei 2024-03-24 10:51:56 +08:00
parent 5a6927160f
commit ac45db9fd1
2 changed files with 51 additions and 3 deletions

View File

@ -88,6 +88,7 @@ CREATE TABLE `t_friend_blacklist` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '账号',
`block_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT '被拉黑的账号',
`add_time` int(11) NOT NULL DEFAULT '0' COMMENT '成为好友时间',
`deleted` int(11) NOT NULL DEFAULT '0' COMMENT '是否已删除',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',

View File

@ -10,13 +10,11 @@ import (
type friendMgr struct {
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.loadFromDB()
}
@ -64,7 +62,38 @@ func (this *friendMgr) loadFriendships() {
}
func (this *friendMgr) loadBlacklist() {
var lastIdx int64
f5.GetSysLog().Info("friendMgr.loadBlacklist begin")
var done = false
for !done {
f5.GetJsStyleDb().SyncSelectCustomQuery(
constant.FRIEND_DB,
fmt.Sprintf("SELECT * FROM t_friend_blacklist WHERE idx > %d AND deleted = 0", lastIdx),
func (err error, ds *f5.DataSet) {
if err != nil {
panic(fmt.Sprintf("friendMgr.loadBlacklist dberror:%s", err))
}
for ds.Next() {
idx := q5.ToInt64(ds.GetByName("idx"))
accountId := ds.GetByName("account_id")
blockId := ds.GetByName("block_id")
addTime := q5.ToInt32(ds.GetByName("add_time"))
if idx > lastIdx {
lastIdx = idx
} else {
panic(fmt.Sprintf("friendMgr.loadBlacklist idxerror:%s %s", idx, lastIdx))
}
this.addBlackList(accountId, blockId, addTime)
}
if ds.NumOfReaded() <= 0 {
done = true
}
})
}
f5.GetSysLog().Info("friendMgr.loadBlacklist end lastIdx:%d friendNum:%d blackNum:%d",
lastIdx,
len(this.friendHash),
len(this.blackHash))
}
func (this *friendMgr) IsFriend(accountId1 string, accountId2 string) bool {
@ -133,6 +162,13 @@ func (this *friendMgr) getFriends(accountId string) *map[string]int32 {
return nil
}
func (this *friendMgr) getBlacks(accountId string) *map[string]int32 {
if blacks, ok := this.blackHash[accountId]; ok {
return &blacks
}
return nil
}
func (this *friendMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
}
@ -179,3 +215,14 @@ func (this *friendMgr) addFriendShip(accountId1 string, accountId2 string, addTi
(*friends)[accountId1] = addTime
}
}
func (this *friendMgr) addBlackList(accountId string, blockId string, addTime int32) {
{
blacks := this.getBlacks(accountId)
if blacks != nil {
this.blackHash[accountId] = make(map[string]int32)
blacks = this.getBlacks(accountId)
}
(*blacks)[blockId] = addTime
}
}