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

Function initTopicSlf

server/init_topic.go:709–814  ·  view source on GitHub ↗

Initialize or load a self-topic 'slf'.

(t *Topic, sreg *ClientComMessage)

Source from the content-addressed store, hash-verified

707
708// Initialize or load a self-topic 'slf'.
709func initTopicSlf(t *Topic, sreg *ClientComMessage) error {
710 t.cat = types.TopicCatSlf
711
712 stopic, err := store.Topics.Get(t.name)
713 if err != nil {
714 return err
715 }
716
717 // If topic exists, load subscriptions
718 if stopic != nil {
719 if err = t.loadSubscribers(); err != nil {
720 return err
721 }
722
723 // t.owner is set by loadSubscriptions
724
725 // Topic exists but subscription is missing. Fail.
726 if len(t.perUser) == 0 {
727 logs.Err.Println("hub: missing subscription for '" + t.name + "' (SHOULD NEVER HAPPEN!)")
728 return types.ErrInternal
729 }
730
731 t.created = stopic.CreatedAt
732 t.updated = stopic.UpdatedAt
733 if !stopic.TouchedAt.IsZero() {
734 t.touched = stopic.TouchedAt
735 }
736 t.aux = stopic.Aux
737 t.lastID = stopic.SeqId
738 t.delID = stopic.DelId
739
740 } else {
741 // Get topic owner.
742 userID := types.ParseUserId(sreg.AsUser)
743 user, err := store.Users.Get(userID)
744 if err != nil {
745 return err
746 }
747 if user == nil {
748 // User not found. Really should not happen.
749 return types.ErrUserNotFound
750 }
751
752 t.owner = userID
753
754 t.accessAuth = getDefaultAccess(t.cat, true, false)
755 t.accessAnon = getDefaultAccess(t.cat, false, false)
756
757 // Default access for the self-owner.
758 userData := perUserData{
759 modeGiven: t.accessAuth,
760 modeWant: t.accessAuth,
761 }
762
763 // Mark the topic as new.
764 sreg.Sub.Created = true
765
766 if sreg.Sub.Set != nil {

Callers 1

topicInitFunction · 0.85

Calls 12

ParseUserIdFunction · 0.92
TimeNowFunction · 0.92
getDefaultAccessFunction · 0.85
isNullValueFunction · 0.85
normalizeTagsFunction · 0.85
restrictedTagsEqualFunction · 0.85
loadSubscribersMethod · 0.80
PrintlnMethod · 0.80
GiveAccessMethod · 0.80
GetMethod · 0.65
CreateMethod · 0.65
IsZeroMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…