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

Method subCommonReply

server/topic.go:336–371  ·  view source on GitHub ↗

subCommonReply generates a response to a subscription request

(h *Hub, sess *Session, pkt *MsgClientSub, sendInfo bool, created bool)

Source from the content-addressed store, hash-verified

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 {
337 log.Println("subCommonReply ", t.name)
338 now := time.Now().UTC().Round(time.Millisecond)
339
340 // The topic t is already initialized by the Hub
341
342 var info, private interface{}
343 var mode string
344
345 if pkt.Sub != nil {
346 if pkt.Sub.User != "" {
347 log.Println("subCommonReply: msg.Sub.Sub.User is ", pkt.Sub.User)
348 simpleByteSender(sess.send, ErrMalformed(pkt.Id, t.original, now))
349 return errors.New("user id must not be specified")
350 }
351
352 info = pkt.Sub.Info
353 mode = pkt.Sub.Mode
354 }
355
356 if pkt.Init != nil {
357 private = pkt.Init.Private
358 }
359
360 if err := t.requestSub(h, sess, pkt.Id, mode, info, private); err != nil {
361 return err
362 }
363
364 simpleByteSender(sess.send, NoErr(pkt.Id, t.original, now))
365
366 if sendInfo {
367 t.replyGetInfo(sess, pkt.Id, created)
368 }
369
370 return nil
371}
372
373// User requests or updates a self-subscription to a topic
374// h - hub

Callers 1

handleSubscriptionMethod · 0.95

Calls 5

requestSubMethod · 0.95
replyGetInfoMethod · 0.95
simpleByteSenderFunction · 0.85
ErrMalformedFunction · 0.85
NoErrFunction · 0.85

Tested by

no test coverage detected