From cef671daf132b83f74ffda94fa6b780f4885400b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 11 Apr 2024 20:45:35 +0800 Subject: [PATCH] 1 --- server/imserver_new/friend/friendmgr.go | 60 +++++++---------------- server/imserver_new/model/friend.go | 27 +++++++++- server/imserver_new/model/friend_apply.go | 18 +++++++ 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/server/imserver_new/friend/friendmgr.go b/server/imserver_new/friend/friendmgr.go index 95b16ccf..36e67e95 100644 --- a/server/imserver_new/friend/friendmgr.go +++ b/server/imserver_new/friend/friendmgr.go @@ -190,8 +190,10 @@ func (this *friendMgr) AsyncGetApplyList(lastIdx int64, accountId string, panic(fmt.Sprintf("AsyncGetApply idx error:%s %s", idx, lastSinceId)) } if this.IsFriend(accountId, senderId) { - this.asyncSetApplyStatus(senderId, accountId, - constant.FRIEND_APPLY_STATUS_ACCEPT) + model.FriendApply.SetStatus(senderId, accountId, constant.FRIEND_APPLY_STATUS_ACCEPT, + func (error, int64, int64) { + + }) } else { *q5.NewSliceElement(&users) = senderId } @@ -227,38 +229,24 @@ func (this *friendMgr) AsyncAcceptApply(senderId string, targetId string, cb fun accountId1, accountId2 := this.sortAccounts(senderId, targetId) func () { if this.IsFriend(senderId, targetId) { - this.asyncSetApplyStatus(senderId, targetId, 1) + model.FriendApply.SetStatus(senderId, targetId, constant.FRIEND_APPLY_STATUS_ACCEPT, + func (error, int64, int64) { + + }) cb(0, "") return } else { nowTime := f5.GetApp().GetNowSeconds() - f5.GetJsStyleDb().Upsert( - constant.FRIEND_DB, - "t_friend_relationship", - [][]string{ - {"account_id1", accountId1}, - {"account_id2", accountId2}, - }, - [][]string{ - {"add_time", q5.ToString(nowTime)}, - {"deleted", "0"}, - }, - [][]string{ - {"account_id1", accountId1}, - {"account_id2", accountId2}, - {"add_time", q5.ToString(nowTime)}, - {"deleted", "0"}, - {"createtime", q5.ToString(nowTime)}, - {"modifytime", q5.ToString(nowTime)}, - }, + model.Friend.Force(accountId1, accountId2, nowTime, func (err error, lastInsertId int64, rowsAffected int64) { if err != nil { cb(1, "") return } - this.asyncSetApplyStatus(senderId, - targetId, - constant.FRIEND_APPLY_STATUS_ACCEPT) + model.FriendApply.SetStatus(senderId, targetId, constant.FRIEND_APPLY_STATUS_ACCEPT, + func (error, int64, int64) { + + }) this.addFriendShip(accountId1, accountId2, int32(nowTime)) cb(0, "") }) @@ -271,7 +259,10 @@ func (this *friendMgr) AsyncRejectApply(senderId string, targetId string, cb fun cb(1, "") return } - this.asyncSetApplyStatus(senderId, targetId, constant.FRIEND_APPLY_STATUS_REJECT) + model.FriendApply.SetStatus(senderId, targetId, constant.FRIEND_APPLY_STATUS_REJECT, + func (error, int64, int64) { + + }) cb(0, "") } @@ -429,20 +420,3 @@ func (this *friendMgr) sortAccounts(senderId string, targetId string) (string, s return targetId, senderId } } - -func (this *friendMgr) asyncSetApplyStatus(senderId string, targetId string, status int32) { - f5.GetJsStyleDb().Update( - constant.FRIEND_DB, - "t_friend_apply", - [][]string{ - {"status", q5.ToString(status)}, - {"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())}, - }, - [][]string{ - {"sender_id", senderId}, - {"target_id", targetId}, - }, - func (err error, lastInsertId int64, rowsAffected int64) { - - }) -} diff --git a/server/imserver_new/model/friend.go b/server/imserver_new/model/friend.go index 438ed498..3ff818be 100644 --- a/server/imserver_new/model/friend.go +++ b/server/imserver_new/model/friend.go @@ -1,14 +1,37 @@ package model -/* import ( "q5" "f5" "main/constant" - )*/ +) type friend struct { } var Friend = new (friend) + +func (this *friend) Force(accountId1 string, accountId2 string, nowTime int64, + cb func (error, int64, int64)) { + f5.GetJsStyleDb().Upsert( + constant.FRIEND_DB, + "t_friend_relationship", + [][]string{ + {"account_id1", accountId1}, + {"account_id2", accountId2}, + }, + [][]string{ + {"add_time", q5.ToString(nowTime)}, + {"deleted", "0"}, + }, + [][]string{ + {"account_id1", accountId1}, + {"account_id2", accountId2}, + {"add_time", q5.ToString(nowTime)}, + {"deleted", "0"}, + {"createtime", q5.ToString(nowTime)}, + {"modifytime", q5.ToString(nowTime)}, + }, + cb) +} diff --git a/server/imserver_new/model/friend_apply.go b/server/imserver_new/model/friend_apply.go index 81a4a760..03cb49eb 100644 --- a/server/imserver_new/model/friend_apply.go +++ b/server/imserver_new/model/friend_apply.go @@ -36,3 +36,21 @@ func (this *friendApply) Force(senderId string, targetId string, }, cb) } + +func (this *friendApply) SetStatus(senderId string, targetId string, status int32, + cb func (error, int64, int64)) { + f5.GetJsStyleDb().Update( + constant.FRIEND_DB, + "t_friend_apply", + [][]string{ + {"status", q5.ToString(status)}, + {"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())}, + }, + [][]string{ + {"sender_id", senderId}, + {"target_id", targetId}, + }, + func (err error, lastInsertId int64, rowsAffected int64) { + + }) +}