|
@@ -64,8 +64,8 @@ func (service *MessageService) DeleteMessage(id []string, appId string) (int64,
|
|
|
// 未读消息合计 isRedis 是否需要初始化redis
|
|
|
func (service *MessageService) CountUnread(userId string, isRedis bool) (map[string]int64, int64) {
|
|
|
var (
|
|
|
- count int64
|
|
|
- msgTypes []string
|
|
|
+ count int64
|
|
|
+ msgTypes, groupIds []string
|
|
|
)
|
|
|
data := make(map[string]int64)
|
|
|
for _, v := range entity.MessageColumn {
|
|
@@ -73,6 +73,7 @@ func (service *MessageService) CountUnread(userId string, isRedis bool) (map[str
|
|
|
//去除全部与私信
|
|
|
msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
|
|
|
key := fmt.Sprintf(MsgCountKey, userId, util.IntAll(v["group_id"]))
|
|
|
+ groupIds = append(groupIds, qutil.InterfaceToStr(v["group_id"]))
|
|
|
if exists, _ := redis.Exists(redisModule, key); exists {
|
|
|
ct := util.Int64All(redis.GetInt(redisModule, key))
|
|
|
data[qutil.InterfaceToStr(v["group_id"])] = ct
|
|
@@ -91,7 +92,7 @@ func (service *MessageService) CountUnread(userId string, isRedis bool) (map[str
|
|
|
}
|
|
|
}
|
|
|
if isRedis { //初始化未读数
|
|
|
- for _, v1 := range msgTypes {
|
|
|
+ for _, v1 := range groupIds {
|
|
|
key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v1))
|
|
|
redis.Put(redisModule, key, data[v1], -1)
|
|
|
}
|