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"
|
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-04-04 10:02:22 +00:00
|
|
|
#include "history/view/history_view_context_menu.h" // For CopyPostLink().
|
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"
|
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"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.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-08-11 07:16:07 +00:00
|
|
|
#include "observer_peer.h"
|
2017-09-04 11:40:02 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.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"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
#include "styles/style_history.h"
|
|
|
|
#include "styles/style_window.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-06-21 08:53:14 +00:00
|
|
|
constexpr auto kPinnedMessageTextLimit = 16;
|
|
|
|
|
2017-12-01 10:21:40 +00:00
|
|
|
MTPDmessage::Flags NewForwardedFlags(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
UserId from,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags NewForwardedClientFlags() {
|
|
|
|
return NewMessageClientFlags();
|
|
|
|
}
|
|
|
|
|
2019-05-25 14:42:01 +00:00
|
|
|
bool CopyMarkupToForward(not_null<const HistoryItem*> item) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
bool HasInlineItems(const HistoryItemsList &items) {
|
|
|
|
for (const auto item : items) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (item->viaBot()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-07-18 10:03:09 +00:00
|
|
|
QString GetErrorTextForForward(
|
|
|
|
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,
|
|
|
|
formatDurationWords(left));
|
|
|
|
}
|
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();
|
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));
|
|
|
|
const auto isGroup = (owner->groups().find(item) != nullptr);
|
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()) {
|
2019-04-04 10:02:22 +00:00
|
|
|
HistoryView::CopyPostLink(item->fullId());
|
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()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
const auto link = Core::App().createInternalLinkFull(
|
2018-11-26 11:55:02 +00:00
|
|
|
bot->username
|
|
|
|
+ qsl("?game=")
|
|
|
|
+ game->shortName);
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(link);
|
|
|
|
|
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 = [=](
|
|
|
|
QVector<PeerData*> &&result,
|
2019-07-26 16:06:22 +00:00
|
|
|
TextWithTags &&comment,
|
|
|
|
bool silent) {
|
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) {
|
|
|
|
const auto error = GetErrorTextForForward(
|
|
|
|
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(
|
|
|
|
Ui::Text::Bold(App::peerName(error.second))
|
|
|
|
).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),
|
2017-09-15 17:34:41 +00:00
|
|
|
LayerOption::KeepOther);
|
2017-07-11 17:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
auto doneCallback = [=](const MTPUpdates &updates, mtpRequestId requestId) {
|
|
|
|
history->session().api().applyUpdates(updates);
|
2017-07-11 17:11:06 +00:00
|
|
|
data->requests.remove(requestId);
|
|
|
|
if (data->requests.empty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::Toast::Show(tr::lng_share_done(tr::now));
|
2017-07-11 17:11:06 +00:00
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-18 13:29:48 +00:00
|
|
|
const auto sendFlags = MTPmessages_ForwardMessages::Flag(0)
|
|
|
|
| MTPmessages_ForwardMessages::Flag::f_with_my_score
|
|
|
|
| (isGroup
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_grouped
|
2019-07-26 16:06:22 +00:00
|
|
|
: MTPmessages_ForwardMessages::Flag(0))
|
|
|
|
| (silent
|
|
|
|
? MTPmessages_ForwardMessages::Flag::f_silent
|
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;
|
|
|
|
};
|
2018-11-26 11:55:02 +00:00
|
|
|
for (const auto peer : result) {
|
2019-01-18 12:27:37 +00:00
|
|
|
const auto history = peer->owner().history(peer);
|
2018-11-26 11:55:02 +00:00
|
|
|
if (!comment.text.isEmpty()) {
|
|
|
|
auto message = ApiWrap::MessageToSend(history);
|
|
|
|
message.textWithTags = comment;
|
|
|
|
message.clearDraft = false;
|
2019-01-03 12:36:01 +00:00
|
|
|
history->session().api().sendMessage(std::move(message));
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
2018-11-26 11:55:02 +00:00
|
|
|
history->sendRequestId = MTP::send(
|
2019-08-08 10:15:59 +00:00
|
|
|
MTPmessages_ForwardMessages(
|
|
|
|
MTP_flags(sendFlags),
|
|
|
|
data->peer->input,
|
|
|
|
MTP_vector<MTPint>(msgIds),
|
|
|
|
MTP_vector<MTPlong>(generateRandom()),
|
|
|
|
peer->input,
|
|
|
|
MTP_int(0)),
|
2018-11-26 11:55:02 +00:00
|
|
|
rpcDone(base::duplicate(doneCallback)),
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
history->sendRequestId);
|
|
|
|
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(
|
2017-12-18 15:44:50 +00:00
|
|
|
const FullMsgId &msgId) {
|
2017-06-22 15:11:41 +00:00
|
|
|
return [dependent = msgId](ChannelData *channel, MsgId msgId) {
|
2019-07-24 11:13:51 +00:00
|
|
|
if (const auto item = Auth().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;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags NewMessageClientFlags() {
|
|
|
|
return MTPDmessage_ClientFlag::f_sending;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
QString GetErrorTextForForward(
|
|
|
|
not_null<PeerData*> peer,
|
2019-07-18 16:09:50 +00:00
|
|
|
const HistoryItemsList &items,
|
|
|
|
bool ignoreSlowmodeCountdown) {
|
|
|
|
return GetErrorTextForForward(peer, items, {}, ignoreSlowmodeCountdown);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
struct HistoryMessage::CreateConfig {
|
|
|
|
MsgId replyTo = 0;
|
|
|
|
UserId viaBotId = 0;
|
|
|
|
int viewsCount = -1;
|
|
|
|
QString author;
|
|
|
|
PeerId senderOriginal = 0;
|
2019-03-15 15:15:56 +00:00
|
|
|
QString senderNameOriginal;
|
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.
|
|
|
|
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) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (const auto channelId = data.vchannel_id()) {
|
|
|
|
config.senderOriginal = peerFromChannel(*channelId);
|
|
|
|
} else if (const auto fromId = data.vfrom_id()) {
|
|
|
|
config.senderOriginal = peerFromUser(*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());
|
|
|
|
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,
|
|
|
|
data.vfrom_id().value_or_empty()) {
|
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
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
config.replyTo = data.vreply_to_msg_id().value_or_empty();
|
|
|
|
config.viaBotId = data.vvia_bot_id().value_or_empty();
|
|
|
|
config.viewsCount = data.vviews().value_or(-1);
|
|
|
|
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
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
setText({
|
|
|
|
TextUtilities::Clean(qs(data.vmessage())),
|
|
|
|
TextUtilities::EntitiesFromMTP(data.ventities().value_or_empty())
|
|
|
|
});
|
|
|
|
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
|
|
|
}
|
2019-07-19 15:05:48 +00:00
|
|
|
|
|
|
|
refreshMessageBadge();
|
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,
|
|
|
|
data.vfrom_id().value_or_empty()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
auto config = CreateConfig();
|
2017-04-27 21:17:00 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
config.replyTo = data.vreply_to_msg_id().value_or_empty();
|
2017-04-27 21:17:00 +00:00
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
switch (data.vaction().type()) {
|
2017-04-27 21:17:00 +00:00
|
|
|
case mtpc_messageActionPhoneCall: {
|
2018-01-14 16:02:25 +00:00
|
|
|
_media = std::make_unique<Data::MediaCall>(
|
|
|
|
this,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vaction().c_messageActionPhoneCall());
|
2017-04-27 21:17:00 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: Unexpected("Service message action type in HistoryMessage.");
|
|
|
|
}
|
|
|
|
|
|
|
|
setText(TextWithEntities {});
|
|
|
|
}
|
|
|
|
|
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,
|
2017-12-05 16:14:28 +00:00
|
|
|
UserId from,
|
|
|
|
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;
|
2019-06-19 14:52:18 +00:00
|
|
|
} else if (isPost()
|
|
|
|
|| (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,
|
2017-12-13 18:10:48 +00:00
|
|
|
UserId from,
|
|
|
|
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,
|
2017-12-13 18:10:48 +00:00
|
|
|
UserId from,
|
|
|
|
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,
|
2017-12-13 18:10:48 +00:00
|
|
|
UserId from,
|
|
|
|
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,
|
2017-12-13 18:10:48 +00:00
|
|
|
UserId from,
|
|
|
|
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);
|
2016-09-28 16:23:25 +00:00
|
|
|
setText(TextWithEntities());
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (flags & MTPDmessage::Flag::f_reply_to_msg_id) config.replyTo = replyTo;
|
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;
|
2016-09-27 14:20:49 +00:00
|
|
|
if (isPost()) config.viewsCount = 1;
|
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
int HistoryMessage::viewsCount() const {
|
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
|
|
|
return views->_views;
|
|
|
|
}
|
|
|
|
return HistoryItem::viewsCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryMessage::updateDependencyItem() {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
return reply->updateData(this, true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-19 15:05:48 +00:00
|
|
|
void HistoryMessage::refreshMessageBadge() {
|
|
|
|
const auto text = [&] {
|
|
|
|
if (isDiscussionPost()) {
|
|
|
|
return tr::lng_channel_badge(tr::now);
|
|
|
|
}
|
2019-07-19 13:34:09 +00:00
|
|
|
const auto channel = history()->peer->asMegagroup();
|
|
|
|
const auto user = author()->asUser();
|
|
|
|
if (!channel || !user) {
|
|
|
|
return QString();
|
2017-12-01 18:38:44 +00:00
|
|
|
}
|
2019-07-19 13:34:09 +00:00
|
|
|
const auto info = channel->mgInfo.get();
|
|
|
|
const auto i = channel->mgInfo->admins.find(peerToUser(user->id));
|
2019-07-23 09:06:31 +00:00
|
|
|
const auto custom = (i != channel->mgInfo->admins.end())
|
|
|
|
? i->second
|
|
|
|
: (info->creator == user)
|
|
|
|
? info->creatorRank
|
|
|
|
: QString();
|
|
|
|
return !custom.isEmpty()
|
|
|
|
? custom
|
|
|
|
: (info->creator == user)
|
|
|
|
? tr::lng_owner_badge(tr::now)
|
|
|
|
: (i != channel->mgInfo->admins.end())
|
2019-07-19 13:34:09 +00:00
|
|
|
? tr::lng_admin_badge(tr::now)
|
2019-07-23 09:06:31 +00:00
|
|
|
: QString();
|
2017-12-01 18:38:44 +00:00
|
|
|
}();
|
2019-07-19 15:05:48 +00:00
|
|
|
if (text.isEmpty()) {
|
|
|
|
_messageBadge.clear();
|
|
|
|
} else {
|
|
|
|
_messageBadge.setText(
|
|
|
|
st::defaultTextStyle,
|
2019-07-28 13:39:06 +00:00
|
|
|
TextUtilities::RemoveEmoji(TextUtilities::SingleLine(text)));
|
2019-07-19 15:05:48 +00:00
|
|
|
}
|
2017-12-01 18:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::applyGroupAdminChanges(
|
2019-07-19 13:34:09 +00:00
|
|
|
const base::flat_set<UserId> &changes) {
|
|
|
|
if (!out() && changes.contains(peerToUser(author()->id))) {
|
2019-07-19 15:05:48 +00:00
|
|
|
refreshMessageBadge();
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2017-12-01 18:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return isScheduled();
|
|
|
|
}
|
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
bool HistoryMessage::isTooOldForEdit(TimeId now) const {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto peer = _history->peer;
|
2018-12-19 11:20:04 +00:00
|
|
|
if (peer->isSelf()) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return false;
|
2018-12-19 11:20:04 +00:00
|
|
|
} else if (const auto megagroup = peer->asMegagroup()) {
|
|
|
|
if (megagroup->canPinMessages()) {
|
|
|
|
return false;
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-19 11:20:04 +00:00
|
|
|
return (now - date() >= Global::EditTimeLimit());
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
if (config.viewsCount >= 0) {
|
|
|
|
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();
|
|
|
|
}
|
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>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
reply->replyToMsgId = config.replyTo;
|
2017-08-04 14:54:32 +00:00
|
|
|
if (!reply->updateData(this)) {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->session().api().requestMessageData(
|
2017-11-23 15:41:13 +00:00
|
|
|
history()->peer->asChannel(),
|
|
|
|
reply->replyToMsgId,
|
|
|
|
HistoryDependentItemCallback(fullId()));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto via = Get<HistoryMessageVia>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
via->create(config.viaBotId);
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
views->_views = config.viewsCount;
|
|
|
|
}
|
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>()) {
|
|
|
|
msgsigned->author = config.author;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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) {
|
2018-01-14 16:02:25 +00:00
|
|
|
_media = nullptr;
|
2018-01-17 16:21:01 +00:00
|
|
|
if (media) {
|
|
|
|
setMedia(*media);
|
|
|
|
}
|
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() {
|
|
|
|
if (!_savedMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto wasGrouped = history()->owner().groups().isGrouped(this);
|
|
|
|
_media = std::move(_savedMedia);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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));
|
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-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()),
|
|
|
|
TextUtilities::EntitiesFromMTP(message.ventities().value_or_empty())
|
|
|
|
};
|
|
|
|
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));
|
2018-04-07 07:41:48 +00:00
|
|
|
setText(textWithEntities);
|
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);
|
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)) {
|
2017-12-08 18:27:28 +00:00
|
|
|
Notify::peerUpdatedDelayed(
|
|
|
|
history()->peer,
|
|
|
|
Notify::PeerUpdate::Flag::UnreadMentionsChanged);
|
2017-08-11 07:16:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:27:28 +00:00
|
|
|
void HistoryMessage::eraseFromUnreadMentions() {
|
2018-12-26 10:28:24 +00:00
|
|
|
if (isUnreadMention()) {
|
2017-08-11 07:16:07 +00:00
|
|
|
history()->eraseFromUnreadMentions(id);
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
|
|
|
|
for_const (auto &entity, textWithEntities.entities) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
clearIsolatedEmoji();
|
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
|
|
|
textWithEntities,
|
|
|
|
Ui::ItemTextOptions(this));
|
|
|
|
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,
|
2019-08-12 10:37:01 +00:00
|
|
|
{ QString::fromUtf8(":-("), EntitiesInText() },
|
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
|
|
|
}
|
2019-08-12 10:37:01 +00:00
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
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) {
|
|
|
|
if (!markup) {
|
|
|
|
if (_flags & MTPDmessage::Flag::f_reply_markup) {
|
|
|
|
_flags &= ~MTPDmessage::Flag::f_reply_markup;
|
|
|
|
if (Has<HistoryMessageReplyMarkup>()) {
|
|
|
|
RemoveComponents(HistoryMessageReplyMarkup::Bit());
|
|
|
|
}
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
Notify::replyMarkupUpdated(this);
|
|
|
|
}
|
|
|
|
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) {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
Notify::replyMarkupUpdated(this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(_flags & MTPDmessage::Flag::f_reply_markup)) {
|
|
|
|
_flags |= MTPDmessage::Flag::f_reply_markup;
|
|
|
|
}
|
|
|
|
if (!Has<HistoryMessageReplyMarkup>()) {
|
|
|
|
AddComponents(HistoryMessageReplyMarkup::Bit());
|
|
|
|
}
|
|
|
|
Get<HistoryMessageReplyMarkup>()->create(*markup);
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
Notify::replyMarkupUpdated(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setViewsCount(int32 count) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views
|
|
|
|
|| views->_views == count
|
|
|
|
|| (count >= 0 && views->_views > count)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto was = views->_viewsWidth;
|
2016-09-27 14:20:49 +00:00
|
|
|
views->_views = count;
|
2019-05-03 14:59:42 +00:00
|
|
|
views->_viewsText = (views->_views > 0)
|
2019-05-20 12:06:34 +00:00
|
|
|
? Lang::FormatCountToShort(views->_views).string
|
2019-06-19 14:52:18 +00:00
|
|
|
: QString("1");
|
2018-01-17 16:21:01 +00:00
|
|
|
views->_viewsWidth = views->_viewsText.isEmpty()
|
|
|
|
? 0
|
|
|
|
: st::msgDateFont->width(views->_viewsText);
|
2016-09-27 14:20:49 +00:00
|
|
|
if (was == views->_viewsWidth) {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemRepaint(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
} else {
|
2019-01-03 12:36:01 +00:00
|
|
|
history()->owner().requestItemResize(this);
|
2016-09-27 14:20:49 +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);
|
|
|
|
}
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) {
|
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->itemRemoved(this, dependency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HistoryMessage::notificationHeader() const {
|
|
|
|
return (!_history->peer->isUser() && !isPost()) ? from()->name : QString();
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
std::unique_ptr<HistoryView::Element> HistoryMessage::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate) {
|
|
|
|
return delegate->elementCreate(this);
|
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();
|
2019-04-01 06:54:48 +00:00
|
|
|
_savedMedia.reset();
|
2016-09-27 14:20:49 +00:00
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->clearData(this);
|
|
|
|
}
|
|
|
|
}
|