@@ -7,9 +7,11 @@ use ruma::{
7
7
membership:: { get_member_events, join_room_by_id, leave_room} ,
8
8
message:: get_message_events,
9
9
room:: get_room_event,
10
+ tag:: { create_tag, delete_tag} ,
10
11
} ,
11
12
events:: {
12
- room:: history_visibility:: HistoryVisibility , AnyStateEvent , AnySyncStateEvent , EventType ,
13
+ room:: history_visibility:: HistoryVisibility , tag:: TagInfo , AnyStateEvent ,
14
+ AnySyncStateEvent , EventType ,
13
15
} ,
14
16
serde:: Raw ,
15
17
EventId , UserId ,
@@ -18,7 +20,7 @@ use ruma::{
18
20
use crate :: {
19
21
media:: { MediaFormat , MediaRequest , MediaType } ,
20
22
room:: RoomType ,
21
- BaseRoom , Client , Result , RoomMember ,
23
+ BaseRoom , Client , HttpError , HttpResult , Result , RoomMember ,
22
24
} ;
23
25
24
26
/// A struct containing methods that are common for Joined, Invited and Left
@@ -444,4 +446,50 @@ impl Common {
444
446
445
447
Ok ( true )
446
448
}
449
+
450
+ /// Adds a tag to the room, or updates it if it already exists.
451
+ ///
452
+ /// Returns the [`create_tag::Response`] from the server.
453
+ ///
454
+ /// # Arguments
455
+ /// * `tag` - The tag to add or update.
456
+ ///
457
+ /// * `tag_info` - Information about the tag, generally containing the
458
+ /// `order` parameter.
459
+ ///
460
+ /// # Example
461
+ ///
462
+ /// ```no_run
463
+ /// # use ruma::events::tag::TagInfo;
464
+ /// # futures::executor::block_on(async {
465
+ /// # let homeserver = url::Url::parse("http://localhost:8080")?;
466
+ /// # let mut client = matrix_sdk::Client::new(homeserver)?;
467
+ /// # let room_id = matrix_sdk::ruma::room_id!("!test:localhost");
468
+ /// use matrix_sdk::ruma::events::tag::TagInfo;
469
+ ///
470
+ /// if let Some(room) = client.get_joined_room(&room_id) {
471
+ /// let mut tag_info = TagInfo::new();
472
+ /// tag_info.order = Some(0.9);
473
+ ///
474
+ /// room.set_tag("u.work", tag_info ).await?;
475
+ /// }
476
+ /// # Result::<_, matrix_sdk::Error>::Ok(()) });
477
+ /// ```
478
+ pub async fn set_tag ( & self , tag : & str , tag_info : TagInfo ) -> HttpResult < create_tag:: Response > {
479
+ let user_id = self . client . user_id ( ) . await . ok_or ( HttpError :: AuthenticationRequired ) ?;
480
+ let request = create_tag:: Request :: new ( & user_id, self . inner . room_id ( ) , tag, tag_info) ;
481
+ self . client . send ( request, None ) . await
482
+ }
483
+
484
+ /// Removes a tag from the room.
485
+ ///
486
+ /// Returns the [`delete_tag::Response`] from the server.
487
+ ///
488
+ /// # Arguments
489
+ /// * `tag` - The tag to remove.
490
+ pub async fn remove_tag ( & self , tag : & str ) -> HttpResult < delete_tag:: Response > {
491
+ let user_id = self . client . user_id ( ) . await . ok_or ( HttpError :: AuthenticationRequired ) ?;
492
+ let request = delete_tag:: Request :: new ( & user_id, self . inner . room_id ( ) , tag) ;
493
+ self . client . send ( request, None ) . await
494
+ }
447
495
}
0 commit comments