2017-08-27 21:55:49 +00:00
|
|
|
|
using Gee;
|
|
|
|
|
using Gdk;
|
|
|
|
|
using Gtk;
|
|
|
|
|
using Markup;
|
|
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
|
|
|
|
|
namespace Dino.Ui.ConversationSummary {
|
|
|
|
|
|
2019-06-01 14:00:21 +00:00
|
|
|
|
public class ConversationItemSkeleton : EventBox {
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2018-01-16 15:17:42 +00:00
|
|
|
|
private AvatarImage image = new AvatarImage() { margin_top=2, valign=Align.START, visible=true, allow_gray = false };
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2019-06-01 14:00:21 +00:00
|
|
|
|
public bool show_skeleton { get; set; }
|
|
|
|
|
public bool last_group_item { get; set; }
|
|
|
|
|
|
2017-08-27 21:55:49 +00:00
|
|
|
|
public StreamInteractor stream_interactor;
|
|
|
|
|
public Conversation conversation { get; set; }
|
2019-06-01 14:00:21 +00:00
|
|
|
|
public Plugins.MetaConversationItem item;
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2019-06-01 14:00:21 +00:00
|
|
|
|
private Box image_content_box = new Box(Orientation.HORIZONTAL, 8) { visible=true };
|
|
|
|
|
private Box header_content_box = new Box(Orientation.VERTICAL, 0) { visible=true };
|
2019-09-10 23:19:24 +00:00
|
|
|
|
private ItemMetaDataHeader metadata_header;
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2017-11-26 18:28:44 +00:00
|
|
|
|
public ConversationItemSkeleton(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
|
2017-08-27 21:55:49 +00:00
|
|
|
|
this.stream_interactor = stream_interactor;
|
2019-09-10 23:19:24 +00:00
|
|
|
|
this.conversation = conversation;
|
|
|
|
|
this.item = item;
|
2019-06-01 14:00:21 +00:00
|
|
|
|
this.get_style_context().add_class("message-box");
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2017-11-26 18:28:44 +00:00
|
|
|
|
if (item.requires_avatar) {
|
2019-10-18 14:52:29 +00:00
|
|
|
|
image.set_conversation_participant(stream_interactor, conversation, item.jid);
|
2018-03-07 16:24:57 +00:00
|
|
|
|
image_content_box.add(image);
|
2017-11-26 18:28:44 +00:00
|
|
|
|
}
|
2020-01-22 00:24:14 +00:00
|
|
|
|
if (item.requires_header) {
|
2019-09-10 23:19:24 +00:00
|
|
|
|
metadata_header = new ItemMetaDataHeader(stream_interactor, conversation, item) { visible=true };
|
|
|
|
|
header_content_box.add(metadata_header);
|
2017-11-26 18:28:44 +00:00
|
|
|
|
}
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2017-11-26 18:28:44 +00:00
|
|
|
|
Widget? widget = item.get_widget(Plugins.WidgetType.GTK) as Widget;
|
|
|
|
|
if (widget != null) {
|
2019-06-16 13:17:08 +00:00
|
|
|
|
widget.valign = Align.END;
|
2019-06-01 14:00:21 +00:00
|
|
|
|
header_content_box.add(widget);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
2017-11-21 21:17:04 +00:00
|
|
|
|
|
2019-06-01 14:00:21 +00:00
|
|
|
|
image_content_box.add(header_content_box);
|
|
|
|
|
this.add(image_content_box);
|
|
|
|
|
|
|
|
|
|
if (item.get_type().is_a(typeof(ContentMetaItem))) {
|
|
|
|
|
this.motion_notify_event.connect((event) => {
|
|
|
|
|
this.set_state_flags(StateFlags.PRELIGHT, false);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
this.enter_notify_event.connect((event) => {
|
|
|
|
|
this.set_state_flags(StateFlags.PRELIGHT, false);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
this.leave_notify_event.connect((event) => {
|
|
|
|
|
this.unset_state_flags(StateFlags.PRELIGHT);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.notify["show-skeleton"].connect(update_margin);
|
|
|
|
|
this.notify["last-group-item"].connect(update_margin);
|
|
|
|
|
|
|
|
|
|
this.show_skeleton = true;
|
|
|
|
|
this.last_group_item = true;
|
|
|
|
|
update_margin();
|
2019-11-13 16:42:47 +00:00
|
|
|
|
this.notify["show-skeleton"].connect(update_margin);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void update_time() {
|
2019-09-10 23:19:24 +00:00
|
|
|
|
if (metadata_header != null) {
|
|
|
|
|
metadata_header.update_time();
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-01 14:00:21 +00:00
|
|
|
|
|
|
|
|
|
public void update_margin() {
|
|
|
|
|
image.visible = this.show_skeleton;
|
2019-09-10 23:19:24 +00:00
|
|
|
|
if (metadata_header != null) {
|
|
|
|
|
metadata_header.visible = this.show_skeleton;
|
2019-06-01 14:00:21 +00:00
|
|
|
|
}
|
|
|
|
|
image_content_box.margin_start = this.show_skeleton ? 15 : 58;
|
2019-09-09 17:47:11 +00:00
|
|
|
|
image_content_box.margin_end = 15;
|
2019-06-01 14:00:21 +00:00
|
|
|
|
|
|
|
|
|
if (this.show_skeleton && this.last_group_item) {
|
|
|
|
|
image_content_box.margin_top = 8;
|
|
|
|
|
image_content_box.margin_bottom = 8;
|
|
|
|
|
} else {
|
|
|
|
|
image_content_box.margin_top = 4;
|
|
|
|
|
image_content_box.margin_bottom = 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-26 18:28:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 01:49:53 +00:00
|
|
|
|
[GtkTemplate (ui = "/im/dino/Dino/conversation_content_view/item_metadata_header.ui")]
|
2019-09-10 23:19:24 +00:00
|
|
|
|
public class ItemMetaDataHeader : Box {
|
|
|
|
|
[GtkChild] public Label name_label;
|
|
|
|
|
[GtkChild] public Label dot_label;
|
|
|
|
|
[GtkChild] public Label time_label;
|
|
|
|
|
[GtkChild] public Image encryption_image;
|
|
|
|
|
[GtkChild] public Image received_image;
|
|
|
|
|
|
|
|
|
|
public static IconSize ICON_SIZE_HEADER = Gtk.icon_size_register("im.dino.Dino.HEADER_ICON", 17, 12);
|
2017-11-26 18:28:44 +00:00
|
|
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
|
private Conversation conversation;
|
|
|
|
|
private Plugins.MetaConversationItem item;
|
|
|
|
|
private ArrayList<Plugins.MetaConversationItem> items = new ArrayList<Plugins.MetaConversationItem>();
|
|
|
|
|
|
2019-09-10 23:19:24 +00:00
|
|
|
|
public ItemMetaDataHeader(StreamInteractor stream_interactor, Conversation conversation, Plugins.MetaConversationItem item) {
|
2017-11-26 18:28:44 +00:00
|
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
|
this.conversation = conversation;
|
|
|
|
|
this.item = item;
|
2019-09-10 23:19:24 +00:00
|
|
|
|
items.add(item);
|
2017-11-26 18:28:44 +00:00
|
|
|
|
|
|
|
|
|
update_name_label();
|
|
|
|
|
name_label.style_updated.connect(update_name_label);
|
2020-01-21 23:09:06 +00:00
|
|
|
|
if (item.encryption != Encryption.NONE) {
|
2017-08-27 21:55:49 +00:00
|
|
|
|
encryption_image.visible = true;
|
2017-11-26 18:28:44 +00:00
|
|
|
|
encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
2017-11-26 18:28:44 +00:00
|
|
|
|
update_time();
|
2017-08-27 21:55:49 +00:00
|
|
|
|
|
2017-11-26 18:28:44 +00:00
|
|
|
|
item.notify["mark"].connect_after(update_received_mark);
|
|
|
|
|
update_received_mark();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void update_time() {
|
|
|
|
|
if (item.display_time != null) {
|
2019-09-10 23:19:24 +00:00
|
|
|
|
time_label.label = get_relative_time(item.display_time.to_local()).to_string();
|
2017-11-26 18:28:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void update_name_label() {
|
2019-10-18 14:52:29 +00:00
|
|
|
|
string display_name = Markup.escape_text(Util.get_participant_display_name(stream_interactor, conversation, item.jid));
|
2017-11-26 18:28:44 +00:00
|
|
|
|
string color = Util.get_name_hex_color(stream_interactor, conversation.account, item.jid, Util.is_dark_theme(name_label));
|
2019-09-10 23:19:24 +00:00
|
|
|
|
name_label.label = @"<span foreground=\"#$color\">$display_name</span>";
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 21:17:04 +00:00
|
|
|
|
private void update_received_mark() {
|
2017-08-27 21:55:49 +00:00
|
|
|
|
bool all_received = true;
|
|
|
|
|
bool all_read = true;
|
2017-08-29 22:03:37 +00:00
|
|
|
|
bool all_sent = true;
|
2017-08-27 21:55:49 +00:00
|
|
|
|
foreach (Plugins.MetaConversationItem item in items) {
|
|
|
|
|
if (item.mark == Message.Marked.WONTSEND) {
|
|
|
|
|
received_image.visible = true;
|
2017-11-26 18:28:44 +00:00
|
|
|
|
received_image.set_from_icon_name("dialog-warning-symbolic", ICON_SIZE_HEADER);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
Util.force_error_color(received_image);
|
|
|
|
|
Util.force_error_color(encryption_image);
|
|
|
|
|
Util.force_error_color(time_label);
|
2020-02-21 17:22:27 +00:00
|
|
|
|
string error_text = _("Unable to send message");
|
|
|
|
|
received_image.tooltip_text = error_text;
|
|
|
|
|
encryption_image.tooltip_text = error_text;
|
|
|
|
|
time_label.tooltip_text = error_text;
|
2017-08-27 21:55:49 +00:00
|
|
|
|
return;
|
|
|
|
|
} else if (item.mark != Message.Marked.READ) {
|
|
|
|
|
all_read = false;
|
|
|
|
|
if (item.mark != Message.Marked.RECEIVED) {
|
|
|
|
|
all_received = false;
|
2017-08-29 22:03:37 +00:00
|
|
|
|
if (item.mark == Message.Marked.UNSENT) {
|
|
|
|
|
all_sent = false;
|
|
|
|
|
}
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (all_read) {
|
|
|
|
|
received_image.visible = true;
|
2017-11-26 18:28:44 +00:00
|
|
|
|
received_image.set_from_icon_name("dino-double-tick-symbolic", ICON_SIZE_HEADER);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
} else if (all_received) {
|
|
|
|
|
received_image.visible = true;
|
2017-11-26 18:28:44 +00:00
|
|
|
|
received_image.set_from_icon_name("dino-tick-symbolic", ICON_SIZE_HEADER);
|
2017-08-29 22:03:37 +00:00
|
|
|
|
} else if (!all_sent) {
|
|
|
|
|
received_image.visible = true;
|
2017-11-26 18:28:44 +00:00
|
|
|
|
received_image.set_from_icon_name("image-loading-symbolic", ICON_SIZE_HEADER);
|
2017-08-27 21:55:49 +00:00
|
|
|
|
} else if (received_image.visible) {
|
2017-11-26 18:28:44 +00:00
|
|
|
|
received_image.set_from_icon_name("image-loading-symbolic", ICON_SIZE_HEADER);
|
|
|
|
|
|
2017-08-27 21:55:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-26 18:28:44 +00:00
|
|
|
|
public static string format_time(DateTime datetime, string format_24h, string format_12h) {
|
2017-08-29 19:51:08 +00:00
|
|
|
|
string format = Util.is_24h_format() ? format_24h : format_12h;
|
|
|
|
|
if (!get_charset(null)) {
|
|
|
|
|
// No UTF-8 support, use simple colon for time instead
|
|
|
|
|
format = format.replace("∶", ":");
|
|
|
|
|
}
|
|
|
|
|
return datetime.format(format);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 22:31:39 +00:00
|
|
|
|
public static string get_relative_time(DateTime datetime) {
|
2017-08-27 21:55:49 +00:00
|
|
|
|
DateTime now = new DateTime.now_local();
|
|
|
|
|
TimeSpan timespan = now.difference(datetime);
|
|
|
|
|
if (timespan > 365 * TimeSpan.DAY) {
|
2017-08-29 19:51:08 +00:00
|
|
|
|
return format_time(datetime,
|
|
|
|
|
/* xgettext:no-c-format */ /* Date + time in 24h format (w/o seconds) */ _("%x, %H∶%M"),
|
|
|
|
|
/* xgettext:no-c-format */ /* Date + time in 12h format (w/o seconds)*/ _("%x, %l∶%M %p"));
|
2017-08-27 21:55:49 +00:00
|
|
|
|
} else if (timespan > 7 * TimeSpan.DAY) {
|
2017-08-29 19:51:08 +00:00
|
|
|
|
return format_time(datetime,
|
|
|
|
|
/* xgettext:no-c-format */ /* Month, day and time in 24h format (w/o seconds) */ _("%b %d, %H∶%M"),
|
|
|
|
|
/* xgettext:no-c-format */ /* Month, day and time in 12h format (w/o seconds) */ _("%b %d, %l∶%M %p"));
|
2017-08-29 22:03:37 +00:00
|
|
|
|
} else if (datetime.get_day_of_month() != now.get_day_of_month()) {
|
2017-08-29 19:51:08 +00:00
|
|
|
|
return format_time(datetime,
|
|
|
|
|
/* xgettext:no-c-format */ /* Day of week and time in 24h format (w/o seconds) */ _("%a, %H∶%M"),
|
|
|
|
|
/* xgettext:no-c-format */ /* Day of week and time in 12h format (w/o seconds) */_("%a, %l∶%M %p"));
|
2017-08-27 21:55:49 +00:00
|
|
|
|
} else if (timespan > 9 * TimeSpan.MINUTE) {
|
2017-08-29 19:51:08 +00:00
|
|
|
|
return format_time(datetime,
|
|
|
|
|
/* xgettext:no-c-format */ /* Time in 24h format (w/o seconds) */ _("%H∶%M"),
|
|
|
|
|
/* xgettext:no-c-format */ /* Time in 12h format (w/o seconds) */ _("%l∶%M %p"));
|
2017-08-27 21:55:49 +00:00
|
|
|
|
} else if (timespan > TimeSpan.MINUTE) {
|
|
|
|
|
ulong mins = (ulong) (timespan.abs() / TimeSpan.MINUTE);
|
|
|
|
|
/* xgettext:this is the beginning of a sentence. */
|
|
|
|
|
return n("%i min ago", "%i mins ago", mins).printf(mins);
|
|
|
|
|
} else {
|
|
|
|
|
return _("Just now");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|