mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-08-08 20:53:54 +00:00
Auto-detected rtl flag for composed rich messages.
This commit is contained in:
@@ -8905,6 +8905,7 @@ void State::rebuild() {
|
||||
|
||||
void State::rebuildPrepared() {
|
||||
_lastPreparedMutationKind = PreparedMutationKind::FullRebuild;
|
||||
_richPage->rtl = DetermineRichPageRtl(*_richPage);
|
||||
_prepared = Markdown::TryPrepareNativeInstantView({
|
||||
.richPage = _richPage,
|
||||
.mediaRuntime = _mediaRuntime,
|
||||
|
||||
@@ -1736,7 +1736,7 @@ SerializeInputRichMessageResult SerializeInputRichMessage(
|
||||
}
|
||||
using Flag = MTPDinputRichMessage::Flag;
|
||||
auto flags = MTPDinputRichMessage::Flags();
|
||||
if (page.rtl) {
|
||||
if (DetermineRichPageRtl(page)) {
|
||||
flags |= Flag::f_rtl;
|
||||
}
|
||||
if (!photos.isEmpty()) {
|
||||
|
||||
@@ -2252,6 +2252,35 @@ std::shared_ptr<const RichPage> ParsePage(
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<bool> RichTextRtl(const RichText &text) {
|
||||
const auto &plain = text.text.text;
|
||||
if (plain.trimmed().isEmpty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return plain.isRightToLeft();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::optional<bool> BlocksTextRtl(
|
||||
const std::vector<Block> &blocks) {
|
||||
for (const auto &block : blocks) {
|
||||
if (const auto result = RichTextRtl(block.text)) {
|
||||
return result;
|
||||
}
|
||||
if (const auto result = BlocksTextRtl(block.blocks)) {
|
||||
return result;
|
||||
}
|
||||
for (const auto &item : block.listItems) {
|
||||
if (const auto result = RichTextRtl(item.text)) {
|
||||
return result;
|
||||
}
|
||||
if (const auto result = BlocksTextRtl(item.blocks)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool RichPagesEqual(
|
||||
@@ -2443,6 +2472,10 @@ TextWithEntities FlattenRichPageToSimpleText(const RichPage &page) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DetermineRichPageRtl(const RichPage &page) {
|
||||
return BlocksTextRtl(page.blocks).value_or(false);
|
||||
}
|
||||
|
||||
std::optional<TextWithEntities> SerializeAsSimple(
|
||||
const RichPage &page,
|
||||
not_null<Main::Session*> session) {
|
||||
|
||||
@@ -312,5 +312,6 @@ inline constexpr auto kTextDiffDeletedColorIndex = 11;
|
||||
bool emptyFallback = true);
|
||||
[[nodiscard]] TextWithEntities FlattenRichPageToSimpleText(
|
||||
const RichPage &page);
|
||||
[[nodiscard]] bool DetermineRichPageRtl(const RichPage &page);
|
||||
|
||||
} // namespace Iv
|
||||
|
||||
Reference in New Issue
Block a user