diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index cf85e5ed..7a7d9cf9 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -141,6 +141,17 @@ func (this *friendMgr) getFriends(accountId string) *map[string]int32 { return nil } +func (this *friendMgr) IsBlack(senderId string, targetId string) bool { + myBlacks := this.getBlacks(senderId) + if myBlacks != nil { + if _, ok := (*myBlacks)[targetId]; ok { + return ok + } + } + return false +} + + func (this *friendMgr) getBlacks(accountId string) *map[string]int32 { if blacks, ok := this.blackHash[accountId]; ok { return &blacks @@ -307,11 +318,64 @@ func (this *friendMgr) AsynDeleteFriend(senderId string, targetId string, cb fun } func (this *friendMgr) AsyncAddBlack(senderId string, targetId string, cb func(int32, string)) { - + if this.IsBlack(senderId, targetId) { + cb(0, "") + return + } + nowTime := f5.GetApp().GetNowSeconds() + f5.GetJsStyleDb().Upsert( + constant.FRIEND_DB, + "t_friend_blacklist", + [][]string{ + {"sender_id", senderId}, + {"block_id", targetId}, + }, + [][]string{ + {"deleted", q5.ToString(0)}, + {"add_time", q5.ToString(nowTime)}, + }, + [][]string{ + {"sender_id", senderId}, + {"block_id", targetId}, + {"deleted", q5.ToString(0)}, + {"add_time", q5.ToString(nowTime)}, + {"createtime", q5.ToString(nowTime)}, + {"modifytime", q5.ToString(nowTime)}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { + if err != nil { + cb(1, "") + return + } + this.addBlackList(senderId, targetId, int32(nowTime)) + cb(0, "") + }) } func (this *friendMgr) AsyncRemoveBlack(senderId string, targetId string, cb func(int32, string)) { + if !this.IsBlack(senderId, targetId) { + cb(0, "") + return + } + f5.GetJsStyleDb().Update( + constant.FRIEND_DB, + "t_friend_blacklist", + [][]string{ + {"deleted", q5.ToString(1)}, + }, + [][]string{ + {"account_id", senderId}, + {"block_id", targetId}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { + if err != nil { + cb(1, "") + return + } + this.removeBlackList(senderId, targetId) + cb(0, "") + }) } func (this *friendMgr) addFriendShip(accountId1 string, accountId2 string, addTime int32) { @@ -359,6 +423,15 @@ func (this *friendMgr) addBlackList(accountId string, blockId string, addTime in } } +func (this *friendMgr) removeBlackList(accountId string, blockId string) { + { + blacks := this.getBlacks(accountId) + if blacks != nil { + delete(*blacks, blockId) + } + } +} + func (this *friendMgr) sortAccounts(senderId string, targetId string) (string, string) { if senderId < targetId { return senderId, targetId