aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2018-01-26 20:35:29 +0100
committerfiaxh <git@mx.ax.lt>2018-01-28 20:32:54 +0100
commitbec810e234a7b9783eb8f35e2ffd7c60d75e09c7 (patch)
tree48ad4e1425920e9865a7db13b881cb7cd3308e86 /main/src
parent57c72d2818dec6c713834cfbb8c4c566a1602907 (diff)
downloaddino-bec810e234a7b9783eb8f35e2ffd7c60d75e09c7.tar.gz
dino-bec810e234a7b9783eb8f35e2ffd7c60d75e09c7.zip
Visually highlight mentions in MUCs
fixes #267
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/conversation_summary/default_message_display.vala3
-rw-r--r--main/src/ui/conversation_summary/message_textview.vala20
-rw-r--r--main/src/ui/conversation_summary/slashme_message_display.vala3
3 files changed, 26 insertions, 0 deletions
diff --git a/main/src/ui/conversation_summary/default_message_display.vala b/main/src/ui/conversation_summary/default_message_display.vala
index 954012a1..519e5107 100644
--- a/main/src/ui/conversation_summary/default_message_display.vala
+++ b/main/src/ui/conversation_summary/default_message_display.vala
@@ -48,6 +48,9 @@ public class MetaMessageItem : Plugins.MetaConversationItem {
public override Object? get_widget(Plugins.WidgetType widget_type) {
MessageTextView text_view = new MessageTextView() { visible = true };
text_view.add_text(message.body);
+ if (conversation.type_ == Conversation.Type.GROUPCHAT) {
+ text_view.highlight_word(conversation.nickname);
+ }
return text_view;
}
}
diff --git a/main/src/ui/conversation_summary/message_textview.vala b/main/src/ui/conversation_summary/message_textview.vala
index 9fe3b60b..d11fd9e1 100644
--- a/main/src/ui/conversation_summary/message_textview.vala
+++ b/main/src/ui/conversation_summary/message_textview.vala
@@ -8,11 +8,13 @@ namespace Dino.Ui.ConversationSummary {
public class MessageTextView : TextView {
private TextTag link_tag;
+ private TextTag bold_tag;
public MessageTextView() {
Object(editable:false, hexpand:true, wrap_mode:WrapMode.WORD_CHAR);
link_tag = buffer.create_tag("url", underline: Pango.Underline.SINGLE, foreground: "blue");
+ bold_tag = buffer.create_tag("semibold", weight: Pango.Weight.SEMIBOLD);
button_release_event.connect((event_button) => {
if (event_button.button == 1) {
open_url(event_button);
@@ -44,6 +46,24 @@ public class MessageTextView : TextView {
format_suffix_urls(text);
}
+ public void highlight_word(string word) {
+ Regex word_regex = new Regex("""\b""" + Regex.escape_string(word) + """\b""");
+ MatchInfo match_info;
+ word_regex.match(buffer.text, 0, out match_info);
+ for (; match_info.matches(); match_info.next()) {
+ int start;
+ int end;
+ match_info.fetch_pos(0, out start, out end);
+ start = buffer.text[0:start].char_count();
+ end = buffer.text[0:end].char_count();
+ TextIter start_iter;
+ TextIter end_iter;
+ buffer.get_iter_at_offset(out start_iter, start);
+ buffer.get_iter_at_offset(out end_iter, end);
+ buffer.apply_tag_by_name("semibold", start_iter, end_iter);
+ }
+ }
+
private void update_display_style() {
LinkButton lnk = new LinkButton("http://example.com");
RGBA link_color = lnk.get_style_context().get_color(StateFlags.LINK);
diff --git a/main/src/ui/conversation_summary/slashme_message_display.vala b/main/src/ui/conversation_summary/slashme_message_display.vala
index 3c8af78c..1ee20748 100644
--- a/main/src/ui/conversation_summary/slashme_message_display.vala
+++ b/main/src/ui/conversation_summary/slashme_message_display.vala
@@ -53,6 +53,9 @@ public class MetaSlashmeItem : Plugins.MetaConversationItem {
public override Object? get_widget(Plugins.WidgetType widget_type) {
text_view = new MessageTextView() { valign=Align.CENTER, vexpand=true, visible = true };
+ if (conversation.type_ == Conversation.Type.GROUPCHAT) {
+ text_view.highlight_word(conversation.nickname);
+ }
string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account);
string color = Util.get_name_hex_color(stream_interactor, conversation.account, conversation.counterpart, Util.is_dark_theme(text_view));