aboutsummaryrefslogtreecommitdiff
path: root/main/src
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-11-21 12:43:44 +0100
committerfiaxh <git@lightrise.org>2020-12-03 18:17:11 +0100
commitc0be0f5f85e9976400be5a6f7f3898366ecbbad4 (patch)
treeb5e9b5d6dea67d4bb7c2fecbae3eb2e522de36e5 /main/src
parent4f4a1036e1ca17eb105d6f35ed83cfbefd936c77 (diff)
downloaddino-c0be0f5f85e9976400be5a6f7f3898366ecbbad4.tar.gz
dino-c0be0f5f85e9976400be5a6f7f3898366ecbbad4.zip
Update date separator at midnight
fixes #868
Diffstat (limited to 'main/src')
-rw-r--r--main/src/ui/conversation_content_view/date_separator_populator.vala66
1 files changed, 54 insertions, 12 deletions
diff --git a/main/src/ui/conversation_content_view/date_separator_populator.vala b/main/src/ui/conversation_content_view/date_separator_populator.vala
index 91485f25..ff3b962d 100644
--- a/main/src/ui/conversation_content_view/date_separator_populator.vala
+++ b/main/src/ui/conversation_content_view/date_separator_populator.vala
@@ -62,30 +62,58 @@ public class MetaDateItem : Plugins.MetaConversationItem {
}
public override Object? get_widget(Plugins.WidgetType widget_type) {
- Box box = new Box(Orientation.HORIZONTAL, 10) { width_request=300, halign=Align.CENTER, visible=true };
- box.add(new Separator(Orientation.HORIZONTAL) { valign=Align.CENTER, hexpand=true, visible=true });
- string date_str = get_relative_time(date);
- Label label = new Label(@"<span size='small'>$date_str</span>") { use_markup=true, halign=Align.CENTER, hexpand=false, visible=true };
- label.get_style_context().add_class("dim-label");
- box.add(label);
- box.add(new Separator(Orientation.HORIZONTAL) { valign=Align.CENTER, hexpand=true, visible=true });
- return box;
+ return new DateSeparatorWidget(date);
}
public override Gee.List<Plugins.MessageAction>? get_item_actions(Plugins.WidgetType type) { return null; }
+
+}
+
+public class DateSeparatorWidget : Box {
+
+ private DateTime date;
+ private Label label;
+ private uint time_update_timeout = 0;
+
+ public DateSeparatorWidget(DateTime date) {
+ Object(orientation:Orientation.HORIZONTAL, spacing:10);
+ width_request = 300;
+ halign = Align.CENTER;
+ visible = true;
+ this.date = date;
+
+ label = new Label("") { use_markup=true, halign=Align.CENTER, hexpand=false, visible=true };
+ label.get_style_context().add_class("dim-label");
+
+ this.add(new Separator(Orientation.HORIZONTAL) { valign=Align.CENTER, hexpand=true, visible=true });
+ this.add(label);
+ this.add(new Separator(Orientation.HORIZONTAL) { valign=Align.CENTER, hexpand=true, visible=true });
+
+ update_time();
+ }
+
+ private void update_time() {
+ label.label = @"<span size='small'>$(get_relative_time(date))</span>";
+ time_update_timeout = Timeout.add_seconds((int) get_next_time_change(), () => {
+ if (this.parent == null) return false;
+ update_time();
+ return false;
+ });
+ }
+
private static string get_relative_time(DateTime time) {
DateTime time_local = time.to_local();
DateTime now_local = new DateTime.now_local();
if (time_local.get_year() == now_local.get_year() &&
- time_local.get_month() == now_local.get_month() &&
- time_local.get_day_of_month() == now_local.get_day_of_month()) {
+ time_local.get_month() == now_local.get_month() &&
+ time_local.get_day_of_month() == now_local.get_day_of_month()) {
return _("Today");
}
DateTime now_local_minus = now_local.add_days(-1);
if (time_local.get_year() == now_local_minus.get_year() &&
- time_local.get_month() == now_local_minus.get_month() &&
- time_local.get_day_of_month() == now_local_minus.get_day_of_month()) {
+ time_local.get_month() == now_local_minus.get_month() &&
+ time_local.get_day_of_month() == now_local_minus.get_day_of_month()) {
return _("Yesterday");
}
if (time_local.get_year() != now_local.get_year()) {
@@ -98,6 +126,20 @@ public class MetaDateItem : Plugins.MetaConversationItem {
return time_local.format(_("%b %d"));
}
}
+
+ private int get_next_time_change() {
+ DateTime now = new DateTime.now_local();
+ return (23 - now.get_hour()) * 3600 + (59 - now.get_minute()) * 60 + (59 - now.get_second()) + 1;
+ }
+
+ public override void dispose() {
+ base.dispose();
+
+ if (time_update_timeout != 0) {
+ Source.remove(time_update_timeout);
+ time_update_timeout = 0;
+ }
+ }
}
}