diff --git a/Telegram/SourceFiles/api/api_sending.cpp b/Telegram/SourceFiles/api/api_sending.cpp index dacd96d0d..1e8627445 100644 --- a/Telegram/SourceFiles/api/api_sending.cpp +++ b/Telegram/SourceFiles/api/api_sending.cpp @@ -30,6 +30,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Api { namespace { +void InnerFillMessagePostFlags( + const Api::SendOptions &options, + not_null peer, + MTPDmessage::Flags &flags) { + const auto channelPost = peer->isChannel() && !peer->isMegagroup(); + if (!channelPost) { + flags |= MTPDmessage::Flag::f_from_id; + return; + } + flags |= MTPDmessage::Flag::f_post; + // Don't display views and author of a new post when it's scheduled. + if (options.scheduled) { + return; + } + flags |= MTPDmessage::Flag::f_views; + if (peer->asChannel()->addsSignature()) { + flags |= MTPDmessage::Flag::f_post_author; + } +} + template void SendExistingMedia( Api::MessageToSend &&message, @@ -60,15 +80,7 @@ void SendExistingMedia( const auto channelPost = peer->isChannel() && !peer->isMegagroup(); const auto silentPost = message.action.options.silent || (channelPost && session->data().notifySilentPosts(peer)); - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + InnerFillMessagePostFlags(message.action.options, peer, flags); if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } @@ -246,15 +258,7 @@ bool SendDice(Api::MessageToSend &message) { const auto channelPost = peer->isChannel() && !peer->isMegagroup(); const auto silentPost = message.action.options.silent || (channelPost && session->data().notifySilentPosts(peer)); - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + InnerFillMessagePostFlags(message.action.options, peer, flags); if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } @@ -320,4 +324,11 @@ bool SendDice(Api::MessageToSend &message) { return true; } +void FillMessagePostFlags( + const Api::SendAction &action, + not_null peer, + MTPDmessage::Flags &flags) { + InnerFillMessagePostFlags(action.options, peer, flags); +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_sending.h b/Telegram/SourceFiles/api/api_sending.h index 86bde8c93..0a8d9f08e 100644 --- a/Telegram/SourceFiles/api/api_sending.h +++ b/Telegram/SourceFiles/api/api_sending.h @@ -25,4 +25,9 @@ void SendExistingPhoto( bool SendDice(Api::MessageToSend &message); +void FillMessagePostFlags( + const SendAction &action, + not_null peer, + MTPDmessage::Flags &flags); + } // namespace Api diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 9786062ce..3426a1551 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -4328,15 +4328,7 @@ void ApiWrap::forwardMessages( auto flags = MTPDmessage::Flags(0); auto clientFlags = MTPDmessage_ClientFlags(); auto sendFlags = MTPmessages_ForwardMessages::Flags(0); - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + FillMessagePostFlags(action, peer, flags); if (silentPost) { sendFlags |= MTPmessages_ForwardMessages::Flag::f_silent; } @@ -4489,15 +4481,7 @@ void ApiWrap::sendSharedContact( if (action.replyTo) { flags |= MTPDmessage::Flag::f_reply_to_msg_id; } - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } - } else { - flags |= MTPDmessage::Flag::f_from_id; - } + FillMessagePostFlags(action, peer, flags); if (action.options.scheduled) { flags |= MTPDmessage::Flag::f_from_scheduled; } else { @@ -4874,15 +4858,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) { const auto channelPost = peer->isChannel() && !peer->isMegagroup(); const auto silentPost = action.options.silent || (channelPost && _session->data().notifySilentPosts(peer)); - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + FillMessagePostFlags(action, peer, flags); if (silentPost) { sendFlags |= MTPmessages_SendMessage::Flag::f_silent; } @@ -5019,15 +4995,7 @@ void ApiWrap::sendInlineResult( bool channelPost = peer->isChannel() && !peer->isMegagroup(); bool silentPost = action.options.silent || (channelPost && _session->data().notifySilentPosts(peer)); - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + FillMessagePostFlags(action, peer, flags); if (silentPost) { sendFlags |= MTPmessages_SendInlineBotResult::Flag::f_silent; } diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 524e4c5ea..6a2232b7c 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -695,7 +695,7 @@ void HistoryMessage::createComponentsHelper( if (flags & MTPDmessage::Flag::f_reply_to_msg_id) config.replyTo = replyTo; if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup; if (flags & MTPDmessage::Flag::f_post_author) config.author = postAuthor; - if (isPost()) config.viewsCount = 1; + if (flags & MTPDmessage::Flag::f_views) config.viewsCount = 1; createComponents(config); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 56f369d1a..74be742ed 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4677,15 +4677,7 @@ void HistoryWidget::sendFileConfirmed( } const auto channelPost = peer->isChannel() && !peer->isMegagroup(); const auto silentPost = file->to.options.silent; - if (channelPost) { - flags |= MTPDmessage::Flag::f_views; - flags |= MTPDmessage::Flag::f_post; - } - if (!channelPost) { - flags |= MTPDmessage::Flag::f_from_id; - } else if (peer->asChannel()->addsSignature()) { - flags |= MTPDmessage::Flag::f_post_author; - } + Api::FillMessagePostFlags(action, peer, flags); if (silentPost) { flags |= MTPDmessage::Flag::f_silent; }