mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +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 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(
|
||||
const QString &attachType,
|
||||
const QString &caption,
|
||||
|
@ -304,6 +263,47 @@ TextForMimeData WithCaptionClipboardText(
|
|||
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) {
|
||||
}
|
||||
|
||||
|
@ -1170,11 +1170,9 @@ std::unique_ptr<HistoryView::Media> MediaLocation::createView(
|
|||
_description);
|
||||
}
|
||||
|
||||
MediaCall::MediaCall(
|
||||
not_null<HistoryItem*> parent,
|
||||
const MTPDmessageActionPhoneCall &call)
|
||||
MediaCall::MediaCall(not_null<HistoryItem*> parent, const Call &call)
|
||||
: Media(parent)
|
||||
, _call(ComputeCallData(call)) {
|
||||
, _call(call) {
|
||||
parent->history()->owner().registerCallItem(parent);
|
||||
}
|
||||
|
||||
|
@ -1456,13 +1454,6 @@ std::unique_ptr<HistoryView::Media> MediaGame::createView(
|
|||
_consumedText);
|
||||
}
|
||||
|
||||
MediaInvoice::MediaInvoice(
|
||||
not_null<HistoryItem*> parent,
|
||||
const MTPDmessageMediaInvoice &data)
|
||||
: Media(parent)
|
||||
, _invoice(ComputeInvoiceData(parent, data)) {
|
||||
}
|
||||
|
||||
MediaInvoice::MediaInvoice(
|
||||
not_null<HistoryItem*> parent,
|
||||
const Invoice &data)
|
||||
|
|
|
@ -286,9 +286,7 @@ private:
|
|||
|
||||
class MediaCall final : public Media {
|
||||
public:
|
||||
MediaCall(
|
||||
not_null<HistoryItem*> parent,
|
||||
const MTPDmessageActionPhoneCall &call);
|
||||
MediaCall(not_null<HistoryItem*> parent, const Call &call);
|
||||
~MediaCall();
|
||||
|
||||
std::unique_ptr<Media> clone(not_null<HistoryItem*> parent) override;
|
||||
|
@ -387,9 +385,6 @@ private:
|
|||
|
||||
class MediaInvoice final : public Media {
|
||||
public:
|
||||
MediaInvoice(
|
||||
not_null<HistoryItem*> parent,
|
||||
const MTPDmessageMediaInvoice &data);
|
||||
MediaInvoice(
|
||||
not_null<HistoryItem*> parent,
|
||||
const Invoice &data);
|
||||
|
@ -478,8 +473,14 @@ private:
|
|||
|
||||
};
|
||||
|
||||
TextForMimeData WithCaptionClipboardText(
|
||||
[[nodiscard]] TextForMimeData WithCaptionClipboardText(
|
||||
const QString &attachType,
|
||||
TextForMimeData &&caption);
|
||||
|
||||
[[nodiscard]] Invoice ComputeInvoiceData(
|
||||
not_null<HistoryItem*> item,
|
||||
const MTPDmessageMediaInvoice &data);
|
||||
|
||||
[[nodiscard]] Call ComputeCallData(const MTPDmessageActionPhoneCall &call);
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -16,7 +16,7 @@ HistoryMessageMarkupButton::HistoryMessageMarkupButton(
|
|||
const QString &text,
|
||||
const QByteArray &data,
|
||||
const QString &forwardText,
|
||||
int32 buttonId)
|
||||
int64 buttonId)
|
||||
: type(type)
|
||||
, text(text)
|
||||
, forwardText(forwardText)
|
||||
|
|
|
@ -47,7 +47,7 @@ struct HistoryMessageMarkupButton {
|
|||
const QString &text,
|
||||
const QByteArray &data = QByteArray(),
|
||||
const QString &forwardText = QString(),
|
||||
int32 buttonId = 0);
|
||||
int64 buttonId = 0);
|
||||
|
||||
static HistoryMessageMarkupButton *Get(
|
||||
not_null<Data::Session*> owner,
|
||||
|
@ -58,7 +58,7 @@ struct HistoryMessageMarkupButton {
|
|||
Type type;
|
||||
QString text, forwardText;
|
||||
QByteArray data;
|
||||
int32 buttonId = 0;
|
||||
int64 buttonId = 0;
|
||||
mutable mtpRequestId requestId = 0;
|
||||
|
||||
};
|
||||
|
|
|
@ -535,7 +535,9 @@ HistoryMessage::HistoryMessage(
|
|||
createComponents(std::move(config));
|
||||
|
||||
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();
|
||||
}, [](const auto &) {
|
||||
Unexpected("Service message action type in HistoryMessage.");
|
||||
|
@ -1346,7 +1348,9 @@ std::unique_ptr<Data::Media> HistoryMessage::CreateMedia(
|
|||
item->history()->owner().processGame(game));
|
||||
});
|
||||
}, [&](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 {
|
||||
return std::make_unique<Data::MediaPoll>(
|
||||
item,
|
||||
|
|
Loading…
Add table
Reference in a new issue