MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / exportDirectMessageLink

Method exportDirectMessageLink

Telegram/SourceFiles/apiwrap.cpp:778–863  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778QString 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 };

Callers 2

CopyPostLinkFunction · 0.80
FillPollOptionPageFunction · 0.80

Calls 15

peerToChannelFunction · 0.85
MTP_flagsFunction · 0.85
qsFunction · 0.85
FormatVideoTimestampFunction · 0.85
isChannelMethod · 0.80
asChannelMethod · 0.80
replyToTopMethod · 0.80
hasUsernameMethod · 0.80
inputChannelMethod · 0.80
has_valueMethod · 0.80

Tested by

no test coverage detected