aboutsummaryrefslogtreecommitdiff
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
parent57c72d2818dec6c713834cfbb8c4c566a1602907 (diff)
downloaddino-bec810e234a7b9783eb8f35e2ffd7c60d75e09c7.tar.gz
dino-bec810e234a7b9783eb8f35e2ffd7c60d75e09c7.zip
Visually highlight mentions in MUCs
fixes #267
-rw-r--r--libdino/src/entity/conversation.vala7
-rw-r--r--libdino/src/service/conversation_manager.vala6
-rw-r--r--libdino/src/service/muc_manager.vala15
-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
6 files changed, 43 insertions, 11 deletions
diff --git a/libdino/src/entity/conversation.vala b/libdino/src/entity/conversation.vala
index a3a28618..9026e33f 100644
--- a/libdino/src/entity/conversation.vala
+++ b/libdino/src/entity/conversation.vala
@@ -16,7 +16,7 @@ public class Conversation : Object {
public Type type_ { get; set; }
public Account account { get; private set; }
public Jid counterpart { get; private set; }
- public string? nickname { get; private set; }
+ public string? nickname { get; set; }
public bool active { get; set; default = false; }
private DateTime? _last_active;
public DateTime? last_active {
@@ -84,6 +84,9 @@ public class Conversation : Object {
if (read_up_to != null) {
insert.value(db.conversation.read_up_to, read_up_to.id);
}
+ if (nickname != null) {
+ insert.value(db.conversation.resource, nickname);
+ }
if (counterpart.is_full()) {
insert.value(db.conversation.resource, counterpart.resourcepart);
}
@@ -145,6 +148,8 @@ public class Conversation : Object {
update.set_null(db.conversation.read_up_to);
}
break;
+ case "nickname":
+ update.set(db.conversation.resource, nickname); break;
case "active":
update.set(db.conversation.active, active); break;
case "last-active":
diff --git a/libdino/src/service/conversation_manager.vala b/libdino/src/service/conversation_manager.vala
index f6e3553d..c72500b4 100644
--- a/libdino/src/service/conversation_manager.vala
+++ b/libdino/src/service/conversation_manager.vala
@@ -26,7 +26,6 @@ public class ConversationManager : StreamInteractionModule, Object {
this.stream_interactor = stream_interactor;
stream_interactor.add_module(this);
stream_interactor.account_added.connect(on_account_added);
- stream_interactor.get_module(MucManager.IDENTITY).joined.connect(on_groupchat_joined);
stream_interactor.get_module(MessageProcessor.IDENTITY).received_pipeline.connect(new MessageListener(stream_interactor));
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(handle_new_message);
}
@@ -155,11 +154,6 @@ public class ConversationManager : StreamInteractionModule, Object {
start_conversation(conversation);
}
- private void on_groupchat_joined(Account account, Jid jid, string nick) {
- Conversation conversation = create_conversation(jid, account, Conversation.Type.GROUPCHAT);
- start_conversation(conversation);
- }
-
private void add_conversation(Conversation conversation) {
conversations[conversation.account][conversation.counterpart] = conversation;
if (conversation.active) {
diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala
index f224a8ec..696f304c 100644
--- a/libdino/src/service/muc_manager.vala
+++ b/libdino/src/service/muc_manager.vala
@@ -208,10 +208,7 @@ public class MucManager : StreamInteractionModule, Object {
private void on_account_added(Account account) {
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_entered.connect( (stream, jid, nick) => {
- enter_errors.unset(jid);
- set_autojoin(stream, jid, nick, null); // TODO password
- joined(account, jid, nick);
- stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
+ on_room_entred(account, stream, jid, nick);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).room_enter_error.connect( (stream, jid, error) => {
enter_errors[jid] = error;
@@ -243,6 +240,16 @@ public class MucManager : StreamInteractionModule, Object {
});
}
+ private void on_room_entred(Account account, XmppStream stream, Jid jid, string nick) {
+ enter_errors.unset(jid);
+ set_autojoin(stream, jid, nick, null); // TODO password
+ joined(account, jid, nick);
+ stream_interactor.get_module(MessageProcessor.IDENTITY).send_unsent_messages(account, jid);
+ Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.GROUPCHAT);
+ stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
+ conversation.nickname = nick;
+ }
+
private void join_all_active(Account account) {
Gee.List<Conversation> conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(account);
foreach (Conversation conversation in conversations) {
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));