Commit 2063566367
Unsigned
Layout: unified · split
src/commands/topic.rs +2 −13
| @@ -2,7 +2,7 @@ use clap::{App as Argparse, AppSettings as ArgParseSettings, Arg}; | ||
| 2 | 2 | use weechat::{ |
| 3 | 3 | buffer::Buffer, |
| 4 | 4 | hooks::{Command, CommandCallback, CommandSettings}, |
| 5 | Args, Prefix, Weechat, | |
| 5 | Args, Weechat, | |
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | 8 | use super::parse_and_run; |
| @@ -87,18 +87,7 @@ impl TopicCommand { | ||
| 87 | 87 | |
| 88 | 88 | fn set_topic(&self, buffer: &Buffer, topic: String) { |
| 89 | 89 | if let Some(room) = self.servers.find_room(buffer) { |
| 90 | let room = room.room().clone(); | |
| 91 | ||
| 92 | Weechat::spawn(async move { | |
| 93 | if let Err(error) = room.set_room_topic(&topic).await { | |
| 94 | Weechat::print(&format!( | |
| 95 | "{}Failed to set room topic: {}", | |
| 96 | Weechat::prefix(Prefix::Error), | |
| 97 | error | |
| 98 | )); | |
| 99 | } | |
| 100 | }) | |
| 101 | .detach(); | |
| 90 | Weechat::spawn(async move { room.set_topic(topic).await }).detach(); | |
| 102 | 91 | } else { |
| 103 | 92 | Weechat::print( |
| 104 | 93 | "The /topic command needs to be run in a Matrix room buffer.", |
src/room/mod.rs +18
| @@ -1526,6 +1526,24 @@ impl MatrixRoom { | ||
| 1526 | 1526 | } |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | pub async fn set_topic(&self, topic: String) { | |
| 1530 | let Some(connection) = self.connection.borrow().clone() else { | |
| 1531 | self.print_error("Not connected. Please connect first."); | |
| 1532 | return; | |
| 1533 | }; | |
| 1534 | ||
| 1535 | let room = self.room().clone(); | |
| 1536 | ||
| 1537 | match connection | |
| 1538 | .spawn(async move { room.set_room_topic(&topic).await }) | |
| 1539 | .await | |
| 1540 | { | |
| 1541 | Ok(()) => (), | |
| 1542 | Err(error) => self | |
| 1543 | .print_error(&format!("Failed to set room topic: {}", error)), | |
| 1544 | } | |
| 1545 | } | |
| 1546 | ||
| 1529 | 1547 | pub async fn ban_user(&self, user_id: OwnedUserId, reason: Option<String>) { |
| 1530 | 1548 | let Some(connection) = self.connection.borrow().clone() else { |
| 1531 | 1549 | self.print_error("Not connected. Please connect first."); |