上传聊天业务代码优化
This commit is contained in:
parent
fe159fb96e
commit
36d3f893c8
@ -24,13 +24,13 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq)
|
|||||||
)
|
)
|
||||||
switch req.Channel {
|
switch req.Channel {
|
||||||
case pb.ChatChannel_World:
|
case pb.ChatChannel_World:
|
||||||
if list, err = this.module.modelChat.GetChatQueue(req.Channel, 0, 0); err != nil {
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case pb.ChatChannel_Union:
|
case pb.ChatChannel_Union:
|
||||||
if list, err = this.module.modelChat.GetChatQueue(req.Channel, 0, 0); err != nil {
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), "", 0); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -50,13 +50,13 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq)
|
|||||||
code = pb.ErrorCode_ReqParameterError
|
code = pb.ErrorCode_ReqParameterError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if list, err = this.module.modelChat.GetChatQueue(req.Channel, 0, req.ChannelId); err != nil {
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), 0, req.ChannelId); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case pb.ChatChannel_System:
|
case pb.ChatChannel_System:
|
||||||
if list, err = this.module.modelChat.GetChatQueue(req.Channel, 0, 0); err != nil {
|
if list, err = this.module.modelChat.getChatQueue(req.Channel, session.GetServiecTag(), 0, 0); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (this *modelChatComp) QueryUserMsg(uid string) (result []*pb.DBChat, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
//查询用户未读消息
|
//查询用户未读消息
|
||||||
func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, area int32) (result []*pb.DBChat, err error) {
|
func (this *modelChatComp) getChatQueue(channel pb.ChatChannel, stag, union string, area int32) (result []*pb.DBChat, err error) {
|
||||||
var (
|
var (
|
||||||
key string
|
key string
|
||||||
find bson.M
|
find bson.M
|
||||||
@ -74,15 +74,15 @@ func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, area int3
|
|||||||
)
|
)
|
||||||
switch channel {
|
switch channel {
|
||||||
case pb.ChatChannel_World:
|
case pb.ChatChannel_World:
|
||||||
key = worldchatkey
|
key = fmt.Sprintf("%s-%s", worldchatkey, stag)
|
||||||
find = bson.M{"channel": channel}
|
find = bson.M{"channel": channel}
|
||||||
break
|
break
|
||||||
case pb.ChatChannel_Union:
|
case pb.ChatChannel_Union:
|
||||||
key = unionchatkey
|
key = fmt.Sprintf("%s-%s", unionchatkey, union)
|
||||||
find = bson.M{"channel": channel, "unionId": union}
|
find = bson.M{"channel": channel, "unionId": union}
|
||||||
break
|
break
|
||||||
case pb.ChatChannel_CrossServer:
|
case pb.ChatChannel_CrossServer:
|
||||||
key = fmt.Sprintf("%s:%d", crosschatkey, area)
|
key = fmt.Sprintf("%s-%d", crosschatkey, area)
|
||||||
find = bson.M{"channel": channel, "areaId": area}
|
find = bson.M{"channel": channel, "areaId": area}
|
||||||
break
|
break
|
||||||
case pb.ChatChannel_System:
|
case pb.ChatChannel_System:
|
||||||
@ -138,7 +138,7 @@ func (this *modelChatComp) AddCrossChannelMember(session comm.IUserSession) (cha
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, channel)
|
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||||
if count, err = this.Redis.Hlen(key); err != nil {
|
if count, err = this.Redis.Hlen(key); err != nil {
|
||||||
this.module.Errorf("err:%v", err)
|
this.module.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
@ -167,7 +167,7 @@ func (this *modelChatComp) ChanageChannel(session comm.IUserSession, channel int
|
|||||||
var (
|
var (
|
||||||
maxnum int32
|
maxnum int32
|
||||||
)
|
)
|
||||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, channel)
|
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||||
count := 0
|
count := 0
|
||||||
if maxnum, err = this.module.configure.GetChanageChannelMax(); err != nil {
|
if maxnum, err = this.module.configure.GetChanageChannelMax(); err != nil {
|
||||||
return
|
return
|
||||||
@ -188,7 +188,7 @@ func (this *modelChatComp) ChanageChannel(session comm.IUserSession, channel int
|
|||||||
|
|
||||||
//读取跨服聊天频道下成员
|
//读取跨服聊天频道下成员
|
||||||
func (this *modelChatComp) GetCrossChannelMember(channel int32) (result []*pb.CacheUser, err error) {
|
func (this *modelChatComp) GetCrossChannelMember(channel int32) (result []*pb.CacheUser, err error) {
|
||||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, channel)
|
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||||
result = make([]*pb.CacheUser, 0)
|
result = make([]*pb.CacheUser, 0)
|
||||||
if err = this.Redis.HGetAll(key, &result); err != nil {
|
if err = this.Redis.HGetAll(key, &result); err != nil {
|
||||||
this.module.Errorf("err:%v", err)
|
this.module.Errorf("err:%v", err)
|
||||||
@ -207,7 +207,7 @@ func (this *modelChatComp) RemoveCrossChannelMember(session comm.IUserSession) (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, result.Chatchannel)
|
key := fmt.Sprintf("%s-%d-member", crosschatkey, result.Chatchannel)
|
||||||
if err = this.Redis.HDel(key, session.GetUserId()); err != nil {
|
if err = this.Redis.HDel(key, session.GetUserId()); err != nil {
|
||||||
this.module.Errorf("err:%v", err)
|
this.module.Errorf("err:%v", err)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user