fix: align group management APIs

This commit is contained in:
richjohnrambo
2026-09-13 16:03:55 +08:00
parent f1279ac607
commit a9afc6ff6a
34 changed files with 1381 additions and 639 deletions
+84
View File
@@ -200,6 +200,90 @@ func (ss *SessionStore) Range(f func(sid string, s *Session) bool) {
ss.lock.Unlock()
}
func (ss *SessionStore) DeliverToUser(tenantID types.TenantID, uid types.Uid, skipSid string, msg *ServerComMessage) int {
if ss == nil || !tenantID.IsValid() || uid.IsZero() || msg == nil {
return 0
}
delivered := 0
ss.Range(func(_ string, sess *Session) bool {
if sess == nil || sess.isCluster() || sess.isProxy() || sess.tenantID != tenantID || sess.uid != uid || sess.sid == skipSid {
return true
}
if sess.queueOut(msg.copy()) {
delivered++
}
return true
})
return delivered
}
func (ss *SessionStore) DeliverToTopicSubscribers(tenantID types.TenantID, topic, skipSid string, msg *ServerComMessage) int {
if ss == nil || !tenantID.IsValid() || topic == "" || msg == nil {
return 0
}
delivered := 0
ss.Range(func(_ string, sess *Session) bool {
if sess == nil || sess.isCluster() || sess.isProxy() || sess.tenantID != tenantID || sess.sid == skipSid || !sess.hasSub(topic) {
return true
}
msgCopy := msg.copy()
if msgCopy.RcptTo == "" {
msgCopy.RcptTo = topic
}
if msgCopy.Data != nil && msgCopy.Data.Topic == "" {
msgCopy.Data.Topic = topic
}
if sess.queueOut(msgCopy) {
delivered++
}
return true
})
return delivered
}
func (ss *SessionStore) DeliverToP2PTopic(tenantID types.TenantID, topic, skipSid string, msg *ServerComMessage) int {
if ss == nil || !tenantID.IsValid() || topic == "" || msg == nil {
return 0
}
uid1, uid2, err := types.ParseP2P(topic)
if err != nil {
return ss.DeliverToTopicSubscribers(tenantID, topic, skipSid, msg)
}
participants := map[types.Uid]struct{}{uid1: {}, uid2: {}}
delivered := 0
ss.Range(func(_ string, sess *Session) bool {
if sess == nil || sess.isCluster() || sess.isProxy() || sess.tenantID != tenantID || sess.sid == skipSid {
return true
}
if _, ok := participants[sess.uid]; !ok {
return true
}
viewTopic, err := types.P2PNameForUser(sess.uid, topic)
if err != nil || viewTopic == "" {
return true
}
if !sess.hasSub(topic) && !sess.hasSub(viewTopic) {
return true
}
msgCopy := msg.copy()
msgCopy.RcptTo = sess.uid.UserId()
if msgCopy.Data != nil {
msgCopy.Data.Topic = viewTopic
}
if msgCopy.Info != nil {
msgCopy.Info.Topic = viewTopic
}
if msgCopy.Pres != nil {
msgCopy.Pres.Topic = viewTopic
}
if sess.queueOut(msgCopy) {
delivered++
}
return true
})
return delivered
}
// Shutdown terminates sessionStore. No need to clean up.
// Don't send to clustered sessions, their servers are not being shut down.
func (ss *SessionStore) Shutdown() {