From e30761f90df1f782810af67ad64b9a72e5eed742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hermann=20H=C3=B6hne?= Date: Wed, 24 Jul 2024 00:23:53 +0200 Subject: [PATCH] Consistently have timestamp unit in seconds in purple, not milliseconds sometimes. --- src/c/presage.h | 2 +- src/c/text.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/c/presage.h b/src/c/presage.h index fdf4c66..40663a2 100755 --- a/src/c/presage.h +++ b/src/c/presage.h @@ -73,7 +73,7 @@ void presage_request_qrcode(PurpleConnection *connection); void presage_handle_uuid(PurpleConnection *connection, const char *uuid); // text messages -void presage_handle_text(PurpleConnection *connection, const char *who, const char *name, const char *group, const char *title, PurpleMessageFlags sent, uint64_t timestamp, const char *body); +void presage_handle_text(PurpleConnection *connection, const char *who, const char *name, const char *group, const char *title, PurpleMessageFlags sent, uint64_t timestamp_ms, const char *body); int presage_send_im(PurpleConnection *connection, const char *who, const char *message, PurpleMessageFlags flags); int presage_send_chat(PurpleConnection *connection, int id, const gchar *message, PurpleMessageFlags flags); diff --git a/src/c/text.c b/src/c/text.c index f11abca..31b9260 100755 --- a/src/c/text.c +++ b/src/c/text.c @@ -2,9 +2,12 @@ #include "presage.h" -void presage_handle_text(PurpleConnection *connection, const char *who, const char *name, const char *group, const char *title, PurpleMessageFlags flags, uint64_t timestamp, const char *body) { +void presage_handle_text(PurpleConnection *connection, const char *who, const char *name, const char *group, const char *title, PurpleMessageFlags flags, uint64_t timestamp_ms, const char *body) { PurpleAccount *account = purple_connection_get_account(connection); + // in Signal, timestamps are milliseconds, but purple wants seconds + time_t timestamp_seconds = timestamp_ms/1000; + // Signal is a plain-text protocol, but Pidgin expects HTML // NOTE: This turns newlines into br-tags which may mess up textual representation of QR-codes gchar *text = purple_markup_escape_text(body, -1); @@ -19,9 +22,9 @@ void presage_handle_text(PurpleConnection *connection, const char *who, const ch if (conv == NULL) { conv = purple_im_conversation_new(account, who); // MEMCHECK: caller takes ownership } - purple_conv_im_write(purple_conversation_get_im_data(conv), who, text, flags, timestamp/1000); + purple_conv_im_write(purple_conversation_get_im_data(conv), who, text, flags, timestamp_seconds); } else { - purple_serv_got_im(connection, who, text, flags, timestamp/1000); + purple_serv_got_im(connection, who, text, flags, timestamp_seconds); } } else { // group message @@ -39,7 +42,7 @@ void presage_handle_text(PurpleConnection *connection, const char *who, const ch // the backend does not include the username for sync messages who = purple_account_get_username(account); } - purple_serv_got_chat_in(connection, g_str_hash(group), who, flags, text, timestamp); + purple_serv_got_chat_in(connection, g_str_hash(group), who, flags, text, timestamp_seconds); } g_free(text);