fix: fan out unread presence to online sessions
This commit is contained in:
@@ -209,6 +209,9 @@ func (ss *SessionStore) DeliverToUser(tenantID types.TenantID, uid types.Uid, sk
|
||||
if sess == nil || sess.isCluster() || sess.isProxy() || sess.tenantID != tenantID || sess.uid != uid || sess.sid == skipSid {
|
||||
return true
|
||||
}
|
||||
if userMessageSkipTopic(msg, sess) {
|
||||
return true
|
||||
}
|
||||
if sess.queueOut(msg.copy()) {
|
||||
delivered++
|
||||
}
|
||||
@@ -217,6 +220,37 @@ func (ss *SessionStore) DeliverToUser(tenantID types.TenantID, uid types.Uid, sk
|
||||
return delivered
|
||||
}
|
||||
|
||||
func userMessageSkipTopic(msg *ServerComMessage, sess *Session) bool {
|
||||
if msg == nil || sess == nil {
|
||||
return false
|
||||
}
|
||||
skipTopic := ""
|
||||
switch {
|
||||
case msg.Pres != nil:
|
||||
skipTopic = msg.Pres.SkipTopic
|
||||
case msg.Info != nil:
|
||||
skipTopic = msg.Info.SkipTopic
|
||||
}
|
||||
return sessionHasTopicOrP2PAlias(sess, skipTopic)
|
||||
}
|
||||
|
||||
func sessionHasTopicOrP2PAlias(sess *Session, topic string) bool {
|
||||
if sess == nil || topic == "" {
|
||||
return false
|
||||
}
|
||||
if sess.hasSub(topic) {
|
||||
return true
|
||||
}
|
||||
if types.GetTopicCat(topic) != types.TopicCatP2P || sess.uid.IsZero() {
|
||||
return false
|
||||
}
|
||||
viewTopic, err := types.P2PNameForUser(sess.uid, topic)
|
||||
if err != nil || viewTopic == "" {
|
||||
return false
|
||||
}
|
||||
return sess.hasSub(viewTopic)
|
||||
}
|
||||
|
||||
func (ss *SessionStore) DeliverToTopicSubscribers(tenantID types.TenantID, topic, skipSid string, msg *ServerComMessage) int {
|
||||
if ss == nil || !tenantID.IsValid() || topic == "" || msg == nil {
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user