上传聊天业务代码优化
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 {
|
||||
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
|
||||
return
|
||||
}
|
||||
break
|
||||
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
|
||||
return
|
||||
}
|
||||
@ -50,13 +50,13 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.ChatGetListReq)
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
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
|
||||
return
|
||||
}
|
||||
break
|
||||
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
|
||||
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 (
|
||||
key string
|
||||
find bson.M
|
||||
@ -74,15 +74,15 @@ func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, area int3
|
||||
)
|
||||
switch channel {
|
||||
case pb.ChatChannel_World:
|
||||
key = worldchatkey
|
||||
key = fmt.Sprintf("%s-%s", worldchatkey, stag)
|
||||
find = bson.M{"channel": channel}
|
||||
break
|
||||
case pb.ChatChannel_Union:
|
||||
key = unionchatkey
|
||||
key = fmt.Sprintf("%s-%s", unionchatkey, union)
|
||||
find = bson.M{"channel": channel, "unionId": union}
|
||||
break
|
||||
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}
|
||||
break
|
||||
case pb.ChatChannel_System:
|
||||
@ -138,7 +138,7 @@ func (this *modelChatComp) AddCrossChannelMember(session comm.IUserSession) (cha
|
||||
return
|
||||
}
|
||||
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 {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
@ -167,7 +167,7 @@ func (this *modelChatComp) ChanageChannel(session comm.IUserSession, channel int
|
||||
var (
|
||||
maxnum int32
|
||||
)
|
||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, channel)
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||
count := 0
|
||||
if maxnum, err = this.module.configure.GetChanageChannelMax(); err != nil {
|
||||
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) {
|
||||
key := fmt.Sprintf("%s:%d-member", crosschatkey, channel)
|
||||
key := fmt.Sprintf("%s-%d-member", crosschatkey, channel)
|
||||
result = make([]*pb.CacheUser, 0)
|
||||
if err = this.Redis.HGetAll(key, &result); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
@ -207,7 +207,7 @@ func (this *modelChatComp) RemoveCrossChannelMember(session comm.IUserSession) (
|
||||
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 {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user