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

Method replyGetDesc

server/topic.go:2082–2200  ·  view source on GitHub ↗

replyGetDesc is a response to a get.desc request on a topic, sent to just the session as a {meta} packet

(sess *Session, asUid types.Uid, _ bool, opts *MsgGetOpts, msg *ClientComMessage)

Source from the content-addressed store, hash-verified

2080
2081// replyGetDesc is a response to a get.desc request on a topic, sent to just the session as a {meta} packet
2082func (t *Topic) replyGetDesc(sess *Session, asUid types.Uid, _ bool, opts *MsgGetOpts, msg *ClientComMessage) error {
2083 now := types.TimeNow()
2084 id := msg.Id
2085
2086 if opts != nil && (opts.User != "" || opts.Limit != 0) {
2087 sess.queueOut(ErrMalformedReply(msg, now))
2088 return errors.New("invalid GetDesc query")
2089 }
2090
2091 // Check if user requested modified data
2092 ifUpdated := opts == nil || opts.IfModifiedSince == nil || opts.IfModifiedSince.Before(t.updated)
2093
2094 desc := &MsgTopicDesc{}
2095 if opts == nil || opts.IfModifiedSince == nil {
2096 // Send CreatedAt only when the user requests full information (nothing is cached at the client).
2097 desc.CreatedAt = &t.created
2098 }
2099 if !t.updated.IsZero() {
2100 desc.UpdatedAt = &t.updated
2101 }
2102
2103 pud, full := t.perUser[asUid]
2104
2105 full = full || t.cat == types.TopicCatMe
2106
2107 if t.cat == types.TopicCatGrp {
2108 desc.IsChan = t.isChan
2109 desc.SubCnt = t.subCnt
2110 logs.Info.Println("replyGetDesc: grp topic", t.name, "subs", t.subCnt)
2111 }
2112
2113 if ifUpdated {
2114 if t.public != nil || t.trusted != nil {
2115 // Not a p2p topic.
2116 desc.Public = t.public
2117 desc.Trusted = t.trusted
2118 } else if full && t.cat == types.TopicCatP2P {
2119 // FIXME: when a P2P participant updates desc at 'me', these cached values are not updated.
2120 desc.Public = pud.public
2121 desc.Trusted = pud.trusted
2122 }
2123 }
2124
2125 // Request may come from a subscriber (full == true) or a stranger.
2126 // Give subscriber a fuller description than to a stranger/channel reader.
2127 if full {
2128 if t.cat == types.TopicCatP2P {
2129 // For p2p topics default access mode makes no sense: only participants have access to topic.
2130 // Don't report it.
2131 } else if t.cat == types.TopicCatMe || (pud.modeGiven & pud.modeWant).IsSharer() {
2132 desc.DefaultAcs = &MsgDefaultAcsMode{
2133 Auth: t.accessAuth.String(),
2134 Anon: t.accessAnon.String(),
2135 }
2136 }
2137
2138 desc.Acs = &MsgAccessMode{
2139 Want: pud.modeWant.String(),

Callers 3

handleMetaGetMethod · 0.95
handleSubscriptionMethod · 0.95

Calls 11

isOnlineMethod · 0.95
TimeNowFunction · 0.92
ErrMalformedReplyFunction · 0.85
maxFunction · 0.85
queueOutMethod · 0.80
PrintlnMethod · 0.80
IsSharerMethod · 0.80
IsPresencerMethod · 0.80
IsReaderMethod · 0.80
IsZeroMethod · 0.45
StringMethod · 0.45

Tested by 1