2016-09-27 14:20:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-27 14:20:49 +00:00
|
|
|
*/
|
|
|
|
#include "history/history_message.h"
|
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "apiwrap.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "api/api_text_entities.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
#include "history/history_location_manager.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_service.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/view/history_view_service_message.h"
|
2019-12-27 10:41:30 +00:00
|
|
|
#include "history/view/history_view_context_menu.h" // CopyPostLink.
|
|
|
|
#include "history/view/media/history_view_media.h" // AddTimestampLinks.
|
2019-08-01 21:14:19 +00:00
|
|
|
#include "chat_helpers/stickers_emoji_pack.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-11-19 13:23:51 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2020-11-17 15:05:35 +00:00
|
|
|
#include "api/api_updates.h"
|
2017-07-11 17:11:06 +00:00
|
|
|
#include "boxes/share_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "ui/toast/toast.h"
|
2019-07-18 10:03:09 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2019-08-02 18:19:14 +00:00
|
|
|
#include "ui/text/text_isolated_emoji.h"
|
2020-09-30 11:32:02 +00:00
|
|
|
#include "ui/text/format_values.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/item_text_options.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2020-06-09 09:36:40 +00:00
|
|
|
#include "core/ui_integration.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-09-04 11:40:02 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2018-12-18 10:45:06 +00:00
|
|
|
#include "data/data_game.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2020-02-21 10:29:48 +00:00
|
|
|
#include "data/data_histories.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_widgets.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "styles/style_window.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
[[nodiscard]] MTPDmessage::Flags NewForwardedFlags(
|
2017-12-01 10:21:40 +00:00
|
|
|
not_null<PeerData*> peer,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-01 10:21:40 +00:00
|
|
|
not_null<HistoryMessage*> fwd) {
|
2017-06-22 15:11:41 +00:00
|
|
|
auto result = NewMessageFlags(peer) | MTPDmessage::Flag::f_fwd_from;
|
2017-06-16 16:04:30 +00:00
|
|
|
if (from) {
|
|
|
|
result |= MTPDmessage::Flag::f_from_id;
|
|
|
|
}
|
|
|
|
if (fwd->Has<HistoryMessageVia>()) {
|
|
|
|
result |= MTPDmessage::Flag::f_via_bot_id;
|
|
|
|
}
|
2019-01-05 10:50:04 +00:00
|
|
|
if (const auto media = fwd->media()) {
|
|
|
|
if (dynamic_cast<Data::MediaWebPage*>(media)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
// Drop web page if we're not allowed to send it.
|
2019-01-05 10:50:04 +00:00
|
|
|
if (peer->amRestricted(ChatRestriction::f_embed_links)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result &= ~MTPDmessage::Flag::f_media;
|
2017-06-16 16:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-01 11:16:55 +00:00
|
|
|
if ((!peer->isChannel() || peer->isMegagroup())
|
|
|
|
&& media->forwardedBecomesUnread()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
result |= MTPDmessage::Flag::f_media_unread;
|
2017-06-16 16:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fwd->hasViews()) {
|
|
|
|
result |= MTPDmessage::Flag::f_views;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
[[nodiscard]] MTPDmessage_ClientFlags NewForwardedClientFlags() {
|
2019-08-09 19:19:23 +00:00
|
|
|
return NewMessageClientFlags();
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
[[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
|
2019-05-25 14:42:01 +00:00
|
|
|
auto mediaOriginal = item->media();
|
|
|
|
if (mediaOriginal && mediaOriginal->game()) {
|
|
|
|
// Copy inline keyboard when forwarding messages with a game.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto markup = item->inlineReplyMarkup();
|
|
|
|
if (!markup) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
using Type = HistoryMessageMarkupButton::Type;
|
|
|
|
for (const auto &row : markup->rows) {
|
|
|
|
for (const auto &button : row) {
|
|
|
|
const auto switchInline = (button.type == Type::SwitchInline)
|
|
|
|
|| (button.type == Type::SwitchInlineSame);
|
|
|
|
const auto url = (button.type == Type::Url)
|
|
|
|
|| (button.type == Type::Auth);
|
|
|
|
if ((!switchInline || !item->viaBot()) && !url) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
[[nodiscard]] bool HasInlineItems(const HistoryItemsList &items) {
|
2017-12-06 10:13:38 +00:00
|
|
|
for (const auto item : items) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (item->viaBot()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
[[nodiscard]] TextWithEntities EnsureNonEmpty(
|
|
|
|
const TextWithEntities &text = TextWithEntities()) {
|
|
|
|
if (!text.text.isEmpty()) {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
return { QString::fromUtf8(":-("), EntitiesInText() };
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-08-30 13:17:46 +00:00
|
|
|
QString GetErrorTextForSending(
|
2019-07-18 10:03:09 +00:00
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const HistoryItemsList &items,
|
2019-07-18 16:09:50 +00:00
|
|
|
const TextWithTags &comment,
|
|
|
|
bool ignoreSlowmodeCountdown) {
|
2019-07-18 10:03:09 +00:00
|
|
|
if (!peer->canWrite()) {
|
|
|
|
return tr::lng_forward_cant(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (const auto media = item->media()) {
|
|
|
|
const auto error = media->errorTextForForward(peer);
|
|
|
|
if (!error.isEmpty() && error != qstr("skip")) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto error = Data::RestrictionError(
|
|
|
|
peer,
|
|
|
|
ChatRestriction::f_send_inline);
|
|
|
|
if (error && HasInlineItems(items)) {
|
|
|
|
return *error;
|
|
|
|
}
|
|
|
|
|
2019-07-18 16:09:50 +00:00
|
|
|
if (peer->slowmodeApplied()) {
|
|
|
|
if (const auto history = peer->owner().historyLoaded(peer)) {
|
|
|
|
if (!ignoreSlowmodeCountdown
|
|
|
|
&& (history->latestSendingMessage() != nullptr)
|
|
|
|
&& (!items.empty() || !comment.text.isEmpty())) {
|
|
|
|
return tr::lng_slowmode_no_many(tr::now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (comment.text.size() > MaxMessageSize) {
|
2019-07-30 16:09:41 +00:00
|
|
|
return tr::lng_slowmode_too_long(tr::now);
|
2019-07-18 16:09:50 +00:00
|
|
|
} else if (!items.empty() && !comment.text.isEmpty()) {
|
|
|
|
return tr::lng_slowmode_no_many(tr::now);
|
|
|
|
} else if (items.size() > 1) {
|
|
|
|
const auto albumForward = [&] {
|
|
|
|
if (const auto groupId = items.front()->groupId()) {
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (item->groupId() != groupId) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-18 10:03:09 +00:00
|
|
|
}
|
2019-07-18 16:09:50 +00:00
|
|
|
return true;
|
2019-07-18 10:03:09 +00:00
|
|
|
}
|
2019-07-18 16:09:50 +00:00
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
if (!albumForward) {
|
|
|
|
return tr::lng_slowmode_no_many(tr::now);
|
2019-07-18 10:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (const auto left = peer->slowmodeSecondsLeft()) {
|
2019-07-18 16:09:50 +00:00
|
|
|
if (!ignoreSlowmodeCountdown) {
|
|
|
|
return tr::lng_slowmode_enabled(
|
|
|
|
tr::now,
|
|
|
|
lt_left,
|
2020-09-30 11:32:02 +00:00
|
|
|
Ui::FormatDurationWords(left));
|
2019-07-18 16:09:50 +00:00
|
|
|
}
|
2019-07-18 10:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void FastShareMessage(not_null<HistoryItem*> item) {
|
2017-07-11 17:11:06 +00:00
|
|
|
struct ShareData {
|
2017-12-15 21:23:20 +00:00
|
|
|
ShareData(not_null<PeerData*> peer, MessageIdsList &&ids)
|
|
|
|
: peer(peer)
|
|
|
|
, msgIds(std::move(ids)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
2017-12-15 21:23:20 +00:00
|
|
|
not_null<PeerData*> peer;
|
|
|
|
MessageIdsList msgIds;
|
|
|
|
base::flat_set<mtpRequestId> requests;
|
2017-07-11 17:11:06 +00:00
|
|
|
};
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto history = item->history();
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto owner = &history->owner();
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto session = &history->session();
|
2018-01-11 15:51:59 +00:00
|
|
|
const auto data = std::make_shared<ShareData>(
|
2019-01-03 12:36:01 +00:00
|
|
|
history->peer,
|
2019-07-24 11:13:51 +00:00
|
|
|
owner->itemOrItsGroup(item));
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto isGame = item->getMessageBot()
|
2018-01-14 16:02:25 +00:00
|
|
|
&& item->media()
|
|
|
|
&& (item->media()->game() != nullptr);
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto canCopyLink = item->hasDirectLink() || isGame;
|
2017-07-11 17:11:06 +00:00
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
auto copyCallback = [=]() {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = owner->message(data->msgIds[0])) {
|
2018-11-26 11:55:02 +00:00
|
|
|
if (item->hasDirectLink()) {
|
2020-09-22 15:28:49 +00:00
|
|
|
HistoryView::CopyPostLink(
|
|
|
|
session,
|
|
|
|
item->fullId(),
|
|
|
|
HistoryView::Context::History);
|
2018-11-26 11:55:02 +00:00
|
|
|
} else if (const auto bot = item->getMessageBot()) {
|
|
|
|
if (const auto media = item->media()) {
|
|
|
|
if (const auto game = media->game()) {
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto link = session->createInternalLinkFull(
|
2018-11-26 11:55:02 +00:00
|
|
|
bot->username
|
|
|
|
+ qsl("?game=")
|
|
|
|
+ game->shortName);
|
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
QGuiApplication::clipboard()->setText(link);
|
2018-11-26 11:55:02 +00:00
|
|
|
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_share_game_link_copied(tr::now));
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-11-04 07:32:26 +00:00
|
|
|
auto submitCallback = [=](
|
2019-09-13 06:06:02 +00:00
|
|
|
std::vector<not_null<PeerData*>> &&result,
|
2019-07-26 16:06:22 +00:00
|
|
|
TextWithTags &&comment,
|
2019-08-12 12:11:34 +00:00
|
|
|
Api::SendOptions options) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (!data->requests.empty()) {
|
|
|
|
return; // Share clicked already.
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
auto items = history->owner().idsToItems(data->msgIds);
|
2017-12-15 21:23:20 +00:00
|
|
|
if (items.empty() || result.empty()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-18 10:03:09 +00:00
|
|
|
const auto error = [&] {
|
|
|
|
for (const auto peer : result) {
|
2019-08-30 13:17:46 +00:00
|
|
|
const auto error = GetErrorTextForSending(
|
2019-07-18 10:03:09 +00:00
|
|
|
peer,
|
|
|
|
items,
|
|
|
|
comment);
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
return std::make_pair(error, peer);
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-18 10:03:09 +00:00
|
|
|
return std::make_pair(QString(), result.front());
|
|
|
|
}();
|
|
|
|
if (!error.first.isEmpty()) {
|
|
|
|
auto text = TextWithEntities();
|
|
|
|
if (result.size() > 1) {
|
|
|
|
text.append(
|
2019-09-13 06:06:02 +00:00
|
|
|
Ui::Text::Bold(error.second->name)
|
2019-07-18 10:03:09 +00:00
|
|
|
).append("\n\n");
|
|
|
|
}
|
|
|
|
text.append(error.first);
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
2019-07-18 10:03:09 +00:00
|
|
|
Box<InformBox>(text),
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::LayerOption::KeepOther);
|
2017-07-11 17:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-19 13:23:51 +00:00
|
|
|
const auto commonSendFlags = MTPmessages_ForwardMessages::Flag(0)
|
2017-12-18 13:29:48 +00:00
|
|
|
| MTPmessages_ForwardMessages::Flag::f_with_my_score
|
2019-09-08 18:26:17 +00:00
|
|
|
| (options.scheduled
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_schedule_date
|
2017-12-18 13:29:48 +00:00
|
|
|
: MTPmessages_ForwardMessages::Flag(0));
|
2017-12-15 21:23:20 +00:00
|
|
|
auto msgIds = QVector<MTPint>();
|
|
|
|
msgIds.reserve(data->msgIds.size());
|
|
|
|
for (const auto fullId : data->msgIds) {
|
|
|
|
msgIds.push_back(MTP_int(fullId.msg));
|
|
|
|
}
|
|
|
|
auto generateRandom = [&] {
|
|
|
|
auto result = QVector<MTPlong>(data->msgIds.size());
|
|
|
|
for (auto &value : result) {
|
|
|
|
value = rand_value<MTPlong>();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
2020-02-21 10:29:48 +00:00
|
|
|
auto &api = owner->session().api();
|
|
|
|
auto &histories = owner->histories();
|
|
|
|
const auto requestType = Data::Histories::RequestType::Send;
|
2018-11-26 11:55:02 +00:00
|
|
|
for (const auto peer : result) {
|
2020-02-21 10:29:48 +00:00
|
|
|
const auto history = owner->history(peer);
|
2018-11-26 11:55:02 +00:00
|
|
|
if (!comment.text.isEmpty()) {
|
|
|
|
auto message = ApiWrap::MessageToSend(history);
|
|
|
|
message.textWithTags = comment;
|
2019-09-08 18:26:17 +00:00
|
|
|
message.action.options = options;
|
2019-08-12 12:11:34 +00:00
|
|
|
message.action.clearDraft = false;
|
2020-02-21 10:29:48 +00:00
|
|
|
api.sendMessage(std::move(message));
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
2020-02-21 10:29:48 +00:00
|
|
|
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
|
|
|
|
auto &api = history->session().api();
|
2020-11-19 13:23:51 +00:00
|
|
|
const auto sendFlags = commonSendFlags
|
|
|
|
| (ShouldSendSilent(peer, options)
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_silent
|
|
|
|
: MTPmessages_ForwardMessages::Flag(0));
|
2020-02-21 10:29:48 +00:00
|
|
|
history->sendRequestId = api.request(MTPmessages_ForwardMessages(
|
2020-11-19 13:23:51 +00:00
|
|
|
MTP_flags(sendFlags),
|
|
|
|
data->peer->input,
|
|
|
|
MTP_vector<MTPint>(msgIds),
|
|
|
|
MTP_vector<MTPlong>(generateRandom()),
|
|
|
|
peer->input,
|
|
|
|
MTP_int(options.scheduled)
|
2020-02-21 10:29:48 +00:00
|
|
|
)).done([=](const MTPUpdates &updates, mtpRequestId requestId) {
|
|
|
|
history->session().api().applyUpdates(updates);
|
|
|
|
data->requests.remove(requestId);
|
|
|
|
if (data->requests.empty()) {
|
|
|
|
Ui::Toast::Show(tr::lng_share_done(tr::now));
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
finish();
|
|
|
|
}).afterRequest(history->sendRequestId).send();
|
|
|
|
return history->sendRequestId;
|
|
|
|
});
|
2018-11-26 11:55:02 +00:00
|
|
|
data->requests.insert(history->sendRequestId);
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
};
|
2017-07-25 19:38:08 +00:00
|
|
|
auto filterCallback = [isGame](PeerData *peer) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (peer->canWrite()) {
|
|
|
|
if (auto channel = peer->asChannel()) {
|
2017-07-25 19:38:08 +00:00
|
|
|
return isGame ? (!channel->isBroadcast()) : true;
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2017-12-05 14:07:01 +00:00
|
|
|
auto copyLinkCallback = canCopyLink
|
2018-06-04 15:35:11 +00:00
|
|
|
? Fn<void()>(std::move(copyCallback))
|
|
|
|
: Fn<void()>();
|
2017-12-05 14:07:01 +00:00
|
|
|
Ui::show(Box<ShareBox>(
|
2019-07-25 18:55:11 +00:00
|
|
|
App::wnd()->sessionController(),
|
2017-12-05 14:07:01 +00:00
|
|
|
std::move(copyLinkCallback),
|
|
|
|
std::move(submitCallback),
|
|
|
|
std::move(filterCallback)));
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
2020-06-08 09:06:50 +00:00
|
|
|
not_null<HistoryItem*> item) {
|
|
|
|
const auto session = &item->history()->session();
|
|
|
|
const auto dependent = item->fullId();
|
|
|
|
return [=](ChannelData *channel, MsgId msgId) {
|
|
|
|
if (const auto item = session->data().message(dependent)) {
|
2017-06-22 15:11:41 +00:00
|
|
|
item->updateDependencyItem();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage::Flags result = 0;
|
2017-06-22 15:11:41 +00:00
|
|
|
if (!peer->isSelf()) {
|
|
|
|
result |= MTPDmessage::Flag::f_out;
|
2019-07-18 08:51:11 +00:00
|
|
|
//if (p->isChat() || (p->isUser() && !p->asUser()->isBot())) {
|
2017-06-22 15:11:41 +00:00
|
|
|
// result |= MTPDmessage::Flag::f_unread;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-11-19 13:23:51 +00:00
|
|
|
bool ShouldSendSilent(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const Api::SendOptions &options) {
|
|
|
|
return options.silent
|
|
|
|
|| (peer->isBroadcast() && peer->owner().notifySilentPosts(peer))
|
|
|
|
|| (peer->session().supportMode()
|
|
|
|
&& peer->session().settings().supportAllSilent());
|
|
|
|
}
|
|
|
|
|
2020-10-06 11:01:19 +00:00
|
|
|
MsgId LookupReplyToTop(not_null<History*> history, MsgId replyToId) {
|
|
|
|
const auto &owner = history->owner();
|
|
|
|
if (const auto item = owner.message(history->channelId(), replyToId)) {
|
|
|
|
return item->replyToTop();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPMessageReplyHeader NewMessageReplyHeader(const Api::SendAction &action) {
|
|
|
|
if (const auto id = action.replyTo) {
|
2020-10-06 11:01:19 +00:00
|
|
|
if (const auto replyToTop = LookupReplyToTop(action.history, id)) {
|
|
|
|
return MTP_messageReplyHeader(
|
|
|
|
MTP_flags(MTPDmessageReplyHeader::Flag::f_reply_to_top_id),
|
|
|
|
MTP_int(id),
|
|
|
|
MTPPeer(),
|
|
|
|
MTP_int(replyToTop));
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
return MTP_messageReplyHeader(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_int(id),
|
|
|
|
MTPPeer(),
|
|
|
|
MTPint());
|
|
|
|
}
|
|
|
|
return MTPMessageReplyHeader();
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags NewMessageClientFlags() {
|
|
|
|
return MTPDmessage_ClientFlag::f_sending;
|
|
|
|
}
|
|
|
|
|
2019-08-30 13:17:46 +00:00
|
|
|
QString GetErrorTextForSending(
|
2017-12-06 10:13:38 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-07-18 16:09:50 +00:00
|
|
|
const HistoryItemsList &items,
|
|
|
|
bool ignoreSlowmodeCountdown) {
|
2019-08-30 13:17:46 +00:00
|
|
|
return GetErrorTextForSending(peer, items, {}, ignoreSlowmodeCountdown);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
struct HistoryMessage::CreateConfig {
|
2020-09-11 16:22:14 +00:00
|
|
|
PeerId replyToPeer = 0;
|
2017-12-18 15:44:50 +00:00
|
|
|
MsgId replyTo = 0;
|
2020-09-01 06:44:18 +00:00
|
|
|
MsgId replyToTop = 0;
|
2017-12-18 15:44:50 +00:00
|
|
|
UserId viaBotId = 0;
|
|
|
|
int viewsCount = -1;
|
|
|
|
QString author;
|
|
|
|
PeerId senderOriginal = 0;
|
2019-03-15 15:15:56 +00:00
|
|
|
QString senderNameOriginal;
|
2020-04-28 19:49:55 +00:00
|
|
|
QString forwardPsaType;
|
2017-12-18 15:44:50 +00:00
|
|
|
MsgId originalId = 0;
|
|
|
|
PeerId savedFromPeer = 0;
|
|
|
|
MsgId savedFromMsgId = 0;
|
|
|
|
QString authorOriginal;
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId originalDate = 0;
|
|
|
|
TimeId editDate = 0;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
// For messages created from MTP structs.
|
2020-09-03 07:19:02 +00:00
|
|
|
const MTPMessageReplies *mtpReplies = nullptr;
|
2017-12-18 15:44:50 +00:00
|
|
|
const MTPReplyMarkup *mtpMarkup = nullptr;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
// For messages created from existing messages (forwarded).
|
|
|
|
const HistoryMessageReplyMarkup *inlineMarkup = nullptr;
|
|
|
|
};
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
void HistoryMessage::FillForwardedInfo(
|
|
|
|
CreateConfig &config,
|
|
|
|
const MTPDmessageFwdHeader &data) {
|
2020-09-01 06:44:18 +00:00
|
|
|
if (const auto fromId = data.vfrom_id()) {
|
|
|
|
config.senderOriginal = peerFromMTP(*fromId);
|
2019-03-15 15:15:56 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
config.originalDate = data.vdate().v;
|
|
|
|
config.senderNameOriginal = qs(data.vfrom_name().value_or_empty());
|
2020-04-28 19:49:55 +00:00
|
|
|
config.forwardPsaType = qs(data.vpsa_type().value_or_empty());
|
2019-07-05 13:38:38 +00:00
|
|
|
config.originalId = data.vchannel_post().value_or_empty();
|
|
|
|
config.authorOriginal = qs(data.vpost_author().value_or_empty());
|
|
|
|
const auto savedFromPeer = data.vsaved_from_peer();
|
|
|
|
const auto savedFromMsgId = data.vsaved_from_msg_id();
|
|
|
|
if (savedFromPeer && savedFromMsgId) {
|
|
|
|
config.savedFromPeer = peerFromMTP(*savedFromPeer);
|
|
|
|
config.savedFromMsgId = savedFromMsgId->v;
|
2019-03-15 15:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
2019-08-09 19:19:23 +00:00
|
|
|
const MTPDmessage &data,
|
|
|
|
MTPDmessage_ClientFlags clientFlags)
|
2018-02-03 19:52:35 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vid().v,
|
|
|
|
data.vflags().v,
|
2019-08-09 19:19:23 +00:00
|
|
|
clientFlags,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vdate().v,
|
2020-09-01 06:44:18 +00:00
|
|
|
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
2019-03-15 15:15:56 +00:00
|
|
|
auto config = CreateConfig();
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto forwarded = data.vfwd_from()) {
|
|
|
|
forwarded->match([&](const MTPDmessageFwdHeader &data) {
|
2019-03-15 15:15:56 +00:00
|
|
|
FillForwardedInfo(config, data);
|
|
|
|
});
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
if (const auto reply = data.vreply_to()) {
|
|
|
|
reply->match([&](const MTPDmessageReplyHeader &data) {
|
2020-09-11 16:22:14 +00:00
|
|
|
if (const auto peer = data.vreply_to_peer_id()) {
|
|
|
|
config.replyToPeer = peerFromMTP(*peer);
|
|
|
|
if (config.replyToPeer == history->peer->id) {
|
|
|
|
config.replyToPeer = 0;
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
config.replyTo = data.vreply_to_msg_id().v;
|
|
|
|
config.replyToTop = data.vreply_to_top_id().value_or(
|
|
|
|
config.replyTo);
|
|
|
|
});
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
config.viaBotId = data.vvia_bot_id().value_or_empty();
|
|
|
|
config.viewsCount = data.vviews().value_or(-1);
|
2020-10-07 18:59:33 +00:00
|
|
|
config.mtpReplies = isScheduled() ? nullptr : data.vreplies();
|
2019-07-05 13:38:38 +00:00
|
|
|
config.mtpMarkup = data.vreply_markup();
|
|
|
|
config.editDate = data.vedit_date().value_or_empty();
|
|
|
|
config.author = qs(data.vpost_author().value_or_empty());
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto media = data.vmedia()) {
|
|
|
|
setMedia(*media);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
2020-05-04 13:03:33 +00:00
|
|
|
const auto textWithEntities = TextWithEntities{
|
2019-07-05 13:38:38 +00:00
|
|
|
TextUtilities::Clean(qs(data.vmessage())),
|
2020-06-08 08:03:45 +00:00
|
|
|
Api::EntitiesFromMTP(
|
|
|
|
&history->session(),
|
|
|
|
data.ventities().value_or_empty())
|
2020-05-04 13:03:33 +00:00
|
|
|
};
|
|
|
|
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto groupedId = data.vgrouped_id()) {
|
2019-05-31 21:51:57 +00:00
|
|
|
setGroupId(
|
2019-07-05 13:38:38 +00:00
|
|
|
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
2018-01-18 13:59:22 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
2019-08-09 19:19:23 +00:00
|
|
|
const MTPDmessageService &data,
|
|
|
|
MTPDmessage_ClientFlags clientFlags)
|
2018-02-03 19:52:35 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vid().v,
|
|
|
|
mtpCastFlags(data.vflags().v),
|
2019-08-09 19:19:23 +00:00
|
|
|
clientFlags,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vdate().v,
|
2020-09-01 06:44:18 +00:00
|
|
|
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0)) {
|
2019-03-15 15:15:56 +00:00
|
|
|
auto config = CreateConfig();
|
2017-04-27 21:17:00 +00:00
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
if (const auto reply = data.vreply_to()) {
|
|
|
|
reply->match([&](const MTPDmessageReplyHeader &data) {
|
2020-09-11 16:22:14 +00:00
|
|
|
const auto peer = data.vreply_to_peer_id()
|
|
|
|
? peerFromMTP(*data.vreply_to_peer_id())
|
|
|
|
: history->peer->id;
|
|
|
|
if (!peer || peer == history->peer->id) {
|
|
|
|
config.replyTo = data.vreply_to_msg_id().v;
|
|
|
|
config.replyToTop = data.vreply_to_top_id().value_or(
|
|
|
|
config.replyTo);
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
});
|
|
|
|
}
|
2017-04-27 21:17:00 +00:00
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
|
2020-05-04 13:03:33 +00:00
|
|
|
data.vaction().match([&](const MTPDmessageActionPhoneCall &data) {
|
|
|
|
_media = std::make_unique<Data::MediaCall>(this, data);
|
|
|
|
setEmptyText();
|
|
|
|
}, [](const auto &) {
|
|
|
|
Unexpected("Service message action type in HistoryMessage.");
|
|
|
|
});
|
2017-04-27 21:17:00 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-05 16:14:28 +00:00
|
|
|
const QString &postAuthor,
|
2018-02-03 19:52:35 +00:00
|
|
|
not_null<HistoryMessage*> original)
|
|
|
|
: HistoryItem(
|
|
|
|
history,
|
|
|
|
id,
|
|
|
|
NewForwardedFlags(history->peer, from, original) | flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
NewForwardedClientFlags() | clientFlags,
|
2018-02-03 19:52:35 +00:00
|
|
|
date,
|
|
|
|
from) {
|
2019-01-05 10:50:04 +00:00
|
|
|
const auto peer = history->peer;
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
auto config = CreateConfig();
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
if (original->Has<HistoryMessageForwarded>() || !original->history()->peer->isSelf()) {
|
2017-04-30 12:42:04 +00:00
|
|
|
// Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself.
|
2018-02-03 19:52:35 +00:00
|
|
|
config.originalDate = original->dateOriginal();
|
2019-03-15 15:15:56 +00:00
|
|
|
if (const auto info = original->hiddenForwardedInfo()) {
|
|
|
|
config.senderNameOriginal = info->name;
|
|
|
|
} else if (const auto senderOriginal = original->senderOriginal()) {
|
|
|
|
config.senderOriginal = senderOriginal->id;
|
|
|
|
if (senderOriginal->isChannel()) {
|
|
|
|
config.originalId = original->idOriginal();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Unexpected("Corrupt forwarded information in message.");
|
2017-04-30 12:42:04 +00:00
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
config.authorOriginal = original->authorOriginal();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-01-05 10:50:04 +00:00
|
|
|
if (peer->isSelf()) {
|
2017-12-05 16:14:28 +00:00
|
|
|
//
|
|
|
|
// iOS app sends you to the original post if we forward a forward from channel.
|
|
|
|
// But server returns not the original post but the forward in saved_from_...
|
|
|
|
//
|
|
|
|
//if (config.originalId) {
|
|
|
|
// config.savedFromPeer = config.senderOriginal;
|
|
|
|
// config.savedFromMsgId = config.originalId;
|
|
|
|
//} else {
|
2018-02-03 19:52:35 +00:00
|
|
|
config.savedFromPeer = original->history()->peer->id;
|
|
|
|
config.savedFromMsgId = original->id;
|
2017-12-05 16:14:28 +00:00
|
|
|
//}
|
|
|
|
}
|
2017-07-12 19:14:20 +00:00
|
|
|
if (flags & MTPDmessage::Flag::f_post_author) {
|
|
|
|
config.author = postAuthor;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto fwdViaBot = original->viaBot()) {
|
|
|
|
config.viaBotId = peerToUser(fwdViaBot->id);
|
|
|
|
}
|
|
|
|
const auto fwdViewsCount = original->viewsCount();
|
2016-09-27 14:20:49 +00:00
|
|
|
if (fwdViewsCount > 0) {
|
|
|
|
config.viewsCount = fwdViewsCount;
|
2020-06-06 08:22:16 +00:00
|
|
|
} else if ((isPost() && !isScheduled())
|
2019-06-19 14:52:18 +00:00
|
|
|
|| (original->senderOriginal()
|
|
|
|
&& original->senderOriginal()->isChannel())) {
|
2016-09-27 14:20:49 +00:00
|
|
|
config.viewsCount = 1;
|
|
|
|
}
|
|
|
|
|
2019-05-25 14:42:01 +00:00
|
|
|
const auto mediaOriginal = original->media();
|
|
|
|
if (CopyMarkupToForward(original)) {
|
2018-02-03 19:52:35 +00:00
|
|
|
config.inlineMarkup = original->inlineReplyMarkup();
|
2016-10-07 07:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
createComponents(config);
|
|
|
|
|
2019-01-05 10:50:04 +00:00
|
|
|
const auto ignoreMedia = [&] {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (mediaOriginal && mediaOriginal->webpage()) {
|
2019-01-05 10:50:04 +00:00
|
|
|
if (peer->amRestricted(ChatRestriction::f_embed_links)) {
|
|
|
|
return true;
|
2017-06-16 16:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
return false;
|
2017-06-16 16:04:30 +00:00
|
|
|
};
|
2018-01-14 16:02:25 +00:00
|
|
|
if (mediaOriginal && !ignoreMedia()) {
|
|
|
|
_media = mediaOriginal->clone(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
setText(original->originalText());
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-13 18:10:48 +00:00
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-13 18:10:48 +00:00
|
|
|
const QString &postAuthor,
|
|
|
|
const TextWithEntities &textWithEntities)
|
2019-08-09 19:19:23 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
|
|
|
id,
|
|
|
|
flags & ~MTPDmessage::Flag::f_reply_markup,
|
|
|
|
clientFlags,
|
|
|
|
date,
|
|
|
|
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
|
|
|
createComponentsHelper(
|
|
|
|
flags & ~MTPDmessage::Flag::f_reply_markup,
|
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
postAuthor,
|
|
|
|
MTPReplyMarkup());
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
setText(textWithEntities);
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
2018-02-03 19:52:35 +00:00
|
|
|
MsgId id,
|
2017-12-13 18:10:48 +00:00
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-13 18:10:48 +00:00
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-13 18:10:48 +00:00
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<DocumentData*> document,
|
2018-01-18 13:59:22 +00:00
|
|
|
const TextWithEntities &caption,
|
2017-12-13 18:10:48 +00:00
|
|
|
const MTPReplyMarkup &markup)
|
2019-08-09 19:19:23 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
|
|
|
id,
|
|
|
|
flags,
|
|
|
|
clientFlags,
|
|
|
|
date,
|
|
|
|
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
2017-07-12 19:14:20 +00:00
|
|
|
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
_media = std::make_unique<Data::MediaFile>(this, document);
|
|
|
|
setText(caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
2018-02-03 19:52:35 +00:00
|
|
|
MsgId id,
|
2017-12-13 18:10:48 +00:00
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-13 18:10:48 +00:00
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-13 18:10:48 +00:00
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<PhotoData*> photo,
|
2018-01-18 13:59:22 +00:00
|
|
|
const TextWithEntities &caption,
|
2017-12-13 18:10:48 +00:00
|
|
|
const MTPReplyMarkup &markup)
|
2019-08-09 19:19:23 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
|
|
|
id,
|
|
|
|
flags,
|
|
|
|
clientFlags,
|
|
|
|
date,
|
|
|
|
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
2017-07-12 19:14:20 +00:00
|
|
|
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
_media = std::make_unique<Data::MediaPhoto>(this, photo);
|
|
|
|
setText(caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
2018-02-03 19:52:35 +00:00
|
|
|
MsgId id,
|
2017-12-13 18:10:48 +00:00
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2017-12-13 18:10:48 +00:00
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from,
|
2017-12-13 18:10:48 +00:00
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const MTPReplyMarkup &markup)
|
2019-08-09 19:19:23 +00:00
|
|
|
: HistoryItem(
|
|
|
|
history,
|
|
|
|
id,
|
|
|
|
flags,
|
|
|
|
clientFlags,
|
|
|
|
date,
|
|
|
|
(flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
2017-07-12 19:14:20 +00:00
|
|
|
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, markup);
|
2016-09-28 16:23:25 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
_media = std::make_unique<Data::MediaGame>(this, game);
|
2020-05-04 13:03:33 +00:00
|
|
|
setEmptyText();
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
void HistoryMessage::createComponentsHelper(
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const MTPReplyMarkup &markup) {
|
2019-03-15 15:15:56 +00:00
|
|
|
auto config = CreateConfig();
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
if (flags & MTPDmessage::Flag::f_via_bot_id) config.viaBotId = viaBotId;
|
2020-09-01 06:44:18 +00:00
|
|
|
if (flags & MTPDmessage::Flag::f_reply_to) {
|
2020-10-06 11:01:19 +00:00
|
|
|
config.replyTo = replyTo;
|
|
|
|
const auto replyToTop = LookupReplyToTop(history(), replyTo);
|
|
|
|
config.replyToTop = replyToTop ? replyToTop : replyTo;
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2016-10-07 07:58:34 +00:00
|
|
|
if (flags & MTPDmessage::Flag::f_reply_markup) config.mtpMarkup = &markup;
|
2017-07-12 19:14:20 +00:00
|
|
|
if (flags & MTPDmessage::Flag::f_post_author) config.author = postAuthor;
|
2020-05-17 09:09:20 +00:00
|
|
|
if (flags & MTPDmessage::Flag::f_views) config.viewsCount = 1;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
int HistoryMessage::viewsCount() const {
|
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-03 07:19:02 +00:00
|
|
|
return std::max(views->views.count, 0);
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
return HistoryItem::viewsCount();
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
bool HistoryMessage::checkCommentsLinkedChat(ChannelId id) const {
|
|
|
|
if (!id) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto channel = history()->peer->asChannel()) {
|
|
|
|
if (channel->linkedChatKnown()
|
|
|
|
|| !(channel->flags() & MTPDchannel::Flag::f_has_link)) {
|
|
|
|
const auto linked = channel->linkedChat();
|
|
|
|
if (!linked || linked->bareId() != id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
int HistoryMessage::repliesCount() const {
|
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!checkCommentsLinkedChat(views->commentsMegagroupId)) {
|
2020-09-10 11:56:46 +00:00
|
|
|
return 0;
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
|
|
|
return std::max(views->replies.count, 0);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
return HistoryItem::repliesCount();
|
|
|
|
}
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
bool HistoryMessage::repliesAreComments() const {
|
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
return (views->commentsMegagroupId != 0)
|
|
|
|
&& checkCommentsLinkedChat(views->commentsMegagroupId);
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
|
|
|
return HistoryItem::repliesAreComments();
|
|
|
|
}
|
|
|
|
|
2020-09-11 17:55:10 +00:00
|
|
|
bool HistoryMessage::externalReply() const {
|
|
|
|
if (!history()->peer->isRepliesChat()) {
|
|
|
|
return false;
|
|
|
|
} else if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->savedFromPeer && forwarded->savedFromMsgId;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
MsgId HistoryMessage::repliesInboxReadTill() const {
|
2020-09-03 08:21:31 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
return views->repliesInboxReadTillId;
|
2020-09-03 08:21:31 +00:00
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
return 0;
|
2020-09-03 08:21:31 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
void HistoryMessage::setRepliesInboxReadTill(MsgId readTillId) {
|
2020-09-03 08:21:31 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto newReadTillId = std::max(readTillId, 1);
|
|
|
|
if (newReadTillId > views->repliesInboxReadTillId) {
|
|
|
|
const auto wasUnread = repliesAreComments() && areRepliesUnread();
|
|
|
|
views->repliesInboxReadTillId = newReadTillId;
|
|
|
|
if (wasUnread && !areRepliesUnread()) {
|
|
|
|
history()->owner().requestItemRepaint(this);
|
|
|
|
}
|
2020-09-03 08:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
MsgId HistoryMessage::computeRepliesInboxReadTillFull() const {
|
|
|
|
const auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const auto local = views->repliesInboxReadTillId;
|
|
|
|
const auto group = views->commentsMegagroupId
|
|
|
|
? history()->owner().historyLoaded(
|
|
|
|
peerFromChannel(views->commentsMegagroupId))
|
|
|
|
: history().get();
|
|
|
|
return group ? std::max(local, group->inboxReadTillId()) : local;
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgId HistoryMessage::repliesOutboxReadTill() const {
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
return views->repliesOutboxReadTillId;
|
2020-09-15 08:39:39 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
void HistoryMessage::setRepliesOutboxReadTill(MsgId readTillId) {
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
|
|
|
const auto newReadTillId = std::max(readTillId, 1);
|
2020-09-22 11:01:49 +00:00
|
|
|
if (newReadTillId > views->repliesOutboxReadTillId) {
|
|
|
|
views->repliesOutboxReadTillId = newReadTillId;
|
|
|
|
if (!repliesAreComments()) {
|
|
|
|
history()->session().changes().historyUpdated(
|
|
|
|
history(),
|
|
|
|
Data::HistoryUpdate::Flag::OutboxRead);
|
2020-09-15 08:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
MsgId HistoryMessage::computeRepliesOutboxReadTillFull() const {
|
|
|
|
const auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const auto local = views->repliesOutboxReadTillId;
|
|
|
|
const auto group = views->commentsMegagroupId
|
|
|
|
? history()->owner().historyLoaded(
|
|
|
|
peerFromChannel(views->commentsMegagroupId))
|
|
|
|
: history().get();
|
|
|
|
return group ? std::max(local, group->outboxReadTillId()) : local;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setRepliesMaxId(MsgId maxId) {
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (views->repliesMaxId != maxId) {
|
|
|
|
const auto comments = repliesAreComments();
|
|
|
|
const auto wasUnread = comments && areRepliesUnread();
|
|
|
|
views->repliesMaxId = maxId;
|
|
|
|
if (comments && wasUnread != areRepliesUnread()) {
|
2020-09-15 08:39:39 +00:00
|
|
|
history()->owner().requestItemRepaint(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
void HistoryMessage::setRepliesPossibleMaxId(MsgId possibleMaxId) {
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (views->repliesMaxId < possibleMaxId) {
|
|
|
|
const auto comments = repliesAreComments();
|
|
|
|
const auto wasUnread = comments && areRepliesUnread();
|
|
|
|
views->repliesMaxId = possibleMaxId;
|
|
|
|
if (comments && !wasUnread && areRepliesUnread()) {
|
2020-09-15 08:39:39 +00:00
|
|
|
history()->owner().requestItemRepaint(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
bool HistoryMessage::areRepliesUnread() const {
|
2020-09-18 11:52:44 +00:00
|
|
|
const auto views = Get<HistoryMessageViews>();
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!views) {
|
|
|
|
return false;
|
2020-09-18 11:52:44 +00:00
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto local = views->repliesInboxReadTillId;
|
|
|
|
if (views->repliesInboxReadTillId < 2 || views->repliesMaxId <= local) {
|
|
|
|
return false;
|
2020-09-18 11:52:44 +00:00
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto group = views->commentsMegagroupId
|
|
|
|
? history()->owner().historyLoaded(
|
|
|
|
peerFromChannel(views->commentsMegagroupId))
|
|
|
|
: history().get();
|
|
|
|
return !group || (views->repliesMaxId > group->inboxReadTillId());
|
2020-09-18 11:52:44 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 11:01:49 +00:00
|
|
|
FullMsgId HistoryMessage::commentsItemId() const {
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
return FullMsgId(views->commentsMegagroupId, views->commentsRootId);
|
|
|
|
}
|
|
|
|
return FullMsgId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setCommentsItemId(FullMsgId id) {
|
|
|
|
if (id.channel == _history->channelId()) {
|
|
|
|
if (id.msg != this->id) {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->replyToMsgTop = id.msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (const auto views = Get<HistoryMessageViews>()) {
|
|
|
|
if (views->commentsMegagroupId != id.channel) {
|
|
|
|
views->commentsMegagroupId = id.channel;
|
|
|
|
history()->owner().requestItemResize(this);
|
2020-09-18 11:52:44 +00:00
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
views->commentsRootId = id.msg;
|
2020-09-15 08:39:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool HistoryMessage::updateDependencyItem() {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2019-12-27 12:15:16 +00:00
|
|
|
const auto documentId = reply->replyToDocumentId;
|
2019-12-27 10:41:30 +00:00
|
|
|
const auto result = reply->updateData(this, true);
|
2019-12-27 12:15:16 +00:00
|
|
|
if (documentId != reply->replyToDocumentId
|
2019-12-27 10:41:30 +00:00
|
|
|
&& generateLocalEntitiesByReply()) {
|
|
|
|
reapplyText();
|
|
|
|
}
|
|
|
|
return result;
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool HistoryMessage::allowsForward() const {
|
2019-08-08 14:13:26 +00:00
|
|
|
if (id < 0 || !isHistoryEntry()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return !_media || _media->allowsForward();
|
2017-12-16 16:32:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 17:58:58 +00:00
|
|
|
bool HistoryMessage::allowsSendNow() const {
|
2020-05-30 08:47:32 +00:00
|
|
|
return isScheduled() && !isSending() && !hasFailed() && !isEditingMedia();
|
2019-08-09 17:58:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
bool HistoryMessage::isTooOldForEdit(TimeId now) const {
|
2020-04-23 12:08:50 +00:00
|
|
|
return !_history->peer->canEditMessagesIndefinitely()
|
2020-05-30 08:47:32 +00:00
|
|
|
&& !isScheduled()
|
2020-06-17 09:36:25 +00:00
|
|
|
&& (now - date() >= _history->session().serverConfig().editTimeLimit);
|
2018-12-19 11:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryMessage::allowsEdit(TimeId now) const {
|
|
|
|
return canStopPoll()
|
|
|
|
&& !isTooOldForEdit(now)
|
2018-12-26 06:18:53 +00:00
|
|
|
&& (!_media || _media->allowsEdit())
|
2019-05-20 14:57:25 +00:00
|
|
|
&& !isLegacyMessage()
|
2019-04-04 10:22:59 +00:00
|
|
|
&& !isEditingMedia();
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool HistoryMessage::uploading() const {
|
|
|
|
return _media && _media->uploading();
|
2017-12-05 16:14:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::createComponents(const CreateConfig &config) {
|
|
|
|
uint64 mask = 0;
|
|
|
|
if (config.replyTo) {
|
|
|
|
mask |= HistoryMessageReply::Bit();
|
|
|
|
}
|
|
|
|
if (config.viaBotId) {
|
|
|
|
mask |= HistoryMessageVia::Bit();
|
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
if (config.viewsCount >= 0 || config.mtpReplies) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageViews::Bit();
|
|
|
|
}
|
2017-07-12 19:14:20 +00:00
|
|
|
if (!config.author.isEmpty()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageSigned::Bit();
|
2020-10-05 13:21:24 +00:00
|
|
|
} else if (_history->peer->isMegagroup() // Discussion posts signatures.
|
|
|
|
&& config.savedFromPeer
|
|
|
|
&& !config.authorOriginal.isEmpty()) {
|
|
|
|
const auto savedFrom = _history->owner().peerLoaded(
|
|
|
|
config.savedFromPeer);
|
|
|
|
if (savedFrom && savedFrom->isChannel()) {
|
|
|
|
mask |= HistoryMessageSigned::Bit();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
if (config.editDate != TimeId(0)) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageEdited::Bit();
|
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
if (config.originalDate != 0) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageForwarded::Bit();
|
|
|
|
}
|
2016-10-07 07:58:34 +00:00
|
|
|
if (config.mtpMarkup) {
|
2016-09-27 14:20:49 +00:00
|
|
|
// optimization: don't create markup component for the case
|
|
|
|
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
2019-07-05 13:38:38 +00:00
|
|
|
if (config.mtpMarkup->type() != mtpc_replyKeyboardHide || config.mtpMarkup->c_replyKeyboardHide().vflags().v != 0) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageReplyMarkup::Bit();
|
|
|
|
}
|
2016-10-07 07:58:34 +00:00
|
|
|
} else if (config.inlineMarkup) {
|
|
|
|
mask |= HistoryMessageReplyMarkup::Bit();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-10-07 07:58:34 +00:00
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
UpdateComponents(mask);
|
2016-10-07 07:58:34 +00:00
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2020-09-11 16:22:14 +00:00
|
|
|
reply->replyToPeerId = config.replyToPeer;
|
2016-09-27 14:20:49 +00:00
|
|
|
reply->replyToMsgId = config.replyTo;
|
2020-09-01 06:44:18 +00:00
|
|
|
reply->replyToMsgTop = isScheduled() ? 0 : config.replyToTop;
|
2017-08-04 14:54:32 +00:00
|
|
|
if (!reply->updateData(this)) {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->session().api().requestMessageData(
|
2020-09-11 16:22:14 +00:00
|
|
|
(peerIsChannel(reply->replyToPeerId)
|
|
|
|
? history()->owner().channel(
|
|
|
|
peerToChannel(reply->replyToPeerId)).get()
|
|
|
|
: history()->peer->asChannel()),
|
2017-11-23 15:41:13 +00:00
|
|
|
reply->replyToMsgId,
|
2020-06-08 09:06:50 +00:00
|
|
|
HistoryDependentItemCallback(this));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto via = Get<HistoryMessageVia>()) {
|
2020-06-08 15:17:33 +00:00
|
|
|
via->create(&history()->owner(), config.viaBotId);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2020-09-03 07:19:02 +00:00
|
|
|
setViewsCount(config.viewsCount);
|
|
|
|
if (config.mtpReplies) {
|
|
|
|
setReplies(*config.mtpReplies);
|
2020-10-01 08:44:03 +00:00
|
|
|
} else if (isSending() && !config.mtpMarkup) {
|
2020-09-03 11:53:54 +00:00
|
|
|
if (const auto broadcast = history()->peer->asBroadcast()) {
|
|
|
|
if (const auto linked = broadcast->linkedChat()) {
|
|
|
|
setReplies(MTP_messageReplies(
|
|
|
|
MTP_flags(MTPDmessageReplies::Flag::f_comments
|
|
|
|
| MTPDmessageReplies::Flag::f_comments),
|
|
|
|
MTP_int(0),
|
|
|
|
MTP_int(0),
|
|
|
|
MTPVector<MTPPeer>(), // recent_repliers
|
|
|
|
MTP_int(linked->bareId()),
|
|
|
|
MTP_int(0), // max_id
|
|
|
|
MTP_int(0))); // read_max_id
|
|
|
|
}
|
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto edited = Get<HistoryMessageEdited>()) {
|
2017-12-16 16:32:10 +00:00
|
|
|
edited->date = config.editDate;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto msgsigned = Get<HistoryMessageSigned>()) {
|
2020-10-05 13:21:24 +00:00
|
|
|
msgsigned->author = config.author.isEmpty()
|
|
|
|
? config.authorOriginal
|
|
|
|
: config.author;
|
|
|
|
msgsigned->isAnonymousRank = !isDiscussionPost()
|
|
|
|
&& author()->isMegagroup();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
setupForwardedComponent(config);
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
2016-10-07 07:58:34 +00:00
|
|
|
if (config.mtpMarkup) {
|
|
|
|
markup->create(*config.mtpMarkup);
|
|
|
|
} else if (config.inlineMarkup) {
|
|
|
|
markup->create(*config.inlineMarkup);
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) {
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-15 15:15:56 +00:00
|
|
|
const auto from = displayFrom();
|
|
|
|
_fromNameVersion = from ? from->nameVersion : 1;
|
|
|
|
}
|
|
|
|
|
2020-11-17 15:05:35 +00:00
|
|
|
bool HistoryMessage::checkRepliesPts(const MTPMessageReplies &data) const {
|
|
|
|
const auto channel = history()->peer->asChannel();
|
|
|
|
const auto pts = channel
|
|
|
|
? channel->pts()
|
|
|
|
: history()->session().updates().pts();
|
|
|
|
const auto repliesPts = data.match([&](const MTPDmessageReplies &data) {
|
|
|
|
return data.vreplies_pts().v;
|
|
|
|
});
|
|
|
|
return (repliesPts >= pts);
|
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
void HistoryMessage::setupForwardedComponent(const CreateConfig &config) {
|
|
|
|
const auto forwarded = Get<HistoryMessageForwarded>();
|
|
|
|
if (!forwarded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
forwarded->originalDate = config.originalDate;
|
|
|
|
forwarded->originalSender = config.senderOriginal
|
|
|
|
? history()->owner().peer(config.senderOriginal).get()
|
|
|
|
: nullptr;
|
|
|
|
if (!forwarded->originalSender) {
|
|
|
|
forwarded->hiddenSenderInfo = std::make_unique<HiddenSenderInfo>(
|
|
|
|
config.senderNameOriginal);
|
|
|
|
}
|
|
|
|
forwarded->originalId = config.originalId;
|
|
|
|
forwarded->originalAuthor = config.authorOriginal;
|
2020-04-28 19:49:55 +00:00
|
|
|
forwarded->psaType = config.forwardPsaType;
|
2019-03-15 15:15:56 +00:00
|
|
|
forwarded->savedFromPeer = history()->owner().peerLoaded(
|
|
|
|
config.savedFromPeer);
|
|
|
|
forwarded->savedFromMsgId = config.savedFromMsgId;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void HistoryMessage::refreshMedia(const MTPMessageMedia *media) {
|
2020-09-17 16:25:06 +00:00
|
|
|
const auto was = (_media != nullptr);
|
2018-01-14 16:02:25 +00:00
|
|
|
_media = nullptr;
|
2018-01-17 16:21:01 +00:00
|
|
|
if (media) {
|
|
|
|
setMedia(*media);
|
|
|
|
}
|
2020-09-17 16:25:06 +00:00
|
|
|
if (was || _media) {
|
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
|
|
|
refreshRepliesText(views);
|
|
|
|
}
|
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::refreshSentMedia(const MTPMessageMedia *media) {
|
2019-01-03 12:36:01 +00:00
|
|
|
const auto wasGrouped = history()->owner().groups().isGrouped(this);
|
2018-01-18 13:59:22 +00:00
|
|
|
refreshMedia(media);
|
2018-01-17 16:21:01 +00:00
|
|
|
if (wasGrouped) {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().groups().refreshMessage(this);
|
2018-03-25 22:01:13 +00:00
|
|
|
} else {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemViewRefresh(this);
|
2018-01-17 16:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-29 14:17:46 +00:00
|
|
|
void HistoryMessage::returnSavedMedia() {
|
2020-05-30 14:41:39 +00:00
|
|
|
if (!isEditingMedia()) {
|
2019-03-29 14:17:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto wasGrouped = history()->owner().groups().isGrouped(this);
|
2020-05-30 14:41:39 +00:00
|
|
|
_media = std::move(_savedLocalEditMediaData.media);
|
|
|
|
setText(_savedLocalEditMediaData.text);
|
|
|
|
clearSavedMedia();
|
2019-03-29 14:17:46 +00:00
|
|
|
if (wasGrouped) {
|
2019-04-01 10:58:51 +00:00
|
|
|
history()->owner().groups().refreshMessage(this, true);
|
2019-03-29 14:17:46 +00:00
|
|
|
} else {
|
|
|
|
history()->owner().requestItemViewRefresh(this);
|
2019-12-27 12:15:16 +00:00
|
|
|
history()->owner().updateDependentMessages(this);
|
2019-03-29 14:17:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
void HistoryMessage::setMedia(const MTPMessageMedia &media) {
|
|
|
|
_media = CreateMedia(this, media);
|
2018-01-18 11:04:50 +00:00
|
|
|
if (const auto invoice = _media ? _media->invoice() : nullptr) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (invoice->receiptMsgId) {
|
|
|
|
replaceBuyWithReceiptInMarkup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
|
|
|
|
not_null<HistoryMessage*> item,
|
|
|
|
const MTPMessageMedia &media) {
|
2018-12-17 08:16:06 +00:00
|
|
|
using Result = std::unique_ptr<Data::Media>;
|
|
|
|
return media.match([&](const MTPDmessageMediaContact &media) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaContact>(
|
|
|
|
item,
|
2019-07-05 13:38:38 +00:00
|
|
|
media.vuser_id().v,
|
|
|
|
qs(media.vfirst_name()),
|
|
|
|
qs(media.vlast_name()),
|
|
|
|
qs(media.vphone_number()));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [&](const MTPDmessageMediaGeo &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
return media.vgeo().match([&](const MTPDgeoPoint &point) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaLocation>(
|
|
|
|
item,
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint(point));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDgeoPointEmpty &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaGeoLive &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
return media.vgeo().match([&](const MTPDgeoPoint &point) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaLocation>(
|
|
|
|
item,
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint(point));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDgeoPointEmpty &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaVenue &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
return media.vgeo().match([&](const MTPDgeoPoint &point) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaLocation>(
|
|
|
|
item,
|
2019-06-21 12:27:46 +00:00
|
|
|
Data::LocationPoint(point),
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(media.vtitle()),
|
|
|
|
qs(media.vaddress()));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDgeoPointEmpty &data) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaPhoto &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto photo = media.vphoto();
|
|
|
|
if (media.vttl_seconds()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
LOG(("App Error: "
|
|
|
|
"Unexpected MTPMessageMediaPhoto "
|
|
|
|
"with ttl_seconds in HistoryMessage."));
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
2019-07-05 13:38:38 +00:00
|
|
|
} else if (!photo) {
|
2018-01-17 16:21:01 +00:00
|
|
|
LOG(("API Error: "
|
|
|
|
"Got MTPMessageMediaPhoto "
|
|
|
|
"without photo and without ttl_seconds."));
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
return photo->match([&](const MTPDphoto &photo) -> Result {
|
2018-12-17 08:16:06 +00:00
|
|
|
return std::make_unique<Data::MediaPhoto>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processPhoto(photo));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDphotoEmpty &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaDocument &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto document = media.vdocument();
|
|
|
|
if (media.vttl_seconds()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
LOG(("App Error: "
|
|
|
|
"Unexpected MTPMessageMediaDocument "
|
|
|
|
"with ttl_seconds in HistoryMessage."));
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
2019-07-05 13:38:38 +00:00
|
|
|
} else if (!document) {
|
2018-01-17 16:21:01 +00:00
|
|
|
LOG(("API Error: "
|
|
|
|
"Got MTPMessageMediaDocument "
|
|
|
|
"without document and without ttl_seconds."));
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
return document->match([&](const MTPDdocument &document) -> Result {
|
2018-12-17 08:16:06 +00:00
|
|
|
return std::make_unique<Data::MediaFile>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processDocument(document));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDdocumentEmpty &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaWebPage &media) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return media.vwebpage().match([](const MTPDwebPageEmpty &) -> Result {
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
|
|
|
}, [&](const MTPDwebPagePending &webpage) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaWebPage>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processWebpage(webpage));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [&](const MTPDwebPage &webpage) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaWebPage>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processWebpage(webpage));
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDwebPageNotModified &) -> Result {
|
2018-01-17 16:21:01 +00:00
|
|
|
LOG(("API Error: "
|
|
|
|
"webPageNotModified is unexpected in message media."));
|
2018-12-17 08:16:06 +00:00
|
|
|
return nullptr;
|
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaGame &media) -> Result {
|
2019-07-05 13:38:38 +00:00
|
|
|
return media.vgame().match([&](const MTPDgame &game) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<Data::MediaGame>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processGame(game));
|
2018-12-17 08:16:06 +00:00
|
|
|
});
|
|
|
|
}, [&](const MTPDmessageMediaInvoice &media) -> Result {
|
|
|
|
return std::make_unique<Data::MediaInvoice>(item, media);
|
2018-12-18 05:43:11 +00:00
|
|
|
}, [&](const MTPDmessageMediaPoll &media) -> Result {
|
|
|
|
return std::make_unique<Data::MediaPoll>(
|
|
|
|
item,
|
2019-01-18 12:27:37 +00:00
|
|
|
item->history()->owner().processPoll(media));
|
2020-03-04 09:21:19 +00:00
|
|
|
}, [&](const MTPDmessageMediaDice &media) -> Result {
|
2020-04-06 09:07:49 +00:00
|
|
|
return std::make_unique<Data::MediaDice>(
|
|
|
|
item,
|
|
|
|
qs(media.vemoticon()),
|
|
|
|
media.vvalue().v);
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDmessageMediaEmpty &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
}, [](const MTPDmessageMediaUnsupported &) -> Result {
|
|
|
|
return nullptr;
|
|
|
|
});
|
2018-01-17 16:21:01 +00:00
|
|
|
return nullptr;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 15:00:59 +00:00
|
|
|
void HistoryMessage::replaceBuyWithReceiptInMarkup() {
|
|
|
|
if (auto markup = inlineReplyMarkup()) {
|
|
|
|
for (auto &row : markup->rows) {
|
|
|
|
for (auto &button : row) {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (button.type == HistoryMessageMarkupButton::Type::Buy) {
|
2019-06-19 15:09:03 +00:00
|
|
|
button.text = tr::lng_payments_receipt_button(tr::now);
|
2017-03-06 15:00:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::applyEdition(const MTPDmessage &message) {
|
|
|
|
int keyboardTop = -1;
|
2018-01-13 12:45:11 +00:00
|
|
|
//if (!pendingResize()) {// #TODO edit bot message
|
|
|
|
// if (auto keyboard = inlineReplyKeyboard()) {
|
|
|
|
// int h = st::msgBotKbButton.margin + keyboard->naturalHeight();
|
|
|
|
// keyboardTop = _height - h + st::msgBotKbButton.margin - marginBottom();
|
|
|
|
// }
|
|
|
|
//}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-10-02 09:00:16 +00:00
|
|
|
const auto copyFlags = MTPDmessage::Flag::f_edit_hide;
|
|
|
|
_flags = (_flags & ~copyFlags) | (message.vflags().v & copyFlags);
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto editDate = message.vedit_date()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
_flags |= MTPDmessage::Flag::f_edit_date;
|
2017-12-16 16:32:10 +00:00
|
|
|
if (!Has<HistoryMessageEdited>()) {
|
|
|
|
AddComponents(HistoryMessageEdited::Bit());
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-16 16:32:10 +00:00
|
|
|
auto edited = Get<HistoryMessageEdited>();
|
2019-07-05 13:38:38 +00:00
|
|
|
edited->date = editDate->v;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto textWithEntities = TextWithEntities{
|
|
|
|
qs(message.vmessage()),
|
2020-06-08 08:03:45 +00:00
|
|
|
Api::EntitiesFromMTP(
|
|
|
|
&history()->session(),
|
|
|
|
message.ventities().value_or_empty())
|
2019-07-05 13:38:38 +00:00
|
|
|
};
|
|
|
|
setReplyMarkup(message.vreply_markup());
|
2019-04-04 10:22:59 +00:00
|
|
|
if (!isLocalUpdateMedia()) {
|
2019-07-05 13:38:38 +00:00
|
|
|
refreshMedia(message.vmedia());
|
2019-03-31 20:45:55 +00:00
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
setViewsCount(message.vviews().value_or(-1));
|
2020-09-01 06:44:18 +00:00
|
|
|
setForwardsCount(message.vforwards().value_or(-1));
|
2020-05-04 13:03:33 +00:00
|
|
|
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
|
2020-10-05 13:20:55 +00:00
|
|
|
if (const auto replies = message.vreplies()) {
|
2020-11-17 15:05:35 +00:00
|
|
|
if (checkRepliesPts(*replies)) {
|
|
|
|
setReplies(*replies);
|
|
|
|
}
|
2020-10-05 13:20:55 +00:00
|
|
|
} else {
|
|
|
|
clearReplies();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
finishEdition(keyboardTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::applyEdition(const MTPDmessageService &message) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (message.vaction().type() == mtpc_messageActionHistoryClear) {
|
2019-04-08 09:16:45 +00:00
|
|
|
setReplyMarkup(nullptr);
|
|
|
|
refreshMedia(nullptr);
|
|
|
|
setEmptyText();
|
|
|
|
setViewsCount(-1);
|
2020-09-01 06:44:18 +00:00
|
|
|
setForwardsCount(-1);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-04-08 09:16:45 +00:00
|
|
|
finishEditionToEmpty();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 14:38:26 +00:00
|
|
|
void HistoryMessage::updateSentContent(
|
|
|
|
const TextWithEntities &textWithEntities,
|
|
|
|
const MTPMessageMedia *media) {
|
|
|
|
const auto isolated = isolatedEmoji();
|
|
|
|
setText(textWithEntities);
|
2019-08-09 19:19:23 +00:00
|
|
|
if (_clientFlags & MTPDmessage_ClientFlag::f_from_inline_bot) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (!media || !_media || !_media->updateInlineResultMedia(*media)) {
|
2018-01-18 13:59:22 +00:00
|
|
|
refreshSentMedia(media);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags &= ~MTPDmessage_ClientFlag::f_from_inline_bot;
|
2019-08-07 14:38:26 +00:00
|
|
|
} else if (media || _media || !isolated || isolated != isolatedEmoji()) {
|
2019-04-04 10:22:59 +00:00
|
|
|
if (!media || !_media || !_media->updateSentMedia(*media)) {
|
2018-01-18 13:59:22 +00:00
|
|
|
refreshSentMedia(media);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
void HistoryMessage::updateForwardedInfo(const MTPMessageFwdHeader *fwd) {
|
|
|
|
const auto forwarded = Get<HistoryMessageForwarded>();
|
|
|
|
if (!fwd) {
|
|
|
|
if (forwarded) {
|
|
|
|
LOG(("API Error: Server removed forwarded information."));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (!forwarded) {
|
|
|
|
LOG(("API Error: Server added forwarded information."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fwd->match([&](const MTPDmessageFwdHeader &data) {
|
|
|
|
auto config = CreateConfig();
|
|
|
|
FillForwardedInfo(config, data);
|
|
|
|
setupForwardedComponent(config);
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-20 09:42:13 +00:00
|
|
|
void HistoryMessage::contributeToSlowmode(TimeId realDate) {
|
|
|
|
if (const auto channel = history()->peer->asChannel()) {
|
|
|
|
if (out() && IsServerMsgId(id)) {
|
|
|
|
channel->growSlowmodeLastMessage(realDate ? realDate : date());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void HistoryMessage::addToUnreadMentions(UnreadMentionType type) {
|
2018-12-26 10:28:24 +00:00
|
|
|
if (IsServerMsgId(id) && isUnreadMention()) {
|
2017-12-21 12:11:33 +00:00
|
|
|
if (history()->addToUnreadMentions(id, type)) {
|
2020-06-12 12:12:34 +00:00
|
|
|
history()->session().changes().historyUpdated(
|
|
|
|
history(),
|
|
|
|
Data::HistoryUpdate::Flag::UnreadMentions);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void HistoryMessage::destroyHistoryEntry() {
|
2018-12-26 10:28:24 +00:00
|
|
|
if (isUnreadMention()) {
|
2017-08-11 07:16:07 +00:00
|
|
|
history()->eraseFromUnreadMentions(id);
|
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2020-09-03 08:42:25 +00:00
|
|
|
changeReplyToTopCounter(reply, -1);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-09-04 11:40:02 +00:00
|
|
|
Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const {
|
|
|
|
auto result = Storage::SharedMediaTypesMask {};
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto media = this->media()) {
|
2017-09-04 11:40:02 +00:00
|
|
|
result.set(media->sharedMediaTypes());
|
|
|
|
}
|
|
|
|
if (hasTextLinks()) {
|
|
|
|
result.set(Storage::SharedMediaType::Link);
|
|
|
|
}
|
2020-10-20 16:29:24 +00:00
|
|
|
if (isPinned()) {
|
|
|
|
result.set(Storage::SharedMediaType::Pinned);
|
|
|
|
}
|
2017-09-04 11:40:02 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-12-27 10:41:30 +00:00
|
|
|
bool HistoryMessage::generateLocalEntitiesByReply() const {
|
|
|
|
return !_media || _media->webpage();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities HistoryMessage::withLocalEntities(
|
|
|
|
const TextWithEntities &textWithEntities) const {
|
|
|
|
if (!generateLocalEntitiesByReply()) {
|
|
|
|
return textWithEntities;
|
|
|
|
}
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2019-12-27 12:15:16 +00:00
|
|
|
const auto document = reply->replyToDocumentId
|
|
|
|
? history()->owner().document(reply->replyToDocumentId).get()
|
|
|
|
: nullptr;
|
|
|
|
if (document && (document->isVideoFile() || document->isSong())) {
|
|
|
|
using namespace HistoryView;
|
|
|
|
const auto duration = document->getDuration();
|
|
|
|
const auto base = (duration > 0)
|
|
|
|
? DocumentTimestampLinkBase(
|
|
|
|
document,
|
|
|
|
reply->replyToMsg->fullId())
|
|
|
|
: QString();
|
|
|
|
if (!base.isEmpty()) {
|
|
|
|
return AddTimestampLinks(
|
|
|
|
textWithEntities,
|
|
|
|
duration,
|
|
|
|
base);
|
2019-12-27 10:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return textWithEntities;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
|
2020-06-09 09:36:40 +00:00
|
|
|
for (const auto &entity : textWithEntities.entities) {
|
2016-09-27 14:20:49 +00:00
|
|
|
auto type = entity.type();
|
2019-04-08 15:10:06 +00:00
|
|
|
if (type == EntityType::Url
|
|
|
|
|| type == EntityType::CustomUrl
|
|
|
|
|| type == EntityType::Email) {
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags |= MTPDmessage_ClientFlag::f_has_text_links;
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-28 11:38:35 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
if (_media && _media->consumeMessageText(textWithEntities)) {
|
2016-09-28 11:38:35 +00:00
|
|
|
setEmptyText();
|
2019-08-12 10:37:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-09 09:36:40 +00:00
|
|
|
|
2019-08-12 10:37:01 +00:00
|
|
|
clearIsolatedEmoji();
|
2020-11-10 16:38:21 +00:00
|
|
|
const auto context = Core::MarkedTextContext{
|
2020-06-09 09:36:40 +00:00
|
|
|
.session = &history()->session()
|
|
|
|
};
|
2019-08-12 10:37:01 +00:00
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
2019-12-27 10:41:30 +00:00
|
|
|
withLocalEntities(textWithEntities),
|
2020-06-09 09:36:40 +00:00
|
|
|
Ui::ItemTextOptions(this),
|
|
|
|
context);
|
2019-08-12 10:37:01 +00:00
|
|
|
if (!textWithEntities.text.isEmpty() && _text.isEmpty()) {
|
|
|
|
// If server has allowed some text that we've trim-ed entirely,
|
|
|
|
// just replace it with something so that UI won't look buggy.
|
2018-01-14 16:02:25 +00:00
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
2020-05-04 13:03:33 +00:00
|
|
|
EnsureNonEmpty(),
|
2018-01-14 16:02:25 +00:00
|
|
|
Ui::ItemTextOptions(this));
|
2019-08-12 10:37:01 +00:00
|
|
|
} else if (!_media) {
|
|
|
|
checkIsolatedEmoji();
|
2016-09-28 11:38:35 +00:00
|
|
|
}
|
2020-06-09 09:36:40 +00:00
|
|
|
|
2019-08-12 10:37:01 +00:00
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 10:41:30 +00:00
|
|
|
void HistoryMessage::reapplyText() {
|
|
|
|
setText(originalText());
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::setEmptyText() {
|
2019-08-12 10:37:01 +00:00
|
|
|
clearIsolatedEmoji();
|
2017-12-28 13:06:06 +00:00
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
|
|
|
{ QString(), EntitiesInText() },
|
|
|
|
Ui::ItemTextOptions(this));
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
|
|
|
}
|
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
void HistoryMessage::clearIsolatedEmoji() {
|
2019-08-09 19:19:23 +00:00
|
|
|
if (!(_clientFlags & MTPDmessage_ClientFlag::f_isolated_emoji)) {
|
2019-08-01 21:14:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
history()->session().emojiStickersPack().remove(this);
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags &= ~MTPDmessage_ClientFlag::f_isolated_emoji;
|
2019-08-01 21:14:19 +00:00
|
|
|
}
|
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
void HistoryMessage::checkIsolatedEmoji() {
|
|
|
|
if (history()->session().emojiStickersPack().add(this)) {
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags |= MTPDmessage_ClientFlag::f_isolated_emoji;
|
2019-08-01 21:14:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::setReplyMarkup(const MTPReplyMarkup *markup) {
|
2020-06-27 15:53:30 +00:00
|
|
|
const auto requestUpdate = [&] {
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
history()->session().changes().messageUpdated(
|
|
|
|
this,
|
|
|
|
Data::MessageUpdate::Flag::ReplyMarkup);
|
|
|
|
};
|
2016-09-27 14:20:49 +00:00
|
|
|
if (!markup) {
|
|
|
|
if (_flags & MTPDmessage::Flag::f_reply_markup) {
|
|
|
|
_flags &= ~MTPDmessage::Flag::f_reply_markup;
|
|
|
|
if (Has<HistoryMessageReplyMarkup>()) {
|
|
|
|
RemoveComponents(HistoryMessageReplyMarkup::Bit());
|
|
|
|
}
|
2020-06-27 15:53:30 +00:00
|
|
|
requestUpdate();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// optimization: don't create markup component for the case
|
|
|
|
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
2019-07-05 13:38:38 +00:00
|
|
|
if (markup->type() == mtpc_replyKeyboardHide && markup->c_replyKeyboardHide().vflags().v == 0) {
|
2016-09-27 14:20:49 +00:00
|
|
|
bool changed = false;
|
|
|
|
if (Has<HistoryMessageReplyMarkup>()) {
|
|
|
|
RemoveComponents(HistoryMessageReplyMarkup::Bit());
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) {
|
|
|
|
_flags |= MTPDmessage::Flag::f_reply_markup;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (changed) {
|
2020-06-27 15:53:30 +00:00
|
|
|
requestUpdate();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) {
|
|
|
|
_flags |= MTPDmessage::Flag::f_reply_markup;
|
|
|
|
}
|
|
|
|
if (!Has<HistoryMessageReplyMarkup>()) {
|
|
|
|
AddComponents(HistoryMessageReplyMarkup::Bit());
|
|
|
|
}
|
|
|
|
Get<HistoryMessageReplyMarkup>()->create(*markup);
|
2020-06-27 15:53:30 +00:00
|
|
|
requestUpdate();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
Ui::Text::IsolatedEmoji HistoryMessage::isolatedEmoji() const {
|
|
|
|
return _text.toIsolatedEmoji();
|
2019-08-01 21:14:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
TextWithEntities HistoryMessage::originalText() const {
|
|
|
|
if (emptyText()) {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
2019-04-08 11:53:08 +00:00
|
|
|
return _text.toTextWithEntities();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextForMimeData HistoryMessage::clipboardText() const {
|
2018-01-26 15:40:11 +00:00
|
|
|
if (emptyText()) {
|
2019-04-08 15:10:06 +00:00
|
|
|
return TextForMimeData();
|
2018-01-26 15:40:11 +00:00
|
|
|
}
|
2019-04-08 15:10:06 +00:00
|
|
|
return _text.toTextForMimeData();
|
2018-01-26 15:40:11 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
bool HistoryMessage::textHasLinks() const {
|
|
|
|
return emptyText() ? false : _text.hasLinks();
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void HistoryMessage::setViewsCount(int count) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views
|
2020-09-03 07:19:02 +00:00
|
|
|
|| views->views.count == count
|
|
|
|
|| (count >= 0 && views->views.count > count)) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
views->views.count = count;
|
|
|
|
views->views.text = Lang::FormatCountToShort(
|
|
|
|
std::max(views->views.count, 1)
|
|
|
|
).string;
|
|
|
|
const auto was = views->views.textWidth;
|
|
|
|
views->views.textWidth = views->views.text.isEmpty()
|
2020-09-01 06:44:18 +00:00
|
|
|
? 0
|
2020-09-03 07:19:02 +00:00
|
|
|
: st::msgDateFont->width(views->views.text);
|
|
|
|
if (was == views->views.textWidth) {
|
2020-09-01 06:44:18 +00:00
|
|
|
history()->owner().requestItemRepaint(this);
|
|
|
|
} else {
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setForwardsCount(int count) {
|
|
|
|
}
|
|
|
|
|
2020-10-06 07:23:58 +00:00
|
|
|
void HistoryMessage::setPostAuthor(const QString &author) {
|
|
|
|
auto msgsigned = Get<HistoryMessageSigned>();
|
|
|
|
if (author.isEmpty()) {
|
|
|
|
if (!msgsigned) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RemoveComponents(HistoryMessageSigned::Bit());
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!msgsigned) {
|
|
|
|
AddComponents(HistoryMessageSigned::Bit());
|
|
|
|
msgsigned = Get<HistoryMessageSigned>();
|
|
|
|
} else if (msgsigned->author == author) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msgsigned->author = author;
|
|
|
|
msgsigned->isAnonymousRank = !isDiscussionPost()
|
|
|
|
&& this->author()->isMegagroup();
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
}
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
void HistoryMessage::setReplies(const MTPMessageReplies &data) {
|
|
|
|
data.match([&](const MTPDmessageReplies &data) {
|
|
|
|
auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views) {
|
|
|
|
AddComponents(HistoryMessageViews::Bit());
|
|
|
|
views = Get<HistoryMessageViews>();
|
|
|
|
}
|
|
|
|
const auto repliers = [&] {
|
2020-09-03 11:53:54 +00:00
|
|
|
auto result = std::vector<PeerId>();
|
2020-09-03 07:19:02 +00:00
|
|
|
if (const auto list = data.vrecent_repliers()) {
|
|
|
|
result.reserve(list->v.size());
|
|
|
|
for (const auto &id : list->v) {
|
2020-09-03 11:53:54 +00:00
|
|
|
result.push_back(peerFromMTP(id));
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}();
|
|
|
|
const auto count = data.vreplies().v;
|
|
|
|
const auto channelId = data.vchannel_id().value_or_empty();
|
2020-09-22 11:01:49 +00:00
|
|
|
const auto readTillId = data.vread_max_id()
|
|
|
|
? std::max(
|
|
|
|
{ views->repliesInboxReadTillId, data.vread_max_id()->v, 1 })
|
|
|
|
: views->repliesInboxReadTillId;
|
|
|
|
const auto maxId = data.vmax_id().value_or(views->repliesMaxId);
|
|
|
|
const auto countsChanged = (views->replies.count != count)
|
|
|
|
|| (views->repliesInboxReadTillId != readTillId)
|
|
|
|
|| (views->repliesMaxId != maxId);
|
|
|
|
const auto megagroupChanged = (views->commentsMegagroupId != channelId);
|
2020-09-03 07:19:02 +00:00
|
|
|
const auto recentChanged = (views->recentRepliers != repliers);
|
2020-09-22 11:01:49 +00:00
|
|
|
if (!countsChanged && !megagroupChanged && !recentChanged) {
|
2020-09-01 06:44:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
views->replies.count = count;
|
|
|
|
if (recentChanged) {
|
|
|
|
views->recentRepliers = repliers;
|
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
views->commentsMegagroupId = channelId;
|
|
|
|
const auto wasUnread = channelId && areRepliesUnread();
|
|
|
|
views->repliesInboxReadTillId = readTillId;
|
|
|
|
views->repliesMaxId = maxId;
|
|
|
|
if (channelId && wasUnread != areRepliesUnread()) {
|
2020-09-15 08:39:39 +00:00
|
|
|
history()->owner().requestItemRepaint(this);
|
|
|
|
}
|
2020-09-22 11:01:49 +00:00
|
|
|
refreshRepliesText(views, megagroupChanged);
|
2020-09-03 07:19:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-01 08:34:59 +00:00
|
|
|
void HistoryMessage::clearReplies() {
|
|
|
|
auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto viewsPart = views->views;
|
|
|
|
if (viewsPart.count < 0) {
|
|
|
|
RemoveComponents(HistoryMessageViews::Bit());
|
|
|
|
} else {
|
|
|
|
*views = HistoryMessageViews();
|
|
|
|
views->views = viewsPart;
|
|
|
|
}
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
}
|
|
|
|
|
2020-09-03 07:19:02 +00:00
|
|
|
void HistoryMessage::refreshRepliesText(
|
|
|
|
not_null<HistoryMessageViews*> views,
|
|
|
|
bool forceResize) {
|
|
|
|
const auto was = views->replies.textWidth;
|
2020-09-22 11:01:49 +00:00
|
|
|
if (views->commentsMegagroupId) {
|
2020-09-03 07:19:02 +00:00
|
|
|
views->replies.text = (views->replies.count > 0)
|
|
|
|
? tr::lng_comments_open_count(
|
|
|
|
tr::now,
|
|
|
|
lt_count_short,
|
|
|
|
views->replies.count)
|
|
|
|
: tr::lng_comments_open_none(tr::now);
|
|
|
|
views->replies.textWidth = st::semiboldFont->width(
|
|
|
|
views->replies.text);
|
2020-09-17 16:25:06 +00:00
|
|
|
views->repliesSmall.text = (views->replies.count > 0)
|
|
|
|
? Lang::FormatCountToShort(views->replies.count).string
|
|
|
|
: QString();
|
|
|
|
views->repliesSmall.textWidth = st::semiboldFont->width(
|
|
|
|
views->repliesSmall.text);
|
2020-09-03 07:19:02 +00:00
|
|
|
} else {
|
|
|
|
views->replies.text = (views->replies.count > 0)
|
|
|
|
? Lang::FormatCountToShort(views->replies.count).string
|
|
|
|
: QString();
|
|
|
|
views->replies.textWidth = views->replies.text.isEmpty()
|
|
|
|
? 0
|
|
|
|
: st::msgDateFont->width(views->replies.text);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
if (forceResize || views->replies.textWidth != was) {
|
2020-09-01 06:44:18 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2020-09-03 07:19:02 +00:00
|
|
|
} else {
|
|
|
|
history()->owner().requestItemRepaint(this);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
}
|
2020-09-01 06:44:18 +00:00
|
|
|
|
2020-09-03 11:53:54 +00:00
|
|
|
void HistoryMessage::changeRepliesCount(int delta, PeerId replier) {
|
2020-09-03 07:19:02 +00:00
|
|
|
const auto views = Get<HistoryMessageViews>();
|
|
|
|
const auto limit = HistoryMessageViews::kMaxRecentRepliers;
|
|
|
|
if (!views || views->replies.count < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
views->replies.count = std::max(views->replies.count + delta, 0);
|
2020-09-22 11:01:49 +00:00
|
|
|
if (replier && views->commentsMegagroupId) {
|
2020-09-03 07:19:02 +00:00
|
|
|
if (delta < 0) {
|
|
|
|
views->recentRepliers.erase(
|
|
|
|
ranges::remove(views->recentRepliers, replier),
|
|
|
|
end(views->recentRepliers));
|
|
|
|
} else if (!ranges::contains(views->recentRepliers, replier)) {
|
|
|
|
views->recentRepliers.insert(views->recentRepliers.begin(), replier);
|
|
|
|
while (views->recentRepliers.size() > limit) {
|
|
|
|
views->recentRepliers.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2020-09-03 07:19:02 +00:00
|
|
|
refreshRepliesText(views);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
void HistoryMessage::setReplyToTop(MsgId replyToTop) {
|
|
|
|
const auto reply = Get<HistoryMessageReply>();
|
|
|
|
if (!reply
|
|
|
|
|| (reply->replyToMsgTop == replyToTop)
|
|
|
|
|| (reply->replyToMsgTop != 0)
|
|
|
|
|| isScheduled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reply->replyToMsgTop = replyToTop;
|
2020-09-03 08:42:25 +00:00
|
|
|
changeReplyToTopCounter(reply, 1);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void HistoryMessage::setRealId(MsgId newId) {
|
|
|
|
HistoryItem::setRealId(newId);
|
2018-06-28 15:20:05 +00:00
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().groups().refreshMessage(this);
|
|
|
|
history()->owner().requestItemResize(this);
|
2018-06-04 16:58:35 +00:00
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
if (reply->replyToLink()) {
|
|
|
|
reply->setReplyToLinkFrom(this);
|
|
|
|
}
|
2020-09-03 08:42:25 +00:00
|
|
|
changeReplyToTopCounter(reply, 1);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::incrementReplyToTopCounter() {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2020-09-03 08:42:25 +00:00
|
|
|
changeReplyToTopCounter(reply, 1);
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 08:42:25 +00:00
|
|
|
void HistoryMessage::changeReplyToTopCounter(
|
|
|
|
not_null<HistoryMessageReply*> reply,
|
|
|
|
int delta) {
|
2020-09-01 06:44:18 +00:00
|
|
|
if (!IsServerMsgId(id) || !reply->replyToTop()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-09-03 08:42:25 +00:00
|
|
|
const auto channelId = history()->channelId();
|
|
|
|
if (!channelId) {
|
|
|
|
return;
|
2020-09-01 06:44:18 +00:00
|
|
|
}
|
2020-09-03 08:42:25 +00:00
|
|
|
const auto top = history()->owner().message(
|
|
|
|
channelId,
|
|
|
|
reply->replyToTop());
|
|
|
|
if (!top) {
|
2020-09-01 06:44:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-09-03 08:42:25 +00:00
|
|
|
const auto changeFor = [&](not_null<HistoryItem*> item) {
|
|
|
|
if (const auto from = displayFrom()) {
|
2020-09-03 11:53:54 +00:00
|
|
|
item->changeRepliesCount(delta, from->id);
|
|
|
|
return;
|
2020-09-03 08:42:25 +00:00
|
|
|
}
|
2020-09-03 11:53:54 +00:00
|
|
|
item->changeRepliesCount(delta, PeerId());
|
2020-09-03 08:42:25 +00:00
|
|
|
};
|
|
|
|
if (const auto views = top->Get<HistoryMessageViews>()) {
|
2020-09-22 11:01:49 +00:00
|
|
|
if (views->commentsMegagroupId) {
|
2020-09-03 08:42:25 +00:00
|
|
|
// This is a post in channel, we don't track its replies.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
changeFor(top);
|
2020-09-15 08:39:39 +00:00
|
|
|
if (const auto original = top->lookupDiscussionPostOriginal()) {
|
|
|
|
changeFor(original);
|
2018-06-04 16:58:35 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) {
|
2019-12-27 10:41:30 +00:00
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2019-12-27 12:15:16 +00:00
|
|
|
const auto documentId = reply->replyToDocumentId;
|
2016-09-27 14:20:49 +00:00
|
|
|
reply->itemRemoved(this, dependency);
|
2019-12-27 12:15:16 +00:00
|
|
|
if (documentId != reply->replyToDocumentId
|
2019-12-27 10:41:30 +00:00
|
|
|
&& generateLocalEntitiesByReply()) {
|
|
|
|
reapplyText();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HistoryMessage::notificationHeader() const {
|
2019-08-28 18:20:49 +00:00
|
|
|
if (out() && isFromScheduled() && !_history->peer->isSelf()) {
|
2019-08-28 14:24:12 +00:00
|
|
|
return tr::lng_from_you(tr::now);
|
|
|
|
} else if (!_history->peer->isUser() && !isPost()) {
|
2019-09-13 06:06:02 +00:00
|
|
|
return from()->name;
|
2019-08-28 14:24:12 +00:00
|
|
|
}
|
|
|
|
return QString();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
std::unique_ptr<HistoryView::Element> HistoryMessage::createView(
|
2020-06-16 16:53:44 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
|
|
|
HistoryView::Element *replacing) {
|
|
|
|
return delegate->elementCreate(this, replacing);
|
2018-01-11 19:33:26 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
HistoryMessage::~HistoryMessage() {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media.reset();
|
2020-05-30 14:41:39 +00:00
|
|
|
clearSavedMedia();
|
2016-09-27 14:20:49 +00:00
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->clearData(this);
|
|
|
|
}
|
|
|
|
}
|