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

Method prepareBroadcastableMessage

server/topic.go:253–282  ·  view source on GitHub ↗

prepareBroadcastableMessage sets the topic field in `msg` depending on the uid and subscription type.

(msg *ServerComMessage, uid types.Uid, isChanSub bool)

Source from the content-addressed store, hash-verified

251
252// prepareBroadcastableMessage sets the topic field in `msg` depending on the uid and subscription type.
253func (t *Topic) prepareBroadcastableMessage(msg *ServerComMessage, uid types.Uid, isChanSub bool) {
254 // We are only interested in broadcastable messages.
255 if msg.Data == nil && msg.Pres == nil && msg.Info == nil {
256 return
257 }
258
259 if (t.cat == types.TopicCatP2P && !uid.IsZero()) || (t.cat == types.TopicCatGrp && t.isChan) {
260 // For p2p topics topic name is dependent on receiver.
261 // Channel topics may be presented as grpXXX or chnXXX.
262 var topicName string
263 if isChanSub {
264 topicName = types.GrpToChn(t.xoriginal)
265 } else {
266 topicName = t.original(uid)
267 }
268 switch {
269 case msg.Data != nil:
270 msg.Data.Topic = topicName
271 case msg.Pres != nil:
272 msg.Pres.Topic = topicName
273 case msg.Info != nil:
274 msg.Info.Topic = topicName
275 }
276 }
277
278 // Send channel messages anonymously.
279 if isChanSub && msg.Data != nil {
280 msg.Data.From = ""
281 }
282}
283
284// computePerUserAcsUnion computes want and given permissions unions over all topic's subscribers.
285func (t *Topic) computePerUserAcsUnion() {

Callers 2

broadcastToSessionsMethod · 0.95
presSubsOnlineDirectMethod · 0.95

Calls 3

originalMethod · 0.95
GrpToChnFunction · 0.92
IsZeroMethod · 0.45

Tested by

no test coverage detected