From b0ff90a14a5d127e17f2371f87e7bb659de3a68f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 29 Jul 2024 13:16:54 +0200 Subject: Add initial message markup (XEP-0394) support --- main/src/ui/util/helper.vala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'main/src/ui/util/helper.vala') diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index 63288fc2..45b96b94 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -297,6 +297,31 @@ public static string parse_add_markup_theme(string s_, string? highlight_word, b return s; } + // Modifies `markups`. + public string remove_fallbacks_adjust_markups(string text, bool contains_quote, Gee.List fallbacks, Gee.List markups) { + string processed_text = text; + + foreach (var fallback in fallbacks) { + if (fallback.ns_uri == Xep.Replies.NS_URI && contains_quote) { + foreach (var fallback_location in fallback.locations) { + processed_text = processed_text[0:processed_text.index_of_nth_char(fallback_location.from_char)] + + processed_text[processed_text.index_of_nth_char(fallback_location.to_char):processed_text.length]; + + int length = fallback_location.to_char - fallback_location.from_char; + foreach (Xep.MessageMarkup.Span span in markups) { + if (span.start_char > fallback_location.to_char) { + span.start_char -= length; + } + if (span.end_char > fallback_location.to_char) { + span.end_char -= length; + } + } + } + } + } + return processed_text; + } + /** * This is a heuristic to count emojis in a string {@link http://example.com/} * -- cgit v1.2.3-70-g09d2