Skip to content

Commit 32327da

Browse files
authored
Make conversation listing sync (node + WASM) (#1475)
1 parent 1dd536d commit 32327da

File tree

5 files changed

+53
-71
lines changed

5 files changed

+53
-71
lines changed

bindings_node/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.0.33
44

55
- Added installation ID `bytes` to return value of `inboxState`
6+
- Refactored `list`, `listGroups`, and `listDms` to be synchronous
67

78
## 0.0.32
89

bindings_node/src/conversations.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl Conversations {
303303
}
304304

305305
#[napi]
306-
pub async fn list(&self, opts: Option<ListConversationsOptions>) -> Result<Vec<Conversation>> {
306+
pub fn list(&self, opts: Option<ListConversationsOptions>) -> Result<Vec<Conversation>> {
307307
let convo_list: Vec<Conversation> = self
308308
.inner_client
309309
.find_groups(opts.unwrap_or_default().into())
@@ -316,29 +316,19 @@ impl Conversations {
316316
}
317317

318318
#[napi]
319-
pub async fn list_groups(
320-
&self,
321-
opts: Option<ListConversationsOptions>,
322-
) -> Result<Vec<Conversation>> {
323-
self
324-
.list(Some(ListConversationsOptions {
325-
conversation_type: Some(ConversationType::Group),
326-
..opts.unwrap_or_default()
327-
}))
328-
.await
319+
pub fn list_groups(&self, opts: Option<ListConversationsOptions>) -> Result<Vec<Conversation>> {
320+
self.list(Some(ListConversationsOptions {
321+
conversation_type: Some(ConversationType::Group),
322+
..opts.unwrap_or_default()
323+
}))
329324
}
330325

331326
#[napi]
332-
pub async fn list_dms(
333-
&self,
334-
opts: Option<ListConversationsOptions>,
335-
) -> Result<Vec<Conversation>> {
336-
self
337-
.list(Some(ListConversationsOptions {
338-
conversation_type: Some(ConversationType::Dm),
339-
..opts.unwrap_or_default()
340-
}))
341-
.await
327+
pub fn list_dms(&self, opts: Option<ListConversationsOptions>) -> Result<Vec<Conversation>> {
328+
self.list(Some(ListConversationsOptions {
329+
conversation_type: Some(ConversationType::Dm),
330+
..opts.unwrap_or_default()
331+
}))
342332
}
343333

344334
#[napi]

bindings_node/test/Conversations.test.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ describe('Conversations', () => {
2222
const user = createUser()
2323
const client = await createRegisteredClient(user)
2424

25-
expect((await client.conversations().list()).length).toBe(0)
26-
expect((await client.conversations().listDms()).length).toBe(0)
27-
expect((await client.conversations().listGroups()).length).toBe(0)
25+
expect(client.conversations().list().length).toBe(0)
26+
expect(client.conversations().listDms().length).toBe(0)
27+
expect(client.conversations().listGroups().length).toBe(0)
2828
})
2929

3030
it('should create a group chat', async () => {
@@ -67,22 +67,22 @@ describe('Conversations', () => {
6767

6868
expect(group.consentState()).toBe(ConsentState.Allowed)
6969

70-
const group1 = await client1.conversations().list()
70+
const group1 = client1.conversations().list()
7171
expect(group1.length).toBe(1)
7272
expect(group1[0].id).toBe(group.id)
73-
expect((await client1.conversations().listDms()).length).toBe(0)
74-
expect((await client1.conversations().listGroups()).length).toBe(1)
73+
expect(client1.conversations().listDms().length).toBe(0)
74+
expect(client1.conversations().listGroups().length).toBe(1)
7575

76-
expect((await client2.conversations().list()).length).toBe(0)
76+
expect(client2.conversations().list().length).toBe(0)
7777

7878
await client2.conversations().sync()
7979

80-
const group2 = await client2.conversations().list()
80+
const group2 = client2.conversations().list()
8181
expect(group2.length).toBe(1)
8282
expect(group2[0].id).toBe(group.id)
8383

84-
expect((await client2.conversations().listDms()).length).toBe(0)
85-
expect((await client2.conversations().listGroups()).length).toBe(1)
84+
expect(client2.conversations().listDms().length).toBe(0)
85+
expect(client2.conversations().listGroups().length).toBe(1)
8686
})
8787

8888
it('should create a group with custom permissions', async () => {
@@ -213,25 +213,25 @@ describe('Conversations', () => {
213213

214214
expect(group.consentState()).toBe(ConsentState.Allowed)
215215

216-
const group1 = await client1.conversations().list()
216+
const group1 = client1.conversations().list()
217217
expect(group1.length).toBe(1)
218218
expect(group1[0].id).toBe(group.id)
219219
expect(group1[0].dmPeerInboxId()).toBe(client2.inboxId())
220220

221-
expect((await client1.conversations().listDms()).length).toBe(1)
222-
expect((await client1.conversations().listGroups()).length).toBe(0)
221+
expect(client1.conversations().listDms().length).toBe(1)
222+
expect(client1.conversations().listGroups().length).toBe(0)
223223

224-
expect((await client2.conversations().list()).length).toBe(0)
224+
expect(client2.conversations().list().length).toBe(0)
225225

226226
await client2.conversations().sync()
227227

228-
const group2 = await client2.conversations().list()
228+
const group2 = client2.conversations().list()
229229
expect(group2.length).toBe(1)
230230
expect(group2[0].id).toBe(group.id)
231231
expect(group2[0].dmPeerInboxId()).toBe(client1.inboxId())
232232

233-
expect((await client2.conversations().listDms()).length).toBe(1)
234-
expect((await client2.conversations().listGroups()).length).toBe(0)
233+
expect(client2.conversations().listDms().length).toBe(1)
234+
expect(client2.conversations().listGroups().length).toBe(0)
235235

236236
const dm1 = client1.conversations().findDmByTargetInboxId(client2.inboxId())
237237
expect(dm1).toBeDefined()
@@ -487,15 +487,15 @@ describe('Conversations', () => {
487487

488488
const groups2 = client2.conversations()
489489
await groups2.sync()
490-
const groupsList2 = await groups2.list()
490+
const groupsList2 = groups2.list()
491491

492492
const groups3 = client3.conversations()
493493
await groups3.sync()
494-
const groupsList3 = await groups3.list()
494+
const groupsList3 = groups3.list()
495495

496-
const groups4 = await client4.conversations()
496+
const groups4 = client4.conversations()
497497
await groups4.sync()
498-
const groupsList4 = await groups4.list()
498+
const groupsList4 = groups4.list()
499499

500500
const message1 = await groupsList2[0].send(encodeTextMessage('gm!'))
501501
const message2 = await groupsList3[0].send(encodeTextMessage('gm2!'))
@@ -530,15 +530,15 @@ describe('Conversations', () => {
530530

531531
const groups2 = client2.conversations()
532532
await groups2.sync()
533-
const groupsList2 = await groups2.list()
533+
const groupsList2 = groups2.list()
534534

535535
const groups3 = client3.conversations()
536536
await groups3.sync()
537-
const groupsList3 = await groups3.list()
537+
const groupsList3 = groups3.list()
538538

539-
const groups4 = await client4.conversations()
539+
const groups4 = client4.conversations()
540540
await groups4.sync()
541-
const groupsList4 = await groups4.list()
541+
const groupsList4 = groups4.list()
542542

543543
await groupsList4[0].send(encodeTextMessage('gm3!'))
544544
const message1 = await groupsList2[0].send(encodeTextMessage('gm!'))
@@ -573,15 +573,15 @@ describe('Conversations', () => {
573573

574574
const groups2 = client2.conversations()
575575
await groups2.sync()
576-
const groupsList2 = await groups2.list()
576+
const groupsList2 = groups2.list()
577577

578578
const groups3 = client3.conversations()
579579
await groups3.sync()
580-
const groupsList3 = await groups3.list()
580+
const groupsList3 = groups3.list()
581581

582-
const groups4 = await client4.conversations()
582+
const groups4 = client4.conversations()
583583
await groups4.sync()
584-
const groupsList4 = await groups4.list()
584+
const groupsList4 = groups4.list()
585585

586586
await groupsList2[0].send(encodeTextMessage('gm!'))
587587
await groupsList3[0].send(encodeTextMessage('gm2!'))

bindings_wasm/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.0.11
44

55
- Added installation ID `bytes` to return value of `inboxState`
6+
- Refactored `list`, `listGroups`, and `listDms` to be synchronous
67

78
## 0.0.10
89

bindings_wasm/src/conversations.rs

+11-21
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ impl Conversations {
323323
}
324324

325325
#[wasm_bindgen]
326-
pub async fn list(
327-
&self,
328-
opts: Option<ListConversationsOptions>,
329-
) -> Result<js_sys::Array, JsError> {
326+
pub fn list(&self, opts: Option<ListConversationsOptions>) -> Result<js_sys::Array, JsError> {
330327
let convo_list: js_sys::Array = self
331328
.inner_client
332329
.find_groups(opts.unwrap_or_default().into())
@@ -345,28 +342,21 @@ impl Conversations {
345342
}
346343

347344
#[wasm_bindgen(js_name = listGroups)]
348-
pub async fn list_groups(
345+
pub fn list_groups(
349346
&self,
350347
opts: Option<ListConversationsOptions>,
351348
) -> Result<js_sys::Array, JsError> {
352-
self
353-
.list(Some(ListConversationsOptions {
354-
conversation_type: Some(ConversationType::Group),
355-
..opts.unwrap_or_default()
356-
}))
357-
.await
349+
self.list(Some(ListConversationsOptions {
350+
conversation_type: Some(ConversationType::Group),
351+
..opts.unwrap_or_default()
352+
}))
358353
}
359354

360355
#[wasm_bindgen(js_name = listDms)]
361-
pub async fn list_dms(
362-
&self,
363-
opts: Option<ListConversationsOptions>,
364-
) -> Result<js_sys::Array, JsError> {
365-
self
366-
.list(Some(ListConversationsOptions {
367-
conversation_type: Some(ConversationType::Dm),
368-
..opts.unwrap_or_default()
369-
}))
370-
.await
356+
pub fn list_dms(&self, opts: Option<ListConversationsOptions>) -> Result<js_sys::Array, JsError> {
357+
self.list(Some(ListConversationsOptions {
358+
conversation_type: Some(ConversationType::Dm),
359+
..opts.unwrap_or_default()
360+
}))
371361
}
372362
}

0 commit comments

Comments
 (0)