aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-03-26 15:27:48 +0100
committerfiaxh <git@lightrise.org>2020-03-26 15:27:48 +0100
commit1fd045236bb5d49d5d7ea82b76ff2f88463d7c7f (patch)
treeb659d71596e86658bce1c5a68743e28d0c3a93c1
parent5a98d2919b55777a708e36a6994041814024a81a (diff)
downloaddino-1fd045236bb5d49d5d7ea82b76ff2f88463d7c7f.tar.gz
dino-1fd045236bb5d49d5d7ea82b76ff2f88463d7c7f.zip
Update time labels in conversation view at the moment they actually change
-rw-r--r--main/src/ui/conversation_content_view/conversation_item_skeleton.vala38
-rw-r--r--main/src/ui/conversation_content_view/conversation_view.vala7
2 files changed, 27 insertions, 18 deletions
diff --git a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
index dfce7067..589bcddd 100644
--- a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
+++ b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala
@@ -51,12 +51,6 @@ public class ConversationItemSkeleton : EventBox {
update_margin();
}
- public void update_time() {
- if (metadata_header != null) {
- metadata_header.update_time();
- }
- }
-
public void update_margin() {
if (item.requires_header && show_skeleton && metadata_header == null) {
metadata_header = new ItemMetaDataHeader(stream_interactor, conversation, item) { visible=true };
@@ -116,16 +110,22 @@ public class ItemMetaDataHeader : Box {
encryption_image.visible = true;
encryption_image.set_from_icon_name("dino-changes-prevent-symbolic", ICON_SIZE_HEADER);
}
- update_time();
+ if (item.display_time != null) {
+ update_time();
+ }
item.notify["mark"].connect_after(update_received_mark);
update_received_mark();
}
- public void update_time() {
- if (item.display_time != null) {
- time_label.label = get_relative_time(item.display_time.to_local()).to_string();
- }
+ private void update_time() {
+ 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() {
@@ -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) {
string format = Util.is_24h_format() ? format_24h : format_12h;
if (!get_charset(null)) {
diff --git a/main/src/ui/conversation_content_view/conversation_view.vala b/main/src/ui/conversation_content_view/conversation_view.vala
index 83d08fb3..c68ee5de 100644
--- a/main/src/ui/conversation_content_view/conversation_view.vala
+++ b/main/src/ui/conversation_content_view/conversation_view.vala
@@ -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 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.LEAVE_NOTIFY_MASK;
main_wrap_event_box.leave_notify_event.connect(on_leave_notify_event);