MCPcopy Create free account
hub / github.com/daodst/chat / handleSubscription

Method handleSubscription

server/topic.go:284–333  ·  view source on GitHub ↗

Session subscribed to a topic, created == true if topic was just created and {pres} needs to be announced

(h *Hub, sreg *sessionJoin)

Source from the content-addressed store, hash-verified

282
283// Session subscribed to a topic, created == true if topic was just created and {pres} needs to be announced
284func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {
285
286 getWhat := parseMsgClientMeta(sreg.pkt.Get)
287
288 if err := t.subCommonReply(h, sreg.sess, sreg.pkt, (getWhat&constMsgMetaInfo != 0), sreg.created); err != nil {
289 return err
290 }
291
292 // New P2P topic is a special case. It requires an invite/notification for the second person
293 if sreg.created && t.cat == TopicCat_P2P {
294 log.Println("about to generate invite for ", t.name)
295 for uid, pud := range t.perUser {
296 if uid != sreg.sess.uid {
297 if pud.modeWant&types.ModeBanned != 0 {
298 break
299 }
300
301 var action types.InviteAction
302 if pud.modeWant == types.ModeNone {
303 action = types.InvJoin
304 } else {
305 action = types.InvInfo
306 }
307 log.Println("sending invite to ", uid.UserId())
308 h.route <- t.makeInvite(uid, uid, sreg.sess.uid, action, pud.modeWant, pud.modeGiven, nil /* Public */)
309 break
310 }
311 }
312 }
313
314 if sreg.loaded {
315 t.presPubTopicOnline()
316 }
317
318 if t.cat == TopicCat_Me {
319 // User attached to !me topic, get the currect state of topics he is interested in
320 t.presSnapshot()
321 }
322
323 if getWhat&constMsgMetaSub != 0 {
324 // Send get.sub response as a separate {meta} packet
325 t.replyGetSub(sreg.sess, sreg.pkt.Id)
326 }
327
328 if getWhat&constMsgMetaData != 0 {
329 // Send get.data response as {data} packets
330 t.replyGetData(sreg.sess, sreg.pkt.Id, sreg.pkt.Browse)
331 }
332 return nil
333}
334
335// subCommonReply generates a response to a subscription request
336func (t *Topic) subCommonReply(h *Hub, sess *Session, pkt *MsgClientSub, sendInfo bool, created bool) error {

Callers 1

runMethod · 0.95

Calls 7

subCommonReplyMethod · 0.95
makeInviteMethod · 0.95
presPubTopicOnlineMethod · 0.95
presSnapshotMethod · 0.95
replyGetSubMethod · 0.95
replyGetDataMethod · 0.95
parseMsgClientMetaFunction · 0.85

Tested by

no test coverage detected