fix: fan out unread presence to online sessions

This commit is contained in:
richjohnrambo
2026-09-17 10:24:39 +08:00
parent 7df3313c78
commit 816be46e03
6 changed files with 161 additions and 5 deletions
+36
View File
@@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"reflect"
"sort"
"strconv"
"strings"
@@ -74,6 +75,7 @@ type RealtimeFanoutEnvelope struct {
TargetType string `json:"target_type"`
Target string `json:"target"`
SkipSid string `json:"skip_sid,omitempty"`
SkipTopic string `json:"skip_topic,omitempty"`
DedupKey string `json:"dedup_key,omitempty"`
Message json.RawMessage `json:"message"`
}
@@ -1060,6 +1062,7 @@ func (r *redisGroupMessageRuntime) PublishRealtimeFanout(originNodeID string, te
TargetType: targetType,
Target: target,
SkipSid: skipSid,
SkipTopic: realtimeFanoutSkipTopic(message),
DedupKey: dedupKey,
Message: payload,
})
@@ -1069,6 +1072,39 @@ func (r *redisGroupMessageRuntime) PublishRealtimeFanout(originNodeID string, te
return r.client.Publish(context.Background(), r.realtimeFanoutChannel(tenantID), envelope).Err()
}
func realtimeFanoutSkipTopic(message any) string {
if message == nil {
return ""
}
v := reflect.ValueOf(message)
if v.Kind() == reflect.Pointer {
if v.IsNil() {
return ""
}
v = v.Elem()
}
if v.Kind() != reflect.Struct {
return ""
}
for _, fieldName := range []string{"Pres", "Info"} {
field := v.FieldByName(fieldName)
if !field.IsValid() || field.IsNil() {
continue
}
if field.Kind() == reflect.Pointer {
field = field.Elem()
}
if field.Kind() != reflect.Struct {
continue
}
skip := field.FieldByName("SkipTopic")
if skip.IsValid() && skip.Kind() == reflect.String {
return strings.TrimSpace(skip.String())
}
}
return ""
}
func (r *redisGroupMessageRuntime) StartGroupFanoutSubscriber(ctx context.Context, nodeID string, handler func([]byte)) error {
return r.StartRealtimeFanoutSubscriber(ctx, nodeID, func(envelope *RealtimeFanoutEnvelope) {
if envelope != nil {