go_dreamfactory/modules/reddot/api_get.go
2024-03-07 14:37:44 +08:00

49 lines
1.2 KiB
Go

package reddot
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/pb"
)
// 参数校验
func (this *apiComp) GetCheck(session comm.IUserSession, req *pb.ReddotGetReq) (errdata *pb.ErrorData) {
return
}
// 红点数据
func (this *apiComp) Get(session comm.IUserSession, req *pb.ReddotGetReq) (errdata *pb.ErrorData) {
var (
reds map[comm.ReddotType]struct{} = make(map[comm.ReddotType]struct{})
)
if errdata = this.GetCheck(session, req); errdata != nil {
return
}
for _, v := range req.Rids {
reds[comm.ReddotType(v)] = struct{}{}
}
session.SendMsg(string(this.module.GetType()), "get", &pb.ReddotGetResp{})
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
var (
modules []core.IModule
reddotItem []*pb.ReddotItem = make([]*pb.ReddotItem, 0)
)
modules, _ = this.module.service.GetAllModules()
for _, module := range modules {
if redot, ok := module.(comm.IGetReddot); ok {
for _, v := range redot.Reddot(session, reds) {
reddotItem = append(reddotItem, v)
}
}
}
if len(reddotItem) > 0 {
session.SendMsg(string(this.module.GetType()), "change", &pb.ReddotChangePush{Rids: reddotItem})
}
})
return
}