Update time labels in conversation view at the moment they actually change
This commit is contained in:
parent
5a98d2919b
commit
1fd045236b
|
@ -51,12 +51,6 @@ public class ConversationItemSkeleton : EventBox {
|
||||||
update_margin();
|
update_margin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update_time() {
|
|
||||||
if (metadata_header != null) {
|
|
||||||
metadata_header.update_time();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update_margin() {
|
public void update_margin() {
|
||||||
if (item.requires_header && show_skeleton && metadata_header == null) {
|
if (item.requires_header && show_skeleton && metadata_header == null) {
|
||||||
metadata_header = new ItemMetaDataHeader(stream_interactor, conversation, item) { visible=true };
|
metadata_header = new ItemMetaDataHeader(stream_interactor, conversation, item) { visible=true };
|
||||||
|
@ -116,16 +110,22 @@ public class ItemMetaDataHeader : Box {
|
||||||
encryption_image.visible = true;
|
encryption_image.visible = true;
|
||||||
encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER);
|
encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER);
|
||||||
}
|
}
|
||||||
|
if (item.display_time != null) {
|
||||||
update_time();
|
update_time();
|
||||||
|
}
|
||||||
|
|
||||||
item.notify["mark"].connect_after(update_received_mark);
|
item.notify["mark"].connect_after(update_received_mark);
|
||||||
update_received_mark();
|
update_received_mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update_time() {
|
private void update_time() {
|
||||||
if (item.display_time != null) {
|
|
||||||
time_label.label = get_relative_time(item.display_time.to_local()).to_string();
|
time_label.label = get_relative_time(item.display_time.to_local()).to_string();
|
||||||
}
|
|
||||||
|
Timeout.add_seconds((int) get_next_time_change(), () => {
|
||||||
|
if (this.parent == null) return false;
|
||||||
|
update_time();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update_name_label() {
|
private void update_name_label() {
|
||||||
|
@ -175,6 +175,22 @@ public class ItemMetaDataHeader : Box {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int get_next_time_change() {
|
||||||
|
DateTime now = new DateTime.now_local();
|
||||||
|
DateTime item_time = item.display_time;
|
||||||
|
TimeSpan timespan = now.difference(item_time);
|
||||||
|
|
||||||
|
if (timespan < 10 * TimeSpan.MINUTE) {
|
||||||
|
if (now.get_second() < item_time.get_second()) {
|
||||||
|
return item_time.get_second() - now.get_second();
|
||||||
|
} else {
|
||||||
|
return 60 - (now.get_second() - item_time.get_second());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return (23 - now.get_hour()) * 3600 + (59 - now.get_minute()) * 60 + (59 - now.get_second());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string format_time(DateTime datetime, string format_24h, string format_12h) {
|
public static string format_time(DateTime datetime, string format_24h, string format_12h) {
|
||||||
string format = Util.is_24h_format() ? format_24h : format_12h;
|
string format = Util.is_24h_format() ? format_24h : format_12h;
|
||||||
if (!get_charset(null)) {
|
if (!get_charset(null)) {
|
||||||
|
|
|
@ -60,13 +60,6 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
|
||||||
app.plugin_registry.register_conversation_addition_populator(new ChatStatePopulator(stream_interactor));
|
app.plugin_registry.register_conversation_addition_populator(new ChatStatePopulator(stream_interactor));
|
||||||
app.plugin_registry.register_conversation_addition_populator(new DateSeparatorPopulator(stream_interactor));
|
app.plugin_registry.register_conversation_addition_populator(new DateSeparatorPopulator(stream_interactor));
|
||||||
|
|
||||||
Timeout.add_seconds(60, () => {
|
|
||||||
foreach (ConversationItemSkeleton item_skeleton in item_skeletons) {
|
|
||||||
item_skeleton.update_time();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
main_wrap_event_box.events = EventMask.ENTER_NOTIFY_MASK;
|
main_wrap_event_box.events = EventMask.ENTER_NOTIFY_MASK;
|
||||||
main_wrap_event_box.events = EventMask.LEAVE_NOTIFY_MASK;
|
main_wrap_event_box.events = EventMask.LEAVE_NOTIFY_MASK;
|
||||||
main_wrap_event_box.leave_notify_event.connect(on_leave_notify_event);
|
main_wrap_event_box.leave_notify_event.connect(on_leave_notify_event);
|
||||||
|
|
Loading…
Reference in a new issue