mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Update extended media, hide inline keyboard.
This commit is contained in:
parent
c2fd4ccd59
commit
d2234d88b6
12 changed files with 112 additions and 27 deletions
|
@ -1650,6 +1650,15 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
}
|
||||
} break;
|
||||
|
||||
case mtpc_updateMessageExtendedMedia: {
|
||||
const auto &d = update.c_updateMessageExtendedMedia();
|
||||
const auto peerId = peerFromMTP(d.vpeer());
|
||||
const auto msgId = d.vmsg_id().v;
|
||||
if (const auto item = session().data().message(peerId, msgId)) {
|
||||
item->applyEdition(d.vextended_media());
|
||||
}
|
||||
} break;
|
||||
|
||||
// Messages being read.
|
||||
case mtpc_updateReadHistoryInbox: {
|
||||
auto &d = update.c_updateReadHistoryInbox();
|
||||
|
|
|
@ -232,6 +232,49 @@ template <typename MediaType>
|
|||
return (i != end(*existing)) ? *i : ItemPreviewImage();
|
||||
}
|
||||
|
||||
bool UpdateExtendedMedia(
|
||||
Invoice &invoice,
|
||||
not_null<HistoryMessage*> item,
|
||||
const MTPMessageExtendedMedia &media) {
|
||||
return media.match([&](const MTPDmessageExtendedMediaPreview &data) {
|
||||
if (invoice.extendedMedia) {
|
||||
return false;
|
||||
}
|
||||
auto changed = false;
|
||||
auto &preview = invoice.extendedPreview;
|
||||
if (const auto &w = data.vw()) {
|
||||
const auto &h = data.vh();
|
||||
Assert(h.has_value());
|
||||
const auto dimensions = QSize(w->v, h->v);
|
||||
if (preview.dimensions != dimensions) {
|
||||
preview.dimensions = dimensions;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (const auto &thumb = data.vthumb()) {
|
||||
if (thumb->type() == mtpc_photoStrippedSize) {
|
||||
const auto bytes = thumb->c_photoStrippedSize().vbytes().v;
|
||||
if (preview.inlineThumbnailBytes != bytes) {
|
||||
preview.inlineThumbnailBytes = bytes;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (const auto &duration = data.vvideo_duration()) {
|
||||
if (preview.videoDuration != duration->v) {
|
||||
preview.videoDuration = duration->v;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}, [&](const MTPDmessageExtendedMedia &data) {
|
||||
invoice.extendedMedia = HistoryMessage::CreateMedia(
|
||||
item,
|
||||
data.vmedia());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TextForMimeData WithCaptionClipboardText(
|
||||
|
@ -266,29 +309,8 @@ Invoice ComputeInvoiceData(
|
|||
.isTest = data.is_test(),
|
||||
};
|
||||
if (const auto &media = data.vextended_media()) {
|
||||
media->match([&](const MTPDmessageExtendedMediaPreview &data) {
|
||||
auto &preview = result.extendedPreview;
|
||||
if (const auto &w = data.vw()) {
|
||||
const auto &h = data.vh();
|
||||
Assert(h.has_value());
|
||||
preview.dimensions = QSize(w->v, h->v);
|
||||
}
|
||||
if (const auto &thumb = data.vthumb()) {
|
||||
if (thumb->type() == mtpc_photoStrippedSize) {
|
||||
preview.inlineThumbnailBytes
|
||||
= thumb->c_photoStrippedSize().vbytes().v;
|
||||
}
|
||||
}
|
||||
if (const auto &duration = data.vvideo_duration()) {
|
||||
preview.videoDuration = duration->v;
|
||||
}
|
||||
}, [&](const MTPDmessageExtendedMedia &data) {
|
||||
result.extendedMedia = HistoryMessage::CreateMedia(
|
||||
item,
|
||||
data.vmedia());
|
||||
});
|
||||
UpdateExtendedMedia(result, item, *media);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1572,6 +1594,14 @@ bool MediaInvoice::updateSentMedia(const MTPMessageMedia &media) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool MediaInvoice::updateExtendedMedia(
|
||||
not_null<HistoryMessage*> item,
|
||||
const MTPMessageExtendedMedia &media) {
|
||||
Expects(item == parent());
|
||||
|
||||
return UpdateExtendedMedia(_invoice, item, media);
|
||||
}
|
||||
|
||||
std::unique_ptr<HistoryView::Media> MediaInvoice::createView(
|
||||
not_null<HistoryView::Element*> message,
|
||||
not_null<HistoryItem*> realParent,
|
||||
|
|
|
@ -132,6 +132,11 @@ public:
|
|||
// the media (all media that was generated on client side, for example).
|
||||
virtual bool updateInlineResultMedia(const MTPMessageMedia &media) = 0;
|
||||
virtual bool updateSentMedia(const MTPMessageMedia &media) = 0;
|
||||
virtual bool updateExtendedMedia(
|
||||
not_null<HistoryMessage*> item,
|
||||
const MTPMessageExtendedMedia &media) {
|
||||
return false;
|
||||
}
|
||||
virtual std::unique_ptr<HistoryView::Media> createView(
|
||||
not_null<HistoryView::Element*> message,
|
||||
not_null<HistoryItem*> realParent,
|
||||
|
@ -415,6 +420,9 @@ public:
|
|||
|
||||
bool updateInlineResultMedia(const MTPMessageMedia &media) override;
|
||||
bool updateSentMedia(const MTPMessageMedia &media) override;
|
||||
bool updateExtendedMedia(
|
||||
not_null<HistoryMessage*> item,
|
||||
const MTPMessageExtendedMedia &media) override;
|
||||
std::unique_ptr<HistoryView::Media> createView(
|
||||
not_null<HistoryView::Element*> message,
|
||||
not_null<HistoryItem*> realParent,
|
||||
|
|
|
@ -281,6 +281,8 @@ public:
|
|||
}
|
||||
virtual void applyEdition(const MTPDmessageService &message) {
|
||||
}
|
||||
virtual void applyEdition(const MTPMessageExtendedMedia &media) {
|
||||
}
|
||||
void applyEditionToHistoryCleared();
|
||||
virtual void updateSentContent(
|
||||
const TextWithEntities &textWithEntities,
|
||||
|
|
|
@ -914,6 +914,18 @@ void HistoryMessageReplyMarkup::updateData(
|
|||
inlineKeyboard = nullptr;
|
||||
}
|
||||
|
||||
bool HistoryMessageReplyMarkup::hiddenBy(Data::Media *media) const {
|
||||
if (media && (data.flags & ReplyMarkupFlag::OnlyBuyButton)) {
|
||||
if (const auto invoice = media->invoice()) {
|
||||
if (!invoice->extendedPreview.dimensions.isEmpty()
|
||||
&& (!invoice->extendedMedia || !invoice->receiptMsgId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal() = default;
|
||||
|
||||
HistoryMessageLogEntryOriginal::HistoryMessageLogEntryOriginal(
|
||||
|
|
|
@ -224,6 +224,8 @@ struct HistoryMessageReplyMarkup
|
|||
void createForwarded(const HistoryMessageReplyMarkup &original);
|
||||
void updateData(HistoryMessageMarkupData &&markup);
|
||||
|
||||
[[nodiscard]] bool hiddenBy(Data::Media *media) const;
|
||||
|
||||
HistoryMessageMarkupData data;
|
||||
std::unique_ptr<ReplyKeyboard> inlineKeyboard;
|
||||
|
||||
|
|
|
@ -49,13 +49,13 @@ void HistoryMessageMarkupData::fillRows(
|
|||
return;
|
||||
}
|
||||
|
||||
using Type = Button::Type;
|
||||
rows.reserve(list.size());
|
||||
for (const auto &row : list) {
|
||||
row.match([&](const MTPDkeyboardButtonRow &data) {
|
||||
auto row = std::vector<Button>();
|
||||
row.reserve(data.vbuttons().v.size());
|
||||
for (const auto &button : data.vbuttons().v) {
|
||||
using Type = Button::Type;
|
||||
button.match([&](const MTPDkeyboardButton &data) {
|
||||
row.emplace_back(Type::Default, qs(data.vtext()));
|
||||
}, [&](const MTPDkeyboardButtonCallback &data) {
|
||||
|
@ -138,6 +138,11 @@ void HistoryMessageMarkupData::fillRows(
|
|||
}
|
||||
});
|
||||
}
|
||||
if (rows.size() == 1
|
||||
&& rows.front().size() == 1
|
||||
&& rows.front().front().type == Type::Buy) {
|
||||
flags |= ReplyMarkupFlag::OnlyBuyButton;
|
||||
}
|
||||
}
|
||||
|
||||
HistoryMessageMarkupData::HistoryMessageMarkupData(
|
||||
|
@ -157,7 +162,8 @@ HistoryMessageMarkupData::HistoryMessageMarkupData(
|
|||
placeholder = QString();
|
||||
fillRows(data.vrows().v);
|
||||
}, [&](const MTPDreplyKeyboardHide &data) {
|
||||
flags = Flag::None | (data.is_selective() ? Flag::Selective : Flag());
|
||||
flags = Flag::None
|
||||
| (data.is_selective() ? Flag::Selective : Flag());
|
||||
placeholder = QString();
|
||||
}, [&](const MTPDreplyKeyboardForceReply &data) {
|
||||
flags = Flag::ForceReply
|
||||
|
|
|
@ -22,6 +22,7 @@ enum class ReplyMarkupFlag : uint32 {
|
|||
SingleUse = (1U << 5),
|
||||
Selective = (1U << 6),
|
||||
IsNull = (1U << 7),
|
||||
OnlyBuyButton = (1U << 8),
|
||||
};
|
||||
inline constexpr bool is_flag_type(ReplyMarkupFlag) { return true; }
|
||||
using ReplyMarkupFlags = base::flags<ReplyMarkupFlag>;
|
||||
|
|
|
@ -1325,6 +1325,15 @@ void HistoryMessage::applyEdition(const MTPDmessageService &message) {
|
|||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::applyEdition(const MTPMessageExtendedMedia &media) {
|
||||
if (const auto existing = this->media()) {
|
||||
if (existing->updateExtendedMedia(this, media)) {
|
||||
checkBuyButton();
|
||||
finishEdition(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryMessage::updateSentContent(
|
||||
const TextWithEntities &textWithEntities,
|
||||
const MTPMessageMedia *media) {
|
||||
|
|
|
@ -168,6 +168,7 @@ public:
|
|||
void applyEdition(HistoryMessageEdition &&edition) override;
|
||||
|
||||
void applyEdition(const MTPDmessageService &message) override;
|
||||
void applyEdition(const MTPMessageExtendedMedia &media) override;
|
||||
void updateSentContent(
|
||||
const TextWithEntities &textWithEntities,
|
||||
const MTPMessageMedia *media) override;
|
||||
|
|
|
@ -604,7 +604,7 @@ QSize Message::performCountOptimalSize() {
|
|||
minHeight = 0;
|
||||
}
|
||||
if (const auto markup = item->inlineReplyMarkup()) {
|
||||
if (!markup->inlineKeyboard) {
|
||||
if (!markup->inlineKeyboard && !markup->hiddenBy(item->media())) {
|
||||
markup->inlineKeyboard = std::make_unique<ReplyKeyboard>(
|
||||
item,
|
||||
std::make_unique<KeyboardStyle>(st::msgBotKbButton));
|
||||
|
@ -612,7 +612,7 @@ QSize Message::performCountOptimalSize() {
|
|||
|
||||
// if we have a text bubble we can resize it to fit the keyboard
|
||||
// but if we have only media we don't do that
|
||||
if (hasVisibleText()) {
|
||||
if (hasVisibleText() && markup->inlineKeyboard) {
|
||||
accumulate_max(maxWidth, markup->inlineKeyboard->naturalWidth());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,12 @@ ExtendedPreview::ExtendedPreview(
|
|||
_link = MakeInvoiceLink(item);
|
||||
}
|
||||
|
||||
ExtendedPreview::~ExtendedPreview() = default;
|
||||
ExtendedPreview::~ExtendedPreview() {
|
||||
if (hasHeavyPart()) {
|
||||
unloadHeavyPart();
|
||||
_parent->checkHeavyPart();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtendedPreview::ensureThumbnailRead() const {
|
||||
if (!_inlineThumbnail.isNull() || _imageCacheInvalid) {
|
||||
|
|
Loading…
Add table
Reference in a new issue