commit 4ce17dd115bb736b209d3e01159c44b3cefbe65b
parent c4545a066e22341c806c29c957341bcb0a096a75
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 14 Mar 2024 00:49:33 +0100
Adjust chat time label contents
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c
@@ -141,8 +141,31 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
handle->timestamp = last_message->timestamp;
+ const struct GNUNET_TIME_Timestamp timestamp = GNUNET_TIME_absolute_to_timestamp(
+ handle->timestamp
+ );
+
+ GDateTime *dt_now = g_date_time_new_now_local();
+ GDateTime *dt_message = g_date_time_new_from_unix_local(
+ (gint64) (timestamp.abs_time.abs_value_us / 1000000)
+ );
+
+ GTimeSpan span = g_date_time_difference(dt_now, dt_message);
+ gchar *time = NULL;
+
+ if (span > 7 * G_TIME_SPAN_DAY)
+ time = g_date_time_format(dt_message, "%F");
+ else if (span > 2 * G_TIME_SPAN_DAY)
+ time = g_date_time_format(dt_message, "%A");
+ else if (span > G_TIME_SPAN_DAY)
+ time = g_date_time_format(dt_message, _("Yesterday"));
+ else
+ time = g_date_time_format(dt_message, "%R");
+
+ g_date_time_unref(dt_now);
+ g_date_time_unref(dt_message);
+
const gchar *text = gtk_label_get_text(last_message->text_label);
- const gchar *time = gtk_label_get_text(last_message->timestamp_label);
if (group)
{
@@ -162,7 +185,11 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
else
gtk_label_set_text(handle->text_label, text);
- gtk_label_set_text(handle->timestamp_label, time);
+ if (time)
+ {
+ gtk_label_set_text(handle->timestamp_label, time);
+ g_free(time);
+ }
gtk_widget_set_visible(
GTK_WIDGET(handle->read_receipt_image),
diff --git a/src/ui/settings.c b/src/ui/settings.c
@@ -384,9 +384,8 @@ ui_settings_dialog_init(MESSENGER_Application *app,
{
g_string_printf(
blocked_text,
- "%u blocked contact%s",
- blocked_count,
- blocked_count == 1? "" : "s"
+ _("%u blocked contacts"),
+ blocked_count
);
gtk_label_set_text(
diff --git a/src/util.h b/src/util.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2024 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -25,8 +25,15 @@
#ifndef UTIL_H_
#define UTIL_H_
+#include <glib-2.0/glib.h>
+
#define UNUSED __attribute__((unused))
-#define _(String) ((const char*) String)
+#define _(String) ( \
+ (const gchar*) g_dgettext( \
+ MESSENGER_APPLICATION_ID, \
+ (const gchar*) String \
+ ) \
+)
#endif /* UTIL_H_ */