diff options
author | fiaxh <git@mx.ax.lt> | 2017-08-23 20:30:44 +0200 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-08-25 22:29:40 +0200 |
commit | 5fcf8e73efeea60413a383e6e6a096a3981be1a2 (patch) | |
tree | 8f7aa88a0b167d46a90c2966b3ea15959a8a4014 /main/src | |
parent | 7b395263c1ec0e6b057f7c3bb1d0525f6f38964d (diff) | |
download | dino-5fcf8e73efeea60413a383e6e6a096a3981be1a2.tar.gz dino-5fcf8e73efeea60413a383e6e6a096a3981be1a2.zip |
Show nicks in MUCs, real jid in individual occupant menu
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/ui/avatar_generator.vala | 31 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/merged_message_item.vala | 14 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/slashme_item.vala | 7 | ||||
-rw-r--r-- | main/src/ui/occupant_menu/view.vala | 14 | ||||
-rw-r--r-- | main/src/ui/util/helper.vala | 38 |
5 files changed, 68 insertions, 36 deletions
diff --git a/main/src/ui/avatar_generator.vala b/main/src/ui/avatar_generator.vala index eb87a3e2..10406699 100644 --- a/main/src/ui/avatar_generator.vala +++ b/main/src/ui/avatar_generator.vala @@ -25,14 +25,21 @@ public class AvatarGenerator { this.scale_factor = scale_factor; } - public Pixbuf draw_jid(StreamInteractor stream_interactor, Jid jid, Account account) { + public Pixbuf draw_jid(StreamInteractor stream_interactor, Jid jid_, Account account) { + Jid? jid = jid_; this.stream_interactor = stream_interactor; + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, account); + if (real_jid != null && stream_interactor.get_module(AvatarManager.IDENTITY).get_avatar(account, real_jid) != null) { + jid = real_jid; + } return crop_corners(draw_tile(jid, account, width * scale_factor, height * scale_factor)); } public Pixbuf draw_message(StreamInteractor stream_interactor, Message message) { - Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_message_real_jid(message); - return draw_jid(stream_interactor, real_jid != null ? real_jid : message.from, message.account); + if (message.real_jid != null && stream_interactor.get_module(AvatarManager.IDENTITY).get_avatar(message.account, message.real_jid) != null) { + return draw_jid(stream_interactor, message.real_jid, message.account); + } + return draw_jid(stream_interactor, message.from, message.account); } public Pixbuf draw_conversation(StreamInteractor stream_interactor, Conversation conversation) { @@ -44,8 +51,7 @@ public class AvatarGenerator { } public Pixbuf draw_text(string text) { - string color = greyscale ? COLOR_GREY : Util.get_avatar_hex_color(text); - Pixbuf pixbuf = draw_colored_rectangle_text(color, text, width, height); + Pixbuf pixbuf = draw_colored_rectangle_text(COLOR_GREY, text, width, height); return crop_corners(pixbuf); } @@ -81,12 +87,6 @@ public class AvatarGenerator { } private Pixbuf draw_chat_tile(Jid jid, Account account, int width, int height) { - if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat_occupant(jid, account)) { - Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, account); - if (real_jid != null) { - return draw_tile(real_jid, account, width, height); - } - } Pixbuf? avatar = stream_interactor.get_module(AvatarManager.IDENTITY).get_avatar(account, jid); if (avatar != null) { double desired_ratio = (double) width / height; @@ -103,7 +103,7 @@ public class AvatarGenerator { return avatar; } else { string display_name = Util.get_display_name(stream_interactor, jid, account); - string color = greyscale ? COLOR_GREY : Util.get_avatar_hex_color(display_name); + string color = greyscale ? COLOR_GREY : Util.get_avatar_hex_color(stream_interactor, account, jid); return draw_colored_rectangle_text(color, display_name.get_char(0).toupper().to_string(), width, height); } } @@ -113,6 +113,13 @@ public class AvatarGenerator { if (stateless || occupants == null || occupants.size == 0) { return draw_chat_tile(jid, account, width, height); } + + for (int i = 0; i < occupants.size && i < 4; i++) { + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(occupants[i], account); + if (real_jid != null && stream_interactor.get_module(AvatarManager.IDENTITY).get_avatar(account, real_jid) != null) { + occupants[i] = real_jid; + } + } Pixbuf pixbuf = initialize_pixbuf(width, height); if (occupants.size == 1 || occupants.size == 2 || occupants.size == 3) { add_tile_to_pixbuf(pixbuf, occupants[0], account, width / 2 - get_right_border(), height, 0, 0); diff --git a/main/src/ui/conversation_summary/merged_message_item.vala b/main/src/ui/conversation_summary/merged_message_item.vala index 6c1166d1..4cabebac 100644 --- a/main/src/ui/conversation_summary/merged_message_item.vala +++ b/main/src/ui/conversation_summary/merged_message_item.vala @@ -16,10 +16,11 @@ public class MergedMessageItem : MessageItem { base(stream_interactor, conversation, message); set_main_widget(textview); set_title_widget(name_label); - add_message(message); + string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account); - name_label.set_markup(@"<span foreground=\"#$(Util.get_name_hex_color(display_name, false))\">$display_name</span>"); + string color = Util.get_name_hex_color(stream_interactor, conversation.account, message.from, false); + name_label.set_markup(@"<span foreground=\"#$color\">$display_name</span>"); textview.style_updated.connect(update_display_style); update_display_style(); @@ -28,7 +29,11 @@ public class MergedMessageItem : MessageItem { public override void add_message(Message message) { base.add_message(message); if (messages.size > 1) textview.add_text("\n"); - textview.add_text(message.body); + string text = message.body; + if (text.length > 10000) { + text = text.slice(0, 10000) + " [" + _("Message too long") + "]"; + } + textview.add_text(text); } public override bool merge(Message message) { @@ -46,7 +51,8 @@ public class MergedMessageItem : MessageItem { private void update_display_style() { string display_name = Util.get_message_display_name(stream_interactor, messages[0], conversation.account); - name_label.set_markup(@"<span foreground=\"#$(Util.get_name_hex_color(display_name, Util.is_dark_theme(textview)))\">$display_name</span>"); + string color = Util.get_name_hex_color(stream_interactor, conversation.account, messages[0].real_jid ?? messages[0].from, Util.is_dark_theme(textview)); + name_label.set_markup(@"<span foreground=\"#$color\">$display_name</span>"); } } diff --git a/main/src/ui/conversation_summary/slashme_item.vala b/main/src/ui/conversation_summary/slashme_item.vala index cd387bc9..2056d2d1 100644 --- a/main/src/ui/conversation_summary/slashme_item.vala +++ b/main/src/ui/conversation_summary/slashme_item.vala @@ -19,7 +19,8 @@ public class SlashMeItem : MessageItem { text = message.body.substring(3); string display_name = Util.get_message_display_name(stream_interactor, message, conversation.account); - nick_tag = textview.buffer.create_tag("nick", foreground: @"#$(Util.get_name_hex_color(display_name, false))"); + string color = Util.get_name_hex_color(stream_interactor, conversation.account, conversation.counterpart, false); + nick_tag = textview.buffer.create_tag("nick", foreground: "#" + color); TextIter iter; textview.buffer.get_start_iter(out iter); textview.buffer.insert_with_tags(ref iter, display_name, display_name.length, nick_tag); @@ -35,8 +36,8 @@ public class SlashMeItem : MessageItem { } private void update_display_style() { - string display_name = Util.get_message_display_name(stream_interactor, messages[0], conversation.account); - nick_tag.foreground = @"#$(Util.get_name_hex_color(display_name, Util.is_dark_theme(textview)))"; + string color = Util.get_name_hex_color(stream_interactor, conversation.account, messages[0].real_jid ?? messages[0].from, Util.is_dark_theme(textview)); + nick_tag.foreground = "#" + color; } } diff --git a/main/src/ui/occupant_menu/view.vala b/main/src/ui/occupant_menu/view.vala index 7918fe46..b93e38e6 100644 --- a/main/src/ui/occupant_menu/view.vala +++ b/main/src/ui/occupant_menu/view.vala @@ -12,6 +12,7 @@ public class View : Popover { private Stack stack = new Stack() { vhomogeneous=false, visible=true }; private List list; private ListBox invite_list; + private Box? jid_menu = null; public View(StreamInteractor stream_interactor, Window window, Conversation conversation) { this.stream_interactor = stream_interactor; @@ -63,13 +64,16 @@ public class View : Popover { stack.visible_child_name = "list"; } - private void show_menu(Jid jid, string name_label) { + private void show_menu(Jid jid, string name_) { stack.transition_type = StackTransitionType.SLIDE_LEFT; + string name = name_; + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, conversation.account); + if (real_jid != null) name += @"\n<span font=\'8\'>$(real_jid.bare_jid)</span>"; + Box header_box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; header_box.add(new Image.from_icon_name("pan-start-symbolic", IconSize.SMALL_TOOLBAR) { visible=true }); - header_box.add(new Label(name_label) { xalign=0.5f, hexpand=true, visible=true }); - + header_box.add(new Label(name) { xalign=0, use_markup=true, hexpand=true, visible=true }); Button header_button = new Button() { relief=ReliefStyle.NONE, visible=true }; header_button.add(header_box); @@ -90,8 +94,10 @@ public class View : Popover { kick_button.clicked.connect(kick_button_clicked); } + if (jid_menu != null) stack.remove(jid_menu); stack.add_named(outer_box, "menu"); stack.visible_child_name = "menu"; + jid_menu = outer_box; } private void private_conversation_button_clicked() { @@ -110,4 +116,4 @@ public class View : Popover { } } -}
\ No newline at end of file +} diff --git a/main/src/ui/util/helper.vala b/main/src/ui/util/helper.vala index d493def2..f1355b39 100644 --- a/main/src/ui/util/helper.vala +++ b/main/src/ui/util/helper.vala @@ -12,18 +12,32 @@ private const string[] material_colors_500 = {"F44336", "E91E63", "9C27B0", "673 private const string[] material_colors_300 = {"E57373", "F06292", "BA68C8", "9575CD", "7986CB", "64B5F6", "4FC3F7", "4DD0E1", "4DB6AC", "81C784", "AED581", "DCE775", "FFD54F", "FFB74D", "FF8A65", "A1887F"}; private const string[] material_colors_200 = {"EF9A9A", "F48FB1", "CE93D8", "B39DDB", "9FA8DA", "90CAF9", "81D4FA", "80DEEA", "80CBC4", "A5D6A7", "C5E1A5", "E6EE9C", "FFE082", "FFCC80", "FFAB91", "BCAAA4"}; -public static string get_avatar_hex_color(string name) { - return material_colors_300[name.hash() % material_colors_300.length]; -// return tango_colors_light[name.hash() % tango_colors_light.length]; +public static string get_avatar_hex_color(StreamInteractor stream_interactor, Account account, Jid jid) { + uint hash = get_relevant_jid(stream_interactor, account, jid).to_string().hash(); + return material_colors_300[hash % material_colors_300.length]; +// return tango_colors_light[name.hash() % tango_colors_light.length]; } -public static string get_name_hex_color(string name, bool dark_theme = false) { +public static string get_name_hex_color(StreamInteractor stream_interactor, Account account, Jid jid, bool dark_theme = false) { + uint hash = get_relevant_jid(stream_interactor, account, jid).to_string().hash(); if (dark_theme) { - return material_colors_300[name.hash() % material_colors_300.length]; + return material_colors_300[hash % material_colors_300.length]; } else { - return material_colors_500[name.hash() % material_colors_500.length]; + return material_colors_500[hash % material_colors_500.length]; } -// return tango_colors_medium[name.hash() % tango_colors_medium.length]; +// return tango_colors_medium[name.hash() % tango_colors_medium.length]; +} + +private static Jid get_relevant_jid(StreamInteractor stream_interactor, Account account, Jid jid) { + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(jid.bare_jid, account)) { + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(jid, account); + if (real_jid != null) { + return real_jid.bare_jid; + } + } else { + return jid.bare_jid; + } + return jid; } public static string color_for_show(string show) { @@ -46,6 +60,9 @@ 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 (jid.resourcepart == account.resourcepart) { + return account.alias; // FIXME temporary. remove again. + } return jid.resourcepart; } else { if (jid.bare_jid.equals(account.bare_jid.bare_jid)) { @@ -64,12 +81,7 @@ public static string get_display_name(StreamInteractor stream_interactor, Jid ji } public static string get_message_display_name(StreamInteractor stream_interactor, Entities.Message message, Account account) { - Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_message_real_jid(message); - if (real_jid != null) { - return get_display_name(stream_interactor, real_jid, account); - } else { - return get_display_name(stream_interactor, message.from, account); - } + return get_display_name(stream_interactor, message.from, account); } public static void image_set_from_scaled_pixbuf(Image image, Gdk.Pixbuf pixbuf, int scale = 0) { |