Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions whatsrust/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ffi::CString;

use super::*;

pub(crate) fn reaction_to_ffi(
Expand Down
19 changes: 1 addition & 18 deletions whatsrust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//! Implementation and focused tests live in owning modules.
//! Explicit reexports keep the public API boundary auditable.

use std::ffi::CString;

#[macro_use]
mod callbacks;
mod abi;
Expand Down Expand Up @@ -37,7 +35,7 @@ pub use models::{
FileId, FileKind, ForwardingInfo, GroupInfo, GroupInfoError, GroupParticipant, JID,
LogoutError, Mention, Message, MessageActionFailed, MessageActionKind, MessageContent,
MessageId, MessageInfo, PresenceUpdate, ProfilePicture, ProfilePictureAvailability,
ProfilePictureError,
ProfilePictureError, VIEW_ONCE_UNAVAILABLE_DESCRIPTION,
};
pub use presence::{SubscribePresenceResult, drain_raw_presence_diagnostics, subscribe_presence};
pub use queries::{
Expand All @@ -54,18 +52,3 @@ pub use caches::{
remove_forward_source, store_forward_source, store_message_mention_ranges,
store_message_push_name,
};

pub const VIEW_ONCE_UNAVAILABLE_DESCRIPTION: &str =
"View-once media is unavailable here. View it on your phone.";

impl CallbackTranslator<CJID> for JID {
unsafe fn to_rust(from: CJID) -> Self {
(&from).into()
}
}

impl CallbackTranslator<i64> for i64 {
unsafe fn to_rust(value: i64) -> Self {
value
}
}
2 changes: 1 addition & 1 deletion whatsrust/src/lifecycle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::{CStr, c_char};
use std::ffi::{CStr, CString, c_char};

use super::*;

Expand Down
5 changes: 4 additions & 1 deletion whatsrust/src/media.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{ffi::CStr, path::Path};
use std::{
ffi::{CStr, CString},
path::Path,
};

use super::*;

Expand Down
10 changes: 10 additions & 0 deletions whatsrust/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use strum::{EnumIter, FromRepr};

use crate::abi::{CContact, CJID, LogoutStatus, ReceiptKind};
use crate::callbacks::CallbackTranslator;

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct JID(pub Arc<str>);
Expand Down Expand Up @@ -34,6 +35,15 @@ impl From<&JID> for CJID {
}
}

impl CallbackTranslator<CJID> for JID {
unsafe fn to_rust(from: CJID) -> Self {
(&from).into()
}
}

pub const VIEW_ONCE_UNAVAILABLE_DESCRIPTION: &str =
"View-once media is unavailable here. View it on your phone.";

pub type MessageId = Arc<str>;

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion whatsrust/src/presence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
ffi::{CStr, c_char},
ffi::{CStr, CString, c_char},
sync::atomic::{AtomicUsize, Ordering},
};

Expand Down
6 changes: 6 additions & 0 deletions whatsrust/src/registrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ impl CallbackTranslator<u8> for u8 {
}
}

impl CallbackTranslator<i64> for i64 {
unsafe fn to_rust(value: i64) -> Self {
value
}
}

pub fn set_presence_handler<F>(mut callback: F)
where
F: FnMut(PresenceUpdate) + 'static,
Expand Down
Loading