| 776 | } |
| 777 | |
| 778 | QString ApiWrap::exportDirectMessageLink( |
| 779 | not_null<HistoryItem*> item, |
| 780 | bool inRepliesContext, |
| 781 | bool forceNonPublicLink, |
| 782 | std::optional<TimeId> videoTimestamp) { |
| 783 | Expects(item->history()->peer->isChannel()); |
| 784 | |
| 785 | const auto itemId = item->fullId(); |
| 786 | const auto channel = item->history()->peer->asChannel(); |
| 787 | const auto fallback = [&] { |
| 788 | auto linkChannel = channel; |
| 789 | auto linkItemId = item->id; |
| 790 | auto linkCommentId = MsgId(); |
| 791 | auto linkThreadId = MsgId(); |
| 792 | auto linkThreadIsTopic = false; |
| 793 | if (inRepliesContext) { |
| 794 | linkThreadIsTopic = item->history()->isForum(); |
| 795 | const auto rootId = linkThreadIsTopic |
| 796 | ? item->topicRootId() |
| 797 | : item->replyToTop(); |
| 798 | if (rootId) { |
| 799 | const auto root = item->history()->owner().message( |
| 800 | channel->id, |
| 801 | rootId); |
| 802 | const auto sender = root |
| 803 | ? root->discussionPostOriginalSender() |
| 804 | : nullptr; |
| 805 | if (sender && sender->hasUsername() && !forceNonPublicLink) { |
| 806 | // Comment to a public channel. |
| 807 | const auto forwarded = root->Get<HistoryMessageForwarded>(); |
| 808 | linkItemId = forwarded->savedFromMsgId; |
| 809 | if (linkItemId) { |
| 810 | linkChannel = sender; |
| 811 | linkCommentId = item->id; |
| 812 | } else { |
| 813 | linkItemId = item->id; |
| 814 | } |
| 815 | } else { |
| 816 | // Reply in a thread, maybe comment in a private channel. |
| 817 | linkThreadId = rootId; |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | const auto base = (linkChannel->hasUsername() && !forceNonPublicLink) |
| 822 | ? linkChannel->username() |
| 823 | : "c/" + QString::number(peerToChannel(linkChannel->id).bare); |
| 824 | const auto post = QString::number(linkItemId.bare); |
| 825 | const auto query = base |
| 826 | + '/' |
| 827 | + (linkCommentId |
| 828 | ? (post + "?comment=" + QString::number(linkCommentId.bare)) |
| 829 | : (linkThreadId && !linkThreadIsTopic) |
| 830 | ? (post + "?thread=" + QString::number(linkThreadId.bare)) |
| 831 | : linkThreadId |
| 832 | ? (QString::number(linkThreadId.bare) + '/' + post) |
| 833 | : post); |
| 834 | return session().createInternalLinkFull(query); |
| 835 | }; |
no test coverage detected