Skip to content

Commit

Permalink
Consistently have timestamp unit in seconds in purple, not millisecon…
Browse files Browse the repository at this point in the history
…ds sometimes.
  • Loading branch information
hoehermann committed Jul 24, 2024
1 parent 856f62a commit e30761f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/c/presage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 7 additions & 4 deletions src/c/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit e30761f

Please sign in to comment.