feature (ui - room info): added basic infos (name & encryption status) to the main ui's 'room info' panel
This commit is contained in:
parent
98f7e806de
commit
5611d8e385
|
@ -19,6 +19,7 @@ pub enum State {
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
matrix_room: matrix_sdk::room::Joined,
|
matrix_room: matrix_sdk::room::Joined,
|
||||||
name: String,
|
name: String,
|
||||||
|
encrypted: bool,
|
||||||
timeline: Vec<AnyTimelineEvent>,
|
timeline: Vec<AnyTimelineEvent>,
|
||||||
timeline_end: Option<String>,
|
timeline_end: Option<String>,
|
||||||
view_scroll: Option<usize>,
|
view_scroll: Option<usize>,
|
||||||
|
@ -39,6 +40,7 @@ impl Room {
|
||||||
Self {
|
Self {
|
||||||
matrix_room,
|
matrix_room,
|
||||||
name: "".to_string(),
|
name: "".to_string(),
|
||||||
|
encrypted: false,
|
||||||
timeline: Vec::new(),
|
timeline: Vec::new(),
|
||||||
timeline_end: None,
|
timeline_end: None,
|
||||||
view_scroll: None,
|
view_scroll: None,
|
||||||
|
@ -101,6 +103,10 @@ impl Room {
|
||||||
pub fn set_view_scroll(&mut self, scroll: Option<usize>) {
|
pub fn set_view_scroll(&mut self, scroll: Option<usize>) {
|
||||||
self.view_scroll = scroll;
|
self.view_scroll = scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn encrypted(&self) -> bool {
|
||||||
|
self.matrix_room.is_encrypted()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
|
|
|
@ -335,14 +335,26 @@ impl UI<'_> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
vec![ListItem::new(Text::styled("No room selected!", Style::default().fg(Color::Magenta)))]
|
vec![ListItem::new(Text::styled("No room selected!", Style::default().fg(Color::Red)))]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut messages_state = ListState::default();
|
let mut messages_state = ListState::default();
|
||||||
|
let mut room_info_content = Text::default();
|
||||||
|
|
||||||
if let Some(room) = status.room() {
|
if let Some(room) = status.room() {
|
||||||
messages_state.select(room.view_scroll());
|
messages_state.select(room.view_scroll());
|
||||||
};
|
|
||||||
|
room_info_content.extend(Text::styled(room.name(), Style::default().fg(Color::Cyan)));
|
||||||
|
if room.encrypted() {
|
||||||
|
room_info_content.extend(Text::styled("Encrypted", Style::default().fg(Color::Green)));
|
||||||
|
} else {
|
||||||
|
room_info_content.extend(Text::styled("Not Encrypted!", Style::default().fg(Color::Red)));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
room_info_content.extend(Text::styled("No room selected!", Style::default().fg(Color::Red)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// calculate to widgets colors, based of which widget is currently selected
|
// calculate to widgets colors, based of which widget is currently selected
|
||||||
let colors = match self.input_position {
|
let colors = match self.input_position {
|
||||||
|
@ -394,10 +406,12 @@ impl UI<'_> {
|
||||||
.highlight_symbol(">")
|
.highlight_symbol(">")
|
||||||
.highlight_style(Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD));
|
.highlight_style(Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD));
|
||||||
|
|
||||||
let room_info_panel = Block::default()
|
let room_info_panel = Paragraph::new(room_info_content)
|
||||||
.title("Room Info")
|
.block(Block::default()
|
||||||
.borders(Borders::ALL)
|
.title("Room Info")
|
||||||
.style(Style::default().fg(colors[MainInputPosition::RoomInfo as usize]));
|
.borders(Borders::ALL)
|
||||||
|
.style(Style::default().fg(colors[MainInputPosition::RoomInfo as usize])))
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
|
||||||
|
|
||||||
// render the widgets
|
// render the widgets
|
||||||
|
|
Reference in New Issue