Skip to content

Commit

Permalink
If message that has been reacted to cannot be resolved, at least show…
Browse files Browse the repository at this point in the history
… its timestamp.
  • Loading branch information
hoehermann committed Jul 28, 2024
1 parent 1d8bbd4 commit 12a049a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/c/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ void free_message(Presage * message) {
* Handle a message according to its content.
*/
static void handle_message(Presage * message) {
//purple_debug_info(PLUGIN_NAME, "handle_message({.account=%p, .qrcode=„%s“, .uuid=„%s“, .who=„%s“, .name=„%s“, .group=„%s“, .title=„%s“, .body=„%s“})\n", message->account, message->qrcode, message->uuid, message->who, message->name, message->group, message->title, message->body);

if (message->debug >= 0) {
// log messages do not need an active connection
purple_debug(message->debug, PLUGIN_NAME, "%s", message->body);
Expand Down
1 change: 1 addition & 0 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ presage = { git = "https://github.com/whisperfish/presage", rev = "e2392c42a0392
presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "e2392c42a0392397b9db782607fdd7ab2ea91b5f" }

hex = "*"
chrono = "*"
mime_guess = "2.0"
#stdint = "0.2"
futures = "0.3"
Expand Down
14 changes: 9 additions & 5 deletions src/rust/src/receive_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,30 @@ fn print_message<C: presage::store::Store>(
..
} => {
let Ok(Some(message)) = manager.store().message(thread, *timestamp) else {
crate::core::purple_error(account, 16, format!("no message in {thread} sent at {timestamp}"));
return None;
// Original message could not be found. As a best effort, give some reference by displaying the timestamp.
let sent_at = chrono::prelude::DateTime::<chrono::Local>::from(std::time::UNIX_EPOCH+std::time::Duration::from_millis(*timestamp)).format("%Y-%m-%d %H:%M:%S");
return Some(format!("Reacted with {emoji} to message from {sent_at}."));
};

let presage::libsignal_service::content::ContentBody::DataMessage(presage::libsignal_service::content::DataMessage {
body: Some(body), ..
}) = message.body
else {
crate::core::purple_debug(account, 2, String::from("message reacted to has no body\n"));
return None;
// Synced messages are not resolved here and reactions to them end up in this arm.
// TODO: try to access the SynchronizeMessage/SyncMessage
let sent_at = chrono::prelude::DateTime::<chrono::Local>::from(std::time::UNIX_EPOCH+std::time::Duration::from_millis(*timestamp)).format("%Y-%m-%d %H:%M:%S");
return Some(format!("Reacted with {emoji} to message from {sent_at}."));
};
let firstline = body.split("\n").next().unwrap_or("<message body missing>");
// TODO: add ellipsis if body contains more than one line
Some(format!("Reacted with {emoji} to message „{firstline}“."))
}
// Plan text message
// Plain text message
// TODO: resolve mentions
presage::libsignal_service::content::DataMessage {
body: Some(body), ..
} => Some(body.to_string()),
// Default (catch all other cases)
c => {
crate::core::purple_debug(account, 2, format!("DataMessage without body {c:?}\n"));
// NOTE: This happens when receiving a file, but not providing a text
Expand Down

0 comments on commit 12a049a

Please sign in to comment.