Commit bae4dcf65d

bae4dcf65dfdb4e11e6cfd275b49bfca10f771c5

parent: 0e0a16c77e

Unsigned

Damir Jelić <poljar@termina.org.uk> · 2021-01-04 18:41 UTC

room: Add the canonical alias to the localvars.

Layout: unified · split

src/bar_items/status.rs +1 −3
@@ -31,9 +31,7 @@ impl BarItemCallback for Status {
3131 }
3232
3333 if room.is_public() {
34 signs.push(
35 server.config().borrow().look().public_room_sign(),
36 );
34 signs.push(server.config().borrow().look().public_room_sign());
3735 }
3836
3937 if room.is_busy() {
src/room/mod.rs +18 −1
@@ -61,7 +61,7 @@ use matrix_sdk::{
6161 AnySyncMessageEvent, AnySyncRoomEvent, AnySyncStateEvent,
6262 SyncMessageEvent, SyncStateEvent,
6363 },
64 identifiers::{EventId, RoomId, UserId},
64 identifiers::{EventId, RoomAliasId, RoomId, UserId},
6565 uuid::Uuid,
6666 JoinedRoom,
6767};
@@ -279,6 +279,10 @@ impl RoomHandle {
279279 buffer.set_localvar("domain", room.room_id().server_name().as_str());
280280 buffer.set_localvar("room_id", room.room_id().as_str());
281281
282 if let Some(alias) = room.alias() {
283 buffer.set_localvar("alias", alias.as_str());
284 }
285
282286 // This is fine since we're only given the room to the buffer input and
283287 // the callback can only run once we yield controll back to Weechat.
284288 unsafe {
@@ -352,6 +356,10 @@ impl MatrixRoom {
352356 self.room.is_public()
353357 }
354358
359 pub fn alias(&self) -> Option<RoomAliasId> {
360 self.room.canonical_alias()
361 }
362
355363 pub fn room_id(&self) -> &RoomId {
356364 &self.room_id
357365 }
@@ -883,6 +891,14 @@ impl MatrixRoom {
883891 }
884892 }
885893
894 fn set_alias(&self) {
895 if let Some(alias) = self.alias() {
896 if let Ok(b) = self.buffer_handle().upgrade() {
897 b.set_localvar("alias", alias.as_str());
898 }
899 }
900 }
901
886902 fn update_buffer_name(&self) {
887903 let name = self.members.calculate_buffer_name();
888904
@@ -1015,6 +1031,7 @@ impl MatrixRoom {
10151031 }
10161032 AnySyncStateEvent::RoomName(_) => self.update_buffer_name(),
10171033 AnySyncStateEvent::RoomTopic(_) => self.set_topic(),
1034 AnySyncStateEvent::RoomCanonicalAlias(_) => self.set_alias(),
10181035 _ => (),
10191036 }
10201037 }