Skip to content

Commit

Permalink
Adjust chat time label contents
Browse files Browse the repository at this point in the history
Signed-off-by: Jacki <[email protected]>
  • Loading branch information
TheJackiMonster committed Mar 13, 2024
1 parent c4545a0 commit 4ce17dd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
31 changes: 29 additions & 2 deletions src/ui/chat_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions src/ui/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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_ */

0 comments on commit 4ce17dd

Please sign in to comment.