handleNoteBroadcast fans out {note} -> {info} messages to recipients in a master topic. This is a NON-proxy broadcast (at master topic).
(msg *ClientComMessage)
| 1137 | // handleNoteBroadcast fans out {note} -> {info} messages to recipients in a master topic. |
| 1138 | // This is a NON-proxy broadcast (at master topic). |
| 1139 | func (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 |
no test coverage detected