Support displaying and editing room descriptions (#12)

This commit is contained in:
Ulyssa 2023-01-05 18:12:25 -08:00
parent 8ed037afca
commit 38f4795886
No known key found for this signature in database
GPG key ID: 1B3965A3D18B9B64
13 changed files with 286 additions and 55 deletions

View file

@ -2,7 +2,13 @@ use matrix_sdk::room::Room as MatrixRoom;
use matrix_sdk::ruma::RoomId;
use matrix_sdk::DisplayName;
use modalkit::tui::{buffer::Buffer, layout::Rect, widgets::StatefulWidget};
use modalkit::tui::{
buffer::Buffer,
layout::Rect,
style::{Modifier as StyleModifier, Style},
text::{Span, Spans},
widgets::StatefulWidget,
};
use modalkit::{
editing::action::{
@ -90,7 +96,7 @@ impl RoomState {
&mut self,
act: RoomAction,
_: ProgramContext,
_: &mut ProgramStore,
store: &mut ProgramStore,
) -> IambResult<Vec<(Action<IambInfo>, ProgramContext)>> {
match act {
RoomAction::Members(mut cmd) => {
@ -103,11 +109,29 @@ impl RoomState {
Ok(vec![(act, cmd.context.take())])
},
RoomAction::Set(field) => {
store.application.worker.set_room(self.id().to_owned(), field)?;
Ok(vec![])
},
}
}
pub fn get_title(&self, store: &mut ProgramStore) -> String {
store.application.get_room_title(self.id())
pub fn get_title(&self, store: &mut ProgramStore) -> Spans {
let title = store.application.get_room_title(self.id());
let style = Style::default().add_modifier(StyleModifier::BOLD);
let mut spans = vec![Span::styled(title, style)];
match self.room().topic() {
Some(desc) if !desc.is_empty() => {
spans.push(" (".into());
spans.push(desc.into());
spans.push(")".into());
},
_ => {},
}
Spans(spans)
}
pub fn focus_toggle(&mut self) {
@ -117,6 +141,13 @@ impl RoomState {
}
}
pub fn room(&self) -> &MatrixRoom {
match self {
RoomState::Chat(chat) => chat.room(),
RoomState::Space(space) => space.room(),
}
}
pub fn id(&self) -> &RoomId {
match self {
RoomState::Chat(chat) => chat.id(),