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, id string)
| 809 | // replyGetSub is a response to a get.sub request on a topic - load a list of subscriptions/subscribers, |
| 810 | // send it just to the session as a {meta} packet |
| 811 | func (t *Topic) replyGetSub(sess *Session, id string) error { |
| 812 | now := time.Now().UTC().Round(time.Millisecond) |
| 813 | |
| 814 | var subs []types.Subscription |
| 815 | var err error |
| 816 | |
| 817 | if t.cat == TopicCat_Me { |
| 818 | // Fetch user's subscriptions, with Topic.Public denormalized into subscription |
| 819 | //log.Println("replyGetSub: loading me list of subscriptions") |
| 820 | subs, err = store.Users.GetTopics(sess.appid, sess.uid, nil) |
| 821 | } else if t.cat == TopicCat_P2P { |
| 822 | // Fetch subscriptions for two users, User.Public denormalized into other user's subscription |
| 823 | subs, err = store.Topics.GetUsers(sess.appid, t.name, nil) |
| 824 | } else { |
| 825 | // Fetch subscriptions for a topic, with User.Public denormalized into subscription |
| 826 | subs, err = store.Topics.GetUsers(sess.appid, t.name, nil) |
| 827 | } |
| 828 | |
| 829 | if err != nil { |
| 830 | log.Printf("topic(%s): error loading subscriptions %s\n", t.original, err.Error()) |
| 831 | reply := ErrUnknown(id, t.original, now) |
| 832 | simpleByteSender(sess.send, reply) |
| 833 | return err |
| 834 | } |
| 835 | |
| 836 | meta := &MsgServerMeta{Id: id, Topic: t.original, Timestamp: &now} |
| 837 | if len(subs) > 0 { |
| 838 | meta.Sub = make([]MsgTopicSub, 0, len(subs)) |
| 839 | for _, sub := range subs { |
| 840 | var mts MsgTopicSub |
| 841 | uid := types.ParseUid(sub.User) |
| 842 | if t.cat == TopicCat_Me { |
| 843 | mts.Topic = sub.Topic |
| 844 | mts.With = sub.GetWith() |
| 845 | mts.LastMsg = sub.LastMessageAt |
| 846 | if when, ok := sub.LastSeen[sess.tag]; ok && !when.IsZero() { |
| 847 | mts.LastSeenTag = &when |
| 848 | } |
| 849 | if len(sub.LastSeen) > 0 { |
| 850 | tag, when := mostRecent(sub.LastSeen) |
| 851 | if !when.IsZero() { |
| 852 | mts.LastSeen = &MsgLastSeenInfo{When: when, Tag: tag} |
| 853 | } |
| 854 | } |
| 855 | } else { |
| 856 | mts.User = uid.UserId() |
| 857 | } |
| 858 | mts.UpdatedAt = sub.UpdatedAt |
| 859 | mts.AcsMode = (sub.ModeGiven & sub.ModeWant).String() |
| 860 | mts.Public = sub.GetPublic() |
| 861 | if uid == sess.uid { |
| 862 | mts.Private = sub.Private |
| 863 | } |
| 864 | |
| 865 | meta.Sub = append(meta.Sub, mts) |
| 866 | } |
| 867 | } |
| 868 |
no test coverage detected