Add consts
This commit is contained in:
parent
8d9bd6bc93
commit
8774fac2c5
@ -22,6 +22,14 @@ const (
|
|||||||
MaxBlockedMembers = 50
|
MaxBlockedMembers = 50
|
||||||
SearchWord = 42 // 搜索关键字
|
SearchWord = 42 // 搜索关键字
|
||||||
MaxSearchResults = 20 // 搜索结果20条
|
MaxSearchResults = 20 // 搜索结果20条
|
||||||
|
FriendReqsStatusDefault = 0 // 好友请求状态, 等待中
|
||||||
|
FriendReqsStatusOk = 1 // 好友请求状态, 接受
|
||||||
|
FriendReqsStatusReject = 2 // 好友请求状态, 拒绝
|
||||||
|
FriendReqsStatusDeleted = 3 // 好友请求状态, 已删除
|
||||||
|
FriendshipStatusOk = 0 // 好友关系状态 正常
|
||||||
|
FriendshipStatusDeleted = 1 // 好友关系状态 已删除0
|
||||||
|
BlacklistStatusDefault = 0 // 好友黑名单状态 是否已移除黑名单 默认0,添加进来 未移除
|
||||||
|
BlacklistStatusIsRemoved = 1 // 好友黑名单状态 已移除黑名单
|
||||||
)
|
)
|
||||||
|
|
||||||
// im server guild
|
// im server guild
|
||||||
@ -29,7 +37,7 @@ const (
|
|||||||
MaxMembers = 10
|
MaxMembers = 10
|
||||||
MaxPendingReqs = 10
|
MaxPendingReqs = 10
|
||||||
DefaultLogs = 20
|
DefaultLogs = 20
|
||||||
LogTypeApprove = 1
|
LogTypeApprove = 1 // 公会日志类型, 批准加入
|
||||||
LogTypeLeave = 2
|
LogTypeLeave = 2
|
||||||
LogTypeDismiss = 3
|
LogTypeDismiss = 3
|
||||||
LogTypePromote = 4
|
LogTypePromote = 4
|
||||||
|
@ -140,7 +140,7 @@ func (fm *FriendsMgr) addFriendRequest(account1Id string, account2Id string) err
|
|||||||
fm.pendingReqs[account2Id][account1Id] = false
|
fm.pendingReqs[account2Id][account1Id] = false
|
||||||
|
|
||||||
// persist to db
|
// persist to db
|
||||||
fm.upsertFriendRequest(account1Id, account2Id, "0")
|
fm.upsertFriendRequest(account1Id, account2Id, q5.ToString(FriendReqsStatusDefault))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -156,12 +156,12 @@ func (fm *FriendsMgr) acceptFriendRequest(account1Id string, account2Id string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// step1. update reqs
|
// step1. update reqs
|
||||||
fm.upsertFriendRequest(account2Id, account1Id, "1")
|
fm.upsertFriendRequest(account2Id, account1Id, q5.ToString(FriendReqsStatusOk))
|
||||||
fm.upsertFriendRequest(account1Id, account2Id, "1")
|
fm.upsertFriendRequest(account1Id, account2Id, q5.ToString(FriendReqsStatusOk))
|
||||||
|
|
||||||
// step2. insert friendship
|
// step2. insert friendship
|
||||||
a1, a2 := swapAccountIds(account1Id, account2Id)
|
a1, a2 := swapAccountIds(account1Id, account2Id)
|
||||||
fm.upsertFriendShip(a1, a2, 0)
|
fm.upsertFriendShip(a1, a2, FriendshipStatusOk)
|
||||||
|
|
||||||
// Create a new friendship
|
// Create a new friendship
|
||||||
friendship := &Friendship{
|
friendship := &Friendship{
|
||||||
@ -186,7 +186,7 @@ func (fm *FriendsMgr) rejectFriendRequest(account1Id string, account2Id string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 申请表,申请者,目标者,
|
// 申请表,申请者,目标者,
|
||||||
fm.upsertFriendRequest(account2Id, account1Id, "2")
|
fm.upsertFriendRequest(account2Id, account1Id, q5.ToString(FriendReqsStatusReject))
|
||||||
|
|
||||||
delete(fm.pendingReqs[account1Id], account2Id)
|
delete(fm.pendingReqs[account1Id], account2Id)
|
||||||
delete(fm.pendingReqs[account2Id], account1Id)
|
delete(fm.pendingReqs[account2Id], account1Id)
|
||||||
@ -211,7 +211,7 @@ func (fm *FriendsMgr) deleteFriendShip(account1Id, account2Id string) error {
|
|||||||
for i, friendship := range user1Friendships {
|
for i, friendship := range user1Friendships {
|
||||||
if friendship.User1.AccountId == account2Id || friendship.User2.AccountId == account2Id {
|
if friendship.User1.AccountId == account2Id || friendship.User2.AccountId == account2Id {
|
||||||
// 删除好友请求, upsert 不存在则新增,存在则替换值
|
// 删除好友请求, upsert 不存在则新增,存在则替换值
|
||||||
fm.upsertFriendRequest(account1Id, account2Id, "3")
|
fm.upsertFriendRequest(account1Id, account2Id, q5.ToString(FriendReqsStatusDeleted))
|
||||||
fm.friendships[account1Id] = append(user1Friendships[:i], user1Friendships[i+1:]...)
|
fm.friendships[account1Id] = append(user1Friendships[:i], user1Friendships[i+1:]...)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@ -225,7 +225,7 @@ func (fm *FriendsMgr) deleteFriendShip(account1Id, account2Id string) error {
|
|||||||
for i, friendship := range user2Friendships {
|
for i, friendship := range user2Friendships {
|
||||||
if friendship.User1.AccountId == account1Id || friendship.User2.AccountId == account1Id {
|
if friendship.User1.AccountId == account1Id || friendship.User2.AccountId == account1Id {
|
||||||
// 删除好友请求, insert和replace, 不存在则新增,存在则替换值
|
// 删除好友请求, insert和replace, 不存在则新增,存在则替换值
|
||||||
fm.upsertFriendRequest(account2Id, account1Id, "3")
|
fm.upsertFriendRequest(account2Id, account1Id, q5.ToString(FriendReqsStatusDeleted))
|
||||||
fm.friendships[account2Id] = append(user2Friendships[:i], user2Friendships[i+1:]...)
|
fm.friendships[account2Id] = append(user2Friendships[:i], user2Friendships[i+1:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ func (fm *FriendsMgr) deleteFriendShip(account1Id, account2Id string) error {
|
|||||||
|
|
||||||
// Delete friendship DB
|
// Delete friendship DB
|
||||||
a1, a2 := swapAccountIds(account1Id, account2Id)
|
a1, a2 := swapAccountIds(account1Id, account2Id)
|
||||||
fields := [][]string{{"is_delete_friendship", q5.ToString(1)}}
|
fields := [][]string{{"is_delete_friendship", q5.ToString(FriendshipStatusDeleted)}}
|
||||||
fm.updateFriendShip(a1, a2, fields)
|
fm.updateFriendShip(a1, a2, fields)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -298,7 +298,7 @@ func (fm *FriendsMgr) addBlacklist(account1Id string, account2Id string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fm.blackList[account1Id][account2Id] = false
|
fm.blackList[account1Id][account2Id] = false
|
||||||
fm.upsertBlacklist(account1Id, account2Id, 0)
|
fm.upsertBlacklist(account1Id, account2Id, BlacklistStatusDefault)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -319,7 +319,7 @@ func (fm *FriendsMgr) removeBlacklist(account1Id string, account2Id string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(fm.blackList[account1Id], account2Id)
|
delete(fm.blackList[account1Id], account2Id)
|
||||||
fm.upsertBlacklist(account1Id, account2Id, 1)
|
fm.upsertBlacklist(account1Id, account2Id, BlacklistStatusIsRemoved)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,7 @@ func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
// init pendingReqs
|
// init pendingReqs
|
||||||
gm.pendingReqs[guildId] = make(map[string]bool)
|
gm.pendingReqs[guildId] = make(map[string]bool)
|
||||||
}
|
}
|
||||||
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadGuildMemberFromDB 加载公会成员
|
// loadGuildMemberFromDB 加载公会成员
|
||||||
@ -89,6 +90,7 @@ func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadPendingReqsFromDB 加载公会申请者列表
|
// loadPendingReqsFromDB 加载公会申请者列表
|
||||||
@ -119,6 +121,7 @@ func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
|||||||
accountId = q5.ToString(*rows.GetByIndex(1))
|
accountId = q5.ToString(*rows.GetByIndex(1))
|
||||||
gm.pendingReqs[guildId][accountId] = true
|
gm.pendingReqs[guildId][accountId] = true
|
||||||
}
|
}
|
||||||
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildReqFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadGuildLogsFromDB 加载公会日志
|
// loadGuildLogsFromDB 加载公会日志
|
||||||
@ -142,7 +145,7 @@ func (gm *GuildMgr) loadGuildLogsFromDB() {
|
|||||||
}
|
}
|
||||||
func (gm *GuildMgr) loadGuildLogsFromDBResult(err error, pagination *f5.Pagination) {
|
func (gm *GuildMgr) loadGuildLogsFromDBResult(err error, pagination *f5.Pagination) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
panic(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//total := pagination.Total
|
//total := pagination.Total
|
||||||
@ -168,6 +171,7 @@ func (gm *GuildMgr) loadGuildLogsFromDBResult(err error, pagination *f5.Paginati
|
|||||||
}
|
}
|
||||||
gm.Logs[guildId] = append(gm.Logs[guildId], guildLog)
|
gm.Logs[guildId] = append(gm.Logs[guildId], guildLog)
|
||||||
}
|
}
|
||||||
|
q5.UnSetBitFlag(&gm.loadedFlags, LoadGuildLogFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// createGuildDB 创建公会
|
// createGuildDB 创建公会
|
||||||
|
@ -6,6 +6,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"q5"
|
"q5"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LoadGuildFlag = iota
|
||||||
|
LoadGuildMemberFlag
|
||||||
|
LoadGuildReqFlag
|
||||||
|
LoadGuildLogFlag
|
||||||
)
|
)
|
||||||
|
|
||||||
type GuildMgr struct {
|
type GuildMgr struct {
|
||||||
@ -13,6 +21,7 @@ type GuildMgr struct {
|
|||||||
Guilds map[int64]*Guild // 公会ID -> 公会列表
|
Guilds map[int64]*Guild // 公会ID -> 公会列表
|
||||||
pendingReqs map[int64]map[string]bool // 公会ID -> 申请者账户ID -> bool
|
pendingReqs map[int64]map[string]bool // 公会ID -> 申请者账户ID -> bool
|
||||||
Logs map[int64][]*GuildLog // 公会ID -> 公会日志
|
Logs map[int64][]*GuildLog // 公会ID -> 公会日志
|
||||||
|
loadedFlags int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGuildMgr() *GuildMgr {
|
func NewGuildMgr() *GuildMgr {
|
||||||
@ -28,14 +37,23 @@ func (gm *GuildMgr) init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gm *GuildMgr) loadFromDB() {
|
func (gm *GuildMgr) loadFromDB() {
|
||||||
|
q5.SetBitFlag(&gm.loadedFlags, LoadGuildFlag)
|
||||||
|
q5.SetBitFlag(&gm.loadedFlags, LoadGuildMemberFlag)
|
||||||
|
q5.SetBitFlag(&gm.loadedFlags, LoadGuildReqFlag)
|
||||||
|
q5.SetBitFlag(&gm.loadedFlags, LoadGuildLogFlag)
|
||||||
|
|
||||||
// 加载公会
|
// 加载公会
|
||||||
gm.loadGuildFromDB()
|
gm.loadGuildFromDB()
|
||||||
// 加载公会成员
|
// 加载公会成员
|
||||||
gm.loadGuildMemberFromDB()
|
gm.loadGuildMemberFromDB()
|
||||||
// 加载公会申请者列表
|
//// 加载公会申请者列表
|
||||||
gm.loadPendingReqsFromDB()
|
gm.loadPendingReqsFromDB()
|
||||||
// 加载公会日志
|
//// 加载公会日志
|
||||||
gm.loadGuildLogsFromDB()
|
gm.loadGuildLogsFromDB()
|
||||||
|
|
||||||
|
for gm.loadedFlags != 0 {
|
||||||
|
time.Sleep(time.Millisecond * 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGuild 创建公会
|
// CreateGuild 创建公会
|
||||||
|
Loading…
x
Reference in New Issue
Block a user