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"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "history/history_media_types.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"
|
2017-02-23 09:32:28 +00:00
|
|
|
#include "auth_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"
|
2017-12-28 13:06:06 +00:00
|
|
|
#include "ui/text_options.h"
|
2017-07-11 17:11:06 +00:00
|
|
|
#include "messenger.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "styles/style_history.h"
|
2017-11-12 16:50:58 +00:00
|
|
|
#include "styles/style_window.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "window/notifications_manager.h"
|
2017-12-05 16:14:28 +00:00
|
|
|
#include "window/window_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"
|
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;
|
|
|
|
}
|
|
|
|
if (auto channel = peer->asChannel()) {
|
|
|
|
if (auto media = fwd->getMedia()) {
|
|
|
|
if (media->type() == MediaTypeWebPage) {
|
|
|
|
// Drop web page if we're not allowed to send it.
|
2017-09-26 13:53:51 +00:00
|
|
|
if (channel->restricted(
|
|
|
|
ChannelRestriction::f_embed_links)) {
|
2017-06-16 16:04:30 +00:00
|
|
|
result &= MTPDmessage::Flag::f_media;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (auto media = fwd->getMedia()) {
|
|
|
|
if (media->type() == MediaTypeVoiceFile) {
|
|
|
|
result |= MTPDmessage::Flag::f_media_unread;
|
|
|
|
// } else if (media->type() == MediaTypeVideo) {
|
|
|
|
// result |= MTPDmessage::flag_media_unread;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fwd->hasViews()) {
|
|
|
|
result |= MTPDmessage::Flag::f_views;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
bool HasMediaItems(const HistoryItemsList &items) {
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (const auto media = item->getMedia()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypePhoto:
|
|
|
|
case MediaTypeVideo:
|
2017-12-16 13:09:53 +00:00
|
|
|
case MediaTypeGrouped:
|
2017-07-11 17:11:06 +00:00
|
|
|
case MediaTypeFile:
|
|
|
|
case MediaTypeMusicFile:
|
|
|
|
case MediaTypeVoiceFile: return true;
|
2017-12-10 10:26:58 +00:00
|
|
|
case MediaTypeGif: return media->getDocument()->isVideoMessage();
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
bool HasStickerItems(const HistoryItemsList &items) {
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (const auto media = item->getMedia()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypeSticker: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
bool HasGifItems(const HistoryItemsList &items) {
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (const auto media = item->getMedia()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
switch (media->type()) {
|
2017-12-10 10:26:58 +00:00
|
|
|
case MediaTypeGif: return !media->getDocument()->isVideoMessage();
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
bool HasGameItems(const HistoryItemsList &items) {
|
|
|
|
for (const auto item : items) {
|
|
|
|
if (const auto media = item->getMedia()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
switch (media->type()) {
|
|
|
|
case MediaTypeGame: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
};
|
2018-01-11 15:51:59 +00:00
|
|
|
const auto data = std::make_shared<ShareData>(
|
|
|
|
item->history()->peer,
|
|
|
|
Auth().data().itemOrItsGroup(item));
|
2017-12-18 13:29:48 +00:00
|
|
|
const auto isGroup = (item->getFullGroup() != nullptr);
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto isGame = item->getMessageBot()
|
2017-12-05 14:07:01 +00:00
|
|
|
&& item->getMedia()
|
|
|
|
&& (item->getMedia()->type() == MediaTypeGame);
|
2017-12-15 21:23:20 +00:00
|
|
|
const auto canCopyLink = item->hasDirectLink() || isGame;
|
2017-07-11 17:11:06 +00:00
|
|
|
|
|
|
|
auto copyCallback = [data]() {
|
|
|
|
if (auto main = App::main()) {
|
2017-12-15 21:23:20 +00:00
|
|
|
if (auto item = App::histItemById(data->msgIds[0])) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (item->hasDirectLink()) {
|
|
|
|
QApplication::clipboard()->setText(item->directLink());
|
|
|
|
|
|
|
|
Ui::Toast::Show(lang(lng_channel_public_link_copied));
|
|
|
|
} else if (auto bot = item->getMessageBot()) {
|
|
|
|
if (auto media = item->getMedia()) {
|
|
|
|
if (media->type() == MediaTypeGame) {
|
|
|
|
auto shortName = static_cast<HistoryGame*>(media)->game()->shortName;
|
|
|
|
|
|
|
|
QApplication::clipboard()->setText(Messenger::Instance().createInternalLinkFull(bot->username + qsl("?game=") + shortName));
|
|
|
|
|
|
|
|
Ui::Toast::Show(lang(lng_share_game_link_copied));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-12-18 13:29:48 +00:00
|
|
|
auto submitCallback = [data, isGroup](const QVector<PeerData*> &result) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (!data->requests.empty()) {
|
|
|
|
return; // Share clicked already.
|
|
|
|
}
|
2017-12-15 21:23:20 +00:00
|
|
|
auto items = Auth().data().idsToItems(data->msgIds);
|
|
|
|
if (items.empty() || result.empty()) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto restrictedSomewhere = false;
|
|
|
|
auto restrictedEverywhere = true;
|
|
|
|
auto firstError = QString();
|
2017-12-06 10:13:38 +00:00
|
|
|
for (const auto peer : result) {
|
|
|
|
const auto error = GetErrorTextForForward(peer, items);
|
2017-07-11 17:11:06 +00:00
|
|
|
if (!error.isEmpty()) {
|
|
|
|
if (firstError.isEmpty()) {
|
|
|
|
firstError = error;
|
|
|
|
}
|
|
|
|
restrictedSomewhere = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
restrictedEverywhere = false;
|
|
|
|
}
|
|
|
|
if (restrictedEverywhere) {
|
2017-09-15 17:34:41 +00:00
|
|
|
Ui::show(
|
|
|
|
Box<InformBox>(firstError),
|
|
|
|
LayerOption::KeepOther);
|
2017-07-11 17:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto doneCallback = [data](const MTPUpdates &updates, mtpRequestId requestId) {
|
|
|
|
if (auto main = App::main()) {
|
|
|
|
main->sentUpdatesReceived(updates);
|
|
|
|
}
|
|
|
|
data->requests.remove(requestId);
|
|
|
|
if (data->requests.empty()) {
|
|
|
|
Ui::Toast::Show(lang(lng_share_done));
|
|
|
|
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
|
|
|
|
: 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;
|
|
|
|
};
|
2017-07-11 17:11:06 +00:00
|
|
|
if (auto main = App::main()) {
|
2017-12-06 10:13:38 +00:00
|
|
|
for (const auto peer : result) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (!GetErrorTextForForward(peer, items).isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-12-15 21:23:20 +00:00
|
|
|
auto request = MTPmessages_ForwardMessages(
|
|
|
|
MTP_flags(sendFlags),
|
|
|
|
data->peer->input,
|
|
|
|
MTP_vector<MTPint>(msgIds),
|
|
|
|
MTP_vector<MTPlong>(generateRandom()),
|
|
|
|
peer->input);
|
2017-07-11 17:11:06 +00:00
|
|
|
auto callback = doneCallback;
|
|
|
|
auto requestId = MTP::send(request, rpcDone(std::move(callback)));
|
|
|
|
data->requests.insert(requestId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
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
|
|
|
|
? base::lambda<void()>(std::move(copyCallback))
|
|
|
|
: base::lambda<void()>();
|
|
|
|
Ui::show(Box<ShareBox>(
|
|
|
|
std::move(copyLinkCallback),
|
|
|
|
std::move(submitCallback),
|
|
|
|
std::move(filterCallback)));
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
base::lambda<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
|
|
|
const FullMsgId &msgId) {
|
2017-06-22 15:11:41 +00:00
|
|
|
return [dependent = msgId](ChannelData *channel, MsgId msgId) {
|
|
|
|
if (auto item = App::histItemById(dependent)) {
|
|
|
|
item->updateDependencyItem();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer) {
|
2017-06-22 15:11:41 +00:00
|
|
|
MTPDmessage::Flags result = 0;
|
|
|
|
if (!peer->isSelf()) {
|
|
|
|
result |= MTPDmessage::Flag::f_out;
|
|
|
|
//if (p->isChat() || (p->isUser() && !p->asUser()->botInfo)) {
|
|
|
|
// result |= MTPDmessage::Flag::f_unread;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-06 10:13:38 +00:00
|
|
|
QString GetErrorTextForForward(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const HistoryItemsList &items) {
|
2017-07-11 17:11:06 +00:00
|
|
|
if (!peer->canWrite()) {
|
|
|
|
return lang(lng_forward_cant);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto megagroup = peer->asMegagroup()) {
|
2017-09-26 13:53:51 +00:00
|
|
|
if (megagroup->restricted(ChannelRestriction::f_send_media) && HasMediaItems(items)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return lang(lng_restricted_send_media);
|
2017-09-26 13:53:51 +00:00
|
|
|
} else if (megagroup->restricted(ChannelRestriction::f_send_stickers) && HasStickerItems(items)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return lang(lng_restricted_send_stickers);
|
2017-09-26 13:53:51 +00:00
|
|
|
} else if (megagroup->restricted(ChannelRestriction::f_send_gifs) && HasGifItems(items)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return lang(lng_restricted_send_gifs);
|
2017-09-26 13:53:51 +00:00
|
|
|
} else if (megagroup->restricted(ChannelRestriction::f_send_games) && HasGameItems(items)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return lang(lng_restricted_send_inline);
|
2017-09-26 13:53:51 +00:00
|
|
|
} else if (megagroup->restricted(ChannelRestriction::f_send_inline) && HasInlineItems(items)) {
|
2017-07-11 17:11:06 +00:00
|
|
|
return lang(lng_restricted_send_inline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
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;
|
|
|
|
MsgId originalId = 0;
|
|
|
|
PeerId savedFromPeer = 0;
|
|
|
|
MsgId savedFromMsgId = 0;
|
|
|
|
QString authorOriginal;
|
|
|
|
QDateTime originalDate;
|
|
|
|
QDateTime editDate;
|
|
|
|
MessageGroupId groupId = MessageGroupId::None;
|
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
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessage &msg)
|
2017-06-16 16:04:30 +00:00
|
|
|
: HistoryItem(history, msg.vid.v, msg.vflags.v, ::date(msg.vdate), msg.has_from_id() ? msg.vfrom_id.v : 0) {
|
2016-09-27 14:20:49 +00:00
|
|
|
CreateConfig config;
|
|
|
|
|
|
|
|
if (msg.has_fwd_from() && msg.vfwd_from.type() == mtpc_messageFwdHeader) {
|
2016-10-07 07:58:34 +00:00
|
|
|
auto &f = msg.vfwd_from.c_messageFwdHeader();
|
2017-06-20 22:05:38 +00:00
|
|
|
config.originalDate = ::date(f.vdate);
|
2016-09-27 14:20:49 +00:00
|
|
|
if (f.has_from_id() || f.has_channel_id()) {
|
2017-12-05 16:14:28 +00:00
|
|
|
config.senderOriginal = f.has_channel_id()
|
|
|
|
? peerFromChannel(f.vchannel_id)
|
|
|
|
: peerFromUser(f.vfrom_id);
|
2016-09-27 14:20:49 +00:00
|
|
|
if (f.has_channel_post()) config.originalId = f.vchannel_post.v;
|
2017-07-12 19:14:20 +00:00
|
|
|
if (f.has_post_author()) config.authorOriginal = qs(f.vpost_author);
|
2017-12-05 16:14:28 +00:00
|
|
|
if (f.has_saved_from_peer() && f.has_saved_from_msg_id()) {
|
|
|
|
config.savedFromPeer = peerFromMTP(f.vsaved_from_peer);
|
|
|
|
config.savedFromMsgId = f.vsaved_from_msg_id.v;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg.has_reply_to_msg_id()) config.replyTo = msg.vreply_to_msg_id.v;
|
|
|
|
if (msg.has_via_bot_id()) config.viaBotId = msg.vvia_bot_id.v;
|
|
|
|
if (msg.has_views()) config.viewsCount = msg.vviews.v;
|
2016-10-07 07:58:34 +00:00
|
|
|
if (msg.has_reply_markup()) config.mtpMarkup = &msg.vreply_markup;
|
2016-09-27 14:20:49 +00:00
|
|
|
if (msg.has_edit_date()) config.editDate = ::date(msg.vedit_date);
|
2017-07-12 19:14:20 +00:00
|
|
|
if (msg.has_post_author()) config.author = qs(msg.vpost_author);
|
2017-12-13 18:10:48 +00:00
|
|
|
if (msg.has_grouped_id()) {
|
|
|
|
config.groupId = MessageGroupId::FromRaw(msg.vgrouped_id.v);
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
|
2016-09-28 11:38:35 +00:00
|
|
|
initMedia(msg.has_media() ? (&msg.vmedia) : nullptr);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-07-06 11:37:42 +00:00
|
|
|
auto text = TextUtilities::Clean(qs(msg.vmessage));
|
2018-01-18 11:04:25 +00:00
|
|
|
auto entities = msg.has_entities()
|
|
|
|
? TextUtilities::EntitiesFromMTP(msg.ventities.v)
|
|
|
|
: EntitiesInText();
|
2017-06-20 16:03:18 +00:00
|
|
|
setText({ text, entities });
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessageService &msg)
|
2017-06-16 16:04:30 +00:00
|
|
|
: HistoryItem(history, msg.vid.v, mtpCastFlags(msg.vflags.v), ::date(msg.vdate), msg.has_from_id() ? msg.vfrom_id.v : 0) {
|
2017-04-27 21:17:00 +00:00
|
|
|
CreateConfig config;
|
|
|
|
|
|
|
|
if (msg.has_reply_to_msg_id()) config.replyTo = msg.vreply_to_msg_id.v;
|
|
|
|
|
|
|
|
createComponents(config);
|
|
|
|
|
|
|
|
switch (msg.vaction.type()) {
|
|
|
|
case mtpc_messageActionPhoneCall: {
|
|
|
|
_media = std::make_unique<HistoryCall>(this, msg.vaction.c_messageActionPhoneCall());
|
|
|
|
} 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,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<HistoryMessage*> fwd)
|
2017-06-22 15:11:41 +00:00
|
|
|
: HistoryItem(history, id, NewForwardedFlags(history->peer, from, fwd) | flags, date, from) {
|
2016-09-27 14:20:49 +00:00
|
|
|
CreateConfig config;
|
|
|
|
|
2017-04-30 12:42:04 +00:00
|
|
|
if (fwd->Has<HistoryMessageForwarded>() || !fwd->history()->peer->isSelf()) {
|
|
|
|
// Server doesn't add "fwd_from" to non-forwarded messages from chat with yourself.
|
2017-06-20 22:05:38 +00:00
|
|
|
config.originalDate = fwd->dateOriginal();
|
2017-07-26 06:05:06 +00:00
|
|
|
auto senderOriginal = fwd->senderOriginal();
|
|
|
|
config.senderOriginal = senderOriginal->id;
|
2017-07-12 19:14:20 +00:00
|
|
|
config.authorOriginal = fwd->authorOriginal();
|
2017-07-26 06:05:06 +00:00
|
|
|
if (senderOriginal->isChannel()) {
|
2017-04-30 12:42:04 +00:00
|
|
|
config.originalId = fwd->idOriginal();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
if (history->peer->isSelf()) {
|
|
|
|
//
|
|
|
|
// 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 {
|
|
|
|
config.savedFromPeer = fwd->history()->peer->id;
|
|
|
|
config.savedFromMsgId = fwd->id;
|
|
|
|
//}
|
|
|
|
}
|
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
|
|
|
auto fwdViaBot = fwd->viaBot();
|
|
|
|
if (fwdViaBot) config.viaBotId = peerToUser(fwdViaBot->id);
|
|
|
|
int fwdViewsCount = fwd->viewsCount();
|
|
|
|
if (fwdViewsCount > 0) {
|
|
|
|
config.viewsCount = fwdViewsCount;
|
|
|
|
} else if (isPost()) {
|
|
|
|
config.viewsCount = 1;
|
|
|
|
}
|
|
|
|
|
2016-10-07 07:58:34 +00:00
|
|
|
// Copy inline keyboard when forwarding messages with a game.
|
|
|
|
auto mediaOriginal = fwd->getMedia();
|
2017-06-16 16:04:30 +00:00
|
|
|
auto mediaType = mediaOriginal ? mediaOriginal->type() : MediaTypeCount;
|
|
|
|
if (mediaOriginal && mediaType == MediaTypeGame) {
|
2016-10-07 07:58:34 +00:00
|
|
|
config.inlineMarkup = fwd->inlineReplyMarkup();
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
createComponents(config);
|
|
|
|
|
2017-06-16 16:04:30 +00:00
|
|
|
auto cloneMedia = [this, history, mediaType] {
|
|
|
|
if (mediaType == MediaTypeWebPage) {
|
|
|
|
if (auto channel = history->peer->asChannel()) {
|
2017-09-26 13:53:51 +00:00
|
|
|
if (channel->restricted(ChannelRestriction::f_embed_links)) {
|
2017-06-16 16:04:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (mediaType != MediaTypeCount);
|
|
|
|
};
|
|
|
|
if (cloneMedia()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
_media = mediaOriginal->clone(this, this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
setText(fwd->originalText());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const TextWithEntities &textWithEntities)
|
2017-12-05 16:14:28 +00:00
|
|
|
: HistoryItem(history, id, flags, date, (flags & MTPDmessage::Flag::f_from_id) ? from : 0) {
|
2017-07-12 19:14:20 +00:00
|
|
|
createComponentsHelper(flags, replyTo, viaBotId, postAuthor, MTPnullMarkup);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
setText(textWithEntities);
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup)
|
2017-12-05 16:14:28 +00:00
|
|
|
: HistoryItem(history, msgId, flags, 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
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
initMediaFromDocument(document, caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
setText(TextWithEntities());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup)
|
2017-12-05 16:14:28 +00:00
|
|
|
: HistoryItem(history, msgId, flags, 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
|
|
|
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryPhoto>(this, photo, caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
setText(TextWithEntities());
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:10:48 +00:00
|
|
|
HistoryMessage::HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const MTPReplyMarkup &markup)
|
2017-12-05 16:14:28 +00:00
|
|
|
: HistoryItem(history, msgId, flags, 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
|
|
|
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryGame>(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) {
|
2016-09-27 14:20:49 +00:00
|
|
|
CreateConfig config;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
not_null<PeerData*> HistoryMessage::displayFrom() const {
|
|
|
|
return history()->peer->isSelf()
|
|
|
|
? senderOriginal()
|
|
|
|
: author();
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool HistoryMessage::updateDependencyItem() {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
return reply->updateData(this, true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:38:44 +00:00
|
|
|
void HistoryMessage::updateAdminBadgeState() {
|
|
|
|
auto hasAdminBadge = [&] {
|
|
|
|
if (auto channel = history()->peer->asChannel()) {
|
|
|
|
if (auto user = author()->asUser()) {
|
|
|
|
return channel->isGroupAdmin(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}();
|
|
|
|
if (hasAdminBadge) {
|
|
|
|
_flags |= MTPDmessage_ClientFlag::f_has_admin_badge;
|
|
|
|
} else {
|
|
|
|
_flags &= ~MTPDmessage_ClientFlag::f_has_admin_badge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::applyGroupAdminChanges(
|
|
|
|
const base::flat_map<UserId, bool> &changes) {
|
|
|
|
auto i = changes.find(peerToUser(author()->id));
|
|
|
|
if (i != changes.end()) {
|
|
|
|
if (i->second) {
|
|
|
|
_flags |= MTPDmessage_ClientFlag::f_has_admin_badge;
|
|
|
|
} else {
|
|
|
|
_flags &= ~MTPDmessage_ClientFlag::f_has_admin_badge;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(this);
|
2017-12-01 18:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:32:10 +00:00
|
|
|
bool HistoryMessage::displayEditedBadge() const {
|
|
|
|
return !displayedEditDate().isNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime HistoryMessage::displayedEditDate() const {
|
|
|
|
auto hasViaBotId = Has<HistoryMessageVia>();
|
|
|
|
auto hasInlineMarkup = (inlineReplyMarkup() != nullptr);
|
|
|
|
return displayedEditDate(hasViaBotId || hasInlineMarkup);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime HistoryMessage::displayedEditDate(
|
|
|
|
bool hasViaBotOrInlineMarkup) const {
|
2016-10-07 07:58:34 +00:00
|
|
|
if (hasViaBotOrInlineMarkup) {
|
2017-12-16 16:32:10 +00:00
|
|
|
return QDateTime();
|
|
|
|
} else if (const auto fromUser = from()->asUser()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
if (fromUser->botInfo) {
|
2017-12-16 16:32:10 +00:00
|
|
|
return QDateTime();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-16 16:32:10 +00:00
|
|
|
if (const auto edited = displayedEditBadge()) {
|
|
|
|
return edited->date;
|
|
|
|
}
|
|
|
|
return QDateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessageEdited *HistoryMessage::displayedEditBadge() {
|
|
|
|
if (_media && _media->overrideEditedDate()) {
|
|
|
|
return _media->displayedEditBadge();
|
|
|
|
}
|
|
|
|
return Get<HistoryMessageEdited>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const HistoryMessageEdited *HistoryMessage::displayedEditBadge() const {
|
|
|
|
if (_media && _media->overrideEditedDate()) {
|
|
|
|
return _media->displayedEditBadge();
|
|
|
|
}
|
|
|
|
return Get<HistoryMessageEdited>();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
bool HistoryMessage::uploading() const {
|
|
|
|
return _media && _media->uploading();
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
bool HistoryMessage::displayRightAction() const {
|
|
|
|
return displayFastShare() || displayGoToOriginal();
|
|
|
|
}
|
|
|
|
|
2017-07-11 17:11:06 +00:00
|
|
|
bool HistoryMessage::displayFastShare() const {
|
|
|
|
if (_history->peer->isChannel()) {
|
|
|
|
return !_history->peer->isMegagroup();
|
|
|
|
} else if (auto user = _history->peer->asUser()) {
|
|
|
|
if (user->botInfo && !out()) {
|
|
|
|
return _media && _media->allowsFastShare();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
bool HistoryMessage::displayGoToOriginal() const {
|
|
|
|
if (_history->peer->isSelf()) {
|
|
|
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
return forwarded->savedFromPeer && forwarded->savedFromMsgId;
|
2017-12-05 16:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2016-10-07 07:58:34 +00:00
|
|
|
auto hasViaBot = (config.viaBotId != 0);
|
|
|
|
auto hasInlineMarkup = [&config] {
|
|
|
|
if (config.mtpMarkup) {
|
|
|
|
return (config.mtpMarkup->type() == mtpc_replyInlineMarkup);
|
|
|
|
}
|
|
|
|
return (config.inlineMarkup != nullptr);
|
|
|
|
};
|
2017-12-16 16:32:10 +00:00
|
|
|
if (!config.editDate.isNull()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
mask |= HistoryMessageEdited::Bit();
|
|
|
|
}
|
2017-07-26 06:05:06 +00:00
|
|
|
if (config.senderOriginal) {
|
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
|
2016-10-07 07:58:34 +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
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (config.groupId) {
|
|
|
|
mask |= HistoryMessageGroup::Bit();
|
|
|
|
}
|
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)) {
|
2017-11-23 15:41:13 +00:00
|
|
|
Auth().api().requestMessageData(
|
|
|
|
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;
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
forwarded->originalDate = config.originalDate;
|
|
|
|
forwarded->originalSender = App::peer(config.senderOriginal);
|
|
|
|
forwarded->originalId = config.originalId;
|
|
|
|
forwarded->originalAuthor = config.authorOriginal;
|
|
|
|
forwarded->savedFromPeer = App::peerLoaded(config.savedFromPeer);
|
|
|
|
forwarded->savedFromMsgId = config.savedFromMsgId;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
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) {
|
|
|
|
_flags |= MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
|
|
|
}
|
|
|
|
}
|
2017-12-13 18:10:48 +00:00
|
|
|
if (const auto group = Get<HistoryMessageGroup>()) {
|
|
|
|
group->groupId = config.groupId;
|
|
|
|
group->leader = this;
|
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
_fromNameVersion = displayFrom()->nameVersion;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString formatViewsCount(int32 views) {
|
|
|
|
if (views > 999999) {
|
|
|
|
views /= 100000;
|
|
|
|
if (views % 10) {
|
|
|
|
return QString::number(views / 10) + '.' + QString::number(views % 10) + 'M';
|
|
|
|
}
|
|
|
|
return QString::number(views / 10) + 'M';
|
|
|
|
} else if (views > 9999) {
|
|
|
|
views /= 100;
|
|
|
|
if (views % 10) {
|
|
|
|
return QString::number(views / 10) + '.' + QString::number(views % 10) + 'K';
|
|
|
|
}
|
|
|
|
return QString::number(views / 10) + 'K';
|
|
|
|
} else if (views > 0) {
|
|
|
|
return QString::number(views);
|
|
|
|
}
|
|
|
|
return qsl("1");
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::initTime() {
|
2017-12-16 16:32:10 +00:00
|
|
|
if (const auto msgsigned = Get<HistoryMessageSigned>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
_timeWidth = msgsigned->maxWidth();
|
2017-12-16 16:32:10 +00:00
|
|
|
} else if (const auto edited = displayedEditBadge()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
_timeWidth = edited->maxWidth();
|
|
|
|
} else {
|
|
|
|
_timeText = date.toString(cTimeFormat());
|
|
|
|
_timeWidth = st::msgDateFont->width(_timeText);
|
|
|
|
}
|
2017-12-16 16:32:10 +00:00
|
|
|
if (const auto views = Get<HistoryMessageViews>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
views->_viewsText = (views->_views >= 0) ? formatViewsCount(views->_views) : QString();
|
|
|
|
views->_viewsWidth = views->_viewsText.isEmpty() ? 0 : st::msgDateFont->width(views->_viewsText);
|
|
|
|
}
|
2017-12-16 16:32:10 +00:00
|
|
|
if (_text.hasSkipBlock()) {
|
|
|
|
_text.setSkipBlock(skipBlockWidth(), skipBlockHeight());
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 11:38:35 +00:00
|
|
|
void HistoryMessage::initMedia(const MTPMessageMedia *media) {
|
2016-09-27 14:20:49 +00:00
|
|
|
switch (media ? media->type() : mtpc_messageMediaEmpty) {
|
|
|
|
case mtpc_messageMediaContact: {
|
|
|
|
auto &d = media->c_messageMediaContact();
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryContact>(this, d.vuser_id.v, qs(d.vfirst_name), qs(d.vlast_name), qs(d.vphone_number));
|
2016-09-27 14:20:49 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_messageMediaGeo: {
|
|
|
|
auto &point = media->c_messageMediaGeo().vgeo;
|
|
|
|
if (point.type() == mtpc_geoPoint) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryLocation>(this, LocationCoords(point.c_geoPoint()));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
2017-11-20 19:54:05 +00:00
|
|
|
case mtpc_messageMediaGeoLive: {
|
|
|
|
auto &point = media->c_messageMediaGeoLive().vgeo;
|
|
|
|
if (point.type() == mtpc_geoPoint) {
|
|
|
|
_media = std::make_unique<HistoryLocation>(this, LocationCoords(point.c_geoPoint()));
|
|
|
|
}
|
|
|
|
} break;
|
2016-09-27 14:20:49 +00:00
|
|
|
case mtpc_messageMediaVenue: {
|
|
|
|
auto &d = media->c_messageMediaVenue();
|
|
|
|
if (d.vgeo.type() == mtpc_geoPoint) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryLocation>(this, LocationCoords(d.vgeo.c_geoPoint()), qs(d.vtitle), qs(d.vaddress));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_messageMediaPhoto: {
|
|
|
|
auto &photo = media->c_messageMediaPhoto();
|
2017-07-12 19:14:20 +00:00
|
|
|
if (photo.has_ttl_seconds()) {
|
|
|
|
LOG(("App Error: Unexpected MTPMessageMediaPhoto with ttl_seconds in HistoryMessage."));
|
|
|
|
} else if (photo.has_photo() && photo.vphoto.type() == mtpc_photo) {
|
|
|
|
_media = std::make_unique<HistoryPhoto>(this, App::feedPhoto(photo.vphoto.c_photo()), photo.has_caption() ? qs(photo.vcaption) : QString());
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: Got MTPMessageMediaPhoto without photo and without ttl_seconds."));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_messageMediaDocument: {
|
2017-07-12 19:14:20 +00:00
|
|
|
auto &document = media->c_messageMediaDocument();
|
|
|
|
if (document.has_ttl_seconds()) {
|
|
|
|
LOG(("App Error: Unexpected MTPMessageMediaDocument with ttl_seconds in HistoryMessage."));
|
|
|
|
} else if (document.has_document() && document.vdocument.type() == mtpc_document) {
|
|
|
|
return initMediaFromDocument(App::feedDocument(document.vdocument.c_document()), document.has_caption() ? qs(document.vcaption) : QString());
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: Got MTPMessageMediaDocument without document and without ttl_seconds."));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_messageMediaWebPage: {
|
|
|
|
auto &d = media->c_messageMediaWebPage().vwebpage;
|
|
|
|
switch (d.type()) {
|
|
|
|
case mtpc_webPageEmpty: break;
|
|
|
|
case mtpc_webPagePending: {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryWebPage>(this, App::feedWebPage(d.c_webPagePending()));
|
2016-09-27 14:20:49 +00:00
|
|
|
} break;
|
|
|
|
case mtpc_webPage: {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryWebPage>(this, App::feedWebPage(d.c_webPage()));
|
2016-09-27 14:20:49 +00:00
|
|
|
} break;
|
2016-12-13 07:59:57 +00:00
|
|
|
case mtpc_webPageNotModified: LOG(("API Error: webPageNotModified is unexpected in message media.")); break;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case mtpc_messageMediaGame: {
|
|
|
|
auto &d = media->c_messageMediaGame().vgame;
|
|
|
|
if (d.type() == mtpc_game) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryGame>(this, App::feedGame(d.c_game()));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
} break;
|
2017-03-05 13:39:10 +00:00
|
|
|
case mtpc_messageMediaInvoice: {
|
|
|
|
_media = std::make_unique<HistoryInvoice>(this, media->c_messageMediaInvoice());
|
2017-03-06 15:00:59 +00:00
|
|
|
if (static_cast<HistoryInvoice*>(getMedia())->getReceiptMsgId()) {
|
|
|
|
replaceBuyWithReceiptInMarkup();
|
|
|
|
}
|
2017-03-05 13:39:10 +00:00
|
|
|
} break;
|
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) {
|
2017-03-06 15:00:59 +00:00
|
|
|
button.text = lang(lng_payments_receipt_button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::initMediaFromDocument(DocumentData *doc, const QString &caption) {
|
|
|
|
if (doc->sticker()) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistorySticker>(this, doc);
|
2016-09-27 14:20:49 +00:00
|
|
|
} else if (doc->isAnimation()) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryGif>(this, doc, caption);
|
2017-12-10 10:26:58 +00:00
|
|
|
} else if (doc->isVideoFile()) {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryVideo>(this, doc, caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
} else {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media = std::make_unique<HistoryDocument>(this, doc, caption);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 HistoryMessage::plainMaxWidth() const {
|
|
|
|
return st::msgPadding.left() + _text.maxWidth() + st::msgPadding.right();
|
|
|
|
}
|
|
|
|
|
2017-06-20 19:48:53 +00:00
|
|
|
bool HistoryMessage::drawBubble() const {
|
2017-12-13 18:10:48 +00:00
|
|
|
if (isHiddenByGroup()) {
|
|
|
|
return false;
|
|
|
|
} else if (Has<HistoryMessageLogEntryOriginal>()) {
|
2017-06-20 19:48:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return _media ? (!emptyText() || _media->needsBubble()) : !isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-12-30 08:15:42 +00:00
|
|
|
bool HistoryMessage::hasFastReply() const {
|
|
|
|
return !hasOutLayout()
|
|
|
|
&& (history()->peer->isChat() || history()->peer->isMegagroup());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryMessage::displayFastReply() const {
|
|
|
|
return hasFastReply() && history()->peer->canWrite();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (message.has_edit_date()) {
|
|
|
|
_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>();
|
|
|
|
edited->date = ::date(message.vedit_date);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities textWithEntities = { qs(message.vmessage), EntitiesInText() };
|
|
|
|
if (message.has_entities()) {
|
2017-07-06 11:37:42 +00:00
|
|
|
textWithEntities.entities = TextUtilities::EntitiesFromMTP(message.ventities.v);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
setText(textWithEntities);
|
|
|
|
setReplyMarkup(message.has_reply_markup() ? (&message.vreply_markup) : nullptr);
|
2017-03-06 15:00:59 +00:00
|
|
|
setMedia(message.has_media() ? (&message.vmedia) : nullptr);
|
2016-09-27 14:20:49 +00:00
|
|
|
setViewsCount(message.has_views() ? message.vviews.v : -1);
|
|
|
|
|
|
|
|
finishEdition(keyboardTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::applyEdition(const MTPDmessageService &message) {
|
|
|
|
if (message.vaction.type() == mtpc_messageActionHistoryClear) {
|
|
|
|
applyEditionToEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::applyEditionToEmpty() {
|
|
|
|
setEmptyText();
|
|
|
|
setMedia(nullptr);
|
|
|
|
setReplyMarkup(nullptr);
|
|
|
|
setViewsCount(-1);
|
|
|
|
|
|
|
|
finishEditionToEmpty();
|
|
|
|
}
|
|
|
|
|
2017-12-16 16:32:10 +00:00
|
|
|
void HistoryMessage::refreshEditedBadge() {
|
|
|
|
const auto edited = displayedEditBadge();
|
|
|
|
const auto editDate = displayedEditDate();
|
|
|
|
const auto dateText = date.toString(cTimeFormat());
|
|
|
|
if (edited) {
|
|
|
|
edited->refresh(dateText, !editDate.isNull());
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto msgsigned = Get<HistoryMessageSigned>()) {
|
2017-12-16 16:32:10 +00:00
|
|
|
const auto text = (!edited || editDate.isNull())
|
|
|
|
? dateText
|
|
|
|
: edited->text.originalText();
|
2017-12-18 15:44:50 +00:00
|
|
|
msgsigned->refresh(text);
|
2017-12-16 16:32:10 +00:00
|
|
|
}
|
|
|
|
initTime();
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:11:41 +00:00
|
|
|
bool HistoryMessage::displayForwardedFrom() const {
|
|
|
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
2017-12-05 16:14:28 +00:00
|
|
|
if (history()->peer->isSelf()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-22 15:11:41 +00:00
|
|
|
return Has<HistoryMessageVia>()
|
|
|
|
|| !_media
|
|
|
|
|| !_media->isDisplayed()
|
|
|
|
|| !_media->hideForwardedFrom()
|
2017-12-18 15:44:50 +00:00
|
|
|
|| forwarded->originalSender->isChannel();
|
2017-06-22 15:11:41 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::updateMedia(const MTPMessageMedia *media) {
|
|
|
|
auto setMediaAllowed = [](HistoryMediaType type) {
|
2017-12-13 18:10:48 +00:00
|
|
|
return (type == MediaTypeWebPage)
|
|
|
|
|| (type == MediaTypeGame)
|
|
|
|
|| (type == MediaTypeLocation);
|
2016-09-27 14:20:49 +00:00
|
|
|
};
|
|
|
|
if (_flags & MTPDmessage_ClientFlag::f_from_inline_bot) {
|
|
|
|
bool needReSet = true;
|
|
|
|
if (media && _media) {
|
|
|
|
needReSet = _media->needReSetInlineResultMedia(*media);
|
|
|
|
}
|
|
|
|
if (needReSet) {
|
|
|
|
setMedia(media);
|
|
|
|
}
|
|
|
|
_flags &= ~MTPDmessage_ClientFlag::f_from_inline_bot;
|
|
|
|
} else if (media && _media && !setMediaAllowed(_media->type())) {
|
|
|
|
_media->updateSentMedia(*media);
|
|
|
|
} else {
|
|
|
|
setMedia(media);
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void HistoryMessage::addToUnreadMentions(UnreadMentionType type) {
|
|
|
|
if (IsServerMsgId(id) && mentionsMe() && isMediaUnread()) {
|
|
|
|
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() {
|
2017-08-11 07:16:07 +00:00
|
|
|
if (mentionsMe() && isMediaUnread()) {
|
|
|
|
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 {};
|
|
|
|
if (auto media = getMedia()) {
|
|
|
|
result.set(media->sharedMediaTypes());
|
|
|
|
}
|
|
|
|
if (hasTextLinks()) {
|
|
|
|
result.set(Storage::SharedMediaType::Link);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
TextWithEntities HistoryMessage::selectedText(TextSelection selection) const {
|
2017-06-24 10:11:29 +00:00
|
|
|
TextWithEntities logEntryOriginalResult;
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto textSelection = (selection == FullSelection)
|
|
|
|
? AllTextSelection
|
|
|
|
: IsSubGroupSelection(selection)
|
|
|
|
? TextSelection(0, 0)
|
|
|
|
: selection;
|
|
|
|
auto textResult = _text.originalTextWithEntities(
|
|
|
|
textSelection,
|
|
|
|
ExpandLinksAll);
|
2017-06-23 19:28:42 +00:00
|
|
|
auto skipped = skipTextSelection(selection);
|
|
|
|
auto mediaDisplayed = (_media && _media->isDisplayed());
|
2017-12-16 15:00:20 +00:00
|
|
|
auto mediaResult = (mediaDisplayed || isHiddenByGroup())
|
|
|
|
? _media->selectedText(skipped)
|
|
|
|
: TextWithEntities();
|
2017-06-23 19:28:42 +00:00
|
|
|
if (auto entry = Get<HistoryMessageLogEntryOriginal>()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
const auto originalSelection = mediaDisplayed
|
|
|
|
? _media->skipSelection(skipped)
|
|
|
|
: skipped;
|
|
|
|
logEntryOriginalResult = entry->_page->selectedText(originalSelection);
|
2017-06-23 19:28:42 +00:00
|
|
|
}
|
|
|
|
auto result = textResult;
|
|
|
|
if (result.text.isEmpty()) {
|
|
|
|
result = std::move(mediaResult);
|
|
|
|
} else if (!mediaResult.text.isEmpty()) {
|
|
|
|
result.text += qstr("\n\n");
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::Append(result, std::move(mediaResult));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
if (result.text.isEmpty()) {
|
|
|
|
result = std::move(logEntryOriginalResult);
|
|
|
|
} else if (!logEntryOriginalResult.text.isEmpty()) {
|
|
|
|
result.text += qstr("\n\n");
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::Append(result, std::move(logEntryOriginalResult));
|
2017-06-23 19:28:42 +00:00
|
|
|
}
|
2017-07-18 16:48:10 +00:00
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
if (selection == FullSelection && reply->replyToMsg) {
|
|
|
|
TextWithEntities wrapped;
|
|
|
|
wrapped.text.reserve(lang(lng_in_reply_to).size() + reply->replyToMsg->author()->name.size() + 4 + result.text.size());
|
|
|
|
wrapped.text.append('[').append(lang(lng_in_reply_to)).append(' ').append(reply->replyToMsg->author()->name).append(qsl("]\n"));
|
|
|
|
TextUtilities::Append(wrapped, std::move(result));
|
|
|
|
result = wrapped;
|
|
|
|
}
|
|
|
|
}
|
2017-04-30 12:44:17 +00:00
|
|
|
if (auto forwarded = Get<HistoryMessageForwarded>()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
if (selection == FullSelection) {
|
2017-12-18 15:44:50 +00:00
|
|
|
auto fwdinfo = forwarded->text.originalTextWithEntities(AllTextSelection, ExpandLinksAll);
|
2017-04-30 12:44:17 +00:00
|
|
|
auto wrapped = TextWithEntities();
|
2016-09-27 14:20:49 +00:00
|
|
|
wrapped.text.reserve(fwdinfo.text.size() + 4 + result.text.size());
|
|
|
|
wrapped.entities.reserve(fwdinfo.entities.size() + result.entities.size());
|
|
|
|
wrapped.text.append('[');
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::Append(wrapped, std::move(fwdinfo));
|
2016-09-27 14:20:49 +00:00
|
|
|
wrapped.text.append(qsl("]\n"));
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::Append(wrapped, std::move(result));
|
2016-09-27 14:20:49 +00:00
|
|
|
result = wrapped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setMedia(const MTPMessageMedia *media) {
|
|
|
|
if (!_media && (!media || media->type() == mtpc_messageMediaEmpty)) return;
|
|
|
|
|
|
|
|
bool mediaRemovedSkipBlock = false;
|
|
|
|
if (_media) {
|
2016-09-29 16:15:44 +00:00
|
|
|
// Don't update Game media because we loose the consumed text of the message.
|
|
|
|
if (_media->type() == MediaTypeGame) return;
|
|
|
|
|
2016-09-28 11:38:35 +00:00
|
|
|
mediaRemovedSkipBlock = _media->isDisplayed() && _media->isBubbleBottom();
|
2017-03-05 13:39:10 +00:00
|
|
|
_media.reset();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-28 11:38:35 +00:00
|
|
|
initMedia(media);
|
|
|
|
auto mediaDisplayed = _media && _media->isDisplayed();
|
|
|
|
if (mediaDisplayed && _media->isBubbleBottom() && !mediaRemovedSkipBlock) {
|
2016-09-27 14:20:49 +00:00
|
|
|
_text.removeSkipBlock();
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
2016-09-28 11:38:35 +00:00
|
|
|
} else if (mediaRemovedSkipBlock && (!mediaDisplayed || !_media->isBubbleBottom())) {
|
2016-09-27 14:20:49 +00:00
|
|
|
_text.setSkipBlock(skipBlockWidth(), skipBlockHeight());
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
|
|
|
}
|
2017-12-16 15:25:21 +00:00
|
|
|
_history->recountGroupingAround(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
|
|
|
|
for_const (auto &entity, textWithEntities.entities) {
|
|
|
|
auto type = entity.type();
|
|
|
|
if (type == EntityInTextUrl || type == EntityInTextCustomUrl || type == EntityInTextEmail) {
|
|
|
|
_flags |= MTPDmessage_ClientFlag::f_has_text_links;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-09-28 11:38:35 +00:00
|
|
|
|
|
|
|
auto mediaDisplayed = _media && _media->isDisplayed();
|
|
|
|
if (mediaDisplayed && _media->consumeMessageText(textWithEntities)) {
|
|
|
|
setEmptyText();
|
|
|
|
} else {
|
2017-06-23 19:28:42 +00:00
|
|
|
auto mediaOnBottom = (_media && _media->isDisplayed() && _media->isBubbleBottom()) || Has<HistoryMessageLogEntryOriginal>();
|
|
|
|
if (mediaOnBottom) {
|
2017-12-28 13:06:06 +00:00
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
|
|
|
textWithEntities,
|
|
|
|
Ui::ItemTextOptions(this));
|
2016-09-28 11:38:35 +00:00
|
|
|
} else {
|
2017-12-28 13:06:06 +00:00
|
|
|
_text.setMarkedText(
|
|
|
|
st::messageTextStyle,
|
|
|
|
{
|
|
|
|
textWithEntities.text + skipBlock(),
|
|
|
|
textWithEntities.entities
|
|
|
|
},
|
|
|
|
Ui::ItemTextOptions(this));
|
2016-09-28 11:38:35 +00:00
|
|
|
}
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setEmptyText() {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(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
|
|
|
|
if (markup->type() == mtpc_replyKeyboardHide && markup->c_replyKeyboardHide().vflags.v == 0) {
|
|
|
|
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) {
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(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);
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
Notify::replyMarkupUpdated(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithEntities HistoryMessage::originalText() const {
|
|
|
|
if (emptyText()) {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
|
|
|
return _text.originalTextWithEntities();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryMessage::textHasLinks() const {
|
|
|
|
return emptyText() ? false : _text.hasLinks();
|
|
|
|
}
|
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
int HistoryMessage::infoWidth() const {
|
|
|
|
int result = _timeWidth;
|
|
|
|
if (auto views = Get<HistoryMessageViews>()) {
|
|
|
|
result += st::historyViewsSpace + views->_viewsWidth + st::historyViewsWidth;
|
|
|
|
} else if (id < 0 && history()->peer->isSelf()) {
|
2017-12-05 16:38:13 +00:00
|
|
|
if (!hasOutLayout()) {
|
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
if (hasOutLayout()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
int HistoryMessage::timeLeft() const {
|
|
|
|
int result = 0;
|
|
|
|
if (auto views = Get<HistoryMessageViews>()) {
|
|
|
|
result += st::historyViewsSpace + views->_viewsWidth + st::historyViewsWidth;
|
|
|
|
} else if (id < 0 && history()->peer->isSelf()) {
|
2017-12-05 16:38:13 +00:00
|
|
|
if (!hasOutLayout()) {
|
|
|
|
result += st::historySendStateSpace;
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::drawInfo(Painter &p, int32 right, int32 bottom, int32 width, bool selected, InfoDisplayType type) const {
|
|
|
|
p.setFont(st::msgDateFont);
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
bool outbg = hasOutLayout();
|
2016-09-27 14:20:49 +00:00
|
|
|
bool invertedsprites = (type == InfoDisplayOverImage || type == InfoDisplayOverBackground);
|
|
|
|
int32 infoRight = right, infoBottom = bottom;
|
|
|
|
switch (type) {
|
|
|
|
case InfoDisplayDefault:
|
2016-09-28 10:15:03 +00:00
|
|
|
infoRight -= st::msgPadding.right() - st::msgDateDelta.x();
|
|
|
|
infoBottom -= st::msgPadding.bottom() - st::msgDateDelta.y();
|
|
|
|
p.setPen(selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg));
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
case InfoDisplayOverImage:
|
2016-09-28 10:15:03 +00:00
|
|
|
infoRight -= st::msgDateImgDelta + st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgDelta + st::msgDateImgPadding.y();
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::msgDateImgFg);
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
case InfoDisplayOverBackground:
|
2016-09-28 10:15:03 +00:00
|
|
|
infoRight -= st::msgDateImgDelta + st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgDelta + st::msgDateImgPadding.y();
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::msgServiceFg);
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 infoW = HistoryMessage::infoWidth();
|
|
|
|
if (rtl()) infoRight = width - infoRight + infoW;
|
|
|
|
|
|
|
|
int32 dateX = infoRight - infoW;
|
|
|
|
int32 dateY = infoBottom - st::msgDateFont->height;
|
|
|
|
if (type == InfoDisplayOverImage) {
|
|
|
|
int32 dateW = infoW + 2 * st::msgDateImgPadding.x(), dateH = st::msgDateFont->height + 2 * st::msgDateImgPadding.y();
|
|
|
|
App::roundRect(p, dateX - st::msgDateImgPadding.x(), dateY - st::msgDateImgPadding.y(), dateW, dateH, selected ? st::msgDateImgBgSelected : st::msgDateImgBg, selected ? DateSelectedCorners : DateCorners);
|
|
|
|
} else if (type == InfoDisplayOverBackground) {
|
|
|
|
int32 dateW = infoW + 2 * st::msgDateImgPadding.x(), dateH = st::msgDateFont->height + 2 * st::msgDateImgPadding.y();
|
2016-12-21 15:05:58 +00:00
|
|
|
App::roundRect(p, dateX - st::msgDateImgPadding.x(), dateY - st::msgDateImgPadding.y(), dateW, dateH, selected ? st::msgServiceBgSelected : st::msgServiceBg, selected ? StickerSelectedCorners : StickerCorners);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
dateX += HistoryMessage::timeLeft();
|
|
|
|
|
2017-12-16 16:32:10 +00:00
|
|
|
if (const auto msgsigned = Get<HistoryMessageSigned>()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
msgsigned->signature.drawElided(p, dateX, dateY, _timeWidth);
|
2017-12-16 16:32:10 +00:00
|
|
|
} else if (const auto edited = displayedEditBadge()) {
|
|
|
|
edited->text.drawElided(p, dateX, dateY, _timeWidth);
|
2016-09-27 14:20:49 +00:00
|
|
|
} else {
|
|
|
|
p.drawText(dateX, dateY + st::msgDateFont->ascent, _timeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto views = Get<HistoryMessageViews>()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = ([this, outbg, invertedsprites, selected] {
|
|
|
|
if (id > 0) {
|
|
|
|
if (outbg) {
|
|
|
|
return &(invertedsprites ? st::historyViewsInvertedIcon : (selected ? st::historyViewsOutSelectedIcon : st::historyViewsOutIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historyViewsInvertedIcon : (selected ? st::historyViewsInSelectedIcon : st::historyViewsInIcon));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &(invertedsprites ? st::historyViewsSendingInvertedIcon : st::historyViewsSendingIcon);
|
|
|
|
})();
|
|
|
|
if (id > 0) {
|
|
|
|
icon->paint(p, infoRight - infoW, infoBottom + st::historyViewsTop, width);
|
|
|
|
p.drawText(infoRight - infoW + st::historyViewsWidth, infoBottom - st::msgDateFont->descent, views->_viewsText);
|
|
|
|
} else if (!outbg) { // sending outbg icon will be painted below
|
|
|
|
auto iconSkip = st::historyViewsSpace + views->_viewsWidth;
|
|
|
|
icon->paint(p, infoRight - infoW + iconSkip, infoBottom + st::historyViewsTop, width);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-12-05 16:38:13 +00:00
|
|
|
} else if (id < 0 && history()->peer->isSelf() && !outbg) {
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = &(invertedsprites ? st::historyViewsSendingInvertedIcon : st::historyViewsSendingIcon);
|
|
|
|
icon->paint(p, infoRight - infoW, infoBottom + st::historyViewsTop, width);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
if (outbg) {
|
2016-09-30 12:52:03 +00:00
|
|
|
auto icon = ([this, invertedsprites, selected] {
|
|
|
|
if (id > 0) {
|
|
|
|
if (unread()) {
|
|
|
|
return &(invertedsprites ? st::historySentInvertedIcon : (selected ? st::historySentSelectedIcon : st::historySentIcon));
|
|
|
|
}
|
|
|
|
return &(invertedsprites ? st::historyReceivedInvertedIcon : (selected ? st::historyReceivedSelectedIcon : st::historyReceivedIcon));
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &(invertedsprites ? st::historySendingInvertedIcon : st::historySendingIcon);
|
|
|
|
})();
|
|
|
|
icon->paint(p, QPoint(infoRight, infoBottom) + st::historySendStatePosition, width);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HistoryMessage::setViewsCount(int32 count) {
|
|
|
|
auto views = Get<HistoryMessageViews>();
|
|
|
|
if (!views || views->_views == count || (count >= 0 && views->_views > count)) return;
|
|
|
|
|
|
|
|
int32 was = views->_viewsWidth;
|
|
|
|
views->_views = count;
|
|
|
|
views->_viewsText = (views->_views >= 0) ? formatViewsCount(views->_views) : QString();
|
|
|
|
views->_viewsWidth = views->_viewsText.isEmpty() ? 0 : st::msgDateFont->width(views->_viewsText);
|
|
|
|
if (was == views->_viewsWidth) {
|
2017-10-05 15:35:52 +00:00
|
|
|
Auth().data().requestItemRepaint(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
} else {
|
|
|
|
if (_text.hasSkipBlock()) {
|
|
|
|
_text.setSkipBlock(HistoryMessage::skipBlockWidth(), HistoryMessage::skipBlockHeight());
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(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);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
if (_text.hasSkipBlock()) {
|
|
|
|
_text.setSkipBlock(HistoryMessage::skipBlockWidth(), HistoryMessage::skipBlockHeight());
|
|
|
|
_textWidth = -1;
|
|
|
|
_textHeight = 0;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
Auth().data().requestItemViewResize(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
void HistoryMessage::drawRightAction(Painter &p, int left, int top, int outerWidth) const {
|
2017-07-11 17:11:06 +00:00
|
|
|
{
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::msgServiceBg);
|
|
|
|
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(rtlrect(left, top, st::historyFastShareSize, st::historyFastShareSize, outerWidth));
|
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
if (displayFastShare()) {
|
|
|
|
st::historyFastShareIcon.paint(p, left, top, outerWidth);
|
|
|
|
} else {
|
|
|
|
st::historyGoToOriginalIcon.paint(p, left, top, outerWidth);
|
|
|
|
}
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryMessage::dependencyItemRemoved(HistoryItem *dependency) {
|
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->itemRemoved(this, dependency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
bool HistoryMessage::pointInTime(int right, int bottom, QPoint point, InfoDisplayType type) const {
|
|
|
|
auto infoRight = right;
|
|
|
|
auto infoBottom = bottom;
|
2016-09-27 14:20:49 +00:00
|
|
|
switch (type) {
|
|
|
|
case InfoDisplayDefault:
|
2016-09-28 10:15:03 +00:00
|
|
|
infoRight -= st::msgPadding.right() - st::msgDateDelta.x();
|
|
|
|
infoBottom -= st::msgPadding.bottom() - st::msgDateDelta.y();
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
case InfoDisplayOverImage:
|
2016-09-28 10:15:03 +00:00
|
|
|
infoRight -= st::msgDateImgDelta + st::msgDateImgPadding.x();
|
|
|
|
infoBottom -= st::msgDateImgDelta + st::msgDateImgPadding.y();
|
2016-09-27 14:20:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
auto dateX = infoRight - HistoryMessage::infoWidth() + HistoryMessage::timeLeft();
|
|
|
|
auto dateY = infoBottom - st::msgDateFont->height;
|
|
|
|
return QRect(dateX, dateY, HistoryMessage::timeWidth(), st::msgDateFont->height).contains(point);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 16:14:28 +00:00
|
|
|
ClickHandlerPtr HistoryMessage::rightActionLink() const {
|
|
|
|
if (!_rightActionLink) {
|
|
|
|
const auto itemId = fullId();
|
|
|
|
const auto forwarded = Get<HistoryMessageForwarded>();
|
2017-12-18 15:44:50 +00:00
|
|
|
const auto savedFromPeer = forwarded ? forwarded->savedFromPeer : nullptr;
|
|
|
|
const auto savedFromMsgId = forwarded ? forwarded->savedFromMsgId : 0;
|
2017-12-18 09:07:18 +00:00
|
|
|
_rightActionLink = std::make_shared<LambdaClickHandler>([=] {
|
2017-12-05 16:14:28 +00:00
|
|
|
if (auto item = App::histItemById(itemId)) {
|
|
|
|
if (savedFromPeer && savedFromMsgId) {
|
|
|
|
App::wnd()->controller()->showPeerHistory(
|
|
|
|
savedFromPeer,
|
|
|
|
Window::SectionShow::Way::Forward,
|
|
|
|
savedFromMsgId);
|
|
|
|
} else {
|
2017-12-15 21:23:20 +00:00
|
|
|
FastShareMessage(item);
|
2017-12-05 16:14:28 +00:00
|
|
|
}
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-05 16:14:28 +00:00
|
|
|
return _rightActionLink;
|
2017-07-11 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-30 08:15:42 +00:00
|
|
|
ClickHandlerPtr HistoryMessage::fastReplyLink() const {
|
|
|
|
if (!_fastReplyLink) {
|
|
|
|
const auto itemId = fullId();
|
|
|
|
_fastReplyLink = std::make_shared<LambdaClickHandler>([=] {
|
|
|
|
if (const auto item = App::histItemById(itemId)) {
|
|
|
|
if (const auto main = App::main()) {
|
|
|
|
main->replyToItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return _fastReplyLink;
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
TextSelection HistoryMessage::adjustSelection(TextSelection selection, TextSelectType type) const {
|
2017-06-23 19:28:42 +00:00
|
|
|
auto result = _text.adjustSelection(selection, type);
|
|
|
|
auto beforeMediaLength = _text.length();
|
|
|
|
if (selection.to <= beforeMediaLength) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
auto mediaDisplayed = _media && _media->isDisplayed();
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
auto mediaSelection = unskipTextSelection(_media->adjustSelection(skipTextSelection(selection), type));
|
|
|
|
if (selection.from >= beforeMediaLength) {
|
|
|
|
result = mediaSelection;
|
|
|
|
} else {
|
|
|
|
result.to = mediaSelection.to;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
auto beforeEntryLength = beforeMediaLength + (mediaDisplayed ? _media->fullSelectionLength() : 0);
|
|
|
|
if (selection.to <= beforeEntryLength) {
|
|
|
|
return result;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2017-06-23 19:28:42 +00:00
|
|
|
if (auto entry = Get<HistoryMessageLogEntryOriginal>()) {
|
|
|
|
auto entrySelection = mediaDisplayed ? _media->skipSelection(skipTextSelection(selection)) : skipTextSelection(selection);
|
|
|
|
auto logEntryOriginalSelection = entry->_page->adjustSelection(entrySelection, type);
|
|
|
|
if (mediaDisplayed) {
|
|
|
|
logEntryOriginalSelection = _media->unskipSelection(logEntryOriginalSelection);
|
|
|
|
}
|
|
|
|
logEntryOriginalSelection = unskipTextSelection(logEntryOriginalSelection);
|
|
|
|
if (selection.from >= beforeEntryLength) {
|
|
|
|
result = logEntryOriginalSelection;
|
|
|
|
} else {
|
|
|
|
result.to = logEntryOriginalSelection.to;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
HistoryView::Context context) {
|
|
|
|
return controller->createMessageView(this, context);
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
HistoryMessage::~HistoryMessage() {
|
2017-03-05 13:39:10 +00:00
|
|
|
_media.reset();
|
2016-09-27 14:20:49 +00:00
|
|
|
if (auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
reply->clearData(this);
|
|
|
|
}
|
|
|
|
}
|