use std::sync::Arc;
use uuid::Uuid;
use wacore_binary::jid::Jid;
use whatsapp_rust::client::Client;
use super::WhatsAppState;
pub(crate) const COMPLETION_EMOJI: &str = "✅";
pub(crate) fn build_self_reaction(
chat_jid: &str,
message_id: &str,
emoji: &str,
timestamp_ms: i64,
) -> waproto::whatsapp::Message {
let key = waproto::whatsapp::MessageKey {
remote_jid: Some(chat_jid.to_string()),
from_me: Some(true),
id: Some(message_id.to_string()),
..Default::default()
};
let reaction = waproto::whatsapp::message::ReactionMessage {
key: key.into(),
text: if emoji.is_empty() {
None
} else {
Some(emoji.to_string())
},
sender_timestamp_ms: Some(timestamp_ms),
..Default::default()
};
waproto::whatsapp::Message {
reaction_message: reaction.into(),
..Default::default()
}
}
pub(crate) async fn acknowledge_completion(
client: &Arc<Client>,
jid: &Jid,
state: &Arc<WhatsAppState>,
session_id: Uuid,
emoji: &str,
) {
let Some(entry) = state.editable_outbound(session_id).await else {
tracing::debug!(
target: "whatsapp",
session = %session_id,
"no tracked message to acknowledge; skipping completion reaction"
);
return;
};
let message = build_self_reaction(
&jid.to_string(),
&entry.message_id,
emoji,
chrono::Utc::now().timestamp_millis(),
);
if let Err(e) = client.send_message(jid.clone(), message).await {
tracing::warn!(
target: "whatsapp",
error = %e,
message_id = %entry.message_id,
"completion reaction failed; the answer itself was delivered"
);
}
}