send_message takes Message, so deps dont need serde. add send_message_raw

This commit is contained in:
Dan Ballard 2023-04-25 07:35:39 -06:00
parent fff85a7a0e
commit 60d6074758
3 changed files with 14 additions and 6 deletions

View File

@ -41,9 +41,7 @@ fn main() {
}
Event::NewMessageFromPeer { profile_id, conversation_id, contact_id: contact, nick, timestamp_received, message, notification, picture } => {
let response = Message { o: message.o.into(), d: message.d };
let response_json =
serde_json::to_string(&response).expect("Error parsing json response");
cwtch.send_message( &profile_id, conversation_id, &response_json);
cwtch.send_message( &profile_id, conversation_id, &response);
}
_ => eprintln!("unhandled event!"),
};

View File

@ -149,9 +149,15 @@ impl CwtchLib for CwtchLibGo {
fn get_messages(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message_index: i32, count: i32) -> String {
self._get_messages(String::from(profile).as_str(), conversation_id.into(), message_index, count)
}
fn send_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String {
fn send_message_raw(&self, profile: &ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String {
self._send_message(String::from(profile).as_str(), conversation_id.into(), msg)
}
fn send_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message: &Message) -> Result<String, CwtchError> {
match serde_json::to_string(&message) {
Ok(message_json) => Ok(self._send_message(&String::from(profile), conversation_id.into(), &message_json)),
Err(e) => Err(format!("Error parsing json response: {}", e.to_string()))
}
}
fn send_invitation(&self, profile: &ProfileIdentity, conversation_id: ConversationID, target_id: i32) -> String {
self._send_invitation(String::from(profile).as_str(), conversation_id.into(), target_id)
}

View File

@ -4,6 +4,7 @@
#![deny(missing_docs)]
use crate::event::{ConversationID, Event, FileKey, ProfileIdentity, ServerIdentity};
use crate::structs::Message;
mod bindings_go;
mod cwtchlib_go;
@ -66,9 +67,12 @@ pub trait CwtchLib {
fn get_messages(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message_index: i32, count: i32) -> String;
/// Send json of a structs::Message from profile to contact. Returns computed sent message (including index and hash values)
fn send_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String;
fn send_message_raw(&self, profile: &ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String;
/// Send profile's contact an invite for/to target. Returns computed sent message (including index and hash values)
/// Send structs::Message from profile to contact. Returns computed sent message (including index and hash values) or Error
fn send_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message: &Message) -> Result<String, CwtchError>;
/// Send profile's contact an invite for/to target. Returns computed sent message (including index and hash values)
fn send_invitation(&self, profile: &ProfileIdentity, conversation_id: ConversationID, target_id: i32) -> String;
/// share a file file_path with a conersation. Returns computed sent message (including index and hash values)