parent
d22d7f9f8d
commit
34b93d5cce
5 changed files with 60 additions and 12 deletions
|
@ -26,7 +26,8 @@
|
|||
color: @theme_selected_bg_color;
|
||||
}
|
||||
|
||||
.room-list list {
|
||||
.room-list list,
|
||||
.rooms-sidebar {
|
||||
background-color: #f4f4f3;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,6 +317,9 @@
|
|||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<style>
|
||||
<class name="rooms-sidebar"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -471,27 +471,21 @@ impl AppOp {
|
|||
.get_object("room_container")
|
||||
.expect("Couldn't find room_container in ui file.");
|
||||
|
||||
let mut array: Vec<Room> = vec![];
|
||||
let selected_room = self.roomlist.get_selected();
|
||||
|
||||
self.rooms.clear();
|
||||
for ch in container.get_children().iter() {
|
||||
container.remove(ch);
|
||||
}
|
||||
|
||||
for r in rooms {
|
||||
for r in rooms.iter() {
|
||||
self.rooms.insert(r.id.clone(), r.clone());
|
||||
array.push(r);
|
||||
}
|
||||
|
||||
// TODO: sort by last message
|
||||
array.sort_by(|x, y| x.name.clone().unwrap_or_default().to_lowercase().cmp(&y.name.clone().unwrap_or_default().to_lowercase()));
|
||||
|
||||
self.roomlist = widgets::RoomList::new(Some(self.server_url.clone()));
|
||||
self.roomlist.add_rooms(rooms.iter().cloned().collect());
|
||||
container.add(&self.roomlist.widget());
|
||||
|
||||
for v in array {
|
||||
self.roomlist.add_room(v.clone());
|
||||
}
|
||||
self.roomlist.set_selected(selected_room);
|
||||
|
||||
let bk = self.backend.clone();
|
||||
self.roomlist.connect(move |room| {
|
||||
|
|
|
@ -102,6 +102,7 @@ impl RoomList {
|
|||
|
||||
b.pack_start(&self.list, true, true, 0);
|
||||
b.show_all();
|
||||
self.render_notifies();
|
||||
|
||||
b
|
||||
}
|
||||
|
@ -113,4 +114,41 @@ impl RoomList {
|
|||
cb(rs[idx as usize].clone());
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_selected(&self) -> Option<String> {
|
||||
match self.list.get_selected_row() {
|
||||
Some(row) => Some(self.roomvec[row.get_index() as usize].id.clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_selected(&self, room: Option<String>) {
|
||||
self.list.unselect_all();
|
||||
|
||||
if room.is_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
let room = room.unwrap();
|
||||
|
||||
if let Some(idx) = self.roomvec.iter().position(|x| { x.id == room}) {
|
||||
if let Some(ref row) = self.list.get_row_at_index(idx as i32) {
|
||||
self.list.select_row(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_rooms(&mut self, mut array: Vec<Room>) {
|
||||
array.sort_by_key(|x| x.name.clone().unwrap_or_default().to_lowercase());
|
||||
|
||||
for r in array {
|
||||
self.add_room(r);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_notifies(&self) {
|
||||
for (_k, r) in self.rooms.iter() {
|
||||
r.render_notifies();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,10 +43,15 @@ impl RoomRow {
|
|||
text.set_alignment(0.0, 0.0);
|
||||
text.set_ellipsize(pango::EllipsizeMode::End);
|
||||
|
||||
let notifications = gtk::Label::new(&format!("{}", room.notifications)[..]);
|
||||
let n = room.notifications;
|
||||
let notifications = gtk::Label::new(&format!("{}", n)[..]);
|
||||
if let Some(style) = notifications.get_style_context() {
|
||||
style.add_class("notify-badge");
|
||||
}
|
||||
match n {
|
||||
0 => notifications.hide(),
|
||||
_ => notifications.show(),
|
||||
}
|
||||
|
||||
icon.default(String::from("avatar-default-symbolic"), Some(ICON_SIZE));
|
||||
if avatar.starts_with("mxc") || avatar.is_empty() {
|
||||
|
@ -72,6 +77,13 @@ impl RoomRow {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn render_notifies(&self) {
|
||||
match self.room.notifications {
|
||||
0 => self.notifications.hide(),
|
||||
_ => self.notifications.show(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: String) {
|
||||
self.room.name = Some(name.clone());
|
||||
self.text.set_text(&name);
|
||||
|
|
Loading…
Reference in a new issue