Initialize or load a self-topic 'slf'.
(t *Topic, sreg *ClientComMessage)
| 707 | |
| 708 | // Initialize or load a self-topic 'slf'. |
| 709 | func 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 { |
no test coverage detected
searching dependent graphs…