aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/util/helper.vala
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/ui/util/helper.vala')
-rw-r--r--main/src/ui/util/helper.vala71
1 files changed, 66 insertions, 5 deletions
diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala
index 3cadfffb..e51b8344 100644
--- a/main/src/ui/util/helper.vala
+++ b/main/src/ui/util/helper.vala
@@ -59,7 +59,13 @@ public static string get_conversation_display_name(StreamInteractor stream_inter
}
public static string get_display_name(StreamInteractor stream_interactor, Jid jid, Account account) {
- if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
+ if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid, account)) {
+ string room_name = stream_interactor.get_module(MucManager.IDENTITY).get_room_name(account, jid);
+ if (room_name != null && room_name != jid.localpart) {
+ return room_name;
+ }
+ return jid.bare_jid.to_string();
+ } else if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) {
return jid.resourcepart;
} else {
if (jid.equals_bare(account.bare_jid)) {
@@ -118,10 +124,6 @@ public static void force_background(Gtk.Widget widget, string color, string sele
force_css(widget, force_background_css.printf(selector, color));
}
-public static void force_base_background(Gtk.Widget widget, string selector = "*") {
- force_background(widget, "@theme_base_color", selector);
-}
-
public static void force_color(Gtk.Widget widget, string color, string selector = "*") {
force_css(widget, force_color_css.printf(selector, color));
}
@@ -142,4 +144,63 @@ public static bool is_24h_format() {
return settings_format == "24h" || p_format == " ";
}
+public static string parse_add_markup(string s_, string? highlight_word, bool parse_links, bool parse_text_markup, bool already_escaped_ = false) {
+ string s = s_;
+ bool already_escaped = already_escaped_;
+
+ if (parse_links) {
+ Regex url_regex = new Regex("""(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""");
+ MatchInfo match_info;
+ url_regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ string link = s[start:end];
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<a href=\"" + Markup.escape_text(link) + "\">" + parse_add_markup(link, highlight_word, false, false, already_escaped) + "</a>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+
+ if (!already_escaped) {
+ s = Markup.escape_text(s);
+ already_escaped = true;
+ }
+
+ if (highlight_word != null) {
+ Regex highlight_regex = new Regex("\\b" + Regex.escape_string(highlight_word.down()) + "\\b");
+ MatchInfo match_info;
+ highlight_regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ "<b>" + s[start:end] + "</b>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+
+ if (parse_text_markup) {
+ string[] markup_string = new string[]{"`", "_", "*"};
+ string[] convenience_tag = new string[]{"tt", "i", "b"};
+
+ for (int i = 0; i < markup_string.length; i++) {
+ Regex regex = new Regex(Regex.escape_string(markup_string[i]) + ".+" + Regex.escape_string(markup_string[i]));
+ MatchInfo match_info;
+ regex.match(s.down(), 0, out match_info);
+ if (match_info.matches()) {
+ int start, end;
+ match_info.fetch_pos(0, out start, out end);
+ start += markup_string[i].length;
+ end -= markup_string[i].length;
+ return parse_add_markup(s[0:start], highlight_word, parse_links, parse_text_markup, already_escaped) +
+ @"<$(convenience_tag[i])>" + s[start:end] + @"</$(convenience_tag[i])>" +
+ parse_add_markup(s[end:s.length], highlight_word, parse_links, parse_text_markup, already_escaped);
+ }
+ }
+ }
+
+ return s;
+}
+
}