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

Method handleNoteBroadcast

server/topic.go:1139–1270  ·  view source on GitHub ↗

handleNoteBroadcast fans out {note} -> {info} messages to recipients in a master topic. This is a NON-proxy broadcast (at master topic).

(msg *ClientComMessage)

Source from the content-addressed store, hash-verified

1137// handleNoteBroadcast fans out {note} -> {info} messages to recipients in a master topic.
1138// This is a NON-proxy broadcast (at master topic).
1139func (t *Topic) handleNoteBroadcast(msg *ClientComMessage) {
1140 if t.isInactive() {
1141 // Ignore broadcast - topic is paused or being deleted.
1142 return
1143 }
1144
1145 if msg.Note.SeqId > t.lastID {
1146 // Drop bogus read notification
1147 return
1148 }
1149
1150 asChan, err := t.verifyChannelAccess(msg.Original)
1151 if err != nil {
1152 // Silently drop invalid notification.
1153 return
1154 }
1155
1156 asUid := types.ParseUserId(msg.AsUser)
1157 pud := t.perUser[asUid]
1158 mode := pud.modeGiven & pud.modeWant
1159 if pud.deleted {
1160 mode = types.ModeInvalid
1161 }
1162
1163 switch msg.Note.What {
1164 case "kp", "kpa", "kpv":
1165 // Filter out "kp*" from users with no 'W' permission (or people without a subscription).
1166 if !mode.IsWriter() || t.isReadOnly() {
1167 return
1168 }
1169 case "read", "recv":
1170 // Filter out "read/recv" from users with no 'R' permission (or people without a subscription).
1171 if !mode.IsReader() {
1172 return
1173 }
1174 case "call":
1175 // Handle calls separately.
1176 t.handleCallEvent(msg)
1177 return
1178 }
1179
1180 var read, recv, unread, seq int
1181
1182 switch msg.Note.What {
1183 case "read":
1184 if msg.Note.SeqId <= pud.readID {
1185 // No need to report stale or bogus read status.
1186 return
1187 }
1188
1189 // The number of unread messages has decreased, negative value.
1190 unread = pud.readID - msg.Note.SeqId
1191 pud.readID = msg.Note.SeqId
1192 if pud.readID > pud.recvID {
1193 pud.recvID = pud.readID
1194 }
1195 read = pud.readID
1196 seq = read

Callers 1

handleClientMsgMethod · 0.95

Calls 14

isInactiveMethod · 0.95
verifyChannelAccessMethod · 0.95
isReadOnlyMethod · 0.95
handleCallEventMethod · 0.95
presPubMessageCountMethod · 0.95
pushForReadRcptMethod · 0.95
infoSubsOfflineMethod · 0.95
broadcastToSessionsMethod · 0.95
ParseUserIdFunction · 0.92
sendPushFunction · 0.85
usersUpdateUnreadFunction · 0.85
IsWriterMethod · 0.80

Tested by

no test coverage detected