Commit 45a37dda authored by Daniel García Moreno's avatar Daniel García Moreno

Show invitation rooms in sidebar

The invitations are showed in the sidebar now. On click does nothing
right now because we need to implement the accept/reject invitation
dialog and implement the api calls for that.
parent ddd9bdeb
...@@ -201,11 +201,10 @@ pub fn evc(events: &JsonValue, t: &str, field: &str) -> String { ...@@ -201,11 +201,10 @@ pub fn evc(events: &JsonValue, t: &str, field: &str) -> String {
pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<Vec<Room>, Error> { pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<Vec<Room>, Error> {
let rooms = &r["rooms"]; let rooms = &r["rooms"];
// TODO: do something with invite
//let invite = rooms["invite"].as_object().ok_or(Error::BackendError)?;
let join = rooms["join"].as_object().ok_or(Error::BackendError)?; let join = rooms["join"].as_object().ok_or(Error::BackendError)?;
let leave = rooms["leave"].as_object().ok_or(Error::BackendError)?; let leave = rooms["leave"].as_object().ok_or(Error::BackendError)?;
let invite = rooms["invite"].as_object().ok_or(Error::BackendError)?;
let mut rooms: Vec<Room> = vec![]; let mut rooms: Vec<Room> = vec![];
for k in join.keys() { for k in join.keys() {
...@@ -256,12 +255,28 @@ pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<V ...@@ -256,12 +255,28 @@ pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<V
rooms.push(r); rooms.push(r);
} }
// left rooms
for k in leave.keys() { for k in leave.keys() {
let mut r = Room::new(k.clone(), None); let mut r = Room::new(k.clone(), None);
r.left = true; r.left = true;
rooms.push(r); rooms.push(r);
} }
// invitations
for k in invite.keys() {
let room = invite.get(k).ok_or(Error::BackendError)?;
let stevents = &room["invite_state"]["events"];
let name = calculate_room_name(stevents, userid)?;
let mut r = Room::new(k.clone(), Some(name));
r.inv = true;
r.avatar = Some(evc(stevents, "m.room.avatar", "url"));
r.alias = Some(evc(stevents, "m.room.canonical_alias", "alias"));
r.topic = Some(evc(stevents, "m.room.topic", "topic"));
rooms.push(r);
}
Ok(rooms) Ok(rooms)
} }
......
...@@ -670,6 +670,12 @@ impl AppOp { ...@@ -670,6 +670,12 @@ impl AppOp {
} }
if let Some(r) = room { if let Some(r) = room {
if r.inv {
//TODO: show invitation accept/reject dialog
println!("INVITATION: {}, {:?}", r.id, r.name);
return;
}
self.set_active_room(&r); self.set_active_room(&r);
} }
} }
......
...@@ -49,17 +49,25 @@ impl RoomRow { ...@@ -49,17 +49,25 @@ impl RoomRow {
let n = room.notifications; let n = room.notifications;
let h = room.highlight; let h = room.highlight;
let notifications = gtk::Label::new(&format!("{}", n)[..]); let ntext = match room.inv {
true => String::from(" "),
false => format!("{}", n),
};
let notifications = gtk::Label::new(&ntext[..]);
if let Some(style) = notifications.get_style_context() { if let Some(style) = notifications.get_style_context() {
style.add_class("notify-badge"); style.add_class("notify-badge");
match h {
0 => style.remove_class("notify-highlight"), if h > 0 || room.inv {
_ => style.add_class("notify-highlight"), style.add_class("notify-highlight");
} else {
style.remove_class("notify-highlight");
} }
} }
match n {
0 => notifications.hide(), if n > 0 || room.inv {
_ => notifications.show(), notifications.show();
} else {
notifications.hide();
} }
icon.default(String::from("avatar-default-symbolic"), Some(ICON_SIZE)); icon.default(String::from("avatar-default-symbolic"), Some(ICON_SIZE));
...@@ -87,14 +95,17 @@ impl RoomRow { ...@@ -87,14 +95,17 @@ impl RoomRow {
self.room.notifications = n; self.room.notifications = n;
self.room.highlight = h; self.room.highlight = h;
self.notifications.set_text(&format!("{}", n)); self.notifications.set_text(&format!("{}", n));
match n { if n > 0 || self.room.inv {
0 => self.notifications.hide(), self.notifications.show();
_ => self.notifications.show(), } else {
self.notifications.hide();
} }
if let Some(style) = self.notifications.get_style_context() { if let Some(style) = self.notifications.get_style_context() {
match h { if h > 0 || self.room.inv {
0 => style.remove_class("notify-highlight"), style.add_class("notify-highlight");
_ => style.add_class("notify-highlight"), } else {
style.remove_class("notify-highlight");
} }
} }
} }
...@@ -109,9 +120,11 @@ impl RoomRow { ...@@ -109,9 +120,11 @@ impl RoomRow {
} }
pub fn render_notifies(&self) { pub fn render_notifies(&self) {
match self.room.notifications { let n = self.room.notifications;
0 => self.notifications.hide(), if n > 0 || self.room.inv {
_ => self.notifications.show(), self.notifications.show();
} else {
self.notifications.hide();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment