fractal-gtk: Rename power_levels to admins

The current power_levels variable really only describes the admins
(hence the call to get_admins()) so let's rename it to be more accurate.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
This commit is contained in:
Alistair Francis 2019-07-07 22:02:56 -07:00
parent aea9d5be85
commit 45939221bc
5 changed files with 14 additions and 15 deletions

View file

@ -26,7 +26,7 @@ impl AppOp {
.rooms
.get(&self.active_room.clone().unwrap_or_default())
{
if let Some(level) = r.power_levels.get(&member.uid) {
if let Some(level) = r.admins.get(&member.uid) {
return *level;
}
}

View file

@ -441,11 +441,11 @@ impl AppOp {
};
let uid = self.uid.clone().unwrap_or_default();
let power_level = match self.uid.clone().and_then(|uid| room.power_levels.get(&uid)) {
let admin = match self.uid.clone().and_then(|uid| room.admins.get(&uid)) {
Some(&pl) => pl,
None => 0,
};
let redactable = power_level != 0 || uid == msg.sender;
let redactable = admin != 0 || uid == msg.sender;
let is_last_viewed = msg.receipt.contains_key(&uid);
Some(create_ui_message(

View file

@ -18,13 +18,13 @@ pub struct MembersList {
search_entry: gtk::SearchEntry,
error: gtk::Label,
members: Vec<Member>,
power_levels: HashMap<String, i32>,
admins: HashMap<String, i32>,
}
impl MembersList {
pub fn new(
m: Vec<Member>,
power_levels: HashMap<String, i32>,
admins: HashMap<String, i32>,
entry: gtk::SearchEntry,
) -> MembersList {
MembersList {
@ -32,7 +32,7 @@ impl MembersList {
error: gtk::Label::new(None),
members: m,
search_entry: entry,
power_levels: power_levels,
admins: admins,
}
}
@ -45,7 +45,7 @@ impl MembersList {
add_rows(
self.container.clone(),
self.members.clone(),
self.power_levels.clone(),
self.admins.clone(),
);
self.error.get_style_context().add_class("no_member_search");
self.error.set_text(&i18n("No matching members found"));
@ -206,15 +206,15 @@ fn load_row_content(member: Member, power_level: Option<i32>) -> gtk::Box {
fn add_rows(
container: gtk::ListBox,
members: Vec<Member>,
power_levels: HashMap<String, i32>,
admins: HashMap<String, i32>,
) -> Option<usize> {
/* Load just enough members to fill atleast the visible list */
for member in members.iter() {
let power_level = match power_levels.get(&member.uid) {
let admin = match admins.get(&member.uid) {
Some(pl) => Some(*pl),
None => None,
};
container.insert(&create_row(member.clone(), power_level)?, -1);
container.insert(&create_row(member.clone(), admin)?, -1);
}
None
}

View file

@ -186,7 +186,7 @@ impl RoomSettings {
let mut is_room = true;
let mut is_group = false;
let members: Vec<Member> = self.room.members.values().cloned().collect();
let power = *self.room.power_levels.get(&self.uid.clone()?).unwrap_or(&0);
let power = *self.room.admins.get(&self.uid.clone()?).unwrap_or(&0);
let edit = power >= 50 && !self.room.direct;
@ -630,8 +630,7 @@ impl RoomSettings {
)
.as_str(),
);
let list =
widgets::MembersList::new(members.clone(), self.room.power_levels.clone(), entry);
let list = widgets::MembersList::new(members.clone(), self.room.admins.clone(), entry);
let w = list.create()?;
b.add(&w);
self.members_list = Some(list);

View file

@ -97,7 +97,7 @@ pub struct Room {
/// Hashmap with the room users power levels
/// the key will be the userid and the value will be the level
pub power_levels: HashMap<String, i32>,
pub admins: HashMap<String, i32>,
}
impl Room {
@ -141,7 +141,7 @@ impl Room {
highlight: room.unread_notifications.highlight_count,
prev_batch: timeline.prev_batch.clone(),
messages: Message::from_json_events_iter(&k, timeline.events.iter()),
power_levels: get_admins(stevents),
admins: get_admins(stevents),
members: stevents
.iter()
.filter(|x| x["type"] == "m.room.member")