mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Don't use MTP* in call and invoice media data.
This commit is contained in:
parent
ae261fcede
commit
bef35b9bc3
5 changed files with 60 additions and 64 deletions
|
@ -65,47 +65,6 @@ constexpr auto kMaxPreviewImages = 3;
|
||||||
using ItemPreview = HistoryView::ItemPreview;
|
using ItemPreview = HistoryView::ItemPreview;
|
||||||
using ItemPreviewImage = HistoryView::ItemPreviewImage;
|
using ItemPreviewImage = HistoryView::ItemPreviewImage;
|
||||||
|
|
||||||
[[nodiscard]] Call ComputeCallData(const MTPDmessageActionPhoneCall &call) {
|
|
||||||
auto result = Call();
|
|
||||||
result.finishReason = [&] {
|
|
||||||
if (const auto reason = call.vreason()) {
|
|
||||||
switch (reason->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.vduration().value_or_empty();
|
|
||||||
result.video = call.is_video();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] Invoice ComputeInvoiceData(
|
|
||||||
not_null<HistoryItem*> item,
|
|
||||||
const MTPDmessageMediaInvoice &data) {
|
|
||||||
return {
|
|
||||||
.receiptMsgId = data.vreceipt_msg_id().value_or_empty(),
|
|
||||||
.amount = data.vtotal_amount().v,
|
|
||||||
.currency = qs(data.vcurrency()),
|
|
||||||
.title = TextUtilities::SingleLine(qs(data.vtitle())),
|
|
||||||
.description = qs(data.vdescription()),
|
|
||||||
.photo = (data.vphoto()
|
|
||||||
? item->history()->owner().photoFromWeb(
|
|
||||||
*data.vphoto(),
|
|
||||||
ImageLocation())
|
|
||||||
: nullptr),
|
|
||||||
.isTest = data.is_test(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] QString WithCaptionDialogsText(
|
[[nodiscard]] QString WithCaptionDialogsText(
|
||||||
const QString &attachType,
|
const QString &attachType,
|
||||||
const QString &caption,
|
const QString &caption,
|
||||||
|
@ -304,6 +263,47 @@ TextForMimeData WithCaptionClipboardText(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Invoice ComputeInvoiceData(
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
const MTPDmessageMediaInvoice &data) {
|
||||||
|
return {
|
||||||
|
.receiptMsgId = data.vreceipt_msg_id().value_or_empty(),
|
||||||
|
.amount = data.vtotal_amount().v,
|
||||||
|
.currency = qs(data.vcurrency()),
|
||||||
|
.title = TextUtilities::SingleLine(qs(data.vtitle())),
|
||||||
|
.description = qs(data.vdescription()),
|
||||||
|
.photo = (data.vphoto()
|
||||||
|
? item->history()->owner().photoFromWeb(
|
||||||
|
*data.vphoto(),
|
||||||
|
ImageLocation())
|
||||||
|
: nullptr),
|
||||||
|
.isTest = data.is_test(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Call ComputeCallData(const MTPDmessageActionPhoneCall &call) {
|
||||||
|
auto result = Call();
|
||||||
|
result.finishReason = [&] {
|
||||||
|
if (const auto reason = call.vreason()) {
|
||||||
|
switch (reason->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.vduration().value_or_empty();
|
||||||
|
result.video = call.is_video();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Media::Media(not_null<HistoryItem*> parent) : _parent(parent) {
|
Media::Media(not_null<HistoryItem*> parent) : _parent(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1170,11 +1170,9 @@ std::unique_ptr<HistoryView::Media> MediaLocation::createView(
|
||||||
_description);
|
_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaCall::MediaCall(
|
MediaCall::MediaCall(not_null<HistoryItem*> parent, const Call &call)
|
||||||
not_null<HistoryItem*> parent,
|
|
||||||
const MTPDmessageActionPhoneCall &call)
|
|
||||||
: Media(parent)
|
: Media(parent)
|
||||||
, _call(ComputeCallData(call)) {
|
, _call(call) {
|
||||||
parent->history()->owner().registerCallItem(parent);
|
parent->history()->owner().registerCallItem(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1456,13 +1454,6 @@ std::unique_ptr<HistoryView::Media> MediaGame::createView(
|
||||||
_consumedText);
|
_consumedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaInvoice::MediaInvoice(
|
|
||||||
not_null<HistoryItem*> parent,
|
|
||||||
const MTPDmessageMediaInvoice &data)
|
|
||||||
: Media(parent)
|
|
||||||
, _invoice(ComputeInvoiceData(parent, data)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
MediaInvoice::MediaInvoice(
|
MediaInvoice::MediaInvoice(
|
||||||
not_null<HistoryItem*> parent,
|
not_null<HistoryItem*> parent,
|
||||||
const Invoice &data)
|
const Invoice &data)
|
||||||
|
|
|
@ -286,9 +286,7 @@ private:
|
||||||
|
|
||||||
class MediaCall final : public Media {
|
class MediaCall final : public Media {
|
||||||
public:
|
public:
|
||||||
MediaCall(
|
MediaCall(not_null<HistoryItem*> parent, const Call &call);
|
||||||
not_null<HistoryItem*> parent,
|
|
||||||
const MTPDmessageActionPhoneCall &call);
|
|
||||||
~MediaCall();
|
~MediaCall();
|
||||||
|
|
||||||
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
||||||
|
@ -387,9 +385,6 @@ private:
|
||||||
|
|
||||||
class MediaInvoice final : public Media {
|
class MediaInvoice final : public Media {
|
||||||
public:
|
public:
|
||||||
MediaInvoice(
|
|
||||||
not_null<HistoryItem*> parent,
|
|
||||||
const MTPDmessageMediaInvoice &data);
|
|
||||||
MediaInvoice(
|
MediaInvoice(
|
||||||
not_null<HistoryItem*> parent,
|
not_null<HistoryItem*> parent,
|
||||||
const Invoice &data);
|
const Invoice &data);
|
||||||
|
@ -478,8 +473,14 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TextForMimeData WithCaptionClipboardText(
|
[[nodiscard]] TextForMimeData WithCaptionClipboardText(
|
||||||
const QString &attachType,
|
const QString &attachType,
|
||||||
TextForMimeData &&caption);
|
TextForMimeData &&caption);
|
||||||
|
|
||||||
|
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
const MTPDmessageMediaInvoice &data);
|
||||||
|
|
||||||
|
[[nodiscard]] Call ComputeCallData(const MTPDmessageActionPhoneCall &call);
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -16,7 +16,7 @@ HistoryMessageMarkupButton::HistoryMessageMarkupButton(
|
||||||
const QString &text,
|
const QString &text,
|
||||||
const QByteArray &data,
|
const QByteArray &data,
|
||||||
const QString &forwardText,
|
const QString &forwardText,
|
||||||
int32 buttonId)
|
int64 buttonId)
|
||||||
: type(type)
|
: type(type)
|
||||||
, text(text)
|
, text(text)
|
||||||
, forwardText(forwardText)
|
, forwardText(forwardText)
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct HistoryMessageMarkupButton {
|
||||||
const QString &text,
|
const QString &text,
|
||||||
const QByteArray &data = QByteArray(),
|
const QByteArray &data = QByteArray(),
|
||||||
const QString &forwardText = QString(),
|
const QString &forwardText = QString(),
|
||||||
int32 buttonId = 0);
|
int64 buttonId = 0);
|
||||||
|
|
||||||
static HistoryMessageMarkupButton *Get(
|
static HistoryMessageMarkupButton *Get(
|
||||||
not_null<Data::Session*> owner,
|
not_null<Data::Session*> owner,
|
||||||
|
@ -58,7 +58,7 @@ struct HistoryMessageMarkupButton {
|
||||||
Type type;
|
Type type;
|
||||||
QString text, forwardText;
|
QString text, forwardText;
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
int32 buttonId = 0;
|
int64 buttonId = 0;
|
||||||
mutable mtpRequestId requestId = 0;
|
mutable mtpRequestId requestId = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -535,7 +535,9 @@ HistoryMessage::HistoryMessage(
|
||||||
createComponents(std::move(config));
|
createComponents(std::move(config));
|
||||||
|
|
||||||
data.vaction().match([&](const MTPDmessageActionPhoneCall &data) {
|
data.vaction().match([&](const MTPDmessageActionPhoneCall &data) {
|
||||||
_media = std::make_unique<Data::MediaCall>(this, data);
|
_media = std::make_unique<Data::MediaCall>(
|
||||||
|
this,
|
||||||
|
Data::ComputeCallData(data));
|
||||||
setEmptyText();
|
setEmptyText();
|
||||||
}, [](const auto &) {
|
}, [](const auto &) {
|
||||||
Unexpected("Service message action type in HistoryMessage.");
|
Unexpected("Service message action type in HistoryMessage.");
|
||||||
|
@ -1346,7 +1348,9 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
|
||||||
item->history()->owner().processGame(game));
|
item->history()->owner().processGame(game));
|
||||||
});
|
});
|
||||||
}, [&](const MTPDmessageMediaInvoice &media) -> Result {
|
}, [&](const MTPDmessageMediaInvoice &media) -> Result {
|
||||||
return std::make_unique<Data::MediaInvoice>(item, media);
|
return std::make_unique<Data::MediaInvoice>(
|
||||||
|
item,
|
||||||
|
Data::ComputeInvoiceData(item, media));
|
||||||
}, [&](const MTPDmessageMediaPoll &media) -> Result {
|
}, [&](const MTPDmessageMediaPoll &media) -> Result {
|
||||||
return std::make_unique<Data::MediaPoll>(
|
return std::make_unique<Data::MediaPoll>(
|
||||||
item,
|
item,
|
||||||
|
|
Loading…
Add table
Reference in a new issue