replyOfflineTopicGetSub reads user's subscription from the database. Only own subscription is available. The requester must be subscribed but need not be attached.
(sess *Session, msg *ClientComMessage)
| 718 | // Only own subscription is available. |
| 719 | // The requester must be subscribed but need not be attached. |
| 720 | func replyOfflineTopicGetSub(sess *Session, msg *ClientComMessage) { |
| 721 | now := types.TimeNow() |
| 722 | |
| 723 | if msg.Get.Sub != nil && msg.Get.Sub.User != "" && msg.Get.Sub.User != msg.AsUser { |
| 724 | sess.queueOut(ErrPermissionDeniedReply(msg, now)) |
| 725 | return |
| 726 | } |
| 727 | |
| 728 | topicName := msg.RcptTo |
| 729 | if types.IsChannel(msg.Original) { |
| 730 | topicName = msg.Original |
| 731 | } |
| 732 | |
| 733 | ssub, err := store.Subs.Get(topicName, types.ParseUserId(msg.AsUser), true) |
| 734 | if err != nil { |
| 735 | logs.Warn.Println("replyOfflineTopicGetSub:", err) |
| 736 | sess.queueOut(decodeStoreErrorExplicitTs(err, msg.Id, msg.Original, now, msg.Timestamp, nil)) |
| 737 | return |
| 738 | } |
| 739 | |
| 740 | if ssub == nil { |
| 741 | sess.queueOut(ErrNotFoundExplicitTs(msg.Id, msg.Original, now, msg.Timestamp)) |
| 742 | return |
| 743 | } |
| 744 | |
| 745 | sub := MsgTopicSub{} |
| 746 | if ssub.DeletedAt == nil { |
| 747 | sub.UpdatedAt = &ssub.UpdatedAt |
| 748 | sub.Acs = MsgAccessMode{ |
| 749 | Want: ssub.ModeWant.String(), |
| 750 | Given: ssub.ModeGiven.String(), |
| 751 | Mode: (ssub.ModeGiven & ssub.ModeWant).String(), |
| 752 | } |
| 753 | // Fnd is asymmetric: desc.private is a string, but sub.private is a []string. |
| 754 | if types.GetTopicCat(msg.RcptTo) != types.TopicCatFnd { |
| 755 | sub.Private = ssub.Private |
| 756 | } |
| 757 | sub.User = types.ParseUid(ssub.User).UserId() |
| 758 | |
| 759 | if (ssub.ModeGiven & ssub.ModeWant).IsReader() && (ssub.ModeWant & ssub.ModeGiven).IsJoiner() { |
| 760 | sub.DelId = ssub.DelId |
| 761 | sub.ReadSeqId = ssub.ReadSeqId |
| 762 | sub.RecvSeqId = ssub.RecvSeqId |
| 763 | } |
| 764 | } else { |
| 765 | sub.DeletedAt = ssub.DeletedAt |
| 766 | } |
| 767 | |
| 768 | sess.queueOut(&ServerComMessage{ |
| 769 | Meta: &MsgServerMeta{ |
| 770 | Id: msg.Id, Topic: msg.Original, Timestamp: &now, Sub: []MsgTopicSub{sub}, |
| 771 | }, |
| 772 | }) |
| 773 | } |
| 774 | |
| 775 | // replyOfflineTopicSetSub updates Desc.Private and Sub.Mode when the topic is not loaded in memory. |
| 776 | // Only Private and Mode are updated and only for the requester. The requester must be subscribed to the |
no test coverage detected
searching dependent graphs…