Merge pull request 'send_message takes Message, so deps dont need serde. add send_message_raw' (#19) from sendmsg into main
Reviewed-on: #19 Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
commit
8e3ea76590
|
@ -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!"),
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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,7 +67,10 @@ 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 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;
|
||||
|
|
Loading…
Reference in New Issue