diff options
-rw-r--r-- | libdino/src/entity/message.vala | 35 | ||||
-rw-r--r-- | libdino/src/service/message_processor.vala | 7 | ||||
-rw-r--r-- | libdino/src/service/muc_manager.vala | 9 | ||||
-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 |
8 files changed, 98 insertions, 57 deletions
diff --git a/libdino/src/entity/message.vala b/libdino/src/entity/message.vala index 3092627e..e5871f49 100644 --- a/libdino/src/entity/message.vala +++ b/libdino/src/entity/message.vala @@ -29,13 +29,13 @@ public class Message : Object { public Jid? counterpart { get; set; } public Jid? ourpart { get; set; } public Jid? from { - get { return direction == DIRECTION_SENT ? account.bare_jid : counterpart; } + get { return direction == DIRECTION_SENT ? ourpart : counterpart; } } public Jid? to { - get { return direction == DIRECTION_SENT ? counterpart : account.bare_jid; } + get { return direction == DIRECTION_SENT ? counterpart : ourpart; } } public bool direction { get; set; } - public string? real_jid { get; set; } + public Jid? real_jid { get; set; } public Type type_ { get; set; default = Type.UNKNOWN; } public string? body { get; set; } public string? stanza_id { get; set; } @@ -56,19 +56,30 @@ public class Message : Object { this.db = db; id = row[db.message.id]; + account = db.get_account_by_id(row[db.message.account_id]); // TODO dont have to generate acc new stanza_id = row[db.message.stanza_id]; - string from = db.get_jid_by_id(row[db.message.counterpart_id]); - string from_resource = row[db.message.counterpart_resource]; - counterpart = from_resource != null ? new Jid(from + "/" + from_resource) : new Jid(from); - direction = row[db.message.direction]; type_ = (Message.Type) row[db.message.type_]; + + string counterpart_jid = db.get_jid_by_id(row[db.message.counterpart_id]); + string counterpart_resource = row[db.message.counterpart_resource]; + counterpart = counterpart_resource != null ? new Jid.with_resource(counterpart_jid, counterpart_resource) : new Jid(counterpart_jid); + + string our_resource = row[db.message.our_resource]; + if (type_ == Type.GROUPCHAT && our_resource != null) { + ourpart = new Jid.with_resource(counterpart_jid, our_resource); + } else if (our_resource != null) { + ourpart = new Jid.with_resource(account.bare_jid.to_string(), our_resource); + } else { + ourpart = account.bare_jid; + } + direction = row[db.message.direction]; time = new DateTime.from_unix_local(row[db.message.time]); local_time = new DateTime.from_unix_local(row[db.message.time]); body = row[db.message.body]; - account = db.get_account_by_id(row[db.message.account_id]); // TODO dont have to generate acc new marked = (Message.Marked) row[db.message.marked]; encryption = (Encryption) row[db.message.encryption]; - real_jid = db.real_jid.select({db.real_jid.real_jid}).with(db.real_jid.message_id, "=", id)[db.real_jid.real_jid]; + string? real_jid_str = db.real_jid.select({db.real_jid.real_jid}).with(db.real_jid.message_id, "=", id)[db.real_jid.real_jid]; + if (real_jid_str != null) real_jid = new Jid(real_jid_str); notify.connect(on_update); } @@ -95,7 +106,7 @@ public class Message : Object { if (real_jid != null) { db.real_jid.insert() .value(db.real_jid.message_id, id) - .value(db.real_jid.real_jid, real_jid) + .value(db.real_jid.real_jid, real_jid.to_string()) .perform(); } notify.connect(on_update); @@ -168,10 +179,10 @@ public class Message : Object { if (sp.get_name() == "real-jid") { db.real_jid.insert().or("REPLACE") .value(db.real_jid.message_id, id) - .value(db.real_jid.real_jid, real_jid) + .value(db.real_jid.real_jid, real_jid.to_string()) .perform(); } } } -}
\ No newline at end of file +} diff --git a/libdino/src/service/message_processor.vala b/libdino/src/service/message_processor.vala index cc99bcc3..2bf3d615 100644 --- a/libdino/src/service/message_processor.vala +++ b/libdino/src/service/message_processor.vala @@ -167,7 +167,12 @@ public class MessageProcessor : StreamInteractionModule, Object { message.local_time = new DateTime.now_local(); message.direction = Entities.Message.DIRECTION_SENT; message.counterpart = conversation.counterpart; - message.ourpart = new Jid(conversation.account.bare_jid.to_string() + "/" + conversation.account.resourcepart); + if (conversation.type_ in new Conversation.Type[]{Conversation.Type.GROUPCHAT, Conversation.Type.GROUPCHAT_PM}) { + message.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); + message.real_jid = conversation.account.bare_jid; + } else { + message.ourpart = new Jid.with_resource(conversation.account.bare_jid.to_string(), conversation.account.resourcepart); + } message.marked = Entities.Message.Marked.UNSENT; message.encryption = conversation.encryption; diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index ea261300..51b3822e 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -191,13 +191,6 @@ public class MucManager : StreamInteractionModule, Object { return ret; } - public Jid? get_message_real_jid(Entities.Message message) { - if (message.real_jid != null) { - return new Jid(message.real_jid); - } - return null; - } - public Jid? get_own_jid(Jid muc_jid, Account account) { Core.XmppStream? stream = stream_interactor.get_stream(account); if (stream != null) { @@ -250,7 +243,7 @@ public class MucManager : StreamInteractionModule, Object { if (Xep.DelayedDelivery.MessageFlag.get_flag(message.stanza) == null) { string? real_jid = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_real_jid(message.counterpart.to_string()); if (real_jid != null && real_jid != message.counterpart.to_string()) { - message.real_jid = real_jid; + message.real_jid = new Jid(real_jid).bare_jid; } } string? muc_nick = stream.get_flag(Xep.Muc.Flag.IDENTITY).get_muc_nick(conversation.counterpart.bare_jid.to_string()); 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) { |