MCPcopy
hub / github.com/tinode/chat / broadcastToSessions

Method broadcastToSessions

server/topic.go:1287–1373  ·  view source on GitHub ↗

broadcastToSessions writes message to attached sessions.

(msg *ServerComMessage)

Source from the content-addressed store, hash-verified

1285
1286// broadcastToSessions writes message to attached sessions.
1287func (t *Topic) broadcastToSessions(msg *ServerComMessage) {
1288 // List of sessions to be dropped.
1289 var dropSessions []*Session
1290 // Broadcast the message. Only {data}, {pres}, {info} are broadcastable.
1291 // {meta} and {ctrl} are sent to the session only
1292 for sess, pssd := range t.sessions {
1293 // Send all messages to multiplexing session.
1294 if !sess.isMultiplex() {
1295 if sess.sid == msg.SkipSid {
1296 continue
1297 }
1298
1299 if msg.Pres != nil {
1300 // Skip notifying - already notified on topic.
1301 if msg.Pres.SkipTopic != "" && sess.getSub(msg.Pres.SkipTopic) != nil {
1302 continue
1303 }
1304
1305 // Notification addressed to a single user only.
1306 if msg.Pres.SingleUser != "" && pssd.uid.UserId() != msg.Pres.SingleUser {
1307 continue
1308 }
1309 // Notification should skip a single user.
1310 if msg.Pres.ExcludeUser != "" && pssd.uid.UserId() == msg.Pres.ExcludeUser {
1311 continue
1312 }
1313
1314 // Check presence filters
1315 if !t.passesPresenceFilters(msg.Pres, pssd.uid) {
1316 continue
1317 }
1318
1319 } else {
1320 if msg.Info != nil {
1321 // Don't forward read receipts and key presses to channel readers and those without the R permission.
1322 // OK to forward with Src != "" because it's sent from another topic to 'me', permissions already
1323 // checked there.
1324 if msg.Info.Src == "" && (pssd.isChanSub || !t.userIsReader(pssd.uid)) {
1325 continue
1326 }
1327
1328 // Skip notifying - already notified on topic.
1329 if msg.Info.SkipTopic != "" && sess.getSub(msg.Info.SkipTopic) != nil {
1330 continue
1331 }
1332
1333 // Don't send key presses from one user's session to the other sessions of the same user.
1334 if msg.Info.What == "kp" && msg.Info.From == pssd.uid.UserId() {
1335 continue
1336 }
1337
1338 } else if !t.userIsReader(pssd.uid) && !pssd.isChanSub {
1339 // Skip {data} if the user has no Read permission and not a channel reader.
1340 continue
1341 }
1342 }
1343 } else if pssd.isChanSub && types.IsChannel(sess.sid) {
1344 // If it's a chnX multiplexing session, check if there's a corresponding

Callers 6

handleProxyBroadcastMethod · 0.95
handleServerMsgMethod · 0.95
handleNoteBroadcastMethod · 0.95
handlePresenceMethod · 0.95

Calls 12

passesPresenceFiltersMethod · 0.95
userIsReaderMethod · 0.95
unregisterSessionMethod · 0.95
IsChannelFunction · 0.92
ChnToGrpFunction · 0.92
isMultiplexMethod · 0.80
getSubMethod · 0.80
UserIdMethod · 0.80
queueOutMethod · 0.80
GetMethod · 0.65
copyMethod · 0.45

Tested by

no test coverage detected