mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-02-10 00:43:09 +00:00
Update content to use byte slice (#45)
This commit is contained in:
parent
2a74066cd4
commit
97a1cf150a
@ -79,11 +79,8 @@ pub fn create_new_private_convo(
|
||||
};
|
||||
};
|
||||
|
||||
// Convert input content to String
|
||||
let msg = String::from_utf8_lossy(&content).into_owned();
|
||||
|
||||
// Create conversation
|
||||
let (convo_handle, payloads) = ctx.0.create_private_convo(&intro, msg);
|
||||
let (convo_handle, payloads) = ctx.0.create_private_convo(&intro, &content);
|
||||
|
||||
// Convert payloads to FFI-compatible vector
|
||||
let ffi_payloads: Vec<Payload> = payloads
|
||||
|
||||
@ -42,7 +42,7 @@ impl Context {
|
||||
pub fn create_private_convo(
|
||||
&mut self,
|
||||
remote_bundle: &Introduction,
|
||||
content: String,
|
||||
content: &[u8],
|
||||
) -> (ConvoHandle, Vec<AddressedEnvelope>) {
|
||||
let (convo, payloads) = self
|
||||
.inbox
|
||||
|
||||
@ -68,7 +68,7 @@ impl Inbox {
|
||||
pub fn invite_to_private_convo(
|
||||
&self,
|
||||
remote_bundle: &Introduction,
|
||||
initial_message: String,
|
||||
initial_message: &[u8],
|
||||
) -> Result<(PrivateV1Convo, Vec<AddressedEncryptedPayload>), ChatError> {
|
||||
let mut rng = OsRng;
|
||||
|
||||
@ -85,7 +85,7 @@ impl Inbox {
|
||||
|
||||
let mut convo = PrivateV1Convo::new_initiator(seed_key, remote_bundle.ephemeral_key);
|
||||
|
||||
let mut payloads = convo.send_message(initial_message.as_bytes())?;
|
||||
let mut payloads = convo.send_message(initial_message)?;
|
||||
|
||||
// Wrap First payload in Invite
|
||||
if let Some(first_message) = payloads.get_mut(0) {
|
||||
@ -241,7 +241,7 @@ mod tests {
|
||||
|
||||
let bundle = raya_inbox.create_bundle();
|
||||
let (_, payloads) = saro_inbox
|
||||
.invite_to_private_convo(&bundle.into(), "hello".into())
|
||||
.invite_to_private_convo(&bundle.into(), "hello".as_bytes())
|
||||
.unwrap();
|
||||
|
||||
let payload = payloads
|
||||
|
||||
@ -1,8 +1,18 @@
|
||||
import options
|
||||
import results
|
||||
import std/strutils
|
||||
|
||||
import ../src/libchat
|
||||
|
||||
|
||||
## Convert a string to seq[byte]
|
||||
proc encode*(s: string): seq[byte] =
|
||||
if s.len == 0:
|
||||
return @[]
|
||||
result = newSeq[byte](s.len)
|
||||
copyMem(addr result[0], unsafeAddr s[0], s.len)
|
||||
|
||||
|
||||
proc pingpong() =
|
||||
|
||||
var raya = newConversationsContext()
|
||||
@ -13,7 +23,7 @@ proc pingpong() =
|
||||
let intro = raya.createIntroductionBundle().expect("[Raya] Couldn't create intro bundle")
|
||||
echo "Raya's Intro Bundle: ",intro
|
||||
|
||||
var (convo_sr, payloads) = saro.createNewPrivateConvo(intro, "Hey Raya").expect("[Saro] Couldn't create convo")
|
||||
var (convo_sr, payloads) = saro.createNewPrivateConvo(intro, encode("Hey Raya")).expect("[Saro] Couldn't create convo")
|
||||
echo "ConvoHandle:: ", convo_sr
|
||||
echo "Payload:: ", payloads
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ proc createIntroductionBundle*(ctx: LibChat): Result[string, string] =
|
||||
return ok(cast[string](buffer))
|
||||
|
||||
## Create a Private Convo
|
||||
proc createNewPrivateConvo*(ctx: LibChat, bundle: string, content: string): Result[(ConvoHandle, seq[PayloadResult]), string] =
|
||||
proc createNewPrivateConvo*(ctx: LibChat, bundle: string, content: seq[byte]): Result[(ConvoHandle, seq[PayloadResult]), string] =
|
||||
if ctx.handle == nil:
|
||||
return err("Context handle is nil")
|
||||
|
||||
@ -83,7 +83,7 @@ proc createNewPrivateConvo*(ctx: LibChat, bundle: string, content: string): Resu
|
||||
return ok((convoId, payloads))
|
||||
|
||||
## Send content to an existing conversation
|
||||
proc sendContent*(ctx: LibChat, convoHandle: ConvoHandle, content: string): Result[seq[PayloadResult], string] =
|
||||
proc sendContent*(ctx: LibChat, convoHandle: ConvoHandle, content: seq[byte]): Result[seq[PayloadResult], string] =
|
||||
if ctx.handle == nil:
|
||||
return err("Context handle is nil")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user