diff --git a/Cargo.lock b/Cargo.lock index f9d99a1..4f62a0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "addr2line" @@ -2020,9 +2020,9 @@ checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" [[package]] name = "hickory-proto" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07698b8420e2f0d6447a436ba999ec85d8fbf2a398bbd737b82cac4a2e96e512" +checksum = "447afdcdb8afb9d0a852af6dc65d9b285ce720ed7a59e42a8bf2e931c67bc1b5" dependencies = [ "async-trait", "cfg-if", @@ -2031,7 +2031,7 @@ dependencies = [ "futures-channel", "futures-io", "futures-util", - "idna 0.4.0", + "idna", "ipnet", "once_cell", "rand 0.8.5", @@ -2045,9 +2045,9 @@ dependencies = [ [[package]] name = "hickory-resolver" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28757f23aa75c98f254cf0405e6d8c25b831b32921b050a66692427679b1f243" +checksum = "0a2e2aba9c389ce5267d31cf1e4dace82390ae276b0b364ea55630b1fa1b44b4" dependencies = [ "cfg-if", "futures-util", @@ -2347,16 +2347,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "idna" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" -dependencies = [ - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "1.0.3" @@ -3708,9 +3698,9 @@ dependencies = [ [[package]] name = "netlink-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416060d346fbaf1f23f9512963e3e878f1a78e707cb699ba9215761754244307" +checksum = "16c903aa70590cb93691bf97a767c8d1d6122d2cc9070433deb3bbf36ce8bd23" dependencies = [ "bytes", "futures", @@ -5829,12 +5819,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - [[package]] name = "unicode-ident" version = "1.0.14" @@ -5907,7 +5891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", - "idna 1.0.3", + "idna", "percent-encoding", ] diff --git a/src/warp/raygun.rs b/src/warp/raygun.rs index a2f56f8..1f5919c 100644 --- a/src/warp/raygun.rs +++ b/src/warp/raygun.rs @@ -7,8 +7,8 @@ use std::str::FromStr; use tsify_next::Tsify; use uuid::Uuid; use warp::raygun::{ - GroupPermissionOpt, RayGunAttachment, RayGunConversationInformation, RayGunEvents, - RayGunGroupConversation, RayGunStream, + community::RayGunCommunity, GroupPermissionOpt, RayGunAttachment, + RayGunConversationInformation, RayGunEvents, RayGunGroupConversation, RayGunStream, }; use warp::warp::dummy::Dummy; use warp::warp::Warp; @@ -546,6 +546,780 @@ impl RayGunBox { } } +/// impl RayGunCommunity trait +#[wasm_bindgen] +impl RayGunBox { + pub async fn get_community_stream( + &mut self, + community_id: String, + ) -> Result { + self.inner + .get_community_stream(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + .map(|ok| { + AsyncIterator::new(Box::pin( + ok.map(|s| serde_wasm_bindgen::to_value(&s).unwrap()), + )) + }) + } + + pub async fn create_community(&mut self, name: String) -> Result { + self.inner + .create_community(&name) + .await + .map_err(|e| e.into()) + .map(|inner| Community { inner }) + } + pub async fn delete_community(&mut self, community_id: String) -> Result<(), JsError> { + self.inner + .delete_community(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + } + pub async fn get_community(&self, community_id: String) -> Result { + self.inner + .get_community(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + .map(|inner| Community { inner }) + } + + pub async fn list_communities_joined(&self) -> Result, JsError> { + self.inner + .list_communities_joined() + .await + .map_err(|e| e.into()) + .map(|ids| ids.iter().map(|id| id.to_string()).collect()) + } + pub async fn list_communities_invited_to(&self) -> Result, JsError> { + self.inner + .list_communities_invited_to() + .await + .map_err(|e| e.into()) + .map(|invites| { + invites + .into_iter() + .map(|(id, inv)| CommunityInvitation { + community: id.to_string(), + invite: inv.into(), + }) + .collect() + }) + } + pub async fn leave_community(&mut self, community_id: String) -> Result<(), JsError> { + self.inner + .leave_community(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + } + + pub async fn get_community_icon( + &self, + community_id: String, + ) -> Result { + self.inner + .get_community_icon(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + .map(|img| ConversationImage(img)) + } + pub async fn get_community_banner( + &self, + community_id: String, + ) -> Result { + self.inner + .get_community_banner(Uuid::from_str(&community_id).unwrap()) + .await + .map_err(|e| e.into()) + .map(|img| ConversationImage(img)) + } + pub async fn edit_community_icon( + &mut self, + community_id: String, + file: AttachmentFile, + ) -> Result<(), JsError> { + self.inner + .edit_community_icon(Uuid::from_str(&community_id).unwrap(), file.into()) + .await + .map_err(|e| e.into()) + } + pub async fn edit_community_banner( + &mut self, + community_id: String, + file: AttachmentFile, + ) -> Result<(), JsError> { + self.inner + .edit_community_banner(Uuid::from_str(&community_id).unwrap(), file.into()) + .await + .map_err(|e| e.into()) + } + + pub async fn create_community_invite( + &mut self, + community_id: String, + target_user: Option, + expiry: Option, + ) -> Result { + self.inner + .create_community_invite( + Uuid::from_str(&community_id).unwrap(), + target_user.map(|did| DID::from_str(&did).unwrap()), + expiry.map(|d| d.into()), + ) + .await + .map_err(|e| e.into()) + .map(|inv| inv.into()) + } + pub async fn delete_community_invite( + &mut self, + community_id: String, + invite_id: String, + ) -> Result<(), JsError> { + self.inner + .delete_community_invite( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&invite_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn get_community_invite( + &self, + community_id: String, + invite_id: String, + ) -> Result { + self.inner + .get_community_invite( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&invite_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|inv| inv.into()) + } + pub async fn accept_community_invite( + &mut self, + community_id: String, + invite_id: String, + ) -> Result<(), JsError> { + self.inner + .accept_community_invite( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&invite_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn edit_community_invite( + &mut self, + community_id: String, + invite_id: String, + invite: CommunityInvite, + ) -> Result<(), JsError> { + self.inner + .edit_community_invite( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&invite_id).unwrap(), + invite.into(), + ) + .await + .map_err(|e| e.into()) + } + + pub async fn create_community_role( + &mut self, + community_id: String, + name: String, + ) -> Result { + self.inner + .create_community_role(Uuid::from_str(&community_id).unwrap(), &name) + .await + .map_err(|e| e.into()) + .map(|role| role.into()) + } + pub async fn delete_community_role( + &mut self, + community_id: String, + role_id: String, + ) -> Result<(), JsError> { + self.inner + .delete_community_role( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn get_community_role( + &mut self, + community_id: String, + role_id: String, + ) -> Result { + self.inner + .get_community_role( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|role| role.into()) + } + pub async fn edit_community_role_name( + &mut self, + community_id: String, + role_id: String, + new_name: String, + ) -> Result<(), JsError> { + self.inner + .edit_community_role_name( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&role_id).unwrap(), + new_name, + ) + .await + .map_err(|e| e.into()) + } + pub async fn grant_community_role( + &mut self, + community_id: String, + role_id: String, + user: String, + ) -> Result<(), JsError> { + self.inner + .grant_community_role( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&role_id).unwrap(), + DID::from_str(&user).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn revoke_community_role( + &mut self, + community_id: String, + role_id: String, + user: String, + ) -> Result<(), JsError> { + self.inner + .revoke_community_role( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&role_id).unwrap(), + DID::from_str(&user).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + + pub async fn create_community_channel( + &mut self, + community_id: String, + channel_name: String, + channel_type: CommunityChannelType, + ) -> Result { + self.inner + .create_community_channel( + Uuid::from_str(&community_id).unwrap(), + &channel_name, + channel_type.into(), + ) + .await + .map_err(|e| e.into()) + .map(|inner| CommunityChannel { inner }) + } + pub async fn delete_community_channel( + &mut self, + community_id: String, + channel_id: String, + ) -> Result<(), JsError> { + self.inner + .delete_community_channel( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn get_community_channel( + &self, + community_id: String, + channel_id: String, + ) -> Result { + self.inner + .get_community_channel( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|inner| CommunityChannel { inner }) + } + + pub async fn edit_community_name( + &mut self, + community_id: String, + name: String, + ) -> Result<(), JsError> { + self.inner + .edit_community_name(Uuid::from_str(&community_id).unwrap(), &name) + .await + .map_err(|e| e.into()) + } + pub async fn edit_community_description( + &mut self, + community_id: String, + description: Option, + ) -> Result<(), JsError> { + self.inner + .edit_community_description(Uuid::from_str(&community_id).unwrap(), description) + .await + .map_err(|e| e.into()) + } + pub async fn grant_community_permission( + &mut self, + community_id: String, + permission: CommunityPermission, + role_id: String, + ) -> Result<(), JsError> { + self.inner + .grant_community_permission( + Uuid::from_str(&community_id).unwrap(), + permission.into(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn revoke_community_permission( + &mut self, + community_id: String, + permission: CommunityPermission, + role_id: String, + ) -> Result<(), JsError> { + self.inner + .revoke_community_permission( + Uuid::from_str(&community_id).unwrap(), + permission.into(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn grant_community_permission_for_all( + &mut self, + community_id: String, + permission: CommunityPermission, + ) -> Result<(), JsError> { + self.inner + .grant_community_permission_for_all( + Uuid::from_str(&community_id).unwrap(), + permission.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn revoke_community_permission_for_all( + &mut self, + community_id: String, + permission: CommunityPermission, + ) -> Result<(), JsError> { + self.inner + .revoke_community_permission_for_all( + Uuid::from_str(&community_id).unwrap(), + permission.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn remove_community_member( + &mut self, + community_id: String, + member: String, + ) -> Result<(), JsError> { + self.inner + .remove_community_member( + Uuid::from_str(&community_id).unwrap(), + DID::from_str(&member).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + + pub async fn edit_community_channel_name( + &mut self, + community_id: String, + channel_id: String, + name: String, + ) -> Result<(), JsError> { + self.inner + .edit_community_channel_name( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + &name, + ) + .await + .map_err(|e| e.into()) + } + pub async fn edit_community_channel_description( + &mut self, + community_id: String, + channel_id: String, + description: Option, + ) -> Result<(), JsError> { + self.inner + .edit_community_channel_description( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + description, + ) + .await + .map_err(|e| e.into()) + } + pub async fn grant_community_channel_permission( + &mut self, + community_id: String, + channel_id: String, + permission: CommunityChannelPermission, + role_id: String, + ) -> Result<(), JsError> { + self.inner + .grant_community_channel_permission( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + permission.into(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn revoke_community_channel_permission( + &mut self, + community_id: String, + channel_id: String, + permission: CommunityChannelPermission, + role_id: String, + ) -> Result<(), JsError> { + self.inner + .revoke_community_channel_permission( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + permission.into(), + Uuid::from_str(&role_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn grant_community_channel_permission_for_all( + &mut self, + community_id: String, + channel_id: String, + permission: CommunityChannelPermission, + ) -> Result<(), JsError> { + self.inner + .grant_community_channel_permission_for_all( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + permission.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn revoke_community_channel_permission_for_all( + &mut self, + community_id: String, + channel_id: String, + permission: CommunityChannelPermission, + ) -> Result<(), JsError> { + self.inner + .revoke_community_channel_permission_for_all( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + permission.into(), + ) + .await + .map_err(|e| e.into()) + } + + pub async fn get_community_channel_message( + &self, + community_id: String, + channel_id: String, + message_id: String, + ) -> Result { + self.inner + .get_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|inner| Message { inner }) + } + pub async fn get_community_channel_messages( + &self, + community_id: String, + channel_id: String, + options: MessageOptions, + ) -> Result { + self.inner + .get_community_channel_messages( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + options.inner, + ) + .await + .map_err(|e| e.into()) + .map(|msgs| Messages::new(msgs)) + } + pub async fn get_community_channel_message_count( + &self, + community_id: String, + channel_id: String, + ) -> Result { + self.inner + .get_community_channel_message_count( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn get_community_channel_message_reference( + &self, + community_id: String, + channel_id: String, + message_id: String, + ) -> Result { + self.inner + .get_community_channel_message_reference( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|inner| MessageReference { inner }) + } + pub async fn get_community_channel_message_references( + &self, + community_id: String, + channel_id: String, + options: MessageOptions, + ) -> Result { + self.inner + .get_community_channel_message_references( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + options.inner, + ) + .await + .map_err(|e| e.into()) + .map(|s| AsyncIterator::new(Box::pin(s.map(|t| MessageReference::new(t).into())))) + } + pub async fn community_channel_message_status( + &self, + community_id: String, + channel_id: String, + message_id: String, + ) -> Result { + self.inner + .community_channel_message_status( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + .map(|status| status.into()) + } + pub async fn send_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message: Vec, + ) -> Result { + self.inner + .send_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + message, + ) + .await + .map_err(|e| e.into()) + .map(|id| id.to_string()) + } + pub async fn edit_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: String, + message: Vec, + ) -> Result<(), JsError> { + self.inner + .edit_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + message, + ) + .await + .map_err(|e| e.into()) + } + pub async fn reply_to_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: String, + message: Vec, + ) -> Result { + self.inner + .reply_to_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + message, + ) + .await + .map_err(|e| e.into()) + .map(|id| id.to_string()) + } + pub async fn delete_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: String, + ) -> Result<(), JsError> { + self.inner + .delete_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn pin_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: String, + state: PinState, + ) -> Result<(), JsError> { + self.inner + .pin_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + state.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn react_to_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: String, + state: ReactionState, + emoji: String, + ) -> Result<(), JsError> { + self.inner + .react_to_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + state.into(), + emoji, + ) + .await + .map_err(|e| e.into()) + } + pub async fn send_community_channel_messsage_event( + &mut self, + community_id: String, + channel_id: String, + event: MessageEvent, + ) -> Result<(), JsError> { + self.inner + .send_community_channel_messsage_event( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + event.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn cancel_community_channel_messsage_event( + &mut self, + community_id: String, + channel_id: String, + event: MessageEvent, + ) -> Result<(), JsError> { + self.inner + .cancel_community_channel_messsage_event( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + event.into(), + ) + .await + .map_err(|e| e.into()) + } + pub async fn attach_to_community_channel_message( + &mut self, + community_id: String, + channel_id: String, + message_id: Option, + files: Vec, + message: Vec, + ) -> Result { + self.inner + .attach_to_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + message_id.map(|id| Uuid::from_str(&id).unwrap()), + files.into_iter().map(|f| f.into()).collect(), + message, + ) + .await + .map_err(|e| e.into()) + .map(|(id, ok)| AttachmentResult { + message_id: id.to_string(), + stream: AsyncIterator::new(Box::pin( + ok.map(|s| serde_wasm_bindgen::to_value(&AttachmentKind::from(s)).unwrap()), + )), + }) + } + /// Stream a file that been attached to a message + /// Note: Must use the filename associated when downloading + pub async fn download_stream_from_community_channel_message( + &self, + community_id: String, + channel_id: String, + message_id: String, + file: String, + ) -> Result { + self.inner + .download_stream_from_community_channel_message( + Uuid::from_str(&community_id).unwrap(), + Uuid::from_str(&channel_id).unwrap(), + Uuid::from_str(&message_id).unwrap(), + &file, + ) + .await + .map_err(|e| e.into()) + .map(|ok| { + AsyncIterator::new(Box::pin(ok.map(|s| match s { + Ok(v) => serde_wasm_bindgen::to_value(&v).unwrap(), + Err(e) => { + let err: JsError = e.into(); + err.into() + } + }))) + }) + } +} + /// impl RayGunEvents trait #[wasm_bindgen] impl RayGunBox { @@ -1255,3 +2029,197 @@ impl From for raygun::MessagesType { } } } + +#[derive(Serialize, Deserialize)] +#[wasm_bindgen] +pub struct Community { + inner: raygun::community::Community, +} + +#[wasm_bindgen] +pub struct CommunityInvitation { + #[wasm_bindgen(readonly, getter_with_clone)] + pub community: String, + #[wasm_bindgen(readonly, getter_with_clone)] + pub invite: CommunityInvite, +} + +#[derive(Clone)] +#[wasm_bindgen] +pub struct CommunityInvite { + #[wasm_bindgen(getter_with_clone)] + pub id: String, + #[wasm_bindgen(getter_with_clone)] + pub target_user: Option, + #[wasm_bindgen(getter_with_clone)] + pub created: js_sys::Date, + #[wasm_bindgen(getter_with_clone)] + pub expiry: Option, +} + +impl From for CommunityInvite { + fn from(value: raygun::community::CommunityInvite) -> Self { + CommunityInvite { + id: value.id().into(), + target_user: value.target_user().map(|u| u.to_string()), + created: value.created().into(), + expiry: value.expiry().map(|d| d.into()), + } + } +} + +impl From for raygun::community::CommunityInvite { + fn from(value: CommunityInvite) -> Self { + let mut community_invite = raygun::community::CommunityInvite::default(); + community_invite.set_id(Uuid::from_str(&value.id).unwrap()); + community_invite + .set_target_user(value.target_user.map(|user| DID::from_str(&user).unwrap())); + community_invite.set_created(value.created.into()); + community_invite.set_expiry(value.expiry.map(|d| d.into())); + community_invite + } +} + +#[derive(Serialize, Deserialize)] +#[wasm_bindgen] +pub struct CommunityRole { + #[wasm_bindgen(readonly, getter_with_clone)] + pub id: String, + #[wasm_bindgen(readonly, getter_with_clone)] + pub name: String, + #[wasm_bindgen(readonly, getter_with_clone)] + pub members: Vec, +} + +impl From for CommunityRole { + fn from(value: raygun::community::CommunityRole) -> Self { + CommunityRole { + id: value.id().to_string(), + name: value.name().to_string(), + members: value.members().iter().map(|id| id.to_string()).collect(), + } + } +} +#[derive(Serialize, Deserialize)] +#[wasm_bindgen] +pub struct CommunityChannel { + inner: raygun::community::CommunityChannel, +} + +#[wasm_bindgen] +pub enum CommunityChannelType { + Standard, + VoiceEnabled, +} + +impl From for raygun::community::CommunityChannelType { + fn from(value: CommunityChannelType) -> Self { + match value { + CommunityChannelType::Standard => raygun::community::CommunityChannelType::Standard, + CommunityChannelType::VoiceEnabled => { + raygun::community::CommunityChannelType::VoiceEnabled + } + } + } +} + +#[wasm_bindgen] +pub enum CommunityPermission { + EditName, + EditDescription, + EditIcon, + EditBanner, + + CreateRoles, + EditRoles, + DeleteRoles, + + GrantRoles, + RevokeRoles, + + GrantPermissions, + RevokePermissions, + + CreateInvites, + EditInvites, + DeleteInvites, + + CreateChannels, + EditChannels, + DeleteChannels, + + RemoveMembers, + + DeleteMessages, + PinMessages, +} + +impl From for raygun::community::CommunityPermission { + fn from(value: CommunityPermission) -> Self { + match value { + CommunityPermission::EditName => raygun::community::CommunityPermission::EditName, + CommunityPermission::EditDescription => { + raygun::community::CommunityPermission::EditDescription + } + CommunityPermission::EditIcon => raygun::community::CommunityPermission::EditIcon, + CommunityPermission::EditBanner => raygun::community::CommunityPermission::EditBanner, + CommunityPermission::CreateRoles => raygun::community::CommunityPermission::CreateRoles, + CommunityPermission::EditRoles => raygun::community::CommunityPermission::EditRoles, + CommunityPermission::DeleteRoles => raygun::community::CommunityPermission::DeleteRoles, + CommunityPermission::GrantRoles => raygun::community::CommunityPermission::GrantRoles, + CommunityPermission::RevokeRoles => raygun::community::CommunityPermission::RevokeRoles, + CommunityPermission::GrantPermissions => { + raygun::community::CommunityPermission::GrantPermissions + } + CommunityPermission::RevokePermissions => { + raygun::community::CommunityPermission::RevokePermissions + } + CommunityPermission::CreateInvites => { + raygun::community::CommunityPermission::CreateInvites + } + CommunityPermission::EditInvites => raygun::community::CommunityPermission::EditInvites, + CommunityPermission::DeleteInvites => { + raygun::community::CommunityPermission::DeleteInvites + } + CommunityPermission::CreateChannels => { + raygun::community::CommunityPermission::CreateChannels + } + CommunityPermission::EditChannels => { + raygun::community::CommunityPermission::EditChannels + } + CommunityPermission::DeleteChannels => { + raygun::community::CommunityPermission::DeleteChannels + } + CommunityPermission::RemoveMembers => { + raygun::community::CommunityPermission::RemoveMembers + } + CommunityPermission::DeleteMessages => { + raygun::community::CommunityPermission::DeleteMessages + } + CommunityPermission::PinMessages => raygun::community::CommunityPermission::PinMessages, + } + } +} + +#[wasm_bindgen] +pub enum CommunityChannelPermission { + ViewChannel, + SendMessages, + SendAttachments, +} + +impl From for raygun::community::CommunityChannelPermission { + fn from(value: CommunityChannelPermission) -> Self { + match value { + CommunityChannelPermission::ViewChannel => { + raygun::community::CommunityChannelPermission::ViewChannel + } + CommunityChannelPermission::SendMessages => { + raygun::community::CommunityChannelPermission::SendMessages + } + CommunityChannelPermission::SendAttachments => { + raygun::community::CommunityChannelPermission::SendAttachments + } + } + } +}