Skip to content

Commit c3ea67a

Browse files
authored
Add more constructors to WASM bindings (#1158)
1 parent c0793cd commit c3ea67a

7 files changed

+168
-3
lines changed

bindings_wasm/src/consent_state.rs

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ pub struct WasmConsent {
5454
pub entity: String,
5555
}
5656

57+
#[wasm_bindgen]
58+
impl WasmConsent {
59+
#[wasm_bindgen(constructor)]
60+
pub fn new(entity_type: WasmConsentEntityType, state: WasmConsentState, entity: String) -> Self {
61+
Self {
62+
entity_type,
63+
state,
64+
entity,
65+
}
66+
}
67+
}
68+
5769
impl From<WasmConsent> for StoredConsentRecord {
5870
fn from(consent: WasmConsent) -> Self {
5971
Self {

bindings_wasm/src/conversations.rs

+36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ pub struct WasmListConversationsOptions {
1515
pub limit: Option<i64>,
1616
}
1717

18+
#[wasm_bindgen]
19+
impl WasmListConversationsOptions {
20+
#[wasm_bindgen(constructor)]
21+
pub fn new(
22+
created_after_ns: Option<i64>,
23+
created_before_ns: Option<i64>,
24+
limit: Option<i64>,
25+
) -> Self {
26+
Self {
27+
created_after_ns,
28+
created_before_ns,
29+
limit,
30+
}
31+
}
32+
}
33+
1834
#[wasm_bindgen(getter_with_clone)]
1935
#[derive(Clone)]
2036
pub struct WasmCreateGroupOptions {
@@ -25,6 +41,26 @@ pub struct WasmCreateGroupOptions {
2541
pub group_pinned_frame_url: Option<String>,
2642
}
2743

44+
#[wasm_bindgen]
45+
impl WasmCreateGroupOptions {
46+
#[wasm_bindgen(constructor)]
47+
pub fn new(
48+
permissions: Option<WasmGroupPermissionsOptions>,
49+
group_name: Option<String>,
50+
group_image_url_square: Option<String>,
51+
group_description: Option<String>,
52+
group_pinned_frame_url: Option<String>,
53+
) -> Self {
54+
Self {
55+
permissions,
56+
group_name,
57+
group_image_url_square,
58+
group_description,
59+
group_pinned_frame_url,
60+
}
61+
}
62+
}
63+
2864
impl WasmCreateGroupOptions {
2965
pub fn into_group_metadata_options(self) -> GroupMetadataOptions {
3066
GroupMetadataOptions {

bindings_wasm/src/encoded_content.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ impl WasmContentTypeId {
2020
type_id: String,
2121
version_major: u32,
2222
version_minor: u32,
23-
) -> WasmContentTypeId {
24-
WasmContentTypeId {
23+
) -> Self {
24+
Self {
2525
authority_id,
2626
type_id,
2727
version_major,

bindings_wasm/src/groups.rs

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ pub struct WasmGroupMember {
5656
pub consent_state: WasmConsentState,
5757
}
5858

59+
#[wasm_bindgen]
60+
impl WasmGroupMember {
61+
#[wasm_bindgen(constructor)]
62+
pub fn new(
63+
inbox_id: String,
64+
account_addresses: Vec<String>,
65+
installation_ids: Vec<String>,
66+
permission_level: WasmPermissionLevel,
67+
consent_state: WasmConsentState,
68+
) -> Self {
69+
Self {
70+
inbox_id,
71+
account_addresses,
72+
installation_ids,
73+
permission_level,
74+
consent_state,
75+
}
76+
}
77+
}
78+
5979
#[wasm_bindgen]
6080
pub struct WasmGroup {
6181
inner_client: Arc<RustXmtpClient>,

bindings_wasm/src/inbox_state.rs

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ pub struct WasmInstallation {
99
pub client_timestamp_ns: Option<u64>,
1010
}
1111

12+
#[wasm_bindgen]
13+
impl WasmInstallation {
14+
#[wasm_bindgen(constructor)]
15+
pub fn new(id: String, client_timestamp_ns: Option<u64>) -> Self {
16+
Self {
17+
id,
18+
client_timestamp_ns,
19+
}
20+
}
21+
}
22+
1223
#[wasm_bindgen(getter_with_clone)]
1324
pub struct WasmInboxState {
1425
pub inbox_id: String,
@@ -17,6 +28,24 @@ pub struct WasmInboxState {
1728
pub account_addresses: Vec<String>,
1829
}
1930

31+
#[wasm_bindgen]
32+
impl WasmInboxState {
33+
#[wasm_bindgen(constructor)]
34+
pub fn new(
35+
inbox_id: String,
36+
recovery_address: String,
37+
installations: Vec<WasmInstallation>,
38+
account_addresses: Vec<String>,
39+
) -> Self {
40+
Self {
41+
inbox_id,
42+
recovery_address,
43+
installations,
44+
account_addresses,
45+
}
46+
}
47+
}
48+
2049
impl From<AssociationState> for WasmInboxState {
2150
fn from(state: AssociationState) -> Self {
2251
Self {

bindings_wasm/src/messages.rs

+42
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ pub struct WasmListMessagesOptions {
5858
pub delivery_status: Option<WasmDeliveryStatus>,
5959
}
6060

61+
#[wasm_bindgen]
62+
impl WasmListMessagesOptions {
63+
#[wasm_bindgen(constructor)]
64+
pub fn new(
65+
sent_before_ns: Option<i64>,
66+
sent_after_ns: Option<i64>,
67+
limit: Option<i64>,
68+
delivery_status: Option<WasmDeliveryStatus>,
69+
) -> Self {
70+
Self {
71+
sent_before_ns,
72+
sent_after_ns,
73+
limit,
74+
delivery_status,
75+
}
76+
}
77+
}
78+
6179
#[wasm_bindgen(getter_with_clone)]
6280
#[derive(Clone)]
6381
pub struct WasmMessage {
@@ -70,6 +88,30 @@ pub struct WasmMessage {
7088
pub delivery_status: WasmDeliveryStatus,
7189
}
7290

91+
#[wasm_bindgen]
92+
impl WasmMessage {
93+
#[wasm_bindgen(constructor)]
94+
pub fn new(
95+
id: String,
96+
sent_at_ns: i64,
97+
convo_id: String,
98+
sender_inbox_id: String,
99+
content: WasmEncodedContent,
100+
kind: WasmGroupMessageKind,
101+
delivery_status: WasmDeliveryStatus,
102+
) -> Self {
103+
Self {
104+
id,
105+
sent_at_ns,
106+
convo_id,
107+
sender_inbox_id,
108+
content,
109+
kind,
110+
delivery_status,
111+
}
112+
}
113+
}
114+
73115
impl From<StoredGroupMessage> for WasmMessage {
74116
fn from(msg: StoredGroupMessage) -> Self {
75117
let id = hex::encode(msg.id.clone());

bindings_wasm/src/permissions.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,33 @@ pub struct WasmPermissionPolicySet {
120120
pub update_group_pinned_frame_url_policy: WasmPermissionPolicy,
121121
}
122122

123+
#[wasm_bindgen]
124+
impl WasmPermissionPolicySet {
125+
#[wasm_bindgen(constructor)]
126+
#[allow(clippy::too_many_arguments)]
127+
pub fn new(
128+
add_member_policy: WasmPermissionPolicy,
129+
remove_member_policy: WasmPermissionPolicy,
130+
add_admin_policy: WasmPermissionPolicy,
131+
remove_admin_policy: WasmPermissionPolicy,
132+
update_group_name_policy: WasmPermissionPolicy,
133+
update_group_description_policy: WasmPermissionPolicy,
134+
update_group_image_url_square_policy: WasmPermissionPolicy,
135+
update_group_pinned_frame_url_policy: WasmPermissionPolicy,
136+
) -> Self {
137+
Self {
138+
add_member_policy,
139+
remove_member_policy,
140+
add_admin_policy,
141+
remove_admin_policy,
142+
update_group_name_policy,
143+
update_group_description_policy,
144+
update_group_image_url_square_policy,
145+
update_group_pinned_frame_url_policy,
146+
}
147+
}
148+
}
149+
123150
impl From<PreconfiguredPolicies> for WasmGroupPermissionsOptions {
124151
fn from(policy: PreconfiguredPolicies) -> Self {
125152
match policy {
@@ -142,7 +169,6 @@ impl WasmGroupPermissions {
142169

143170
#[wasm_bindgen]
144171
impl WasmGroupPermissions {
145-
#[wasm_bindgen]
146172
#[wasm_bindgen]
147173
pub fn policy_type(&self) -> Result<WasmGroupPermissionsOptions, JsError> {
148174
if let Ok(preconfigured_policy) = self.inner.preconfigured_policy() {

0 commit comments

Comments
 (0)