diff --git a/conversations/src/api.rs b/conversations/src/api.rs index 62d635c..84f8ff8 100644 --- a/conversations/src/api.rs +++ b/conversations/src/api.rs @@ -129,6 +129,29 @@ pub fn create_new_private_convo( } } +/// List existing conversations +/// +/// # Returns +/// Returns a struct with conversation ids of available conversations +/// The ListConvoResult must be freed. +#[ffi_export] +pub fn list_conversations(ctx: &mut ContextHandle) -> ListConvoResult { + return match ctx.0.list_conversations() { + Ok(ids) => { + let ffi_ids: Vec = + ids.into_iter().map(|id| id.to_string().into()).collect(); + ListConvoResult { + error_code: ErrorCode::None as i32, + convo_ids: ffi_ids.into(), + } + } + Err(_) => ListConvoResult { + error_code: ErrorCode::UnknownError as i32, + convo_ids: repr_c::Vec::EMPTY, + }, + }; +} + /// Sends content to an existing conversation /// /// # Returns @@ -295,3 +318,18 @@ pub struct NewConvoResult { pub fn destroy_convo_result(result: NewConvoResult) { drop(result); } + +/// Result structure for create_new_private_convo +/// error_code is 0 on success, negative on error (see ErrorCode) +#[derive_ReprC] +#[repr(C)] +pub struct ListConvoResult { + pub error_code: i32, + pub convo_ids: repr_c::Vec, +} + +/// Free the result from create_new_private_convo +#[ffi_export] +pub fn destroy_list_result(result: ListConvoResult) { + drop(result); +} diff --git a/conversations/src/context.rs b/conversations/src/context.rs index 44dbce5..2b36f68 100644 --- a/conversations/src/context.rs +++ b/conversations/src/context.rs @@ -55,6 +55,10 @@ impl Context { (convo_id, payload_bytes) } + pub fn list_conversations(&self) -> Result, ChatError> { + Ok(self.store.conversation_ids()) + } + pub fn send_content( &mut self, convo_id: ConversationId,