diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index 60ae26ee..03afa6a2 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -178,6 +178,38 @@ func (this *friendMgr) AsyncGetApplyList(lastIdx int64, accountId string, cb fun } func (this *friendMgr) AsyncAddFriend(senderId string, targetId string, cb func(int32, string)) { + if this.IsFriend(senderId, targetId) { + cb(0, "") + return + } + nowTime := f5.GetApp().GetNowSeconds() + f5.GetJsStyleDb().Upsert( + constant.FRIEND_DB, + "t_friend_apply", + [][]string{ + {"sender_id", senderId}, + {"target_id", targetId}, + }, + [][]string{ + {"status", q5.ToString(0)}, + {"last_apply_time", q5.ToString(nowTime)}, + }, + [][]string{ + {"sender_id", senderId}, + {"target_id", targetId}, + {"status", q5.ToString(0)}, + {"last_apply_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.asyncSetApplyStatus(senderId, targetId, 1) + cb(0, "") + }) } func (this *friendMgr) AsyncAccpetApply(senderId string, targetId string, cb func(int32, string)) { @@ -185,6 +217,7 @@ func (this *friendMgr) AsyncAccpetApply(senderId string, targetId string, cb fun cb(1, "") return } + accountId1, accountId2 := this.sortAccounts(senderId, targetId) queryCb := func () { if this.IsFriend(senderId, targetId) { this.asyncSetApplyStatus(senderId, targetId, 1) @@ -192,7 +225,6 @@ func (this *friendMgr) AsyncAccpetApply(senderId string, targetId string, cb fun return } else { nowTime := f5.GetApp().GetNowSeconds() - accountId1, accountId2 := this.sortAccounts(senderId, targetId) f5.GetJsStyleDb().Upsert( constant.FRIEND_DB, "t_friend_relationship", @@ -218,6 +250,7 @@ func (this *friendMgr) AsyncAccpetApply(senderId string, targetId string, cb fun return } this.asyncSetApplyStatus(senderId, targetId, 1) + this.addFriendShip(accountId1, accountId2, int32(nowTime)) cb(0, "") }) }