mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 22:46:10 +00:00
Don't use MTP* in call and invoice media data.
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user