mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 13:49:52 -07:00
Support displaying and editing room descriptions (#12)
This commit is contained in:
parent
8ed037afca
commit
38f4795886
13 changed files with 286 additions and 55 deletions
|
@ -44,6 +44,7 @@ use super::scrollback::{Scrollback, ScrollbackState};
|
|||
|
||||
pub struct ChatState {
|
||||
room_id: OwnedRoomId,
|
||||
room: MatrixRoom,
|
||||
|
||||
tbox: TextBoxState<IambInfo>,
|
||||
sent: HistoryList<EditRope>,
|
||||
|
@ -63,6 +64,7 @@ impl ChatState {
|
|||
|
||||
ChatState {
|
||||
room_id,
|
||||
room,
|
||||
|
||||
tbox,
|
||||
sent: HistoryList::new(EditRope::from(""), 100),
|
||||
|
@ -80,6 +82,10 @@ impl ChatState {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn room(&self) -> &MatrixRoom {
|
||||
&self.room
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &RoomId {
|
||||
&self.room_id
|
||||
}
|
||||
|
@ -133,6 +139,7 @@ impl WindowOps<IambInfo> for ChatState {
|
|||
|
||||
ChatState {
|
||||
room_id: self.room_id.clone(),
|
||||
room: self.room.clone(),
|
||||
|
||||
tbox,
|
||||
sent: self.sent.clone(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -18,6 +18,7 @@ use crate::windows::RoomItem;
|
|||
|
||||
pub struct SpaceState {
|
||||
room_id: OwnedRoomId,
|
||||
room: MatrixRoom,
|
||||
list: ListState<RoomItem, IambInfo>,
|
||||
}
|
||||
|
||||
|
@ -27,7 +28,11 @@ impl SpaceState {
|
|||
let content = IambBufferId::Room(room_id.clone(), RoomFocus::Scrollback);
|
||||
let list = ListState::new(content, vec![]);
|
||||
|
||||
SpaceState { room_id, list }
|
||||
SpaceState { room_id, room, list }
|
||||
}
|
||||
|
||||
pub fn room(&self) -> &MatrixRoom {
|
||||
&self.room
|
||||
}
|
||||
|
||||
pub fn id(&self) -> &RoomId {
|
||||
|
@ -37,6 +42,7 @@ impl SpaceState {
|
|||
pub fn dup(&self, store: &mut ProgramStore) -> Self {
|
||||
SpaceState {
|
||||
room_id: self.room_id.clone(),
|
||||
room: self.room.clone(),
|
||||
list: self.list.dup(store),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue