@@ -75,21 +75,21 @@ public actor Conversations {
75
75
public func sync() async throws {
76
76
try await ffiConversations.sync()
77
77
}
78
- public func syncAllConversations(consentState: ConsentState? = nil)
78
+ public func syncAllConversations(consentStates: [ ConsentState] ? = nil)
79
79
async throws -> UInt32
80
80
{
81
81
return try await ffiConversations.syncAllConversations(
82
- consentState: consentState ?.toFFI)
82
+ consentStates: consentStates ?.toFFI)
83
83
}
84
84
85
85
public func listGroups(
86
86
createdAfter: Date? = nil, createdBefore: Date? = nil,
87
87
limit: Int? = nil,
88
- consentState: ConsentState? = nil
88
+ consentStates: [ ConsentState] ? = nil
89
89
) throws -> [Group] {
90
90
var options = FfiListConversationsOptions(
91
91
createdAfterNs: nil, createdBeforeNs: nil, limit: nil,
92
- consentState: consentState ?.toFFI, includeDuplicateDms: false)
92
+ consentStates: consentStates ?.toFFI, includeDuplicateDms: false)
93
93
if let createdAfter {
94
94
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
95
95
}
@@ -111,11 +111,11 @@ public actor Conversations {
111
111
public func listDms(
112
112
createdAfter: Date? = nil, createdBefore: Date? = nil,
113
113
limit: Int? = nil,
114
- consentState: ConsentState? = nil
114
+ consentStates: [ ConsentState] ? = nil
115
115
) throws -> [Dm] {
116
116
var options = FfiListConversationsOptions(
117
117
createdAfterNs: nil, createdBeforeNs: nil, limit: nil,
118
- consentState: consentState ?.toFFI, includeDuplicateDms: false)
118
+ consentStates: consentStates ?.toFFI, includeDuplicateDms: false)
119
119
if let createdAfter {
120
120
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
121
121
}
@@ -137,11 +137,11 @@ public actor Conversations {
137
137
public func list(
138
138
createdAfter: Date? = nil, createdBefore: Date? = nil,
139
139
limit: Int? = nil,
140
- consentState: ConsentState? = nil
140
+ consentStates: [ ConsentState] ? = nil
141
141
) async throws -> [Conversation] {
142
142
var options = FfiListConversationsOptions(
143
143
createdAfterNs: nil, createdBeforeNs: nil, limit: nil,
144
- consentState: consentState ?.toFFI, includeDuplicateDms: false)
144
+ consentStates: consentStates ?.toFFI, includeDuplicateDms: false)
145
145
if let createdAfter {
146
146
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
147
147
}
@@ -227,6 +227,13 @@ public actor Conversations {
227
227
}
228
228
}
229
229
230
+ public func newConversation(
231
+ with peerAddress: String
232
+ ) async throws -> Conversation {
233
+ let dm = try await findOrCreateDm(with: peerAddress)
234
+ return Conversation.dm(dm)
235
+ }
236
+
230
237
public func findOrCreateDm(with peerAddress: String) async throws -> Dm {
231
238
if peerAddress.lowercased() == client.address.lowercased() {
232
239
throw ConversationError.memberCannotBeSelf
@@ -249,13 +256,39 @@ public actor Conversations {
249
256
return newDm
250
257
}
251
258
259
+ public func newConversationWithInboxId(
260
+ with peerInboxId: String
261
+ ) async throws -> Conversation {
262
+ let dm = try await findOrCreateDmWithInboxId(with: peerInboxId)
263
+ return Conversation.dm(dm)
264
+ }
265
+
266
+ public func findOrCreateDmWithInboxId(with peerInboxId: String)
267
+ async throws -> Dm
268
+ {
269
+ if peerInboxId.lowercased() == client.inboxID.lowercased() {
270
+ throw ConversationError.memberCannotBeSelf
271
+ }
272
+ if let existingDm = try client.findDmByInboxId(inboxId: peerInboxId) {
273
+ return existingDm
274
+ }
275
+
276
+ let newDm =
277
+ try await ffiConversations
278
+ .createDmWithInboxId(inboxId: peerInboxId)
279
+ .dmFromFFI(client: client)
280
+ return newDm
281
+ }
282
+
252
283
public func newGroup(
253
284
with addresses: [String],
254
285
permissions: GroupPermissionPreconfiguration = .allMembers,
255
286
name: String = "",
256
287
imageUrlSquare: String = "",
257
288
description: String = "",
258
- pinnedFrameUrl: String = ""
289
+ pinnedFrameUrl: String = "",
290
+ messageExpirationFromMs: Int64? = nil,
291
+ messageExpirationMs: Int64? = nil
259
292
) async throws -> Group {
260
293
return try await newGroupInternal(
261
294
with: addresses,
@@ -266,7 +299,9 @@ public actor Conversations {
266
299
imageUrlSquare: imageUrlSquare,
267
300
description: description,
268
301
pinnedFrameUrl: pinnedFrameUrl,
269
- permissionPolicySet: nil
302
+ permissionPolicySet: nil,
303
+ messageExpirationFromMs: messageExpirationMs,
304
+ messageExpirationMs: messageExpirationMs
270
305
)
271
306
}
272
307
@@ -276,7 +311,9 @@ public actor Conversations {
276
311
name: String = "",
277
312
imageUrlSquare: String = "",
278
313
description: String = "",
279
- pinnedFrameUrl: String = ""
314
+ pinnedFrameUrl: String = "",
315
+ messageExpirationFromMs: Int64? = nil,
316
+ messageExpirationMs: Int64? = nil
280
317
) async throws -> Group {
281
318
return try await newGroupInternal(
282
319
with: addresses,
@@ -286,18 +323,22 @@ public actor Conversations {
286
323
description: description,
287
324
pinnedFrameUrl: pinnedFrameUrl,
288
325
permissionPolicySet: PermissionPolicySet.toFfiPermissionPolicySet(
289
- permissionPolicySet)
326
+ permissionPolicySet),
327
+ messageExpirationFromMs: messageExpirationMs,
328
+ messageExpirationMs: messageExpirationMs
290
329
)
291
330
}
292
331
293
332
private func newGroupInternal(
294
333
with addresses: [String],
295
- permissions: FfiGroupPermissionsOptions = .allMembers ,
334
+ permissions: FfiGroupPermissionsOptions = .default ,
296
335
name: String = "",
297
336
imageUrlSquare: String = "",
298
337
description: String = "",
299
338
pinnedFrameUrl: String = "",
300
- permissionPolicySet: FfiPermissionPolicySet? = nil
339
+ permissionPolicySet: FfiPermissionPolicySet? = nil,
340
+ messageExpirationFromMs: Int64? = nil,
341
+ messageExpirationMs: Int64? = nil
301
342
) async throws -> Group {
302
343
if addresses.first(where: {
303
344
$0.lowercased() == client.address.lowercased()
@@ -322,7 +363,90 @@ public actor Conversations {
322
363
groupImageUrlSquare: imageUrlSquare,
323
364
groupDescription: description,
324
365
groupPinnedFrameUrl: pinnedFrameUrl,
325
- customPermissionPolicySet: permissionPolicySet
366
+ customPermissionPolicySet: permissionPolicySet,
367
+ messageExpirationFromMs: messageExpirationMs,
368
+ messageExpirationMs: messageExpirationMs
369
+ )
370
+ ).groupFromFFI(client: client)
371
+ return group
372
+ }
373
+
374
+ public func newGroupWithInboxIds(
375
+ with inboxIds: [String],
376
+ permissions: GroupPermissionPreconfiguration = .allMembers,
377
+ name: String = "",
378
+ imageUrlSquare: String = "",
379
+ description: String = "",
380
+ pinnedFrameUrl: String = "",
381
+ messageExpirationFromMs: Int64? = nil,
382
+ messageExpirationMs: Int64? = nil
383
+ ) async throws -> Group {
384
+ return try await newGroupInternalWithInboxIds(
385
+ with: inboxIds,
386
+ permissions:
387
+ GroupPermissionPreconfiguration.toFfiGroupPermissionOptions(
388
+ option: permissions),
389
+ name: name,
390
+ imageUrlSquare: imageUrlSquare,
391
+ description: description,
392
+ pinnedFrameUrl: pinnedFrameUrl,
393
+ permissionPolicySet: nil,
394
+ messageExpirationFromMs: messageExpirationMs,
395
+ messageExpirationMs: messageExpirationMs
396
+ )
397
+ }
398
+
399
+ public func newGroupCustomPermissionsWithInboxIds(
400
+ with inboxIds: [String],
401
+ permissionPolicySet: PermissionPolicySet,
402
+ name: String = "",
403
+ imageUrlSquare: String = "",
404
+ description: String = "",
405
+ pinnedFrameUrl: String = "",
406
+ messageExpirationFromMs: Int64? = nil,
407
+ messageExpirationMs: Int64? = nil
408
+ ) async throws -> Group {
409
+ return try await newGroupInternalWithInboxIds(
410
+ with: inboxIds,
411
+ permissions: FfiGroupPermissionsOptions.customPolicy,
412
+ name: name,
413
+ imageUrlSquare: imageUrlSquare,
414
+ description: description,
415
+ pinnedFrameUrl: pinnedFrameUrl,
416
+ permissionPolicySet: PermissionPolicySet.toFfiPermissionPolicySet(
417
+ permissionPolicySet),
418
+ messageExpirationFromMs: messageExpirationMs,
419
+ messageExpirationMs: messageExpirationMs
420
+ )
421
+ }
422
+
423
+ private func newGroupInternalWithInboxIds(
424
+ with inboxIds: [String],
425
+ permissions: FfiGroupPermissionsOptions = .default,
426
+ name: String = "",
427
+ imageUrlSquare: String = "",
428
+ description: String = "",
429
+ pinnedFrameUrl: String = "",
430
+ permissionPolicySet: FfiPermissionPolicySet? = nil,
431
+ messageExpirationFromMs: Int64? = nil,
432
+ messageExpirationMs: Int64? = nil
433
+ ) async throws -> Group {
434
+ if inboxIds.contains(where: {
435
+ $0.lowercased() == client.inboxID.lowercased()
436
+ }) {
437
+ throw ConversationError.memberCannotBeSelf
438
+ }
439
+ let group = try await ffiConversations.createGroupWithInboxIds(
440
+ inboxIds: inboxIds,
441
+ opts: FfiCreateGroupOptions(
442
+ permissions: permissions,
443
+ groupName: name,
444
+ groupImageUrlSquare: imageUrlSquare,
445
+ groupDescription: description,
446
+ groupPinnedFrameUrl: pinnedFrameUrl,
447
+ customPermissionPolicySet: permissionPolicySet,
448
+ messageExpirationFromMs: messageExpirationMs,
449
+ messageExpirationMs: messageExpirationMs
326
450
)
327
451
).groupFromFFI(client: client)
328
452
return group
@@ -334,7 +458,7 @@ public actor Conversations {
334
458
AsyncThrowingStream { continuation in
335
459
let ffiStreamActor = FfiStreamActor()
336
460
337
- let messageCallback = MessageCallback() {
461
+ let messageCallback = MessageCallback {
338
462
message in
339
463
guard !Task.isCancelled else {
340
464
continuation.finish()
@@ -343,8 +467,7 @@ public actor Conversations {
343
467
}
344
468
return
345
469
}
346
- if let message = Message.create(ffiMessage: message)
347
- {
470
+ if let message = Message.create(ffiMessage: message) {
348
471
continuation.yield(message)
349
472
}
350
473
}
@@ -386,13 +509,6 @@ public actor Conversations {
386
509
return try await conversation.toConversation(client: client)
387
510
}
388
511
389
- public func newConversation(
390
- with peerAddress: String
391
- ) async throws -> Conversation {
392
- let dm = try await findOrCreateDm(with: peerAddress)
393
- return Conversation.dm(dm)
394
- }
395
-
396
512
public func getHmacKeys() throws
397
513
-> Xmtp_KeystoreApi_V1_GetConversationHmacKeysResponse
398
514
{
0 commit comments