@tagea/capacitor-matrix 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,780 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc(MatrixPlugin)
5
+ public class MatrixPlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "MatrixPlugin"
7
+ public let jsName = "Matrix"
8
+ public let pluginMethods: [CAPPluginMethod] = [
9
+ CAPPluginMethod(name: "login", returnType: CAPPluginReturnPromise),
10
+ CAPPluginMethod(name: "loginWithToken", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
12
+ CAPPluginMethod(name: "getSession", returnType: CAPPluginReturnPromise),
13
+ CAPPluginMethod(name: "startSync", returnType: CAPPluginReturnPromise),
14
+ CAPPluginMethod(name: "stopSync", returnType: CAPPluginReturnPromise),
15
+ CAPPluginMethod(name: "getSyncState", returnType: CAPPluginReturnPromise),
16
+ CAPPluginMethod(name: "getRooms", returnType: CAPPluginReturnPromise),
17
+ CAPPluginMethod(name: "getRoomMembers", returnType: CAPPluginReturnPromise),
18
+ CAPPluginMethod(name: "joinRoom", returnType: CAPPluginReturnPromise),
19
+ CAPPluginMethod(name: "leaveRoom", returnType: CAPPluginReturnPromise),
20
+ CAPPluginMethod(name: "sendMessage", returnType: CAPPluginReturnPromise),
21
+ CAPPluginMethod(name: "getRoomMessages", returnType: CAPPluginReturnPromise),
22
+ CAPPluginMethod(name: "markRoomAsRead", returnType: CAPPluginReturnPromise),
23
+ CAPPluginMethod(name: "createRoom", returnType: CAPPluginReturnPromise),
24
+ CAPPluginMethod(name: "initializeCrypto", returnType: CAPPluginReturnPromise),
25
+ CAPPluginMethod(name: "getEncryptionStatus", returnType: CAPPluginReturnPromise),
26
+ CAPPluginMethod(name: "bootstrapCrossSigning", returnType: CAPPluginReturnPromise),
27
+ CAPPluginMethod(name: "setupKeyBackup", returnType: CAPPluginReturnPromise),
28
+ CAPPluginMethod(name: "getKeyBackupStatus", returnType: CAPPluginReturnPromise),
29
+ CAPPluginMethod(name: "restoreKeyBackup", returnType: CAPPluginReturnPromise),
30
+ CAPPluginMethod(name: "setupRecovery", returnType: CAPPluginReturnPromise),
31
+ CAPPluginMethod(name: "isRecoveryEnabled", returnType: CAPPluginReturnPromise),
32
+ CAPPluginMethod(name: "recoverAndSetup", returnType: CAPPluginReturnPromise),
33
+ CAPPluginMethod(name: "resetRecoveryKey", returnType: CAPPluginReturnPromise),
34
+ CAPPluginMethod(name: "exportRoomKeys", returnType: CAPPluginReturnPromise),
35
+ CAPPluginMethod(name: "importRoomKeys", returnType: CAPPluginReturnPromise),
36
+ CAPPluginMethod(name: "redactEvent", returnType: CAPPluginReturnPromise),
37
+ CAPPluginMethod(name: "sendReaction", returnType: CAPPluginReturnPromise),
38
+ CAPPluginMethod(name: "setRoomName", returnType: CAPPluginReturnPromise),
39
+ CAPPluginMethod(name: "setRoomTopic", returnType: CAPPluginReturnPromise),
40
+ CAPPluginMethod(name: "inviteUser", returnType: CAPPluginReturnPromise),
41
+ CAPPluginMethod(name: "kickUser", returnType: CAPPluginReturnPromise),
42
+ CAPPluginMethod(name: "banUser", returnType: CAPPluginReturnPromise),
43
+ CAPPluginMethod(name: "unbanUser", returnType: CAPPluginReturnPromise),
44
+ CAPPluginMethod(name: "searchUsers", returnType: CAPPluginReturnPromise),
45
+ CAPPluginMethod(name: "sendTyping", returnType: CAPPluginReturnPromise),
46
+ CAPPluginMethod(name: "getMediaUrl", returnType: CAPPluginReturnPromise),
47
+ CAPPluginMethod(name: "setPresence", returnType: CAPPluginReturnPromise),
48
+ CAPPluginMethod(name: "getPresence", returnType: CAPPluginReturnPromise),
49
+ CAPPluginMethod(name: "refreshEventStatuses", returnType: CAPPluginReturnPromise),
50
+ CAPPluginMethod(name: "forgetRoom", returnType: CAPPluginReturnPromise),
51
+ CAPPluginMethod(name: "editMessage", returnType: CAPPluginReturnPromise),
52
+ CAPPluginMethod(name: "sendReply", returnType: CAPPluginReturnPromise),
53
+ CAPPluginMethod(name: "setRoomAvatar", returnType: CAPPluginReturnPromise),
54
+ CAPPluginMethod(name: "uploadContent", returnType: CAPPluginReturnPromise),
55
+ CAPPluginMethod(name: "getThumbnailUrl", returnType: CAPPluginReturnPromise),
56
+ CAPPluginMethod(name: "getDevices", returnType: CAPPluginReturnPromise),
57
+ CAPPluginMethod(name: "deleteDevice", returnType: CAPPluginReturnPromise),
58
+ CAPPluginMethod(name: "setPusher", returnType: CAPPluginReturnPromise),
59
+ ]
60
+
61
+ private let matrixBridge = MatrixSDKBridge()
62
+
63
+ @objc func login(_ call: CAPPluginCall) {
64
+ guard let homeserverUrl = call.getString("homeserverUrl"),
65
+ let userId = call.getString("userId"),
66
+ let password = call.getString("password") else {
67
+ return call.reject("Missing required parameters")
68
+ }
69
+
70
+ Task {
71
+ do {
72
+ let session = try await matrixBridge.login(homeserverUrl: homeserverUrl, userId: userId, password: password)
73
+ call.resolve(session)
74
+ } catch {
75
+ call.reject(error.localizedDescription)
76
+ }
77
+ }
78
+ }
79
+
80
+ @objc func loginWithToken(_ call: CAPPluginCall) {
81
+ guard let homeserverUrl = call.getString("homeserverUrl"),
82
+ let accessToken = call.getString("accessToken"),
83
+ let userId = call.getString("userId"),
84
+ let deviceId = call.getString("deviceId") else {
85
+ return call.reject("Missing required parameters")
86
+ }
87
+
88
+ Task {
89
+ do {
90
+ let session = try await matrixBridge.loginWithToken(
91
+ homeserverUrl: homeserverUrl,
92
+ accessToken: accessToken,
93
+ userId: userId,
94
+ deviceId: deviceId
95
+ )
96
+ call.resolve(session)
97
+ } catch {
98
+ call.reject(error.localizedDescription)
99
+ }
100
+ }
101
+ }
102
+
103
+ @objc func logout(_ call: CAPPluginCall) {
104
+ Task {
105
+ do {
106
+ try await matrixBridge.logout()
107
+ call.resolve()
108
+ } catch {
109
+ call.reject(error.localizedDescription)
110
+ }
111
+ }
112
+ }
113
+
114
+ @objc func clearAllData(_ call: CAPPluginCall) {
115
+ matrixBridge.clearAllData()
116
+ call.resolve()
117
+ }
118
+
119
+ @objc func getSession(_ call: CAPPluginCall) {
120
+ if let session = matrixBridge.getSession() {
121
+ call.resolve(session)
122
+ } else {
123
+ call.resolve([:])
124
+ }
125
+ }
126
+
127
+ @objc func startSync(_ call: CAPPluginCall) {
128
+ Task {
129
+ do {
130
+ try await matrixBridge.startSync(
131
+ onSyncState: { [weak self] state in
132
+ DispatchQueue.main.async {
133
+ self?.notifyListeners("syncStateChange", data: ["state": state])
134
+ }
135
+ },
136
+ onMessage: { [weak self] event in
137
+ print("[CapMatrixPlugin] onMessage: eventId=\(event["eventId"] ?? "nil") type=\(event["type"] ?? "nil")")
138
+ DispatchQueue.main.async {
139
+ print("[CapMatrixPlugin] notifyListeners messageReceived on main thread")
140
+ self?.notifyListeners("messageReceived", data: ["event": event])
141
+ }
142
+ },
143
+ onRoomUpdate: { [weak self] roomId, summary in
144
+ DispatchQueue.main.async {
145
+ self?.notifyListeners("roomUpdated", data: ["roomId": roomId, "summary": summary])
146
+ }
147
+ },
148
+ onReceipt: { [weak self] roomId in
149
+ DispatchQueue.main.async {
150
+ self?.notifyListeners("receiptReceived", data: ["roomId": roomId])
151
+ }
152
+ }
153
+ )
154
+ call.resolve()
155
+ } catch {
156
+ call.reject(error.localizedDescription)
157
+ }
158
+ }
159
+ }
160
+
161
+ @objc func stopSync(_ call: CAPPluginCall) {
162
+ Task {
163
+ do {
164
+ try await matrixBridge.stopSync()
165
+ call.resolve()
166
+ } catch {
167
+ call.reject(error.localizedDescription)
168
+ }
169
+ }
170
+ }
171
+
172
+ @objc func getSyncState(_ call: CAPPluginCall) {
173
+ let state = matrixBridge.getSyncState()
174
+ call.resolve(["state": state])
175
+ }
176
+
177
+ @objc func getRooms(_ call: CAPPluginCall) {
178
+ Task {
179
+ do {
180
+ let rooms = try await matrixBridge.getRooms()
181
+ call.resolve(["rooms": rooms])
182
+ } catch {
183
+ call.reject(error.localizedDescription)
184
+ }
185
+ }
186
+ }
187
+
188
+ @objc func getRoomMembers(_ call: CAPPluginCall) {
189
+ guard let roomId = call.getString("roomId") else {
190
+ return call.reject("Missing roomId")
191
+ }
192
+
193
+ Task {
194
+ do {
195
+ let members = try await matrixBridge.getRoomMembers(roomId: roomId)
196
+ call.resolve(["members": members])
197
+ } catch {
198
+ call.reject(error.localizedDescription)
199
+ }
200
+ }
201
+ }
202
+
203
+ @objc func joinRoom(_ call: CAPPluginCall) {
204
+ guard let roomIdOrAlias = call.getString("roomIdOrAlias") else {
205
+ return call.reject("Missing roomIdOrAlias")
206
+ }
207
+
208
+ Task {
209
+ do {
210
+ let roomId = try await matrixBridge.joinRoom(roomIdOrAlias: roomIdOrAlias)
211
+ call.resolve(["roomId": roomId])
212
+ } catch {
213
+ call.reject(error.localizedDescription)
214
+ }
215
+ }
216
+ }
217
+
218
+ @objc func leaveRoom(_ call: CAPPluginCall) {
219
+ guard let roomId = call.getString("roomId") else {
220
+ return call.reject("Missing roomId")
221
+ }
222
+
223
+ Task {
224
+ do {
225
+ try await matrixBridge.leaveRoom(roomId: roomId)
226
+ call.resolve()
227
+ } catch {
228
+ call.reject(error.localizedDescription)
229
+ }
230
+ }
231
+ }
232
+
233
+ @objc func sendMessage(_ call: CAPPluginCall) {
234
+ guard let roomId = call.getString("roomId"),
235
+ let body = call.getString("body") else {
236
+ return call.reject("Missing required parameters")
237
+ }
238
+ let msgtype = call.getString("msgtype") ?? "m.text"
239
+
240
+ Task {
241
+ do {
242
+ let eventId = try await matrixBridge.sendMessage(roomId: roomId, body: body, msgtype: msgtype)
243
+ call.resolve(["eventId": eventId])
244
+ } catch {
245
+ call.reject(error.localizedDescription)
246
+ }
247
+ }
248
+ }
249
+
250
+ @objc func getRoomMessages(_ call: CAPPluginCall) {
251
+ guard let roomId = call.getString("roomId") else {
252
+ return call.reject("Missing roomId")
253
+ }
254
+ let limit = call.getInt("limit") ?? 20
255
+ let from = call.getString("from")
256
+
257
+ Task {
258
+ do {
259
+ let result = try await matrixBridge.getRoomMessages(roomId: roomId, limit: limit, from: from)
260
+ call.resolve(result)
261
+ } catch {
262
+ call.reject(error.localizedDescription)
263
+ }
264
+ }
265
+ }
266
+
267
+ @objc func markRoomAsRead(_ call: CAPPluginCall) {
268
+ guard let roomId = call.getString("roomId"),
269
+ let eventId = call.getString("eventId") else {
270
+ return call.reject("Missing required parameters")
271
+ }
272
+
273
+ Task {
274
+ do {
275
+ try await matrixBridge.markRoomAsRead(roomId: roomId, eventId: eventId)
276
+ call.resolve()
277
+ } catch {
278
+ call.reject(error.localizedDescription)
279
+ }
280
+ }
281
+ }
282
+
283
+ @objc func refreshEventStatuses(_ call: CAPPluginCall) {
284
+ guard let roomId = call.getString("roomId"),
285
+ let eventIds = call.getArray("eventIds") as? [String] else {
286
+ return call.reject("Missing roomId or eventIds")
287
+ }
288
+
289
+ Task {
290
+ do {
291
+ let events = try await matrixBridge.refreshEventStatuses(roomId: roomId, eventIds: eventIds)
292
+ call.resolve(["events": events])
293
+ } catch {
294
+ call.reject(error.localizedDescription)
295
+ }
296
+ }
297
+ }
298
+
299
+ @objc func createRoom(_ call: CAPPluginCall) {
300
+ let name = call.getString("name")
301
+ let topic = call.getString("topic")
302
+ let isEncrypted = call.getBool("isEncrypted") ?? false
303
+ let invite = call.getArray("invite") as? [String]
304
+ let isDirect = call.getBool("isDirect") ?? false
305
+ let preset = call.getString("preset")
306
+
307
+ Task {
308
+ do {
309
+ let roomId = try await matrixBridge.createRoom(
310
+ name: name,
311
+ topic: topic,
312
+ isEncrypted: isEncrypted,
313
+ isDirect: isDirect,
314
+ invite: invite,
315
+ preset: preset
316
+ )
317
+ call.resolve(["roomId": roomId])
318
+ } catch {
319
+ call.reject(error.localizedDescription)
320
+ }
321
+ }
322
+ }
323
+
324
+ @objc func initializeCrypto(_ call: CAPPluginCall) {
325
+ Task {
326
+ do {
327
+ try await matrixBridge.initializeCrypto()
328
+ call.resolve()
329
+ } catch {
330
+ call.reject(error.localizedDescription)
331
+ }
332
+ }
333
+ }
334
+
335
+ @objc func getEncryptionStatus(_ call: CAPPluginCall) {
336
+ Task {
337
+ do {
338
+ let status = try await matrixBridge.getEncryptionStatus()
339
+ call.resolve(status)
340
+ } catch {
341
+ call.reject(error.localizedDescription)
342
+ }
343
+ }
344
+ }
345
+
346
+ @objc func bootstrapCrossSigning(_ call: CAPPluginCall) {
347
+ Task {
348
+ do {
349
+ try await matrixBridge.bootstrapCrossSigning()
350
+ call.resolve()
351
+ } catch {
352
+ call.reject(error.localizedDescription)
353
+ }
354
+ }
355
+ }
356
+
357
+ @objc func setupKeyBackup(_ call: CAPPluginCall) {
358
+ Task {
359
+ do {
360
+ let result = try await matrixBridge.setupKeyBackup()
361
+ call.resolve(result)
362
+ } catch {
363
+ call.reject(error.localizedDescription)
364
+ }
365
+ }
366
+ }
367
+
368
+ @objc func getKeyBackupStatus(_ call: CAPPluginCall) {
369
+ Task {
370
+ do {
371
+ let status = try await matrixBridge.getKeyBackupStatus()
372
+ call.resolve(status)
373
+ } catch {
374
+ call.reject(error.localizedDescription)
375
+ }
376
+ }
377
+ }
378
+
379
+ @objc func restoreKeyBackup(_ call: CAPPluginCall) {
380
+ let recoveryKey = call.getString("recoveryKey")
381
+
382
+ Task {
383
+ do {
384
+ let result = try await matrixBridge.restoreKeyBackup(recoveryKey: recoveryKey)
385
+ call.resolve(result)
386
+ } catch {
387
+ call.reject(error.localizedDescription)
388
+ }
389
+ }
390
+ }
391
+
392
+ @objc func setupRecovery(_ call: CAPPluginCall) {
393
+ let passphrase = call.getString("passphrase")
394
+
395
+ Task {
396
+ do {
397
+ let result = try await matrixBridge.setupRecovery(passphrase: passphrase)
398
+ call.resolve(result)
399
+ } catch {
400
+ call.reject(error.localizedDescription)
401
+ }
402
+ }
403
+ }
404
+
405
+ @objc func isRecoveryEnabled(_ call: CAPPluginCall) {
406
+ Task {
407
+ do {
408
+ let enabled = try await matrixBridge.isRecoveryEnabled()
409
+ call.resolve(["enabled": enabled])
410
+ } catch {
411
+ call.reject(error.localizedDescription)
412
+ }
413
+ }
414
+ }
415
+
416
+ @objc func recoverAndSetup(_ call: CAPPluginCall) {
417
+ guard let recoveryKey = call.getString("recoveryKey") ?? call.getString("passphrase") else {
418
+ return call.reject("Missing recoveryKey or passphrase")
419
+ }
420
+
421
+ Task {
422
+ do {
423
+ try await matrixBridge.recoverAndSetup(recoveryKey: recoveryKey)
424
+ call.resolve()
425
+ } catch {
426
+ call.reject(error.localizedDescription)
427
+ }
428
+ }
429
+ }
430
+
431
+ @objc func resetRecoveryKey(_ call: CAPPluginCall) {
432
+ let passphrase = call.getString("passphrase")
433
+
434
+ Task {
435
+ do {
436
+ let result = try await matrixBridge.resetRecoveryKey(passphrase: passphrase)
437
+ call.resolve(result)
438
+ } catch {
439
+ call.reject(error.localizedDescription)
440
+ }
441
+ }
442
+ }
443
+
444
+ @objc func exportRoomKeys(_ call: CAPPluginCall) {
445
+ guard let passphrase = call.getString("passphrase") else {
446
+ return call.reject("Missing passphrase")
447
+ }
448
+
449
+ Task {
450
+ do {
451
+ let data = try await matrixBridge.exportRoomKeys(passphrase: passphrase)
452
+ call.resolve(["data": data])
453
+ } catch {
454
+ call.reject(error.localizedDescription)
455
+ }
456
+ }
457
+ }
458
+
459
+ @objc func importRoomKeys(_ call: CAPPluginCall) {
460
+ guard let data = call.getString("data"),
461
+ let passphrase = call.getString("passphrase") else {
462
+ return call.reject("Missing required parameters")
463
+ }
464
+
465
+ Task {
466
+ do {
467
+ let count = try await matrixBridge.importRoomKeys(data: data, passphrase: passphrase)
468
+ call.resolve(["importedKeys": count])
469
+ } catch {
470
+ call.reject(error.localizedDescription)
471
+ }
472
+ }
473
+ }
474
+
475
+ @objc func redactEvent(_ call: CAPPluginCall) {
476
+ guard let roomId = call.getString("roomId"),
477
+ let eventId = call.getString("eventId") else {
478
+ return call.reject("Missing required parameters")
479
+ }
480
+ let reason = call.getString("reason")
481
+
482
+ Task {
483
+ do {
484
+ try await matrixBridge.redactEvent(roomId: roomId, eventId: eventId, reason: reason)
485
+ call.resolve()
486
+ } catch {
487
+ call.reject(error.localizedDescription)
488
+ }
489
+ }
490
+ }
491
+
492
+ @objc func sendReaction(_ call: CAPPluginCall) {
493
+ guard let roomId = call.getString("roomId"),
494
+ let eventId = call.getString("eventId"),
495
+ let key = call.getString("key") else {
496
+ return call.reject("Missing required parameters")
497
+ }
498
+
499
+ Task {
500
+ do {
501
+ try await matrixBridge.sendReaction(roomId: roomId, eventId: eventId, key: key)
502
+ call.resolve(["eventId": ""])
503
+ } catch {
504
+ call.reject(error.localizedDescription)
505
+ }
506
+ }
507
+ }
508
+
509
+ @objc func searchUsers(_ call: CAPPluginCall) {
510
+ guard let searchTerm = call.getString("searchTerm") else {
511
+ return call.reject("Missing searchTerm")
512
+ }
513
+ let limit = call.getInt("limit") ?? 10
514
+
515
+ Task {
516
+ do {
517
+ let result = try await matrixBridge.searchUsers(searchTerm: searchTerm, limit: limit)
518
+ call.resolve(result)
519
+ } catch {
520
+ call.reject(error.localizedDescription)
521
+ }
522
+ }
523
+ }
524
+
525
+ @objc func setRoomName(_ call: CAPPluginCall) {
526
+ guard let roomId = call.getString("roomId"),
527
+ let name = call.getString("name") else {
528
+ return call.reject("Missing required parameters")
529
+ }
530
+
531
+ Task {
532
+ do {
533
+ try await matrixBridge.setRoomName(roomId: roomId, name: name)
534
+ call.resolve()
535
+ } catch {
536
+ call.reject(error.localizedDescription)
537
+ }
538
+ }
539
+ }
540
+
541
+ @objc func setRoomTopic(_ call: CAPPluginCall) {
542
+ guard let roomId = call.getString("roomId"),
543
+ let topic = call.getString("topic") else {
544
+ return call.reject("Missing required parameters")
545
+ }
546
+
547
+ Task {
548
+ do {
549
+ try await matrixBridge.setRoomTopic(roomId: roomId, topic: topic)
550
+ call.resolve()
551
+ } catch {
552
+ call.reject(error.localizedDescription)
553
+ }
554
+ }
555
+ }
556
+
557
+ @objc func inviteUser(_ call: CAPPluginCall) {
558
+ guard let roomId = call.getString("roomId"),
559
+ let userId = call.getString("userId") else {
560
+ return call.reject("Missing required parameters")
561
+ }
562
+
563
+ Task {
564
+ do {
565
+ try await matrixBridge.inviteUser(roomId: roomId, userId: userId)
566
+ call.resolve()
567
+ } catch {
568
+ call.reject(error.localizedDescription)
569
+ }
570
+ }
571
+ }
572
+
573
+ @objc func kickUser(_ call: CAPPluginCall) {
574
+ guard let roomId = call.getString("roomId"),
575
+ let userId = call.getString("userId") else {
576
+ return call.reject("Missing required parameters")
577
+ }
578
+ let reason = call.getString("reason")
579
+
580
+ Task {
581
+ do {
582
+ try await matrixBridge.kickUser(roomId: roomId, userId: userId, reason: reason)
583
+ call.resolve()
584
+ } catch {
585
+ call.reject(error.localizedDescription)
586
+ }
587
+ }
588
+ }
589
+
590
+ @objc func banUser(_ call: CAPPluginCall) {
591
+ guard let roomId = call.getString("roomId"),
592
+ let userId = call.getString("userId") else {
593
+ return call.reject("Missing required parameters")
594
+ }
595
+ let reason = call.getString("reason")
596
+
597
+ Task {
598
+ do {
599
+ try await matrixBridge.banUser(roomId: roomId, userId: userId, reason: reason)
600
+ call.resolve()
601
+ } catch {
602
+ call.reject(error.localizedDescription)
603
+ }
604
+ }
605
+ }
606
+
607
+ @objc func unbanUser(_ call: CAPPluginCall) {
608
+ guard let roomId = call.getString("roomId"),
609
+ let userId = call.getString("userId") else {
610
+ return call.reject("Missing required parameters")
611
+ }
612
+
613
+ Task {
614
+ do {
615
+ try await matrixBridge.unbanUser(roomId: roomId, userId: userId)
616
+ call.resolve()
617
+ } catch {
618
+ call.reject(error.localizedDescription)
619
+ }
620
+ }
621
+ }
622
+
623
+ @objc func sendTyping(_ call: CAPPluginCall) {
624
+ guard let roomId = call.getString("roomId"),
625
+ let isTyping = call.getBool("isTyping") else {
626
+ return call.reject("Missing required parameters")
627
+ }
628
+
629
+ Task {
630
+ do {
631
+ try await matrixBridge.sendTyping(roomId: roomId, isTyping: isTyping)
632
+ call.resolve()
633
+ } catch {
634
+ call.reject(error.localizedDescription)
635
+ }
636
+ }
637
+ }
638
+
639
+ @objc func getMediaUrl(_ call: CAPPluginCall) {
640
+ guard let mxcUrl = call.getString("mxcUrl") else {
641
+ return call.reject("Missing mxcUrl")
642
+ }
643
+ do {
644
+ let httpUrl = try matrixBridge.getMediaUrl(mxcUrl: mxcUrl)
645
+ call.resolve(["url": httpUrl])
646
+ } catch {
647
+ call.reject(error.localizedDescription)
648
+ }
649
+ }
650
+
651
+ @objc func setPresence(_ call: CAPPluginCall) {
652
+ call.reject("setPresence is not supported on this platform")
653
+ }
654
+
655
+ @objc func getPresence(_ call: CAPPluginCall) {
656
+ call.reject("getPresence is not supported on this platform")
657
+ }
658
+
659
+ @objc func forgetRoom(_ call: CAPPluginCall) {
660
+ guard let roomId = call.getString("roomId") else {
661
+ return call.reject("Missing roomId")
662
+ }
663
+
664
+ Task {
665
+ do {
666
+ try await matrixBridge.forgetRoom(roomId: roomId)
667
+ call.resolve()
668
+ } catch {
669
+ call.reject(error.localizedDescription)
670
+ }
671
+ }
672
+ }
673
+
674
+ @objc func editMessage(_ call: CAPPluginCall) {
675
+ guard let roomId = call.getString("roomId"),
676
+ let eventId = call.getString("eventId"),
677
+ let newBody = call.getString("newBody") else {
678
+ return call.reject("Missing required parameters")
679
+ }
680
+
681
+ Task {
682
+ do {
683
+ let resultEventId = try await matrixBridge.editMessage(roomId: roomId, eventId: eventId, newBody: newBody)
684
+ call.resolve(["eventId": resultEventId])
685
+ } catch {
686
+ call.reject(error.localizedDescription)
687
+ }
688
+ }
689
+ }
690
+
691
+ @objc func sendReply(_ call: CAPPluginCall) {
692
+ guard let roomId = call.getString("roomId"),
693
+ let body = call.getString("body"),
694
+ let replyToEventId = call.getString("replyToEventId") else {
695
+ return call.reject("Missing required parameters")
696
+ }
697
+ let msgtype = call.getString("msgtype") ?? "m.text"
698
+
699
+ Task {
700
+ do {
701
+ let resultEventId = try await matrixBridge.sendReply(roomId: roomId, body: body, replyToEventId: replyToEventId, msgtype: msgtype)
702
+ call.resolve(["eventId": resultEventId])
703
+ } catch {
704
+ call.reject(error.localizedDescription)
705
+ }
706
+ }
707
+ }
708
+
709
+ @objc func setRoomAvatar(_ call: CAPPluginCall) {
710
+ guard let _ = call.getString("roomId"),
711
+ let _ = call.getString("mxcUrl") else {
712
+ return call.reject("Missing required parameters")
713
+ }
714
+ // No-op placeholder: Rust SDK doesn't have direct setAvatar
715
+ call.resolve()
716
+ }
717
+
718
+ @objc func uploadContent(_ call: CAPPluginCall) {
719
+ guard let fileUri = call.getString("fileUri"),
720
+ let fileName = call.getString("fileName"),
721
+ let mimeType = call.getString("mimeType") else {
722
+ return call.reject("Missing required parameters")
723
+ }
724
+
725
+ Task {
726
+ do {
727
+ let contentUri = try await matrixBridge.uploadContent(fileUri: fileUri, fileName: fileName, mimeType: mimeType)
728
+ call.resolve(["contentUri": contentUri])
729
+ } catch {
730
+ call.reject(error.localizedDescription)
731
+ }
732
+ }
733
+ }
734
+
735
+ @objc func getThumbnailUrl(_ call: CAPPluginCall) {
736
+ guard let mxcUrl = call.getString("mxcUrl") else {
737
+ return call.reject("Missing mxcUrl")
738
+ }
739
+ let width = call.getInt("width") ?? 320
740
+ let height = call.getInt("height") ?? 240
741
+ let method = call.getString("method") ?? "scale"
742
+
743
+ do {
744
+ let url = try matrixBridge.getThumbnailUrl(mxcUrl: mxcUrl, width: width, height: height, method: method)
745
+ call.resolve(["url": url])
746
+ } catch {
747
+ call.reject(error.localizedDescription)
748
+ }
749
+ }
750
+
751
+ @objc func getDevices(_ call: CAPPluginCall) {
752
+ Task {
753
+ do {
754
+ let devices = try await matrixBridge.getDevices()
755
+ call.resolve(["devices": devices])
756
+ } catch {
757
+ call.reject(error.localizedDescription)
758
+ }
759
+ }
760
+ }
761
+
762
+ @objc func deleteDevice(_ call: CAPPluginCall) {
763
+ guard let deviceId = call.getString("deviceId") else {
764
+ return call.reject("Missing deviceId")
765
+ }
766
+
767
+ Task {
768
+ do {
769
+ try await matrixBridge.deleteDevice(deviceId: deviceId)
770
+ call.resolve()
771
+ } catch {
772
+ call.reject(error.localizedDescription)
773
+ }
774
+ }
775
+ }
776
+
777
+ @objc func setPusher(_ call: CAPPluginCall) {
778
+ call.reject("setPusher is not yet supported")
779
+ }
780
+ }