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

Method replyGetSub

server/topic.go:2398–2713  ·  view source on GitHub ↗

replyGetSub is a response to a get.sub request on a topic - load a list of subscriptions/subscribers, send it just to the session as a {meta} packet

(sess *Session, asUid types.Uid, authLevel auth.Level, asChan bool, msg *ClientComMessage)

Source from the content-addressed store, hash-verified

2396// replyGetSub is a response to a get.sub request on a topic - load a list of subscriptions/subscribers,
2397// send it just to the session as a {meta} packet
2398func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level, asChan bool, msg *ClientComMessage) error {
2399 now := types.TimeNow()
2400 id := msg.Id
2401 incomingReqTs := msg.Timestamp
2402 var req *MsgGetOpts
2403 if msg.Sub != nil {
2404 req = msg.Sub.Get.Sub
2405 } else {
2406 req = msg.Get.Sub
2407 }
2408
2409 if req != nil && (req.SinceId != 0 || req.BeforeId != 0) {
2410 sess.queueOut(ErrMalformedReply(msg, now))
2411 return errors.New("invalid MsgGetOpts query")
2412 }
2413
2414 var err error
2415
2416 var ifModified time.Time
2417 if req != nil && req.IfModifiedSince != nil {
2418 ifModified = *req.IfModifiedSince
2419 }
2420
2421 userData := t.perUser[asUid]
2422 var subs []types.Subscription
2423
2424 switch t.cat {
2425 case types.TopicCatMe:
2426 if req != nil {
2427 // If topic is provided, it could be in the form of user ID 'usrAbCd'.
2428 // Convert it to P2P topic name. Likewise for Self topic 'slf' -> 'slfAbcD'.
2429 if uid2 := types.ParseUserId(req.Topic); !uid2.IsZero() {
2430 req.Topic = uid2.P2PName(asUid)
2431 }
2432 if req.Topic == "slf" {
2433 req.Topic = asUid.SlfName()
2434 }
2435 }
2436 // Fetch user's subscriptions, with Topic.Public+Topic.Trusted denormalized into subscription.
2437 if ifModified.IsZero() {
2438 // No cache management. Skip deleted subscriptions.
2439 subs, err = store.Users.GetTopics(asUid, msgOpts2storeOpts(req))
2440 } else {
2441 // User manages cache. Include deleted subscriptions too.
2442 subs, err = store.Users.GetTopicsAny(asUid, msgOpts2storeOpts(req))
2443
2444 // Returned subscriptions do not contain topics which are online now but otherwise unchanged.
2445 // We need to add these topic to the list otherwise the user would see them as offline.
2446 selected := map[string]struct{}{}
2447 for i := range subs {
2448 sub := &subs[i]
2449 with := sub.GetWith()
2450 if with != "" {
2451 selected[with] = struct{}{}
2452 } else {
2453 selected[sub.Topic] = struct{}{}
2454 }
2455 }

Callers 2

handleMetaGetMethod · 0.95
handleSubscriptionMethod · 0.95

Calls 15

GetWithMethod · 0.95
SetWithMethod · 0.95
SetDummyMethod · 0.95
fndGetPublicMethod · 0.95
GetTouchedAtMethod · 0.95
GetSeqIdMethod · 0.95
GetLastSeenMethod · 0.95
GetUserAgentMethod · 0.95
GetSubCntMethod · 0.95
IsDummyMethod · 0.95
GetDefaultAccessMethod · 0.95
GetPublicMethod · 0.95

Tested by

no test coverage detected