2018-01-14 16:02:25 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "data/data_media_types.h"
|
|
|
|
|
|
|
|
#include "history/history_media_types.h"
|
|
|
|
#include "history/history_item.h"
|
|
|
|
#include "history/history_location_manager.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2018-01-26 15:40:11 +00:00
|
|
|
#include "ui/text_options.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
|
|
|
#include "storage/localstorage.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "auth_session.h"
|
2018-01-14 16:02:25 +00:00
|
|
|
#include "layout.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
Call ComputeCallData(const MTPDmessageActionPhoneCall &call) {
|
|
|
|
auto result = Call();
|
|
|
|
result.finishReason = [&] {
|
|
|
|
if (call.has_reason()) {
|
|
|
|
switch (call.vreason.type()) {
|
|
|
|
case mtpc_phoneCallDiscardReasonBusy:
|
|
|
|
return CallFinishReason::Busy;
|
|
|
|
case mtpc_phoneCallDiscardReasonDisconnect:
|
|
|
|
return CallFinishReason::Disconnected;
|
|
|
|
case mtpc_phoneCallDiscardReasonHangup:
|
|
|
|
return CallFinishReason::Hangup;
|
|
|
|
case mtpc_phoneCallDiscardReasonMissed:
|
|
|
|
return CallFinishReason::Missed;
|
|
|
|
}
|
|
|
|
Unexpected("Call reason type.");
|
|
|
|
}
|
|
|
|
return CallFinishReason::Hangup;
|
|
|
|
}();
|
|
|
|
result.duration = call.has_duration() ? call.vduration.v : 0;;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Invoice ComputeInvoiceData(const MTPDmessageMediaInvoice &data) {
|
|
|
|
auto result = Invoice();
|
|
|
|
result.isTest = data.is_test();
|
|
|
|
result.amount = data.vtotal_amount.v;
|
|
|
|
result.currency = qs(data.vcurrency);
|
|
|
|
result.description = qs(data.vdescription);
|
|
|
|
result.title = TextUtilities::SingleLine(qs(data.vtitle));
|
|
|
|
if (data.has_receipt_msg_id()) {
|
|
|
|
result.receiptMsgId = data.vreceipt_msg_id.v;
|
|
|
|
}
|
2018-03-04 20:04:13 +00:00
|
|
|
if (data.has_photo()) {
|
|
|
|
const auto thumb = ImagePtr();
|
|
|
|
result.photo = Auth().data().photoFromWeb(data.vphoto, thumb);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WithCaptionDialogsText(
|
|
|
|
const QString &attachType,
|
|
|
|
const QString &caption) {
|
|
|
|
if (caption.isEmpty()) {
|
|
|
|
return textcmdLink(1, TextUtilities::Clean(attachType));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto captionText = TextUtilities::Clean(caption);
|
|
|
|
auto attachTypeWrapped = textcmdLink(1, lng_dialogs_text_media_wrapped(
|
|
|
|
lt_media,
|
|
|
|
TextUtilities::Clean(attachType)));
|
|
|
|
return lng_dialogs_text_media(
|
|
|
|
lt_media_part,
|
|
|
|
attachTypeWrapped,
|
|
|
|
lt_caption,
|
|
|
|
captionText);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString WithCaptionNotificationText(
|
|
|
|
const QString &attachType,
|
|
|
|
const QString &caption) {
|
|
|
|
if (caption.isEmpty()) {
|
|
|
|
return attachType;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto attachTypeWrapped = lng_dialogs_text_media_wrapped(
|
|
|
|
lt_media,
|
|
|
|
attachType);
|
|
|
|
return lng_dialogs_text_media(
|
|
|
|
lt_media_part,
|
|
|
|
attachTypeWrapped,
|
|
|
|
lt_caption,
|
|
|
|
caption);
|
|
|
|
}
|
|
|
|
|
2018-01-27 17:26:24 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities WithCaptionClipboardText(
|
|
|
|
const QString &attachType,
|
|
|
|
TextWithEntities &&caption) {
|
|
|
|
TextWithEntities result;
|
|
|
|
result.text.reserve(5 + attachType.size() + caption.text.size());
|
|
|
|
result.text.append(qstr("[ ")).append(attachType).append(qstr(" ]"));
|
|
|
|
if (!caption.text.isEmpty()) {
|
|
|
|
result.text.append(qstr("\n"));
|
|
|
|
TextUtilities::Append(result, std::move(caption));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
Media::Media(not_null<HistoryItem*> parent) : _parent(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<HistoryItem*> Media::parent() const {
|
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *Media::document() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *Media::photo() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebPageData *Media::webpage() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SharedContact *Media::sharedContact() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Call *Media::call() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameData *Media::game() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Invoice *Media::invoice() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocationData *Media::location() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::uploading() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage::SharedMediaTypesMask Media::sharedMediaTypes() const {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
bool Media::canBeGrouped() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString Media::chatsListText() const {
|
|
|
|
auto result = notificationText();
|
|
|
|
return result.isEmpty()
|
|
|
|
? QString()
|
|
|
|
: textcmdLink(1, TextUtilities::Clean(std::move(result)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::hasReplyPreview() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr Media::replyPreview() const {
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::allowsForward() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::allowsEdit() const {
|
|
|
|
return allowsEditCaption();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::allowsEditCaption() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::allowsRevoke() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::forwardedBecomesUnread() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Media::errorTextForForward(not_null<ChannelData*> channel) const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Media::consumeMessageText(const TextWithEntities &text) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:41:48 +00:00
|
|
|
TextWithEntities Media::consumedMessageText() const {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
std::unique_ptr<HistoryMedia> Media::createView(
|
|
|
|
not_null<HistoryView::Element*> message) {
|
|
|
|
return createView(message, message->data());
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
MediaPhoto::MediaPhoto(
|
|
|
|
not_null<HistoryItem*> parent,
|
2018-01-18 13:59:22 +00:00
|
|
|
not_null<PhotoData*> photo)
|
2018-01-14 16:02:25 +00:00
|
|
|
: Media(parent)
|
2018-01-18 13:59:22 +00:00
|
|
|
, _photo(photo) {
|
2018-01-21 19:52:44 +00:00
|
|
|
Auth().data().registerPhotoItem(_photo, parent);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaPhoto::MediaPhoto(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<PeerData*> chat,
|
|
|
|
not_null<PhotoData*> photo)
|
|
|
|
: Media(parent)
|
|
|
|
, _photo(photo)
|
|
|
|
, _chat(chat) {
|
2018-01-21 19:52:44 +00:00
|
|
|
Auth().data().registerPhotoItem(_photo, parent);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaPhoto::~MediaPhoto() {
|
2018-01-21 19:52:44 +00:00
|
|
|
Auth().data().unregisterPhotoItem(_photo, parent());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaPhoto::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return _chat
|
|
|
|
? std::make_unique<MediaPhoto>(parent, _chat, _photo)
|
2018-01-18 13:59:22 +00:00
|
|
|
: std::make_unique<MediaPhoto>(parent, _photo);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *MediaPhoto::photo() const {
|
|
|
|
return _photo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaPhoto::uploading() const {
|
|
|
|
return _photo->uploading();
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage::SharedMediaTypesMask MediaPhoto::sharedMediaTypes() const {
|
|
|
|
using Type = Storage::SharedMediaType;
|
|
|
|
if (_chat) {
|
|
|
|
return Type::ChatPhoto;
|
|
|
|
}
|
|
|
|
return Storage::SharedMediaTypesMask{}
|
|
|
|
.added(Type::Photo)
|
|
|
|
.added(Type::PhotoVideo);
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
bool MediaPhoto::canBeGrouped() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:55:53 +00:00
|
|
|
bool MediaPhoto::hasReplyPreview() const {
|
|
|
|
return !_photo->thumb->isNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr MediaPhoto::replyPreview() const {
|
|
|
|
return _photo->makeReplyPreview();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaPhoto::notificationText() const {
|
2018-01-18 13:59:22 +00:00
|
|
|
return WithCaptionNotificationText(
|
|
|
|
lang(lng_in_dlg_photo),
|
|
|
|
parent()->originalText().text);
|
2018-01-14 16:02:25 +00:00
|
|
|
//return WithCaptionNotificationText(lang(lng_in_dlg_album), _caption);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaPhoto::chatsListText() const {
|
2018-01-18 13:59:22 +00:00
|
|
|
return WithCaptionDialogsText(
|
|
|
|
lang(lng_in_dlg_photo),
|
|
|
|
parent()->originalText().text);
|
2018-01-14 16:02:25 +00:00
|
|
|
//return WithCaptionDialogsText(lang(lng_in_dlg_album), _caption);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaPhoto::pinnedTextSubstring() const {
|
|
|
|
return lang(lng_action_pinned_media_photo);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaPhoto::clipboardText() const {
|
|
|
|
return WithCaptionClipboardText(
|
|
|
|
lang(lng_in_dlg_photo),
|
|
|
|
parent()->clipboardText());
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaPhoto::allowsEditCaption() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaPhoto::errorTextForForward(
|
|
|
|
not_null<ChannelData*> channel) const {
|
|
|
|
if (channel->restricted(ChannelRestriction::f_send_media)) {
|
|
|
|
return lang(lng_restricted_send_media);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaPhoto::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaPhoto) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &photo = media.c_messageMediaPhoto();
|
|
|
|
if (photo.has_photo() && !photo.has_ttl_seconds()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
if (auto existing = Auth().data().photo(photo.vphoto)) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (existing == _photo) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
// collect data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"Got MTPMessageMediaPhoto without photo "
|
|
|
|
"or with ttl_seconds in updateInlineResultMedia()"));
|
|
|
|
}
|
|
|
|
// Can return false if we collect the data.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaPhoto) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &mediaPhoto = media.c_messageMediaPhoto();
|
|
|
|
if (!mediaPhoto.has_photo() || mediaPhoto.has_ttl_seconds()) {
|
|
|
|
LOG(("Api Error: "
|
|
|
|
"Got MTPMessageMediaPhoto without photo "
|
|
|
|
"or with ttl_seconds in updateSentMedia()"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto &photo = mediaPhoto.vphoto;
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().photoConvert(_photo, photo);
|
2018-01-14 16:02:25 +00:00
|
|
|
|
|
|
|
if (photo.type() != mtpc_photo) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &sizes = photo.c_photo().vsizes.v;
|
|
|
|
auto max = 0;
|
|
|
|
const MTPDfileLocation *maxLocation = 0;
|
|
|
|
for (const auto &data : sizes) {
|
|
|
|
char size = 0;
|
|
|
|
const MTPFileLocation *loc = 0;
|
|
|
|
switch (data.type()) {
|
|
|
|
case mtpc_photoSize: {
|
|
|
|
const auto &s = data.c_photoSize().vtype.v;
|
|
|
|
loc = &data.c_photoSize().vlocation;
|
|
|
|
if (s.size()) size = s[0];
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case mtpc_photoCachedSize: {
|
|
|
|
const auto &s = data.c_photoCachedSize().vtype.v;
|
|
|
|
loc = &data.c_photoCachedSize().vlocation;
|
|
|
|
if (s.size()) size = s[0];
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!loc || loc->type() != mtpc_fileLocation) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (size == 's') {
|
|
|
|
Local::writeImage(storageKey(loc->c_fileLocation()), _photo->thumb);
|
|
|
|
} else if (size == 'm') {
|
|
|
|
Local::writeImage(storageKey(loc->c_fileLocation()), _photo->medium);
|
|
|
|
} else if (size == 'x' && max < 1) {
|
|
|
|
max = 1;
|
|
|
|
maxLocation = &loc->c_fileLocation();
|
|
|
|
} else if (size == 'y' && max < 2) {
|
|
|
|
max = 2;
|
|
|
|
maxLocation = &loc->c_fileLocation();
|
|
|
|
//} else if (size == 'w' && max < 3) {
|
|
|
|
// max = 3;
|
|
|
|
// maxLocation = &loc->c_fileLocation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (maxLocation) {
|
|
|
|
Local::writeImage(storageKey(*maxLocation), _photo->full);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaPhoto::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (_chat) {
|
|
|
|
return std::make_unique<HistoryPhoto>(
|
|
|
|
message,
|
|
|
|
_chat,
|
|
|
|
_photo,
|
|
|
|
st::msgServicePhotoWidth);
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<HistoryPhoto>(
|
|
|
|
message,
|
|
|
|
realParent,
|
2018-01-18 13:59:22 +00:00
|
|
|
_photo);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaFile::MediaFile(
|
|
|
|
not_null<HistoryItem*> parent,
|
2018-01-18 13:59:22 +00:00
|
|
|
not_null<DocumentData*> document)
|
2018-01-14 16:02:25 +00:00
|
|
|
: Media(parent)
|
|
|
|
, _document(document)
|
|
|
|
, _emoji(document->sticker() ? document->sticker()->alt : QString()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().registerDocumentItem(_document, parent);
|
2018-01-14 16:02:25 +00:00
|
|
|
|
|
|
|
if (!_emoji.isEmpty()) {
|
|
|
|
if (const auto emoji = Ui::Emoji::Find(_emoji)) {
|
|
|
|
_emoji = emoji->text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaFile::~MediaFile() {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().unregisterDocumentItem(_document, parent());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaFile::clone(not_null<HistoryItem*> parent) {
|
2018-01-18 13:59:22 +00:00
|
|
|
return std::make_unique<MediaFile>(parent, _document);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *MediaFile::document() const {
|
|
|
|
return _document;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFile::uploading() const {
|
|
|
|
return _document->uploading();
|
|
|
|
}
|
|
|
|
|
|
|
|
Storage::SharedMediaTypesMask MediaFile::sharedMediaTypes() const {
|
|
|
|
using Type = Storage::SharedMediaType;
|
|
|
|
if (_document->sticker()) {
|
|
|
|
return {};
|
|
|
|
} else if (_document->isVideoMessage()) {
|
|
|
|
return Storage::SharedMediaTypesMask{}
|
|
|
|
.added(Type::RoundFile)
|
|
|
|
.added(Type::RoundVoiceFile);
|
|
|
|
} else if (_document->isGifv()) {
|
|
|
|
return Type::GIF;
|
|
|
|
} else if (_document->isVideoFile()) {
|
|
|
|
return Storage::SharedMediaTypesMask{}
|
|
|
|
.added(Type::Video)
|
|
|
|
.added(Type::PhotoVideo);
|
|
|
|
} else if (_document->isVoiceMessage()) {
|
|
|
|
return Storage::SharedMediaTypesMask{}
|
|
|
|
.added(Type::VoiceFile)
|
|
|
|
.added(Type::RoundVoiceFile);
|
|
|
|
} else if (_document->isSharedMediaMusic()) {
|
|
|
|
return Type::MusicFile;
|
|
|
|
}
|
|
|
|
return Type::File;
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
bool MediaFile::canBeGrouped() const {
|
|
|
|
return _document->isVideoFile();
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:55:53 +00:00
|
|
|
bool MediaFile::hasReplyPreview() const {
|
|
|
|
return !_document->thumb->isNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr MediaFile::replyPreview() const {
|
|
|
|
return _document->makeReplyPreview();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaFile::chatsListText() const {
|
|
|
|
if (const auto sticker = _document->sticker()) {
|
|
|
|
return Media::chatsListText();
|
|
|
|
}
|
|
|
|
const auto type = [&] {
|
|
|
|
if (_document->isVideoMessage()) {
|
|
|
|
return lang(lng_in_dlg_video_message);
|
|
|
|
} else if (_document->isAnimation()) {
|
|
|
|
return qsl("GIF");
|
|
|
|
} else if (_document->isVideoFile()) {
|
|
|
|
return lang(lng_in_dlg_video);
|
|
|
|
} else if (_document->isVoiceMessage()) {
|
|
|
|
return lang(lng_in_dlg_audio);
|
2018-03-14 23:38:39 +00:00
|
|
|
} else if (const auto name = _document->composeNameString();
|
|
|
|
!name.isEmpty()) {
|
|
|
|
return name;
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (_document->isAudioFile()) {
|
|
|
|
return lang(lng_in_dlg_audio_file);
|
|
|
|
}
|
|
|
|
return lang(lng_in_dlg_file);
|
|
|
|
}();
|
2018-01-18 13:59:22 +00:00
|
|
|
return WithCaptionDialogsText(type, parent()->originalText().text);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaFile::notificationText() const {
|
|
|
|
if (const auto sticker = _document->sticker()) {
|
|
|
|
return _emoji.isEmpty()
|
|
|
|
? lang(lng_in_dlg_sticker)
|
|
|
|
: lng_in_dlg_sticker_emoji(lt_emoji, _emoji);
|
|
|
|
}
|
|
|
|
const auto type = [&] {
|
|
|
|
if (_document->isVideoMessage()) {
|
|
|
|
return lang(lng_in_dlg_video_message);
|
|
|
|
} else if (_document->isAnimation()) {
|
|
|
|
return qsl("GIF");
|
|
|
|
} else if (_document->isVideoFile()) {
|
|
|
|
return lang(lng_in_dlg_video);
|
|
|
|
} else if (_document->isVoiceMessage()) {
|
|
|
|
return lang(lng_in_dlg_audio);
|
|
|
|
} else if (!_document->filename().isEmpty()) {
|
|
|
|
return _document->filename();
|
|
|
|
} else if (_document->isAudioFile()) {
|
|
|
|
return lang(lng_in_dlg_audio_file);
|
|
|
|
}
|
|
|
|
return lang(lng_in_dlg_file);
|
|
|
|
}();
|
2018-01-18 13:59:22 +00:00
|
|
|
return WithCaptionNotificationText(type, parent()->originalText().text);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaFile::pinnedTextSubstring() const {
|
|
|
|
if (const auto sticker = _document->sticker()) {
|
|
|
|
if (!_emoji.isEmpty()) {
|
|
|
|
return lng_action_pinned_media_emoji_sticker(lt_emoji, _emoji);
|
|
|
|
}
|
|
|
|
return lang(lng_action_pinned_media_sticker);
|
|
|
|
} else if (_document->isAnimation()) {
|
|
|
|
if (_document->isVideoMessage()) {
|
|
|
|
return lang(lng_action_pinned_media_video_message);
|
|
|
|
}
|
|
|
|
return lang(lng_action_pinned_media_gif);
|
|
|
|
} else if (_document->isVideoFile()) {
|
|
|
|
return lang(lng_action_pinned_media_video);
|
|
|
|
} else if (_document->isVoiceMessage()) {
|
|
|
|
return lang(lng_action_pinned_media_voice);
|
|
|
|
} else if (_document->isSong()) {
|
|
|
|
return lang(lng_action_pinned_media_audio);
|
|
|
|
}
|
|
|
|
return lang(lng_action_pinned_media_file);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaFile::clipboardText() const {
|
|
|
|
const auto attachType = [&] {
|
|
|
|
const auto name = _document->composeNameString();
|
|
|
|
const auto addName = !name.isEmpty()
|
|
|
|
? qstr(" : ") + name
|
|
|
|
: QString();
|
|
|
|
if (const auto sticker = _document->sticker()) {
|
|
|
|
if (!_emoji.isEmpty()) {
|
|
|
|
return lng_in_dlg_sticker_emoji(lt_emoji, _emoji);
|
|
|
|
}
|
|
|
|
return lang(lng_in_dlg_sticker);
|
|
|
|
} else if (_document->isAnimation()) {
|
|
|
|
if (_document->isVideoMessage()) {
|
|
|
|
return lang(lng_in_dlg_video_message);
|
|
|
|
}
|
|
|
|
return qsl("GIF");
|
|
|
|
} else if (_document->isVideoFile()) {
|
|
|
|
return lang(lng_in_dlg_video);
|
|
|
|
} else if (_document->isVoiceMessage()) {
|
|
|
|
return lang(lng_in_dlg_audio) + addName;
|
|
|
|
} else if (_document->isSong()) {
|
|
|
|
return lang(lng_in_dlg_audio_file) + addName;
|
|
|
|
}
|
|
|
|
return lang(lng_in_dlg_file) + addName;
|
|
|
|
}();
|
|
|
|
return WithCaptionClipboardText(
|
|
|
|
attachType,
|
|
|
|
parent()->clipboardText());
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaFile::allowsEditCaption() const {
|
|
|
|
return !_document->isVideoMessage() && !_document->sticker();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFile::forwardedBecomesUnread() const {
|
|
|
|
return _document->isVoiceMessage()
|
|
|
|
//|| _document->isVideoFile()
|
|
|
|
|| _document->isVideoMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaFile::errorTextForForward(
|
|
|
|
not_null<ChannelData*> channel) const {
|
|
|
|
if (const auto sticker = _document->sticker()) {
|
|
|
|
if (channel->restricted(ChannelRestriction::f_send_stickers)) {
|
|
|
|
return lang(lng_restricted_send_stickers);
|
|
|
|
}
|
|
|
|
} else if (_document->isAnimation()) {
|
|
|
|
if (_document->isVideoMessage()) {
|
|
|
|
if (channel->restricted(ChannelRestriction::f_send_media)) {
|
|
|
|
return lang(lng_restricted_send_media);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (channel->restricted(ChannelRestriction::f_send_gifs)) {
|
|
|
|
return lang(lng_restricted_send_gifs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (channel->restricted(ChannelRestriction::f_send_media)) {
|
|
|
|
return lang(lng_restricted_send_media);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFile::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaDocument) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &data = media.c_messageMediaDocument();
|
|
|
|
if (data.has_document() && !data.has_ttl_seconds()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
const auto document = Auth().data().document(data.vdocument);
|
|
|
|
if (document == _document) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
document->collectLocalData(_document);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: "
|
|
|
|
"Got MTPMessageMediaDocument without document "
|
|
|
|
"or with ttl_seconds in updateInlineResultMedia()"));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaFile::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaDocument) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto &data = media.c_messageMediaDocument();
|
|
|
|
if (!data.has_document() || data.has_ttl_seconds()) {
|
|
|
|
LOG(("Api Error: "
|
|
|
|
"Got MTPMessageMediaDocument without document "
|
|
|
|
"or with ttl_seconds in updateSentMedia()"));
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().documentConvert(_document, data.vdocument);
|
|
|
|
if (!_document->data().isEmpty()) {
|
|
|
|
if (_document->isVoiceMessage()) {
|
|
|
|
Local::writeAudio(_document->mediaKey(), _document->data());
|
2018-01-14 16:02:25 +00:00
|
|
|
} else {
|
2018-01-17 16:21:01 +00:00
|
|
|
Local::writeStickerImage(_document->mediaKey(), _document->data());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaFile::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
if (_document->sticker()) {
|
|
|
|
return std::make_unique<HistorySticker>(message, _document);
|
|
|
|
} else if (_document->isAnimation()) {
|
2018-01-18 13:59:22 +00:00
|
|
|
return std::make_unique<HistoryGif>(message, _document);
|
2018-01-14 16:02:25 +00:00
|
|
|
} else if (_document->isVideoFile()) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return std::make_unique<HistoryVideo>(
|
|
|
|
message,
|
|
|
|
realParent,
|
2018-01-18 13:59:22 +00:00
|
|
|
_document);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
return std::make_unique<HistoryDocument>(message, _document);
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaContact::MediaContact(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
UserId userId,
|
|
|
|
const QString &firstName,
|
|
|
|
const QString &lastName,
|
|
|
|
const QString &phoneNumber)
|
|
|
|
: Media(parent) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().registerContactItem(userId, parent);
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
_contact.userId = userId;
|
|
|
|
_contact.firstName = firstName;
|
|
|
|
_contact.lastName = lastName;
|
|
|
|
_contact.phoneNumber = phoneNumber;
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:21:01 +00:00
|
|
|
MediaContact::~MediaContact() {
|
|
|
|
Auth().data().unregisterContactItem(_contact.userId, parent());
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
std::unique_ptr<Media> MediaContact::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return std::make_unique<MediaContact>(
|
|
|
|
parent,
|
|
|
|
_contact.userId,
|
|
|
|
_contact.firstName,
|
|
|
|
_contact.lastName,
|
|
|
|
_contact.phoneNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
const SharedContact *MediaContact::sharedContact() const {
|
|
|
|
return &_contact;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaContact::notificationText() const {
|
|
|
|
return lang(lng_in_dlg_contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaContact::pinnedTextSubstring() const {
|
|
|
|
return lang(lng_action_pinned_media_contact);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaContact::clipboardText() const {
|
|
|
|
const auto text = qsl("[ ") + lang(lng_in_dlg_contact) + qsl(" ]\n")
|
|
|
|
+ lng_full_name(
|
|
|
|
lt_first_name,
|
|
|
|
_contact.firstName,
|
|
|
|
lt_last_name,
|
|
|
|
_contact.lastName).trimmed()
|
|
|
|
+ '\n'
|
|
|
|
+ _contact.phoneNumber;
|
|
|
|
return { text, EntitiesInText() };
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaContact::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaContact::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaContact) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (_contact.userId != media.c_messageMediaContact().vuser_id.v) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().unregisterContactItem(_contact.userId, parent());
|
2018-01-14 16:02:25 +00:00
|
|
|
_contact.userId = media.c_messageMediaContact().vuser_id.v;
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().registerContactItem(_contact.userId, parent());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaContact::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryContact>(
|
|
|
|
message,
|
|
|
|
_contact.userId,
|
|
|
|
_contact.firstName,
|
|
|
|
_contact.lastName,
|
|
|
|
_contact.phoneNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaLocation::MediaLocation(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
const LocationCoords &coords)
|
|
|
|
: MediaLocation(parent, coords, QString(), QString()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaLocation::MediaLocation(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
const LocationCoords &coords,
|
|
|
|
const QString &title,
|
|
|
|
const QString &description)
|
|
|
|
: Media(parent)
|
|
|
|
, _location(App::location(coords))
|
|
|
|
, _title(title)
|
|
|
|
, _description(description) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaLocation::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return std::make_unique<MediaLocation>(
|
|
|
|
parent,
|
|
|
|
_location->coords,
|
|
|
|
_title,
|
|
|
|
_description);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocationData *MediaLocation::location() const {
|
|
|
|
return _location;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaLocation::chatsListText() const {
|
|
|
|
return WithCaptionDialogsText(lang(lng_maps_point), _title);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaLocation::notificationText() const {
|
|
|
|
return WithCaptionNotificationText(lang(lng_maps_point), _title);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaLocation::pinnedTextSubstring() const {
|
|
|
|
return lang(lng_action_pinned_media_location);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaLocation::clipboardText() const {
|
|
|
|
TextWithEntities result = {
|
|
|
|
qsl("[ ") + lang(lng_maps_point) + qsl(" ]\n"),
|
|
|
|
EntitiesInText()
|
|
|
|
};
|
|
|
|
auto titleResult = TextUtilities::ParseEntities(
|
|
|
|
TextUtilities::Clean(_title),
|
|
|
|
Ui::WebpageTextTitleOptions().flags);
|
|
|
|
auto descriptionResult = TextUtilities::ParseEntities(
|
|
|
|
TextUtilities::Clean(_description),
|
|
|
|
TextParseLinks | TextParseMultiline | TextParseRichText);
|
|
|
|
if (!titleResult.text.isEmpty()) {
|
|
|
|
TextUtilities::Append(result, std::move(titleResult));
|
|
|
|
result.text.append('\n');
|
|
|
|
}
|
|
|
|
if (!descriptionResult.text.isEmpty()) {
|
|
|
|
TextUtilities::Append(result, std::move(descriptionResult));
|
|
|
|
result.text.append('\n');
|
|
|
|
}
|
|
|
|
result.text += LocationClickHandler(_location->coords).dragText();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaLocation::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaLocation::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaLocation::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryLocation>(
|
|
|
|
message,
|
|
|
|
_location,
|
|
|
|
_title,
|
|
|
|
_description);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaCall::MediaCall(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
const MTPDmessageActionPhoneCall &call)
|
|
|
|
: Media(parent)
|
|
|
|
, _call(ComputeCallData(call)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaCall::clone(not_null<HistoryItem*> parent) {
|
|
|
|
Unexpected("Clone of call media.");
|
|
|
|
}
|
|
|
|
|
|
|
|
const Call *MediaCall::call() const {
|
|
|
|
return &_call;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaCall::notificationText() const {
|
|
|
|
auto result = Text(parent(), _call.finishReason);
|
|
|
|
if (_call.duration > 0) {
|
|
|
|
result = lng_call_type_and_duration(
|
|
|
|
lt_type,
|
|
|
|
result,
|
|
|
|
lt_duration,
|
|
|
|
formatDurationWords(_call.duration));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaCall::pinnedTextSubstring() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaCall::clipboardText() const {
|
|
|
|
return { qsl("[ ") + notificationText() + qsl(" ]"), EntitiesInText() };
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaCall::allowsForward() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaCall::allowsRevoke() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaCall::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaCall::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaCall::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryCall>(message, &_call);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaCall::Text(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
CallFinishReason reason) {
|
|
|
|
if (item->out()) {
|
|
|
|
return lang(reason == CallFinishReason::Missed
|
|
|
|
? lng_call_cancelled
|
|
|
|
: lng_call_outgoing);
|
|
|
|
} else if (reason == CallFinishReason::Missed) {
|
|
|
|
return lang(lng_call_missed);
|
|
|
|
} else if (reason == CallFinishReason::Busy) {
|
|
|
|
return lang(lng_call_declined);
|
|
|
|
}
|
|
|
|
return lang(lng_call_incoming);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaWebPage::MediaWebPage(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<WebPageData*> page)
|
|
|
|
: Media(parent)
|
|
|
|
, _page(page) {
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().registerWebPageItem(_page, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaWebPage::~MediaWebPage() {
|
|
|
|
Auth().data().unregisterWebPageItem(_page, parent());
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaWebPage::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return std::make_unique<MediaWebPage>(parent, _page);
|
|
|
|
}
|
|
|
|
|
2018-03-25 19:55:04 +00:00
|
|
|
DocumentData *MediaWebPage::document() const {
|
|
|
|
return _page->document;
|
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *MediaWebPage::photo() const {
|
|
|
|
return _page->photo;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
WebPageData *MediaWebPage::webpage() const {
|
|
|
|
return _page;
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:55:53 +00:00
|
|
|
bool MediaWebPage::hasReplyPreview() const {
|
|
|
|
if (const auto document = _page->document) {
|
|
|
|
return !document->thumb->isNull();
|
|
|
|
} else if (const auto photo = _page->photo) {
|
|
|
|
return !photo->thumb->isNull();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr MediaWebPage::replyPreview() const {
|
|
|
|
if (const auto document = _page->document) {
|
|
|
|
return document->makeReplyPreview();
|
|
|
|
} else if (const auto photo = _page->photo) {
|
|
|
|
return photo->makeReplyPreview();
|
|
|
|
}
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
|
2018-01-18 13:59:22 +00:00
|
|
|
QString MediaWebPage::chatsListText() const {
|
|
|
|
return notificationText();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaWebPage::notificationText() const {
|
2018-01-18 13:59:22 +00:00
|
|
|
return parent()->originalText().text;
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaWebPage::pinnedTextSubstring() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaWebPage::clipboardText() const {
|
|
|
|
return TextWithEntities();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaWebPage::allowsEdit() const {
|
2018-01-19 12:13:06 +00:00
|
|
|
return true;
|
2018-01-14 16:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaWebPage::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaWebPage::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaWebPage::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryWebPage>(message, _page);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaGame::MediaGame(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
not_null<GameData*> game)
|
|
|
|
: Media(parent)
|
|
|
|
, _game(game) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaGame::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return std::make_unique<MediaGame>(parent, _game);
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:55:53 +00:00
|
|
|
bool MediaGame::hasReplyPreview() const {
|
|
|
|
if (const auto document = _game->document) {
|
|
|
|
return !document->thumb->isNull();
|
|
|
|
} else if (const auto photo = _game->photo) {
|
|
|
|
return !photo->thumb->isNull();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr MediaGame::replyPreview() const {
|
|
|
|
if (const auto document = _game->document) {
|
|
|
|
return document->makeReplyPreview();
|
|
|
|
} else if (const auto photo = _game->photo) {
|
|
|
|
return photo->makeReplyPreview();
|
|
|
|
}
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaGame::notificationText() const {
|
|
|
|
// Add a game controller emoji before game title.
|
|
|
|
auto result = QString();
|
|
|
|
result.reserve(_game->title.size() + 3);
|
|
|
|
result.append(
|
|
|
|
QChar(0xD83C)
|
|
|
|
).append(
|
|
|
|
QChar(0xDFAE)
|
|
|
|
).append(
|
|
|
|
QChar(' ')
|
|
|
|
).append(_game->title);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameData *MediaGame::game() const {
|
|
|
|
return _game;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaGame::pinnedTextSubstring() const {
|
|
|
|
auto title = _game->title;
|
|
|
|
return lng_action_pinned_media_game(lt_game, title);
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaGame::clipboardText() const {
|
|
|
|
return TextWithEntities();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaGame::errorTextForForward(
|
|
|
|
not_null<ChannelData*> channel) const {
|
|
|
|
if (channel->restricted(ChannelRestriction::f_send_games)) {
|
|
|
|
return lang(lng_restricted_send_inline);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaGame::consumeMessageText(const TextWithEntities &text) {
|
|
|
|
_consumedText = text;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-07 07:41:48 +00:00
|
|
|
TextWithEntities MediaGame::consumedMessageText() const {
|
|
|
|
return _consumedText;
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaGame::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return updateSentMedia(media);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaGame::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
if (media.type() != mtpc_messageMediaGame) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
Auth().data().gameConvert(_game, media.c_messageMediaGame().vgame);
|
2018-01-14 16:02:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaGame::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryGame>(message, _game, _consumedText);
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaInvoice::MediaInvoice(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
const MTPDmessageMediaInvoice &data)
|
|
|
|
: Media(parent)
|
|
|
|
, _invoice(ComputeInvoiceData(data)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaInvoice::MediaInvoice(
|
|
|
|
not_null<HistoryItem*> parent,
|
|
|
|
const Invoice &data)
|
|
|
|
: Media(parent)
|
|
|
|
, _invoice(data) {
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Media> MediaInvoice::clone(not_null<HistoryItem*> parent) {
|
|
|
|
return std::make_unique<MediaInvoice>(parent, _invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Invoice *MediaInvoice::invoice() const {
|
|
|
|
return &_invoice;
|
|
|
|
}
|
|
|
|
|
2018-03-03 12:55:53 +00:00
|
|
|
bool MediaInvoice::hasReplyPreview() const {
|
|
|
|
if (const auto photo = _invoice.photo) {
|
|
|
|
return !photo->thumb->isNull();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr MediaInvoice::replyPreview() const {
|
|
|
|
if (const auto photo = _invoice.photo) {
|
|
|
|
return photo->makeReplyPreview();
|
|
|
|
}
|
|
|
|
return ImagePtr();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
QString MediaInvoice::notificationText() const {
|
|
|
|
return _invoice.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MediaInvoice::pinnedTextSubstring() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2018-01-26 15:40:11 +00:00
|
|
|
TextWithEntities MediaInvoice::clipboardText() const {
|
|
|
|
return TextWithEntities();
|
|
|
|
}
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
bool MediaInvoice::updateInlineResultMedia(const MTPMessageMedia &media) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<HistoryMedia> MediaInvoice::createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::Element*> message,
|
|
|
|
not_null<HistoryItem*> realParent) {
|
2018-01-14 16:02:25 +00:00
|
|
|
return std::make_unique<HistoryInvoice>(message, &_invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Data
|