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

Method replySetSub

server/topic.go:876–896  ·  view source on GitHub ↗

replySetSub is a response to new subscription request or an update to a subscription {set.sub}: update topic metadata cache, save/update subs, reply to the caller as {ctrl} message, generate an invite

(h *Hub, sess *Session, set *MsgClientSet)

Source from the content-addressed store, hash-verified

874// replySetSub is a response to new subscription request or an update to a subscription {set.sub}:
875// update topic metadata cache, save/update subs, reply to the caller as {ctrl} message, generate an invite
876func (t *Topic) replySetSub(h *Hub, sess *Session, set *MsgClientSet) error {
877 now := time.Now().UTC().Round(time.Millisecond)
878
879 var uid types.Uid
880 if uid = types.ParseUserId(set.Sub.User); uid.IsZero() && set.Sub.User != "" {
881 // Invalid user ID
882 simpleByteSender(sess.send, ErrMalformed(set.Id, set.Topic, now))
883 return errors.New("invalid user id")
884 }
885
886 // if set.User is not set, request is for the current user
887 if !uid.IsZero() {
888 uid = sess.uid
889 }
890
891 if uid == sess.uid {
892 return t.requestSub(h, sess, set.Id, set.Sub.Mode, set.Sub.Info, nil)
893 } else {
894 return t.approveSub(h, sess, uid, set)
895 }
896}
897
898// replyGetData is a response to a get.data request - load a list of stored messages, send them to session as {data}
899// response goes to a single session rather than all sessions in a topic

Callers

nothing calls this directly

Calls 4

requestSubMethod · 0.95
approveSubMethod · 0.95
simpleByteSenderFunction · 0.85
ErrMalformedFunction · 0.85

Tested by

no test coverage detected