Commit 57d64410 authored by Daniel García Moreno's avatar Daniel García Moreno

Show gold or silver circle on admin users

Gold is for admins (100 PL) and Silver is for moderators (50PL).
Currently the badge is drawn with a DrawingArea and attached to the
avatar with a GtkOverlay.
parent 3ae2c30a
Pipeline #11671 failed with stages
in 22 minutes and 35 seconds
......@@ -34,6 +34,16 @@ impl AppOp {
}
}
pub fn member_level(&self, member: &Member) -> i32 {
if let Some(r) = self.rooms.get(&self.active_room.clone().unwrap_or_default()) {
if let Some(level) = r.power_levels.get(&member.uid) {
return *level;
}
}
0
}
pub fn show_members(&self, members: Vec<Member>) {
self.clean_member_list();
......
......@@ -139,3 +139,50 @@ impl AvatarExt for gtk::Box {
});
}
}
pub enum AdminColor {
Gold,
Silver,
}
pub fn admin_badge(kind: AdminColor, size: Option<i32>) -> gtk::DrawingArea {
let s = size.unwrap_or(10);
let da = DrawingArea::new();
da.set_size_request(s, s);
let color = match kind {
AdminColor::Gold => (237.0, 212.0, 0.0),
AdminColor::Silver => (186.0, 186.0, 186.0),
};
let border = match kind {
AdminColor::Gold => (107.0, 114.0, 0.0),
AdminColor::Silver => (137.0, 137.0, 137.0),
};
da.connect_draw(move |da, g| {
use std::f64::consts::PI;
g.set_antialias(cairo::Antialias::Best);
let width = s as f64;
let height = s as f64;
let context = da.get_style_context().unwrap();
gtk::render_background(&context, g, 0.0, 0.0, width, height);
g.set_source_rgba(color.0 / 256.0, color.1 / 256.0, color.2 / 256.0, 1.);
g.arc(width / 2.0, height / 2.0, width.min(height) / 2.5, 0.0, 2.0 * PI);
g.fill();
g.set_source_rgba(border.0 / 256.0, border.1 / 256.0, border.2 / 256.0, 0.5);
g.arc(width / 2.0, height / 2.0, width.min(height) / 2.5, 0.0, 2.0 * PI);
g.stroke();
Inhibit(false)
});
da
}
......@@ -74,7 +74,24 @@ impl<'a> MemberBox<'a> {
v.pack_start(&uid, true, true, 0);
}
w.add(&avatar);
match self.op.member_level(self.member) {
100 => {
let overlay = gtk::Overlay::new();
overlay.add(&avatar);
overlay.add_overlay(&widgets::admin_badge(widgets::AdminColor::Gold, None));
w.add(&overlay);
}
50 => {
let overlay = gtk::Overlay::new();
overlay.add(&avatar);
overlay.add_overlay(&widgets::admin_badge(widgets::AdminColor::Silver, None));
w.add(&overlay);
}
_ => {
w.add(&avatar);
}
}
w.add(&v);
event_box.add(&w);
......
......@@ -15,3 +15,5 @@ pub use self::roomrow::RoomRow;
pub use self::roomlist::RoomList;
pub use self::avatar::Avatar;
pub use self::avatar::AvatarExt;
pub use self::avatar::admin_badge;
pub use self::avatar::AdminColor;
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