mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Fix reply-to-media timestamps in captions.
This commit is contained in:
parent
0fa458737a
commit
db0c57a186
8 changed files with 32 additions and 57 deletions
|
@ -343,6 +343,10 @@ public:
|
|||
[[nodiscard]] virtual TextWithEntities originalText() const {
|
||||
return TextWithEntities();
|
||||
}
|
||||
[[nodiscard]] virtual auto originalTextWithLocalEntities() const
|
||||
-> TextWithEntities {
|
||||
return TextWithEntities();
|
||||
}
|
||||
[[nodiscard]] virtual TextForMimeData clipboardText() const {
|
||||
return TextForMimeData();
|
||||
}
|
||||
|
|
|
@ -1536,19 +1536,31 @@ Storage::SharedMediaTypesMask HistoryMessage::sharedMediaTypes() const {
|
|||
}
|
||||
|
||||
bool HistoryMessage::generateLocalEntitiesByReply() const {
|
||||
using namespace HistoryView;
|
||||
if (!_media) {
|
||||
return true;
|
||||
} else if (const auto document = _media->document()) {
|
||||
return !DurationForTimestampLinks(document);
|
||||
} else if (const auto webpage = _media->webpage()) {
|
||||
return !webpage->document && webpage->type != WebPageType::Video;
|
||||
return (webpage->type != WebPageType::Video)
|
||||
&& !DurationForTimestampLinks(webpage);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
TextWithEntities HistoryMessage::withLocalEntities(
|
||||
const TextWithEntities &textWithEntities) const {
|
||||
using namespace HistoryView;
|
||||
if (!generateLocalEntitiesByReply()) {
|
||||
if (const auto webpage = _media ? _media->webpage() : nullptr) {
|
||||
if (!_media) {
|
||||
} else if (const auto document = _media->document()) {
|
||||
if (const auto duration = DurationForTimestampLinks(document)) {
|
||||
return AddTimestampLinks(
|
||||
textWithEntities,
|
||||
duration,
|
||||
TimestampLinkBase(document, fullId()));
|
||||
}
|
||||
} else if (const auto webpage = _media->webpage()) {
|
||||
if (const auto duration = DurationForTimestampLinks(webpage)) {
|
||||
return AddTimestampLinks(
|
||||
textWithEntities,
|
||||
|
@ -1712,6 +1724,10 @@ TextWithEntities HistoryMessage::originalText() const {
|
|||
return _text.toTextWithEntities();
|
||||
}
|
||||
|
||||
TextWithEntities HistoryMessage::originalTextWithLocalEntities() const {
|
||||
return withLocalEntities(originalText());
|
||||
}
|
||||
|
||||
TextForMimeData HistoryMessage::clipboardText() const {
|
||||
if (emptyText()) {
|
||||
return TextForMimeData();
|
||||
|
|
|
@ -173,6 +173,8 @@ public:
|
|||
void setText(const TextWithEntities &textWithEntities) override;
|
||||
[[nodiscard]] Ui::Text::IsolatedEmoji isolatedEmoji() const override;
|
||||
[[nodiscard]] TextWithEntities originalText() const override;
|
||||
[[nodiscard]] auto originalTextWithLocalEntities() const
|
||||
-> TextWithEntities override;
|
||||
[[nodiscard]] TextForMimeData clipboardText() const override;
|
||||
[[nodiscard]] bool textHasLinks() const override;
|
||||
|
||||
|
|
|
@ -1084,14 +1084,7 @@ TextWithEntities Document::getCaption() const {
|
|||
}
|
||||
|
||||
Ui::Text::String Document::createCaption() {
|
||||
const auto timestampLinksDuration = DurationForTimestampLinks(_data);
|
||||
const auto timestampLinkBase = timestampLinksDuration
|
||||
? TimestampLinkBase(_data, _realParent->fullId())
|
||||
: QString();
|
||||
return File::createCaption(
|
||||
_realParent,
|
||||
timestampLinksDuration,
|
||||
timestampLinkBase);
|
||||
return File::createCaption(_realParent);
|
||||
}
|
||||
|
||||
bool DrawThumbnailAsSongCover(
|
||||
|
|
|
@ -1322,14 +1322,7 @@ void Gif::refreshParentId(not_null<HistoryItem*> realParent) {
|
|||
}
|
||||
|
||||
void Gif::refreshCaption() {
|
||||
const auto timestampLinksDuration = DurationForTimestampLinks(_data);
|
||||
const auto timestampLinkBase = timestampLinksDuration
|
||||
? TimestampLinkBase(_data, _realParent->fullId())
|
||||
: QString();
|
||||
_caption = createCaption(
|
||||
_parent->data(),
|
||||
timestampLinksDuration,
|
||||
timestampLinkBase);
|
||||
_caption = createCaption(_parent->data());
|
||||
}
|
||||
|
||||
int Gif::additionalWidth(const HistoryMessageVia *via, const HistoryMessageReply *reply, const HistoryMessageForwarded *forwarded) const {
|
||||
|
|
|
@ -64,7 +64,7 @@ QString TimestampLinkBase(
|
|||
|
||||
TimeId DurationForTimestampLinks(not_null<WebPageData*> webpage) {
|
||||
if (!webpage->collage.items.empty()) {
|
||||
return false;
|
||||
return 0;
|
||||
} else if (const auto document = webpage->document) {
|
||||
return DurationForTimestampLinks(document);
|
||||
} else if (webpage->type != WebPageType::Video
|
||||
|
@ -185,12 +185,7 @@ QSize Media::countCurrentSize(int newWidth) {
|
|||
return QSize(qMin(newWidth, maxWidth()), minHeight());
|
||||
}
|
||||
|
||||
Ui::Text::String Media::createCaption(
|
||||
not_null<HistoryItem*> item,
|
||||
TimeId timestampLinksDuration,
|
||||
const QString ×tampLinkBase) const {
|
||||
Expects(timestampLinksDuration >= 0);
|
||||
|
||||
Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const {
|
||||
if (item->emptyText()) {
|
||||
return {};
|
||||
}
|
||||
|
@ -203,12 +198,7 @@ Ui::Text::String Media::createCaption(
|
|||
};
|
||||
result.setMarkedText(
|
||||
st::messageTextStyle,
|
||||
(timestampLinksDuration
|
||||
? AddTimestampLinks(
|
||||
item->originalText(),
|
||||
timestampLinksDuration,
|
||||
timestampLinkBase)
|
||||
: item->originalText()),
|
||||
item->originalTextWithLocalEntities(),
|
||||
Ui::ItemTextOptions(item),
|
||||
context);
|
||||
if (const auto width = _parent->skipBlockWidth()) {
|
||||
|
|
|
@ -297,9 +297,7 @@ public:
|
|||
protected:
|
||||
[[nodiscard]] QSize countCurrentSize(int newWidth) override;
|
||||
[[nodiscard]] Ui::Text::String createCaption(
|
||||
not_null<HistoryItem*> item,
|
||||
TimeId timestampLinksDuration = 0,
|
||||
const QString ×tampLinkBase = QString()) const;
|
||||
not_null<HistoryItem*> item) const;
|
||||
|
||||
virtual void playAnimation(bool autoplay) {
|
||||
}
|
||||
|
|
|
@ -672,28 +672,7 @@ void GroupedMedia::updateNeedBubbleState() {
|
|||
}();
|
||||
if (captionPart) {
|
||||
const auto &part = (*captionPart);
|
||||
struct Timestamp {
|
||||
int duration = 0;
|
||||
QString base;
|
||||
};
|
||||
const auto timestamp = [&]() -> Timestamp {
|
||||
const auto document = part->content->getDocument();
|
||||
const auto duration = document
|
||||
? DurationForTimestampLinks(document)
|
||||
: TimeId(0);
|
||||
if (!duration) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
.duration = duration,
|
||||
.base = TimestampLinkBase(document, part->item->fullId()),
|
||||
};
|
||||
}();
|
||||
_caption = createCaption(
|
||||
part->item,
|
||||
timestamp.duration,
|
||||
timestamp.base);
|
||||
|
||||
_caption = createCaption(part->item);
|
||||
_captionItem = part->item;
|
||||
} else {
|
||||
_captionItem = nullptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue