226 lines
5.4 KiB
Go
226 lines
5.4 KiB
Go
package main
|
|
|
|
import (
|
|
"f5"
|
|
"fmt"
|
|
"q5"
|
|
)
|
|
|
|
func (fm *FriendsMgr) upsertFriendRequest(account1Id string, account2Id string, isFriendship string) {
|
|
where := [][]string{
|
|
{"account1_id", account1Id},
|
|
{"account2_id", account2Id},
|
|
}
|
|
insertKv := [][]string{
|
|
{"sender_account_id", account1Id},
|
|
{"receiver_account_id", account2Id},
|
|
{"is_friendship", isFriendship},
|
|
}
|
|
updateKv := insertKv
|
|
f5.GetJsStyleDb().Upsert(
|
|
FRIEND_DB,
|
|
"t_friend_pending_request",
|
|
where,
|
|
updateKv,
|
|
insertKv,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
fmt.Printf("error:%v\n", err)
|
|
}
|
|
fmt.Printf("lastInsertId:%d\n", lastInsertId)
|
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) upsertFriendShip(account1Id string, account2Id string, isDeleteFriendship int) {
|
|
where := [][]string{
|
|
{"account1_id", account1Id},
|
|
{"account2_id", account2Id},
|
|
}
|
|
fields := [][]string{
|
|
{"account1_id", account1Id},
|
|
{"account2_id", account2Id},
|
|
{"is_delete_friendship", q5.ToString(isDeleteFriendship)},
|
|
}
|
|
insertKv := fields
|
|
updateKv := fields
|
|
f5.GetJsStyleDb().Upsert(
|
|
FRIEND_DB,
|
|
"t_friend_ships",
|
|
where,
|
|
updateKv,
|
|
insertKv,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
fmt.Printf("error:%v\n", err)
|
|
}
|
|
fmt.Printf("lastInsertId:%d\n", lastInsertId)
|
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) updateFriendShip(account1Id string, account2Id string, fields [][]string) {
|
|
where := [][]string{
|
|
{"account1_id", account1Id},
|
|
{"account2_id", account2Id},
|
|
}
|
|
f5.GetJsStyleDb().Update(
|
|
FRIEND_DB,
|
|
"t_friend_ships",
|
|
fields,
|
|
where,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
fmt.Printf("error:%v\n", err)
|
|
}
|
|
fmt.Printf("lastInsertId:%d\n", lastInsertId)
|
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) upsertBlacklist(account1Id string, account2Id string, isRemoved int) {
|
|
where := [][]string{
|
|
{"account_id", account1Id},
|
|
}
|
|
insertKv := [][]string{
|
|
{"account_id", account1Id},
|
|
{"blocked_account_id", account2Id},
|
|
{"is_removed", q5.ToString(isRemoved)},
|
|
}
|
|
updateKv := insertKv
|
|
f5.GetJsStyleDb().Upsert(
|
|
FRIEND_DB,
|
|
"t_friend_blacklist",
|
|
where,
|
|
updateKv,
|
|
insertKv,
|
|
func(err error, lastInsertId int64, rowsAffected int64) {
|
|
if err != nil {
|
|
fmt.Printf("error:%v\n", err)
|
|
}
|
|
fmt.Printf("lastInsertId:%d\n", lastInsertId)
|
|
fmt.Printf("rowsAffected:%d\n", rowsAffected)
|
|
},
|
|
)
|
|
}
|
|
|
|
// loadUsers 加载所有用户
|
|
func (fm *FriendsMgr) loadUsers() {
|
|
fields := []string{"account_id", "name"}
|
|
f5.GetJsStyleDb().Select(
|
|
GAME_DB,
|
|
"t_user",
|
|
fields,
|
|
[][]string{},
|
|
fm.loadUsersResult,
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) loadUsersResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
fmt.Printf("loadUsersResult err:%v \n", err)
|
|
return
|
|
}
|
|
|
|
fm.users = make(map[string]*User, 100)
|
|
for rows.Next() {
|
|
user := &User{
|
|
AccountId: q5.ToString(*rows.GetByIndex(0)),
|
|
Username: q5.ToString(*rows.GetByIndex(1)),
|
|
}
|
|
fm.users[user.AccountId] = user
|
|
}
|
|
fm.userCount = len(fm.users)
|
|
}
|
|
|
|
// loadFriendships 加载好友关系表
|
|
func (fm *FriendsMgr) loadFriendships() {
|
|
fields := []string{"account1_id", "account2_id"}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_friend_ships",
|
|
fields,
|
|
[][]string{},
|
|
fm.loadFriendshipsResult,
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) loadFriendshipsResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
fmt.Printf("loadFriendshipsResult err:%v \n", err)
|
|
return
|
|
}
|
|
fm.friendships = make(map[string][]*Friendship)
|
|
for rows.Next() {
|
|
user1 := fm.getUser(q5.ToString(*rows.GetByIndex(0)))
|
|
user2 := fm.getUser(q5.ToString(*rows.GetByIndex(1)))
|
|
if user1 == nil || user2 == nil {
|
|
continue
|
|
}
|
|
friendship := &Friendship{}
|
|
friendship.User1 = user1
|
|
friendship.User2 = user2
|
|
fm.addFriendshipToMap(user1.AccountId, friendship)
|
|
fm.addFriendshipToMap(user2.AccountId, friendship)
|
|
}
|
|
}
|
|
|
|
// loadPendingRequests 加载等待验证好友请求
|
|
func (fm *FriendsMgr) loadPendingRequests() {
|
|
fields := []string{"sender_account_id", "receiver_account_id"}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_friend_pending_request",
|
|
fields,
|
|
[][]string{
|
|
{"is_friendship", "0"},
|
|
},
|
|
fm.loadPendingRequestsResult,
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) loadPendingRequestsResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
fmt.Printf("loadPendingRequestsResult err:%v \n", err)
|
|
return
|
|
}
|
|
fm.pendingReqs = make(map[string]map[string]bool)
|
|
for rows.Next() {
|
|
senderAccountId := q5.ToString(*rows.GetByIndex(0))
|
|
receiverAccountId := q5.ToString(*rows.GetByIndex(1))
|
|
fm.pendingReqs[receiverAccountId] = make(map[string]bool)
|
|
fm.pendingReqs[receiverAccountId][senderAccountId] = true
|
|
}
|
|
}
|
|
|
|
// loadPendingRequests 加载等待验证好友请求
|
|
func (fm *FriendsMgr) loadBlacklist() {
|
|
fields := []string{"account_id", "blocked_account_id"}
|
|
f5.GetJsStyleDb().Select(
|
|
FRIEND_DB,
|
|
"t_friend_blacklist",
|
|
fields,
|
|
[][]string{
|
|
{"is_removed", "0"},
|
|
},
|
|
fm.loadBlacklistResult,
|
|
)
|
|
}
|
|
|
|
func (fm *FriendsMgr) loadBlacklistResult(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
fmt.Printf("loadBlacklistResult err:%v \n", err)
|
|
return
|
|
}
|
|
fm.blackList = make(map[string]map[string]bool, 100)
|
|
for rows.Next() {
|
|
account1Id := q5.ToString(*rows.GetByIndex(0))
|
|
account2Id := q5.ToString(*rows.GetByIndex(1))
|
|
fm.blackList[account1Id] = make(map[string]bool, MaxBlockedMembers)
|
|
fm.blackList[account1Id][account2Id] = false
|
|
}
|
|
}
|