fix: fan out unread presence to online sessions
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user