diff options
author | Marvin W <git@larma.de> | 2023-02-07 20:10:17 +0100 |
---|---|---|
committer | Marvin W <git@larma.de> | 2023-02-07 20:23:52 +0100 |
commit | 116682e311edca6665a0497c8b225b4fe69859a7 (patch) | |
tree | b9a9de7e705c3fec2fda528c2b8b2529486201fc /main/src/ui/conversation_content_view | |
parent | 32ae87a3c4cebaa05e0e702d744900cd414000db (diff) | |
download | dino-116682e311edca6665a0497c8b225b4fe69859a7.tar.gz dino-116682e311edca6665a0497c8b225b4fe69859a7.zip |
Fix various date/time stamps not updated or wrong time zone
Diffstat (limited to 'main/src/ui/conversation_content_view')
3 files changed, 29 insertions, 13 deletions
diff --git a/main/src/ui/conversation_content_view/call_widget.vala b/main/src/ui/conversation_content_view/call_widget.vala index df4b7386..4f7e2953 100644 --- a/main/src/ui/conversation_content_view/call_widget.vala +++ b/main/src/ui/conversation_content_view/call_widget.vala @@ -175,7 +175,7 @@ namespace Dino.Ui { case Call.State.ENDED: image.set_from_icon_name("dino-phone-hangup-symbolic"); title_label.label = _("Call ended"); - string formated_end = Util.format_time(call.end_time, _("%H∶%M"), _("%l∶%M %p")); + string formated_end = Util.format_time(call.end_time.to_local(), _("%H∶%M"), _("%l∶%M %p")); string duration = get_duration_string(call.end_time.difference(call.local_time)); subtitle_label.label = _("Ended at %s").printf(formated_end) + " · " + 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 96cb6c3d..9e98cacb 100644 --- a/main/src/ui/conversation_content_view/conversation_item_skeleton.vala +++ b/main/src/ui/conversation_content_view/conversation_item_skeleton.vala @@ -173,7 +173,7 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface, private void update_time() { time_label.label = get_relative_time(item.time.to_local()).to_string(); - time_update_timeout = Timeout.add_seconds((int) get_next_time_change(), () => { + time_update_timeout = Timeout.add_seconds((int) get_next_time_change(item.time), () => { if (this.main_grid.parent == null) return false; update_time(); return false; @@ -206,16 +206,15 @@ public class ConversationItemSkeleton : Plugins.ConversationItemWidgetInterface, } } - private int get_next_time_change() { + public static int get_next_time_change(DateTime datetime) { DateTime now = new DateTime.now_local(); - DateTime item_time = item.time; - TimeSpan timespan = now.difference(item_time); + TimeSpan timespan = now.difference(datetime); if (timespan < 10 * TimeSpan.MINUTE) { - if (now.get_second() < item_time.get_second()) { - return item_time.get_second() - now.get_second(); + if (now.get_second() < datetime.get_second()) { + return datetime.get_second() - now.get_second(); } else { - return 60 - (now.get_second() - item_time.get_second()); + return 60 - (now.get_second() - datetime.get_second()); } } else { return (23 - now.get_hour()) * 3600 + (59 - now.get_minute()) * 60 + (59 - now.get_second()); diff --git a/main/src/ui/conversation_content_view/quote_widget.vala b/main/src/ui/conversation_content_view/quote_widget.vala index cfe2f153..6dbf459c 100644 --- a/main/src/ui/conversation_content_view/quote_widget.vala +++ b/main/src/ui/conversation_content_view/quote_widget.vala @@ -13,6 +13,7 @@ namespace Dino.Ui.Quote { public string display_name { get; set; } public string message { get; set; } + public string display_time { get; set; } public DateTime message_time { get; set; } public StreamInteractor stream_interactor { get; set; } @@ -21,6 +22,8 @@ namespace Dino.Ui.Quote { public bool can_abort { get; set; default=false; } + private uint display_time_timeout; + public Model.from_content_item(ContentItem content_item, Conversation conversation, StreamInteractor stream_interactor) { this.display_name = Util.get_participant_display_name(stream_interactor, conversation, content_item.jid, true); if (content_item.type_ == MessageItem.TYPE) { @@ -31,11 +34,29 @@ namespace Dino.Ui.Quote { this.message = _("File") + ": " + file_transfer.file_name; } this.message_time = content_item.time; + update_display_time(); this.stream_interactor = stream_interactor; this.conversation = conversation; this.author_jid = content_item.jid; } + + private void update_display_time() { + this.display_time = ConversationItemSkeleton.get_relative_time(message_time.to_local()); + display_time_timeout = Timeout.add_seconds((int) ConversationItemSkeleton.get_next_time_change(message_time), () => { + if (display_time_timeout != 0) update_display_time(); + return false; + }); + } + + public override void dispose() { + base.dispose(); + + if (display_time_timeout != 0) { + Source.remove(display_time_timeout); + display_time_timeout = 0; + } + } } public Widget get_widget(Model model) { @@ -48,11 +69,7 @@ namespace Dino.Ui.Quote { avatar.set_conversation_participant(model.stream_interactor, model.conversation, model.author_jid); model.bind_property("display-name", author, "label", BindingFlags.SYNC_CREATE); - model.bind_property("message-time", time, "label", BindingFlags.SYNC_CREATE, (_, from_value, ref to_value) => { - DateTime message_time = (DateTime) from_value; - to_value = ConversationItemSkeleton.get_relative_time(message_time); - return true; - }); + model.bind_property("display-time", time, "label", BindingFlags.SYNC_CREATE); model.bind_property("message", message, "label", BindingFlags.SYNC_CREATE); model.bind_property("can-abort", abort_button, "visible", BindingFlags.SYNC_CREATE); |