Auto-detected rtl flag for composed rich messages.

This commit is contained in:
John Preston
2026-07-16 11:47:50 +04:00
parent 528124715e
commit 59015fffeb
4 changed files with 36 additions and 1 deletions
@@ -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()) {
+33
View File
@@ -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) {
+1
View File
@@ -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