forked from trinitrix/core
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 {
|
||||
matrix_room: matrix_sdk::room::Joined,
|
||||
name: String,
|
||||
encrypted: bool,
|
||||
timeline: Vec<AnyTimelineEvent>,
|
||||
timeline_end: Option<String>,
|
||||
view_scroll: Option<usize>,
|
||||
|
@ -39,6 +40,7 @@ impl Room {
|
|||
Self {
|
||||
matrix_room,
|
||||
name: "".to_string(),
|
||||
encrypted: false,
|
||||
timeline: Vec::new(),
|
||||
timeline_end: None,
|
||||
view_scroll: None,
|
||||
|
@ -101,6 +103,10 @@ impl Room {
|
|||
pub fn set_view_scroll(&mut self, scroll: Option<usize>) {
|
||||
self.view_scroll = scroll;
|
||||
}
|
||||
|
||||
pub fn encrypted(&self) -> bool {
|
||||
self.matrix_room.is_encrypted()
|
||||
}
|
||||
}
|
||||
|
||||
impl Status {
|
||||
|
|
|
@ -335,14 +335,26 @@ impl UI<'_> {
|
|||
.collect::<Vec<_>>()
|
||||
},
|
||||
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 room_info_content = Text::default();
|
||||
|
||||
if let Some(room) = status.room() {
|
||||
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
|
||||
let colors = match self.input_position {
|
||||
|
@ -394,10 +406,12 @@ impl UI<'_> {
|
|||
.highlight_symbol(">")
|
||||
.highlight_style(Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD));
|
||||
|
||||
let room_info_panel = Block::default()
|
||||
.title("Room Info")
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default().fg(colors[MainInputPosition::RoomInfo as usize]));
|
||||
let room_info_panel = Paragraph::new(room_info_content)
|
||||
.block(Block::default()
|
||||
.title("Room Info")
|
||||
.borders(Borders::ALL)
|
||||
.style(Style::default().fg(colors[MainInputPosition::RoomInfo as usize])))
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
|
||||
// render the widgets
|
||||
|
|
Loading…
Reference in New Issue