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

Method replyGetInfo

server/topic.go:631–686  ·  view source on GitHub ↗

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

(sess *Session, id string, created bool)

Source from the content-addressed store, hash-verified

629
630// replyGetInfo is a response to a get.info request on a topic, sent to just the session as a {meta} packet
631func (t *Topic) replyGetInfo(sess *Session, id string, created bool) error {
632 now := time.Now().UTC().Round(time.Millisecond)
633
634 pud, full := t.perUser[sess.uid]
635
636 info := &MsgTopicInfo{
637 CreatedAt: &t.created,
638 UpdatedAt: &t.updated}
639
640 if t.public != nil {
641 info.Public = t.public
642 } else if full {
643 // p2p topic
644 info.Public = pud.public
645 }
646
647 // Request may come from a subscriber or a stranger. Give a stranger a lot less info than a subscriber
648 if full {
649 if pud.modeGiven&pud.modeWant&types.ModeShare != 0 {
650 info.DefaultAcs = &MsgDefaultAcsMode{
651 Auth: t.accessAuth.String(),
652 Anon: t.accessAnon.String()}
653 }
654
655 info.Acs = &MsgAccessMode{
656 Want: pud.modeWant.String(),
657 Given: pud.modeGiven.String()}
658
659 info.Private = pud.private
660
661 if !t.lastMessage.IsZero() {
662 info.LastMessage = &t.lastMessage
663 }
664
665 if when, ok := pud.lastSeenTag[sess.tag]; ok {
666 info.LastSeenTag = &when
667 }
668
669 if len(pud.lastSeenTag) > 0 {
670 tag, when := mostRecent(pud.lastSeenTag)
671 if !when.IsZero() {
672 info.LastSeen = &MsgLastSeenInfo{When: when, Tag: tag}
673 }
674 }
675
676 // When a topic is first created, its name may change. Report the new name
677 if created {
678 info.Name = t.name
679 }
680 }
681
682 simpleByteSender(sess.send, &ServerComMessage{
683 Meta: &MsgServerMeta{Id: id, Topic: t.original, Info: info, Timestamp: &now}})
684
685 return nil
686}
687
688// replySetInfo updates topic metadata, saves it to DB,

Callers 2

runMethod · 0.95
subCommonReplyMethod · 0.95

Calls 3

mostRecentFunction · 0.85
simpleByteSenderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected