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_item.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"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-10 13:13:33 +00:00
|
|
|
#include "history/view/history_view_service_message.h"
|
2017-12-18 15:44:50 +00:00
|
|
|
#include "history/history_item_components.h"
|
2019-08-02 13:21:09 +00:00
|
|
|
#include "history/view/media/history_view_media_grouped.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "history/history_service.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_message.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/clip/media_clip_reader.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
2019-08-02 18:19:14 +00:00
|
|
|
#include "ui/text/text_isolated_emoji.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "ui/text/text_options.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_upload.h"
|
2017-09-04 11:40:02 +00:00
|
|
|
#include "storage/storage_facade.h"
|
|
|
|
#include "storage/storage_shared_media.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
//#include "storage/storage_feed_messages.h" // #feed
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-12-25 14:17:00 +00:00
|
|
|
#include "apiwrap.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2017-10-03 13:05:58 +00:00
|
|
|
#include "mainwindow.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-01-02 13:44:12 +00:00
|
|
|
#include "core/crash_reports.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2020-01-14 22:23:16 +00:00
|
|
|
#include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "data/data_messages.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "data/data_media_types.h"
|
2019-04-15 11:54:03 +00:00
|
|
|
#include "data/data_folder.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_user.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
2020-10-10 09:15:37 +00:00
|
|
|
#include "styles/style_chat.h"
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-04-08 11:53:08 +00:00
|
|
|
constexpr auto kNotificationTextLimit = 255;
|
|
|
|
|
2018-12-17 08:16:06 +00:00
|
|
|
enum class MediaCheckResult {
|
|
|
|
Good,
|
|
|
|
Unsupported,
|
|
|
|
Empty,
|
|
|
|
HasTimeToLive,
|
|
|
|
};
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
not_null<HistoryItem*> CreateUnsupportedMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2018-01-14 16:02:25 +00:00
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from) {
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto siteLink = qsl("https://desktop.telegram.org");
|
|
|
|
auto text = TextWithEntities{
|
2019-06-19 16:39:25 +00:00
|
|
|
tr::lng_message_unsupported(tr::now, lt_link, siteLink)
|
2018-01-14 16:02:25 +00:00
|
|
|
};
|
|
|
|
TextUtilities::ParseEntities(text, Ui::ItemTextNoMonoOptions().flags);
|
|
|
|
text.entities.push_front(
|
2019-04-08 15:10:06 +00:00
|
|
|
EntityInText(EntityType::Italic, 0, text.text.size()));
|
2018-01-14 16:02:25 +00:00
|
|
|
flags &= ~MTPDmessage::Flag::f_post_author;
|
2019-05-20 14:57:25 +00:00
|
|
|
flags |= MTPDmessage::Flag::f_legacy;
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeMessage(
|
2018-01-14 16:02:25 +00:00
|
|
|
msgId,
|
|
|
|
flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
clientFlags,
|
2018-01-14 16:02:25 +00:00
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
date,
|
|
|
|
from,
|
|
|
|
QString(),
|
|
|
|
text);
|
|
|
|
}
|
|
|
|
|
2018-12-17 08:16:06 +00:00
|
|
|
MediaCheckResult CheckMessageMedia(const MTPMessageMedia &media) {
|
|
|
|
using Result = MediaCheckResult;
|
|
|
|
return media.match([](const MTPDmessageMediaEmpty &) {
|
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDmessageMediaContact &) {
|
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDmessageMediaGeo &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vgeo().match([](const MTPDgeoPoint &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDgeoPointEmpty &) {
|
|
|
|
return Result::Empty;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaVenue &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vgeo().match([](const MTPDgeoPoint &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDgeoPointEmpty &) {
|
|
|
|
return Result::Empty;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaGeoLive &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vgeo().match([](const MTPDgeoPoint &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDgeoPointEmpty &) {
|
|
|
|
return Result::Empty;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaPhoto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto photo = data.vphoto();
|
|
|
|
if (data.vttl_seconds()) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::HasTimeToLive;
|
2019-07-05 13:38:38 +00:00
|
|
|
} else if (!photo) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Empty;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
return photo->match([](const MTPDphoto &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDphotoEmpty &) {
|
|
|
|
return Result::Empty;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaDocument &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto document = data.vdocument();
|
|
|
|
if (data.vttl_seconds()) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::HasTimeToLive;
|
2019-07-05 13:38:38 +00:00
|
|
|
} else if (!document) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Empty;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
return document->match([](const MTPDdocument &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDdocumentEmpty &) {
|
|
|
|
return Result::Empty;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaWebPage &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vwebpage().match([](const MTPDwebPage &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDwebPageEmpty &) {
|
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDwebPagePending &) {
|
|
|
|
return Result::Good;
|
|
|
|
}, [](const MTPDwebPageNotModified &) {
|
|
|
|
return Result::Unsupported;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaGame &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
return data.vgame().match([](const MTPDgame &) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return Result::Good;
|
|
|
|
});
|
|
|
|
}, [](const MTPDmessageMediaInvoice &) {
|
|
|
|
return Result::Good;
|
2018-12-18 05:43:11 +00:00
|
|
|
}, [](const MTPDmessageMediaPoll &) {
|
|
|
|
return Result::Good;
|
2020-02-07 16:06:35 +00:00
|
|
|
}, [](const MTPDmessageMediaDice &) {
|
2020-03-04 09:21:19 +00:00
|
|
|
return Result::Good;
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [](const MTPDmessageMediaUnsupported &) {
|
|
|
|
return Result::Unsupported;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
} // namespace
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-02-05 20:19:51 +00:00
|
|
|
void HistoryItem::HistoryItem::Destroyer::operator()(HistoryItem *value) {
|
|
|
|
if (value) {
|
|
|
|
value->destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-25 15:17:46 +00:00
|
|
|
HistoryItem::HistoryItem(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
2019-08-09 19:19:23 +00:00
|
|
|
MTPDmessage_ClientFlags clientFlags,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2020-09-01 06:44:18 +00:00
|
|
|
PeerId from)
|
2018-01-13 12:45:11 +00:00
|
|
|
: id(id)
|
2016-09-27 14:20:49 +00:00
|
|
|
, _history(history)
|
2020-09-01 06:44:18 +00:00
|
|
|
, _from(from ? history->owner().peer(from) : history->peer)
|
2018-02-03 20:26:39 +00:00
|
|
|
, _flags(flags)
|
2019-08-09 19:19:23 +00:00
|
|
|
, _clientFlags(clientFlags)
|
2018-02-03 20:26:39 +00:00
|
|
|
, _date(date) {
|
2019-08-31 11:25:24 +00:00
|
|
|
if (isHistoryEntry() && IsClientMsgId(id)) {
|
2019-07-17 12:41:48 +00:00
|
|
|
_history->registerLocalMessage(this);
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId HistoryItem::date() const {
|
|
|
|
return _date;
|
|
|
|
}
|
|
|
|
|
2019-08-12 16:33:36 +00:00
|
|
|
TimeId HistoryItem::NewMessageDate(TimeId scheduled) {
|
2020-10-07 10:08:54 +00:00
|
|
|
return scheduled ? scheduled : base::unixtime::now();
|
2019-08-12 16:33:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryItem::finishEdition(int oldKeyboardTop) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().requestItemViewRefresh(this);
|
2019-01-15 11:57:45 +00:00
|
|
|
invalidateChatListEntry();
|
2019-01-03 12:36:01 +00:00
|
|
|
if (const auto group = _history->owner().groups().find(this)) {
|
2020-09-16 08:25:57 +00:00
|
|
|
const auto leader = group->items.front();
|
2018-01-18 13:59:22 +00:00
|
|
|
if (leader != this) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().requestItemViewRefresh(leader);
|
2019-01-15 11:57:45 +00:00
|
|
|
leader->invalidateChatListEntry();
|
2018-01-18 13:59:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2020-06-27 16:27:27 +00:00
|
|
|
// Should be completely redesigned as the oldTop no longer exists.
|
2018-01-13 12:45:11 +00:00
|
|
|
//if (oldKeyboardTop >= 0) { // #TODO edit bot message
|
|
|
|
// if (auto keyboard = Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
// keyboard->oldTop = oldKeyboardTop;
|
|
|
|
// }
|
|
|
|
//}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-04-25 12:45:15 +00:00
|
|
|
_history->owner().updateDependentMessages(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void HistoryItem::setGroupId(MessageGroupId groupId) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Expects(!_groupId);
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
_groupId = groupId;
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().groups().registerMessage(this);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
HistoryMessageReplyMarkup *HistoryItem::inlineReplyMarkup() {
|
|
|
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
|
|
|
return markup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReplyKeyboard *HistoryItem::inlineReplyKeyboard() {
|
|
|
|
if (const auto markup = inlineReplyMarkup()) {
|
|
|
|
return markup->inlineKeyboard.get();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-25 15:05:57 +00:00
|
|
|
ChannelData *HistoryItem::discussionPostOriginalSender() const {
|
|
|
|
if (!history()->peer->isMegagroup()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
const auto from = forwarded->savedFromPeer;
|
|
|
|
if (const auto result = from ? from->asChannel() : nullptr) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryItem::isDiscussionPost() const {
|
|
|
|
return (discussionPostOriginalSender() != nullptr);
|
|
|
|
}
|
|
|
|
|
2020-09-15 08:39:39 +00:00
|
|
|
HistoryItem *HistoryItem::lookupDiscussionPostOriginal() const {
|
|
|
|
if (!history()->peer->isMegagroup()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const auto forwarded = Get<HistoryMessageForwarded>();
|
|
|
|
if (!forwarded
|
|
|
|
|| !forwarded->savedFromPeer
|
|
|
|
|| !forwarded->savedFromMsgId) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return _history->owner().message(
|
|
|
|
forwarded->savedFromPeer->asChannel(),
|
|
|
|
forwarded->savedFromMsgId);
|
|
|
|
}
|
|
|
|
|
2019-05-25 15:05:57 +00:00
|
|
|
PeerData *HistoryItem::displayFrom() const {
|
|
|
|
if (const auto sender = discussionPostOriginalSender()) {
|
|
|
|
return sender;
|
2020-09-11 15:33:26 +00:00
|
|
|
} else if (history()->peer->isSelf()
|
|
|
|
|| history()->peer->isRepliesChat()) {
|
2019-05-25 15:05:57 +00:00
|
|
|
return senderOriginal();
|
|
|
|
}
|
|
|
|
return author().get();
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:57:45 +00:00
|
|
|
void HistoryItem::invalidateChatListEntry() {
|
2020-06-12 14:09:04 +00:00
|
|
|
history()->session().changes().messageUpdated(
|
|
|
|
this,
|
|
|
|
Data::MessageUpdate::Flag::DialogRowRefresh);
|
2017-12-16 09:27:45 +00:00
|
|
|
|
|
|
|
// invalidate cache for drawInDialog
|
|
|
|
if (history()->textCachedFor == this) {
|
|
|
|
history()->textCachedFor = nullptr;
|
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//if (const auto feed = history()->peer->feed()) { // #TODO archive
|
|
|
|
// if (feed->textCachedFor == this) {
|
|
|
|
// feed->textCachedFor = nullptr;
|
|
|
|
// feed->updateChatListEntry();
|
|
|
|
// }
|
|
|
|
//}
|
2017-12-16 09:27:45 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void HistoryItem::finishEditionToEmpty() {
|
|
|
|
finishEdition(-1);
|
2018-01-31 17:10:29 +00:00
|
|
|
_history->itemVanished(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 10:28:24 +00:00
|
|
|
bool HistoryItem::hasUnreadMediaFlag() const {
|
|
|
|
if (_history->peer->isChannel()) {
|
2019-07-10 17:28:33 +00:00
|
|
|
const auto passed = base::unixtime::now() - date();
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto &config = _history->session().serverConfig();
|
|
|
|
if (passed >= config.channelsReadMediaPeriod) {
|
2017-11-20 19:54:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _flags & MTPDmessage::Flag::f_media_unread;
|
|
|
|
}
|
|
|
|
|
2018-12-26 10:28:24 +00:00
|
|
|
bool HistoryItem::isUnreadMention() const {
|
|
|
|
return mentionsMe() && (_flags & MTPDmessage::Flag::f_media_unread);
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:53:36 +00:00
|
|
|
bool HistoryItem::mentionsMe() const {
|
|
|
|
if (Has<HistoryServicePinned>()
|
2020-06-18 18:04:16 +00:00
|
|
|
&& !Core::App().settings().notifyAboutPinned()) {
|
2019-05-28 14:53:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return _flags & MTPDmessage::Flag::f_mentioned;
|
|
|
|
}
|
|
|
|
|
2018-12-26 10:28:24 +00:00
|
|
|
bool HistoryItem::isUnreadMedia() const {
|
|
|
|
if (!hasUnreadMediaFlag()) {
|
|
|
|
return false;
|
|
|
|
} else if (const auto media = this->media()) {
|
|
|
|
if (const auto document = media->document()) {
|
|
|
|
if (document->isVoiceMessage() || document->isVideoMessage()) {
|
|
|
|
return (media->webpage() == nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-25 12:48:10 +00:00
|
|
|
void HistoryItem::markMediaRead() {
|
|
|
|
_flags &= ~MTPDmessage::Flag::f_media_unread;
|
|
|
|
|
|
|
|
if (mentionsMe()) {
|
|
|
|
history()->updateChatListEntry();
|
|
|
|
history()->eraseFromUnreadMentions(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 12:56:33 +00:00
|
|
|
void HistoryItem::setIsPinned(bool pinned) {
|
2020-10-22 09:13:00 +00:00
|
|
|
const auto changed = (isPinned() != pinned);
|
2020-10-09 12:56:33 +00:00
|
|
|
if (pinned) {
|
|
|
|
_flags |= MTPDmessage::Flag::f_pinned;
|
2020-10-20 16:29:24 +00:00
|
|
|
history()->session().storage().add(Storage::SharedMediaAddExisting(
|
|
|
|
history()->peer->id,
|
|
|
|
Storage::SharedMediaType::Pinned,
|
|
|
|
id,
|
|
|
|
{ id, id }));
|
2020-10-21 11:07:49 +00:00
|
|
|
history()->peer->setHasPinnedMessages(true);
|
2020-10-09 12:56:33 +00:00
|
|
|
} else {
|
|
|
|
_flags &= ~MTPDmessage::Flag::f_pinned;
|
2020-10-20 16:29:24 +00:00
|
|
|
history()->session().storage().remove(Storage::SharedMediaRemoveOne(
|
|
|
|
history()->peer->id,
|
|
|
|
Storage::SharedMediaType::Pinned,
|
|
|
|
id));
|
2020-10-09 12:56:33 +00:00
|
|
|
}
|
2020-10-22 09:13:00 +00:00
|
|
|
if (changed) {
|
|
|
|
history()->owner().requestItemResize(this);
|
|
|
|
}
|
2020-10-09 12:56:33 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool HistoryItem::definesReplyKeyboard() const {
|
|
|
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_inline) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// optimization: don't create markup component for the case
|
|
|
|
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
|
|
|
return (_flags & MTPDmessage::Flag::f_reply_markup);
|
|
|
|
}
|
|
|
|
|
|
|
|
MTPDreplyKeyboardMarkup::Flags HistoryItem::replyKeyboardFlags() const {
|
|
|
|
Expects(definesReplyKeyboard());
|
|
|
|
|
|
|
|
if (const auto markup = Get<HistoryMessageReplyMarkup>()) {
|
|
|
|
return markup->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
// optimization: don't create markup component for the case
|
|
|
|
// MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag
|
|
|
|
return MTPDreplyKeyboardMarkup_ClientFlag::f_zero | 0;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void HistoryItem::addLogEntryOriginal(
|
|
|
|
WebPageId localId,
|
|
|
|
const QString &label,
|
|
|
|
const TextWithEntities &content) {
|
2019-09-06 09:20:12 +00:00
|
|
|
Expects(isAdminLogEntry());
|
2018-01-14 16:02:25 +00:00
|
|
|
|
2017-06-18 13:08:49 +00:00
|
|
|
AddComponents(HistoryMessageLogEntryOriginal::Bit());
|
2019-01-03 12:36:01 +00:00
|
|
|
Get<HistoryMessageLogEntryOriginal>()->page = _history->owner().webpage(
|
2018-01-14 16:02:25 +00:00
|
|
|
localId,
|
|
|
|
label,
|
|
|
|
content);
|
2017-06-18 13:08:49 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
PeerData *HistoryItem::specialNotificationPeer() const {
|
|
|
|
return (mentionsMe() && !_history->peer->isUser())
|
|
|
|
? from().get()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
UserData *HistoryItem::viaBot() const {
|
|
|
|
if (const auto via = Get<HistoryMessageVia>()) {
|
|
|
|
return via->bot;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
UserData *HistoryItem::getMessageBot() const {
|
|
|
|
if (const auto bot = viaBot()) {
|
|
|
|
return bot;
|
|
|
|
}
|
|
|
|
auto bot = from()->asUser();
|
|
|
|
if (!bot) {
|
|
|
|
bot = history()->peer->asUser();
|
|
|
|
}
|
2019-07-18 08:51:11 +00:00
|
|
|
return (bot && bot->isBot()) ? bot : nullptr;
|
2019-08-28 14:24:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryItem::isHistoryEntry() const {
|
|
|
|
return IsServerMsgId(id)
|
|
|
|
|| (_clientFlags & MTPDmessage_ClientFlag::f_local_history_entry);
|
|
|
|
}
|
|
|
|
|
2019-09-06 09:20:12 +00:00
|
|
|
bool HistoryItem::isAdminLogEntry() const {
|
|
|
|
return (_clientFlags & MTPDmessage_ClientFlag::f_admin_log_entry);
|
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
bool HistoryItem::isFromScheduled() const {
|
|
|
|
return isHistoryEntry()
|
|
|
|
&& (_flags & MTPDmessage::Flag::f_from_scheduled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryItem::isScheduled() const {
|
|
|
|
return !isHistoryEntry()
|
2019-09-06 09:20:12 +00:00
|
|
|
&& !isAdminLogEntry()
|
2019-08-28 14:24:12 +00:00
|
|
|
&& (_flags & MTPDmessage::Flag::f_from_scheduled);
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2017-06-18 13:08:49 +00:00
|
|
|
void HistoryItem::destroy() {
|
2020-02-20 08:45:25 +00:00
|
|
|
_history->destroyMessage(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
void HistoryItem::refreshMainView() {
|
|
|
|
if (const auto view = mainView()) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().notifyHistoryChangeDelayed(_history);
|
2018-01-18 13:59:22 +00:00
|
|
|
view->refreshInBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryItem::removeMainView() {
|
|
|
|
if (const auto view = mainView()) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().notifyHistoryChangeDelayed(_history);
|
2018-01-11 13:07:29 +00:00
|
|
|
view->removeFromBlock();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void HistoryItem::clearMainView() {
|
2018-01-10 13:13:33 +00:00
|
|
|
_mainView = nullptr;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void HistoryItem::addToUnreadMentions(UnreadMentionType type) {
|
|
|
|
}
|
|
|
|
|
2019-04-08 09:16:45 +00:00
|
|
|
void HistoryItem::applyEditionToHistoryCleared() {
|
|
|
|
applyEdition(
|
|
|
|
MTP_messageService(
|
|
|
|
MTP_flags(0),
|
|
|
|
MTP_int(id),
|
2020-09-01 06:44:18 +00:00
|
|
|
peerToMTP(PeerId(0)), // from_id
|
2019-04-08 09:16:45 +00:00
|
|
|
peerToMTP(history()->peer->id),
|
2020-09-01 06:44:18 +00:00
|
|
|
MTPMessageReplyHeader(),
|
2019-04-08 09:16:45 +00:00
|
|
|
MTP_int(date()),
|
|
|
|
MTP_messageActionHistoryClear()
|
|
|
|
).c_messageService());
|
|
|
|
}
|
|
|
|
|
2017-12-21 12:11:33 +00:00
|
|
|
void HistoryItem::indexAsNewItem() {
|
|
|
|
if (IsServerMsgId(id)) {
|
|
|
|
addToUnreadMentions(UnreadMentionType::New);
|
|
|
|
if (const auto types = sharedMediaTypes()) {
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->session().storage().add(Storage::SharedMediaAddNew(
|
2020-10-21 11:07:49 +00:00
|
|
|
_history->peer->id,
|
2017-12-21 12:11:33 +00:00
|
|
|
types,
|
|
|
|
id));
|
2020-10-21 11:07:49 +00:00
|
|
|
if (types.test(Storage::SharedMediaType::Pinned)) {
|
|
|
|
_history->peer->setHasPinnedMessages(true);
|
|
|
|
}
|
2020-10-09 12:56:33 +00:00
|
|
|
}
|
2019-04-15 11:54:03 +00:00
|
|
|
//if (const auto channel = history()->peer->asChannel()) { // #feed
|
|
|
|
// if (const auto feed = channel->feed()) {
|
|
|
|
// _history->session().storage().add(Storage::FeedMessagesAddNew(
|
|
|
|
// feed->id(),
|
|
|
|
// position()));
|
|
|
|
// }
|
|
|
|
//}
|
2017-12-21 12:11:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
void HistoryItem::setRealId(MsgId newId) {
|
2019-08-09 19:19:23 +00:00
|
|
|
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
2019-07-17 12:41:48 +00:00
|
|
|
Expects(IsClientMsgId(id));
|
2016-11-18 16:27:47 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
const auto oldId = std::exchange(id, newId);
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags &= ~MTPDmessage_ClientFlag::f_sending;
|
2019-07-17 12:41:48 +00:00
|
|
|
if (IsServerMsgId(id)) {
|
|
|
|
_history->unregisterLocalMessage(this);
|
|
|
|
}
|
2019-04-25 12:45:15 +00:00
|
|
|
_history->owner().notifyItemIdChange({ this, oldId });
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2020-06-27 15:53:30 +00:00
|
|
|
// We don't fire MessageUpdate::Flag::ReplyMarkup and update keyboard
|
2016-09-27 14:20:49 +00:00
|
|
|
// in history widget, because it can't exist for an outgoing message.
|
|
|
|
// Only inline keyboards can be in outgoing messages.
|
2018-01-14 16:02:25 +00:00
|
|
|
if (const auto markup = inlineReplyMarkup()) {
|
2016-09-27 14:20:49 +00:00
|
|
|
if (markup->inlineKeyboard) {
|
|
|
|
markup->inlineKeyboard->updateMessageId();
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 10:32:30 +00:00
|
|
|
|
2019-01-03 12:36:01 +00:00
|
|
|
_history->owner().requestItemRepaint(this);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 13:58:45 +00:00
|
|
|
bool HistoryItem::canPin() const {
|
2017-11-21 13:23:56 +00:00
|
|
|
if (id < 0 || !toHistoryMessage()) {
|
2017-06-04 11:09:29 +00:00
|
|
|
return false;
|
2020-10-23 07:04:28 +00:00
|
|
|
} else if (const auto m = media(); m && m->call()) {
|
|
|
|
return false;
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
2018-10-31 11:29:14 +00:00
|
|
|
return _history->peer->canPinMessages();
|
2017-04-30 13:58:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 17:58:58 +00:00
|
|
|
bool HistoryItem::allowsSendNow() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool HistoryItem::allowsForward() const {
|
2017-04-27 21:17:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
bool HistoryItem::allowsEdit(TimeId now) const {
|
2016-09-27 14:20:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-19 11:20:04 +00:00
|
|
|
bool HistoryItem::canStopPoll() const {
|
|
|
|
if (id < 0
|
|
|
|
|| Has<HistoryMessageVia>()
|
|
|
|
|| Has<HistoryMessageForwarded>()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto peer = _history->peer;
|
|
|
|
if (peer->isSelf()) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto channel = peer->asChannel()) {
|
|
|
|
if (isPost() && channel->canEditMessages()) {
|
|
|
|
return true;
|
|
|
|
} else if (out()) {
|
|
|
|
return isPost() ? channel->canPublish() : channel->canWrite();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out();
|
|
|
|
}
|
|
|
|
|
2017-04-30 13:58:45 +00:00
|
|
|
bool HistoryItem::canDelete() const {
|
2019-08-08 14:13:26 +00:00
|
|
|
if (!IsServerMsgId(id) && serviceMsg()) {
|
|
|
|
return false;
|
|
|
|
} else if (!isHistoryEntry() && !isScheduled()) {
|
2017-06-29 09:32:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-30 13:58:45 +00:00
|
|
|
auto channel = _history->peer->asChannel();
|
|
|
|
if (!channel) {
|
2019-01-22 07:50:21 +00:00
|
|
|
return !isGroupMigrate();
|
2017-04-30 13:58:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (id == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
if (channel->canDeleteMessages()) {
|
2017-04-30 13:58:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
if (out() && toHistoryMessage()) {
|
|
|
|
return isPost() ? channel->canPublish() : true;
|
2017-04-30 13:58:45 +00:00
|
|
|
}
|
2017-06-09 16:12:02 +00:00
|
|
|
return false;
|
2017-04-30 13:58:45 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
bool HistoryItem::canDeleteForEveryone(TimeId now) const {
|
2018-03-11 18:50:24 +00:00
|
|
|
const auto peer = history()->peer;
|
2020-06-17 09:36:25 +00:00
|
|
|
const auto &config = history()->session().serverConfig();
|
2018-03-11 18:50:24 +00:00
|
|
|
const auto messageToMyself = peer->isSelf();
|
|
|
|
const auto messageTooOld = messageToMyself
|
2018-02-03 19:52:35 +00:00
|
|
|
? false
|
2018-03-11 18:50:24 +00:00
|
|
|
: peer->isUser()
|
2020-06-17 09:36:25 +00:00
|
|
|
? (now - date() >= config.revokePrivateTimeLimit)
|
|
|
|
: (now - date() >= config.revokeTimeLimit);
|
2017-04-30 13:58:45 +00:00
|
|
|
if (id < 0 || messageToMyself || messageTooOld || isPost()) {
|
2017-04-02 10:25:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-11 18:50:24 +00:00
|
|
|
if (peer->isChannel()) {
|
2017-04-02 10:25:54 +00:00
|
|
|
return false;
|
2018-03-11 18:50:24 +00:00
|
|
|
} else if (const auto user = peer->asUser()) {
|
2017-11-30 11:06:30 +00:00
|
|
|
// Bots receive all messages and there is no sense in revoking them.
|
|
|
|
// See https://github.com/telegramdesktop/tdesktop/issues/3818
|
2019-04-03 12:14:05 +00:00
|
|
|
if (user->isBot() && !user->isSupport()) {
|
2017-11-30 11:06:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-04-02 10:25:54 +00:00
|
|
|
}
|
2020-10-01 15:20:56 +00:00
|
|
|
if (const auto media = this->media()) {
|
2020-05-01 09:21:26 +00:00
|
|
|
if (!media->allowsRevoke(now)) {
|
2017-04-27 21:17:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-04-30 13:58:45 +00:00
|
|
|
if (!out()) {
|
2018-03-11 18:50:24 +00:00
|
|
|
if (const auto chat = peer->asChat()) {
|
2019-01-13 08:03:34 +00:00
|
|
|
if (!chat->amCreator()
|
|
|
|
&& !(chat->adminRights()
|
|
|
|
& ChatAdminRight::f_delete_messages)) {
|
2017-04-30 13:58:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-11 18:50:24 +00:00
|
|
|
} else if (peer->isUser()) {
|
2020-06-17 09:36:25 +00:00
|
|
|
return config.revokePrivateInbox;
|
2017-04-30 13:58:45 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 14:15:16 +00:00
|
|
|
bool HistoryItem::suggestReport() const {
|
|
|
|
if (out() || serviceMsg() || !IsServerMsgId(id)) {
|
|
|
|
return false;
|
|
|
|
} else if (const auto channel = history()->peer->asChannel()) {
|
|
|
|
return true;
|
|
|
|
} else if (const auto user = history()->peer->asUser()) {
|
2019-07-18 08:51:11 +00:00
|
|
|
return user->isBot();
|
2018-05-10 14:15:16 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-04 11:09:29 +00:00
|
|
|
bool HistoryItem::suggestBanReport() const {
|
|
|
|
auto channel = history()->peer->asChannel();
|
2017-06-09 16:12:02 +00:00
|
|
|
auto fromUser = from()->asUser();
|
|
|
|
if (!channel || !fromUser || !channel->canRestrictUser(fromUser)) {
|
2017-06-04 11:09:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-02 12:52:26 +00:00
|
|
|
return !isPost() && !out();
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryItem::suggestDeleteAllReport() const {
|
|
|
|
auto channel = history()->peer->asChannel();
|
|
|
|
if (!channel || !channel->canDeleteMessages()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-02 13:02:06 +00:00
|
|
|
return !isPost() && !out() && from()->isUser();
|
2017-06-04 11:09:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 17:21:24 +00:00
|
|
|
bool HistoryItem::hasDirectLink() const {
|
2019-04-04 10:02:22 +00:00
|
|
|
return IsServerMsgId(id) && _history->peer->isChannel();
|
2017-07-11 17:21:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
ChannelId HistoryItem::channelId() const {
|
|
|
|
return _history->channelId();
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
Data::MessagePosition HistoryItem::position() const {
|
2020-10-09 12:56:33 +00:00
|
|
|
return { .fullId = fullId(), .date = date() };
|
2018-01-09 17:08:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
MsgId HistoryItem::replyToId() const {
|
2018-06-04 16:58:35 +00:00
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
2017-12-18 15:44:50 +00:00
|
|
|
return reply->replyToId();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
MsgId HistoryItem::replyToTop() const {
|
|
|
|
if (const auto reply = Get<HistoryMessageReply>()) {
|
|
|
|
return reply->replyToTop();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
not_null<PeerData*> HistoryItem::author() const {
|
|
|
|
return isPost() ? history()->peer : from();
|
|
|
|
}
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId HistoryItem::dateOriginal() const {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->originalDate;
|
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
return date();
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
PeerData *HistoryItem::senderOriginal() const {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->originalSender;
|
|
|
|
}
|
|
|
|
const auto peer = history()->peer;
|
|
|
|
return (peer->isChannel() && !peer->isMegagroup()) ? peer : from();
|
|
|
|
}
|
|
|
|
|
2019-03-15 15:15:56 +00:00
|
|
|
const HiddenSenderInfo *HistoryItem::hiddenForwardedInfo() const {
|
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->hiddenSenderInfo.get();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
not_null<PeerData*> HistoryItem::fromOriginal() const {
|
2017-12-18 15:44:50 +00:00
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
2019-03-15 15:15:56 +00:00
|
|
|
if (forwarded->originalSender) {
|
|
|
|
if (const auto user = forwarded->originalSender->asUser()) {
|
|
|
|
return user;
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return from();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString HistoryItem::authorOriginal() const {
|
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->originalAuthor;
|
|
|
|
} else if (const auto msgsigned = Get<HistoryMessageSigned>()) {
|
2020-10-01 09:57:03 +00:00
|
|
|
if (!msgsigned->isAnonymousRank) {
|
|
|
|
return msgsigned->author;
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
MsgId HistoryItem::idOriginal() const {
|
|
|
|
if (const auto forwarded = Get<HistoryMessageForwarded>()) {
|
|
|
|
return forwarded->originalId;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2020-05-09 20:34:57 +00:00
|
|
|
void HistoryItem::updateDate(TimeId newDate) {
|
|
|
|
if (canUpdateDate() && _date != newDate) {
|
|
|
|
_date = newDate;
|
|
|
|
_history->owner().requestItemViewRefresh(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HistoryItem::canUpdateDate() const {
|
|
|
|
return isScheduled();
|
|
|
|
}
|
|
|
|
|
2020-06-04 10:29:16 +00:00
|
|
|
bool HistoryItem::canBeEditedFromHistory() const {
|
|
|
|
// Skip if message is editing media.
|
|
|
|
if (isEditingMedia()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Skip if message is video message or sticker.
|
|
|
|
if (const auto m = media()) {
|
|
|
|
// Skip only if media is not webpage.
|
|
|
|
if (!m->webpage() && !m->allowsEditCaption()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((IsServerMsgId(id) || isScheduled())
|
|
|
|
&& !serviceMsg()
|
|
|
|
&& (out() || history()->peer->isSelf())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-17 14:34:39 +00:00
|
|
|
void HistoryItem::sendFailed() {
|
2019-08-09 19:19:23 +00:00
|
|
|
Expects(_clientFlags & MTPDmessage_ClientFlag::f_sending);
|
|
|
|
Expects(!(_clientFlags & MTPDmessage_ClientFlag::f_failed));
|
2019-07-17 14:34:39 +00:00
|
|
|
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags = (_clientFlags | MTPDmessage_ClientFlag::f_failed)
|
2019-07-17 14:34:39 +00:00
|
|
|
& ~MTPDmessage_ClientFlag::f_sending;
|
2020-06-12 12:12:34 +00:00
|
|
|
history()->session().changes().historyUpdated(
|
|
|
|
history(),
|
|
|
|
Data::HistoryUpdate::Flag::LocalMessages);
|
2019-07-17 14:34:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
bool HistoryItem::needCheck() const {
|
|
|
|
return out() || (id < 0 && history()->peer->isSelf());
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
bool HistoryItem::unread() const {
|
2019-08-31 11:32:15 +00:00
|
|
|
// Messages from myself are always read, unless scheduled.
|
|
|
|
if (history()->peer->isSelf() && !isFromScheduled()) {
|
2019-04-23 09:40:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
if (out()) {
|
|
|
|
// Outgoing messages in converted chats are always read.
|
2017-04-02 10:25:54 +00:00
|
|
|
if (history()->peer->migrateTo()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
if (IsServerMsgId(id)) {
|
|
|
|
if (!history()->isServerSideUnread(this)) {
|
2017-04-02 10:25:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-31 17:10:29 +00:00
|
|
|
if (const auto user = history()->peer->asUser()) {
|
2019-07-18 08:51:11 +00:00
|
|
|
if (user->isBot()) {
|
2017-04-02 10:25:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-23 09:40:14 +00:00
|
|
|
} else if (const auto channel = history()->peer->asChannel()) {
|
2017-04-02 10:25:54 +00:00
|
|
|
if (!channel->isMegagroup()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-31 17:10:29 +00:00
|
|
|
if (IsServerMsgId(id)) {
|
|
|
|
if (!history()->isServerSideUnread(this)) {
|
2017-04-02 10:25:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-09 19:19:23 +00:00
|
|
|
return (_clientFlags & MTPDmessage_ClientFlag::f_clientside_unread);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 14:24:12 +00:00
|
|
|
bool HistoryItem::showNotification() const {
|
|
|
|
const auto channel = _history->peer->asChannel();
|
|
|
|
if (channel && !channel->amIn()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-25 09:08:08 +00:00
|
|
|
return (out() || _history->peer->isSelf())
|
|
|
|
? isFromScheduled()
|
|
|
|
: unread();
|
2019-08-28 14:24:12 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 09:48:48 +00:00
|
|
|
void HistoryItem::markClientSideAsRead() {
|
2019-08-09 19:19:23 +00:00
|
|
|
_clientFlags &= ~MTPDmessage_ClientFlag::f_clientside_unread;
|
2019-04-30 09:48:48 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
MessageGroupId HistoryItem::groupId() const {
|
2018-01-14 16:02:25 +00:00
|
|
|
return _groupId;
|
2017-12-13 18:10:48 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool HistoryItem::isEmpty() const {
|
|
|
|
return _text.isEmpty()
|
|
|
|
&& !_media
|
|
|
|
&& !Has<HistoryMessageLogEntryOriginal>();
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
QString HistoryItem::notificationText() const {
|
2019-04-08 11:53:08 +00:00
|
|
|
const auto result = [&] {
|
2018-01-18 13:59:22 +00:00
|
|
|
if (_media) {
|
|
|
|
return _media->notificationText();
|
|
|
|
} else if (!emptyText()) {
|
2019-04-08 11:53:08 +00:00
|
|
|
return _text.toString();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
return QString();
|
2019-04-08 11:53:08 +00:00
|
|
|
}();
|
|
|
|
return (result.size() <= kNotificationTextLimit)
|
|
|
|
? result
|
|
|
|
: result.mid(0, kNotificationTextLimit) + qsl("...");
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2017-09-05 17:21:56 +00:00
|
|
|
QString HistoryItem::inDialogsText(DrawInDialog way) const {
|
2016-09-27 14:20:49 +00:00
|
|
|
auto getText = [this]() {
|
2018-01-18 13:59:22 +00:00
|
|
|
if (_media) {
|
2019-03-03 09:32:01 +00:00
|
|
|
if (_groupId) {
|
2019-06-19 15:09:03 +00:00
|
|
|
return textcmdLink(1, TextUtilities::Clean(tr::lng_in_dlg_album(tr::now)));
|
2019-03-03 09:32:01 +00:00
|
|
|
}
|
2019-01-15 11:57:45 +00:00
|
|
|
return _media->chatListText();
|
2018-01-18 13:59:22 +00:00
|
|
|
} else if (!emptyText()) {
|
2019-04-08 11:53:08 +00:00
|
|
|
return TextUtilities::Clean(_text.toString());
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
return QString();
|
2016-09-27 14:20:49 +00:00
|
|
|
};
|
2017-12-05 16:38:13 +00:00
|
|
|
const auto plainText = getText();
|
|
|
|
const auto sender = [&]() -> PeerData* {
|
|
|
|
if (isPost() || isEmpty() || (way == DrawInDialog::WithoutSender)) {
|
|
|
|
return nullptr;
|
|
|
|
} else if (!_history->peer->isUser() || out()) {
|
2019-05-25 15:05:57 +00:00
|
|
|
return displayFrom();
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (_history->peer->isSelf() && !Has<HistoryMessageForwarded>()) {
|
2017-12-05 16:38:13 +00:00
|
|
|
return senderOriginal();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
|
|
|
if (sender) {
|
2019-06-19 15:09:03 +00:00
|
|
|
auto fromText = sender->isSelf() ? tr::lng_from_you(tr::now) : sender->shortName();
|
2019-06-19 16:39:25 +00:00
|
|
|
auto fromWrapped = textcmdLink(1, tr::lng_dialogs_text_from_wrapped(tr::now, lt_from, TextUtilities::Clean(fromText)));
|
|
|
|
return tr::lng_dialogs_text_with_from(tr::now, lt_from_part, fromWrapped, lt_message, plainText);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
return plainText;
|
|
|
|
}
|
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
Ui::Text::IsolatedEmoji HistoryItem::isolatedEmoji() const {
|
|
|
|
return Ui::Text::IsolatedEmoji();
|
|
|
|
}
|
|
|
|
|
2017-09-05 17:21:56 +00:00
|
|
|
void HistoryItem::drawInDialog(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &r,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
|
|
|
DrawInDialog way,
|
|
|
|
const HistoryItem *&cacheFor,
|
2019-06-12 13:26:04 +00:00
|
|
|
Ui::Text::String &cache) const {
|
2019-04-23 12:29:23 +00:00
|
|
|
if (r.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
if (cacheFor != this) {
|
|
|
|
cacheFor = this;
|
2017-12-28 13:06:06 +00:00
|
|
|
cache.setText(st::dialogsTextStyle, inDialogsText(way), Ui::DialogTextOptions());
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-04-23 12:29:23 +00:00
|
|
|
p.setTextPalette(active ? st::dialogsTextPaletteActive : (selected ? st::dialogsTextPaletteOver : st::dialogsTextPalette));
|
|
|
|
p.setFont(st::dialogsTextFont);
|
|
|
|
p.setPen(active ? st::dialogsTextFgActive : (selected ? st::dialogsTextFgOver : st::dialogsTextFg));
|
|
|
|
cache.drawElided(p, r.left(), r.top(), r.width(), r.height() / st::dialogsTextFont->height);
|
|
|
|
p.restoreTextPalette();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 08:04:42 +00:00
|
|
|
HistoryItem::~HistoryItem() = default;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
QDateTime ItemDateTime(not_null<const HistoryItem*> item) {
|
2019-07-10 17:28:33 +00:00
|
|
|
return base::unixtime::parse(item->date());
|
2018-02-03 19:52:35 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 22:23:16 +00:00
|
|
|
QString ItemDateText(not_null<const HistoryItem*> item, bool isUntilOnline) {
|
|
|
|
const auto dateText = langDayOfMonthFull(ItemDateTime(item).date());
|
|
|
|
return !item->isScheduled()
|
|
|
|
? dateText
|
|
|
|
: isUntilOnline
|
|
|
|
? tr::lng_scheduled_date_until_online(tr::now)
|
|
|
|
: tr::lng_scheduled_date(tr::now, lt_date, dateText);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsItemScheduledUntilOnline(not_null<const HistoryItem*> item) {
|
|
|
|
return item->isScheduled()
|
|
|
|
&& (item->date() ==
|
|
|
|
Data::ScheduledMessages::kScheduledUntilOnlineTimestamp);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
FullMsgId returnToId) {
|
|
|
|
return goToMessageClickHandler(
|
|
|
|
item->history()->peer,
|
|
|
|
item->id,
|
|
|
|
returnToId);
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<PeerData*> peer,
|
2018-01-26 15:40:11 +00:00
|
|
|
MsgId msgId,
|
|
|
|
FullMsgId returnToId) {
|
2018-01-13 12:45:11 +00:00
|
|
|
return std::make_shared<LambdaClickHandler>([=] {
|
2020-06-11 16:33:15 +00:00
|
|
|
if (const auto main = App::main()) { // multi good
|
|
|
|
if (&main->session() == &peer->session()) {
|
2020-08-31 11:17:02 +00:00
|
|
|
auto params = Window::SectionShow{
|
|
|
|
Window::SectionShow::Way::Forward
|
|
|
|
};
|
|
|
|
params.origin = Window::SectionShow::OriginMessage{
|
|
|
|
returnToId
|
|
|
|
};
|
|
|
|
main->controller()->showPeerHistory(peer, params, msgId);
|
2016-11-16 10:44:06 +00:00
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-11-16 10:44:06 +00:00
|
|
|
});
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
not_null<HistoryItem*> HistoryItem::Create(
|
|
|
|
not_null<History*> history,
|
2019-08-09 19:19:23 +00:00
|
|
|
const MTPMessage &message,
|
|
|
|
MTPDmessage_ClientFlags clientFlags) {
|
2018-12-17 08:16:06 +00:00
|
|
|
return message.match([&](const MTPDmessage &data) -> HistoryItem* {
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto media = data.vmedia();
|
|
|
|
const auto checked = media
|
|
|
|
? CheckMessageMedia(*media)
|
2018-12-17 08:16:06 +00:00
|
|
|
: MediaCheckResult::Good;
|
|
|
|
if (checked == MediaCheckResult::Unsupported) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return CreateUnsupportedMessage(
|
|
|
|
history,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vid().v,
|
|
|
|
data.vflags().v,
|
2019-08-09 19:19:23 +00:00
|
|
|
clientFlags,
|
2020-09-11 16:22:14 +00:00
|
|
|
MsgId(0), // No need to pass reply_to data here.
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vvia_bot_id().value_or_empty(),
|
|
|
|
data.vdate().v,
|
2020-09-01 06:44:18 +00:00
|
|
|
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0));
|
2018-12-17 08:16:06 +00:00
|
|
|
} else if (checked == MediaCheckResult::Empty) {
|
2020-09-01 06:44:18 +00:00
|
|
|
const auto text = HistoryService::PreparedText{
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_message_empty(tr::now)
|
2018-01-14 16:02:25 +00:00
|
|
|
};
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeServiceMessage(
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vid().v,
|
2020-02-20 08:45:25 +00:00
|
|
|
clientFlags,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vdate().v,
|
2018-01-14 16:02:25 +00:00
|
|
|
text,
|
2019-07-05 13:38:38 +00:00
|
|
|
data.vflags().v,
|
2020-09-01 06:44:18 +00:00
|
|
|
data.vfrom_id() ? peerFromMTP(*data.vfrom_id()) : PeerId(0));
|
2018-12-17 08:16:06 +00:00
|
|
|
} else if (checked == MediaCheckResult::HasTimeToLive) {
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeServiceMessage(data, clientFlags);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeMessage(data, clientFlags);
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [&](const MTPDmessageService &data) -> HistoryItem* {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (data.vaction().type() == mtpc_messageActionPhoneCall) {
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeMessage(data, clientFlags);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeServiceMessage(data, clientFlags);
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [&](const MTPDmessageEmpty &data) -> HistoryItem* {
|
|
|
|
const auto text = HistoryService::PreparedText{
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_message_empty(tr::now)
|
2018-12-17 08:16:06 +00:00
|
|
|
};
|
2020-02-20 08:45:25 +00:00
|
|
|
return history->makeServiceMessage(
|
2019-08-09 19:19:23 +00:00
|
|
|
data.vid().v,
|
2020-02-20 08:45:25 +00:00
|
|
|
clientFlags,
|
2019-08-09 19:19:23 +00:00
|
|
|
TimeId(0),
|
|
|
|
text);
|
2018-12-17 08:16:06 +00:00
|
|
|
});
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|