@@ -570,21 +570,6 @@ impl Room {
570
570
Ok ( ( ) )
571
571
}
572
572
573
- pub async fn can_user_redact_own ( & self , user_id : String ) -> Result < bool , ClientError > {
574
- let user_id = UserId :: parse ( & user_id) ?;
575
- Ok ( self . inner . can_user_redact_own ( & user_id) . await ?)
576
- }
577
-
578
- pub async fn can_user_redact_other ( & self , user_id : String ) -> Result < bool , ClientError > {
579
- let user_id = UserId :: parse ( & user_id) ?;
580
- Ok ( self . inner . can_user_redact_other ( & user_id) . await ?)
581
- }
582
-
583
- pub async fn can_user_ban ( & self , user_id : String ) -> Result < bool , ClientError > {
584
- let user_id = UserId :: parse ( & user_id) ?;
585
- Ok ( self . inner . can_user_ban ( & user_id) . await ?)
586
- }
587
-
588
573
pub async fn ban_user (
589
574
& self ,
590
575
user_id : String ,
@@ -603,16 +588,6 @@ impl Room {
603
588
Ok ( self . inner . unban_user ( & user_id, reason. as_deref ( ) ) . await ?)
604
589
}
605
590
606
- pub async fn can_user_invite ( & self , user_id : String ) -> Result < bool , ClientError > {
607
- let user_id = UserId :: parse ( & user_id) ?;
608
- Ok ( self . inner . can_user_invite ( & user_id) . await ?)
609
- }
610
-
611
- pub async fn can_user_kick ( & self , user_id : String ) -> Result < bool , ClientError > {
612
- let user_id = UserId :: parse ( & user_id) ?;
613
- Ok ( self . inner . can_user_kick ( & user_id) . await ?)
614
- }
615
-
616
591
pub async fn kick_user (
617
592
& self ,
618
593
user_id : String ,
@@ -622,37 +597,6 @@ impl Room {
622
597
Ok ( self . inner . kick_user ( & user_id, reason. as_deref ( ) ) . await ?)
623
598
}
624
599
625
- pub async fn can_user_send_state (
626
- & self ,
627
- user_id : String ,
628
- state_event : StateEventType ,
629
- ) -> Result < bool , ClientError > {
630
- let user_id = UserId :: parse ( & user_id) ?;
631
- Ok ( self . inner . can_user_send_state ( & user_id, state_event. into ( ) ) . await ?)
632
- }
633
-
634
- pub async fn can_user_send_message (
635
- & self ,
636
- user_id : String ,
637
- message : MessageLikeEventType ,
638
- ) -> Result < bool , ClientError > {
639
- let user_id = UserId :: parse ( & user_id) ?;
640
- Ok ( self . inner . can_user_send_message ( & user_id, message. into ( ) ) . await ?)
641
- }
642
-
643
- pub async fn can_user_pin_unpin ( & self , user_id : String ) -> Result < bool , ClientError > {
644
- let user_id = UserId :: parse ( & user_id) ?;
645
- Ok ( self . inner . can_user_pin_unpin ( & user_id) . await ?)
646
- }
647
-
648
- pub async fn can_user_trigger_room_notification (
649
- & self ,
650
- user_id : String ,
651
- ) -> Result < bool , ClientError > {
652
- let user_id = UserId :: parse ( & user_id) ?;
653
- Ok ( self . inner . can_user_trigger_room_notification ( & user_id) . await ?)
654
- }
655
-
656
600
pub fn own_user_id ( & self ) -> String {
657
601
self . inner . own_user_id ( ) . to_string ( )
658
602
}
@@ -717,9 +661,9 @@ impl Room {
717
661
Ok ( ( ) )
718
662
}
719
663
720
- pub async fn get_power_levels ( & self ) -> Result < RoomPowerLevels , ClientError > {
664
+ pub async fn get_power_levels ( & self ) -> Result < Arc < RoomPowerLevels > , ClientError > {
721
665
let power_levels = self . inner . power_levels ( ) . await . map_err ( matrix_sdk:: Error :: from) ?;
722
- Ok ( RoomPowerLevels :: from ( power_levels) )
666
+ Ok ( Arc :: new ( RoomPowerLevels :: from ( power_levels) ) )
723
667
}
724
668
725
669
pub async fn apply_power_level_changes (
@@ -755,8 +699,8 @@ impl Room {
755
699
Ok ( self . inner . get_suggested_user_role ( & user_id) . await ?)
756
700
}
757
701
758
- pub async fn reset_power_levels ( & self ) -> Result < RoomPowerLevels , ClientError > {
759
- Ok ( RoomPowerLevels :: from ( self . inner . reset_power_levels ( ) . await ?) )
702
+ pub async fn reset_power_levels ( & self ) -> Result < Arc < RoomPowerLevels > , ClientError > {
703
+ Ok ( Arc :: new ( RoomPowerLevels :: from ( self . inner . reset_power_levels ( ) . await ?) ) )
760
704
}
761
705
762
706
pub async fn matrix_to_permalink ( & self ) -> Result < String , ClientError > {
@@ -1284,8 +1228,115 @@ pub fn matrix_to_room_alias_permalink(
1284
1228
Ok ( room_alias. matrix_to_uri ( ) . to_string ( ) )
1285
1229
}
1286
1230
1287
- #[ derive( uniffi:: Record ) ]
1231
+ #[ derive( uniffi:: Object ) ]
1288
1232
pub struct RoomPowerLevels {
1233
+ inner : RumaPowerLevels ,
1234
+ }
1235
+
1236
+ #[ matrix_sdk_ffi_macros:: export]
1237
+ impl RoomPowerLevels {
1238
+ fn values ( & self ) -> RoomPowerLevelsValues {
1239
+ self . inner . clone ( ) . into ( )
1240
+ }
1241
+
1242
+ /// Returns true if the user with the given user_id is able to ban in the
1243
+ /// room.
1244
+ ///
1245
+ /// The call may fail if there is an error in getting the power levels.
1246
+ pub fn can_user_ban ( & self , user_id : String ) -> Result < bool , ClientError > {
1247
+ let user_id = UserId :: parse ( & user_id) ?;
1248
+ Ok ( self . inner . user_can_ban ( & user_id) )
1249
+ }
1250
+
1251
+ /// Returns true if the user with the given user_id is able to redact
1252
+ /// their own messages in the room.
1253
+ ///
1254
+ /// The call may fail if there is an error in getting the power levels.
1255
+ pub fn can_user_redact_own ( & self , user_id : String ) -> Result < bool , ClientError > {
1256
+ let user_id = UserId :: parse ( & user_id) ?;
1257
+ Ok ( self . inner . user_can_redact_own_event ( & user_id) )
1258
+ }
1259
+
1260
+ /// Returns true if the user with the given user_id is able to redact
1261
+ /// messages of other users in the room.
1262
+ ///
1263
+ /// The call may fail if there is an error in getting the power levels.
1264
+ pub fn can_user_redact_other ( & self , user_id : String ) -> Result < bool , ClientError > {
1265
+ let user_id = UserId :: parse ( & user_id) ?;
1266
+ Ok ( self . inner . user_can_redact_event_of_other ( & user_id) )
1267
+ }
1268
+
1269
+ /// Returns true if the user with the given user_id is able to kick in the
1270
+ /// room.
1271
+ ///
1272
+ /// The call may fail if there is an error in getting the power levels.
1273
+ pub fn can_user_invite ( & self , user_id : String ) -> Result < bool , ClientError > {
1274
+ let user_id = UserId :: parse ( & user_id) ?;
1275
+ Ok ( self . inner . user_can_invite ( & user_id) )
1276
+ }
1277
+
1278
+ /// Returns true if the user with the given user_id is able to kick in the
1279
+ /// room.
1280
+ ///
1281
+ /// The call may fail if there is an error in getting the power levels.
1282
+ pub fn can_user_kick ( & self , user_id : String ) -> Result < bool , ClientError > {
1283
+ let user_id = UserId :: parse ( & user_id) ?;
1284
+ Ok ( self . inner . user_can_kick ( & user_id) )
1285
+ }
1286
+
1287
+ /// Returns true if the user with the given user_id is able to send a
1288
+ /// specific state event type in the room.
1289
+ ///
1290
+ /// The call may fail if there is an error in getting the power levels.
1291
+ pub fn can_user_send_state (
1292
+ & self ,
1293
+ user_id : String ,
1294
+ state_event : StateEventType ,
1295
+ ) -> Result < bool , ClientError > {
1296
+ let user_id = UserId :: parse ( & user_id) ?;
1297
+ Ok ( self . inner . user_can_send_state ( & user_id, state_event. into ( ) ) )
1298
+ }
1299
+
1300
+ /// Returns true if the user with the given user_id is able to send a
1301
+ /// specific message type in the room.
1302
+ ///
1303
+ /// The call may fail if there is an error in getting the power levels.
1304
+ pub fn can_user_send_message (
1305
+ & self ,
1306
+ user_id : String ,
1307
+ message : MessageLikeEventType ,
1308
+ ) -> Result < bool , ClientError > {
1309
+ let user_id = UserId :: parse ( & user_id) ?;
1310
+ Ok ( self . inner . user_can_send_message ( & user_id, message. into ( ) ) )
1311
+ }
1312
+
1313
+ /// Returns true if the user with the given user_id is able to pin or unpin
1314
+ /// events in the room.
1315
+ ///
1316
+ /// The call may fail if there is an error in getting the power levels.
1317
+ pub fn can_user_pin_unpin ( & self , user_id : String ) -> Result < bool , ClientError > {
1318
+ let user_id = UserId :: parse ( & user_id) ?;
1319
+ Ok ( self . inner . user_can_send_state ( & user_id, StateEventType :: RoomPinnedEvents . into ( ) ) )
1320
+ }
1321
+
1322
+ /// Returns true if the user with the given user_id is able to trigger a
1323
+ /// notification in the room.
1324
+ ///
1325
+ /// The call may fail if there is an error in getting the power levels.
1326
+ pub fn can_user_trigger_room_notification ( & self , user_id : String ) -> Result < bool , ClientError > {
1327
+ let user_id = UserId :: parse ( & user_id) ?;
1328
+ Ok ( self . inner . user_can_trigger_room_notification ( & user_id) )
1329
+ }
1330
+ }
1331
+
1332
+ impl From < RumaPowerLevels > for RoomPowerLevels {
1333
+ fn from ( value : RumaPowerLevels ) -> Self {
1334
+ Self { inner : value }
1335
+ }
1336
+ }
1337
+
1338
+ #[ derive( uniffi:: Record ) ]
1339
+ pub struct RoomPowerLevelsValues {
1289
1340
/// The level required to ban a user.
1290
1341
pub ban : i64 ,
1291
1342
/// The level required to invite a user.
@@ -1308,7 +1359,7 @@ pub struct RoomPowerLevels {
1308
1359
pub room_topic : i64 ,
1309
1360
}
1310
1361
1311
- impl From < RumaPowerLevels > for RoomPowerLevels {
1362
+ impl From < RumaPowerLevels > for RoomPowerLevelsValues {
1312
1363
fn from ( value : RumaPowerLevels ) -> Self {
1313
1364
fn state_event_level_for (
1314
1365
power_levels : & RumaPowerLevels ,
0 commit comments