Commit cf7dffd8 authored by Julian Sparber's avatar Julian Sparber

roomsettings: clean up code from old memberslist

parent 44b2d283
......@@ -15,7 +15,6 @@ mod load_more;
mod login;
mod markdown;
mod media_viewer;
mod more_members;
mod new_room;
mod roomlist_search;
mod scroll;
......@@ -69,7 +68,6 @@ impl App {
});
self.create_load_more_spn();
self.connect_more_members_btn();
self.create_actions();
self.connect_headerbars();
......@@ -94,7 +92,6 @@ impl App {
self.connect_search();
self.connect_member_search();
self.connect_invite_dialog();
self.connect_invite_user();
self.connect_direct_chat();
......
extern crate gtk;
use self::gtk::prelude::*;
use app::App;
impl App {
pub fn connect_more_members_btn(&self) {
let mlist: gtk::ListBox = self.ui.builder
.get_object("member_list")
.expect("Couldn't find member_list in ui file.");
let btn = self.op.lock().unwrap().more_members_btn.clone();
btn.show();
let op = self.op.clone();
btn.connect_clicked(move |_| {
op.lock().unwrap().member_limit += 50;
op.lock().unwrap().show_all_members();
});
mlist.add(&btn);
}
}
......@@ -18,15 +18,4 @@ impl App {
let op = self.op.clone();
btn.connect_clicked(move |_| op.lock().unwrap().search(input.get_text()));
}
pub fn connect_member_search(&self) {
let input: gtk::SearchEntry = self.ui.builder
.get_object("members_search")
.expect("Couldn't find members_searcn in ui file.");
let op = self.op.clone();
input.connect_search_changed(move |_| {
op.lock().unwrap().show_all_members();
});
}
}
extern crate gtk;
use i18n::ni18n_k;
use self::gtk::prelude::*;
use std::collections::HashMap;
......@@ -24,102 +22,15 @@ pub enum SearchType {
impl AppOp {
pub fn clean_member_list(&self) {
let mlist: gtk::ListBox = self.ui.builder
.get_object("member_list")
.expect("Couldn't find member_list in ui file.");
let childs = mlist.get_children();
let n = childs.len() - 1;
for ch in childs.iter().take(n) {
mlist.remove(ch);
}
}
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();
let mlist: gtk::ListBox = self.ui.builder
.get_object("member_list")
.expect("Couldn't find member_list in ui file.");
let msg_entry: gtk::Entry = self.ui.builder
.get_object("msg_entry")
.expect("Couldn't find msg_entry in ui file.");
// limiting the number of members to show in the list
for member in members.iter().take(self.member_limit) {
let w;
let m = member.clone();
{
let mb = widgets::MemberBox::new(&m, &self);
w = mb.widget(false);
}
let msg = msg_entry.clone();
w.connect_button_press_event(move |_, _| {
if let Some(ref a) = m.alias {
let mut pos = msg.get_position();
msg.insert_text(&a.clone(), &mut pos);
pos = msg.get_text_length() as i32;
msg.grab_focus_without_selecting();
msg.set_position(pos);
}
glib::signal::Inhibit(true)
});
let p = mlist.get_children().len() - 1;
mlist.insert(&w, p as i32);
}
if members.len() > self.member_limit {
let n = (members.len() - self.member_limit) as u32;
let newlabel = ni18n_k("and one more", "and {member_count} more", n,
&[("member_count", &n.to_string())]);
self.more_members_btn.set_label(&newlabel);
self.more_members_btn.show();
} else {
self.more_members_btn.hide();
}
}
pub fn show_all_members(&self) {
let inp: gtk::SearchEntry = self.ui.builder
.get_object("members_search")
.expect("Couldn't find members_searcn in ui file.");
let text = inp.get_text();
if let Some(r) = self.rooms.get(&self.active_room.clone().unwrap_or_default()) {
let mut members: Vec<Member> = match text {
// all members if no search text
None => r.members.values().cloned().collect(),
Some(t) => {
// members with the text in the alias
r.members.values().filter(move |x| {
match x.alias {
None => false,
Some(ref a) => a.to_lowercase().contains(&t.to_lowercase())
}
}).cloned().collect()
}
};
members.sort_by_key(|m| {
-r.power_levels.get(&m.uid).unwrap_or(&0)
});
self.show_members(members);
}
}
pub fn set_room_members(&mut self, roomid: String, members: Vec<Member>) {
if let Some(r) = self.rooms.get_mut(&roomid) {
r.members = HashMap::new();
......@@ -130,22 +41,12 @@ impl AppOp {
self.recalculate_room_name(roomid.clone());
if let Some(aroom) = self.active_room.clone() {
if aroom == roomid {
self.reload_members();
}
}
/* FIXME: update the current room settings insteat of creating a new one */
if self.room_settings.is_some() {
self.create_room_settings();
}
}
pub fn reload_members(&mut self) {
self.clean_member_list();
self.show_all_members();
}
pub fn room_member_event(&mut self, ev: Event) {
// NOTE: maybe we should show this events in the message list to notify enters and leaves
// to the user
......@@ -170,22 +71,6 @@ impl AppOp {
// ignoring other memberships
_ => {}
}
if ev.room != self.active_room.clone().unwrap_or_default() {
// if it isn't the current room, this event we don't need to update the UI
return;
}
match ev.content["membership"].as_str() {
Some("leave") => {
self.show_all_members();
}
Some("join") => {
self.show_all_members();
}
// ignoring other memberships
_ => {}
}
}
pub fn user_search_finished(&self, users: Vec<Member>) {
......
extern crate gtk;
use i18n::i18n;
use std::sync::mpsc::Sender;
use std::collections::HashMap;
......@@ -80,7 +78,6 @@ pub struct AppOp {
pub room_settings: Option<widgets::RoomSettings>,
pub roomlist: widgets::RoomList,
pub load_more_spn: gtk::Spinner,
pub more_members_btn: gtk::Button,
pub unsent_messages: HashMap<String, (String, i32)>,
pub inhibit_escape: bool,
......@@ -116,7 +113,6 @@ impl AppOp {
ui: ui,
gtk_app: app,
load_more_spn: gtk::Spinner::new(),
more_members_btn: gtk::Button::new_with_label(i18n("Load more members").as_str()),
backend: tx,
internal: itx,
autoscroll: true,
......
......@@ -208,7 +208,6 @@ impl AppOp {
// getting room details
self.backend.send(BKCommand::SetRoom(room.clone())).unwrap();
self.reload_members();
self.set_room_topic_label(room.topic.clone());
......
......@@ -7,15 +7,6 @@ use appop::AppState;
use app::InternalCommand;
/* needed to request members list */
/*
use backend::BKCommand;
use fractal_api::types::Member;
use std::sync::mpsc::channel;
use std::sync::mpsc::TryRecvError;
use std::sync::mpsc::{Receiver, Sender};
*/
use widgets;
impl AppOp {
......@@ -104,48 +95,4 @@ impl AppOp {
panel.show_new_room_topic();
None
}
/*
pub fn update_members_list(&self, uid: String) -> Option<()> {
self.room_settings.clone()?.update_members_list(uid);
None
}
*/
/*
pub fn request_members_list(&self) -> Option<()> {
let room = self.rooms.get(&self.active_room.clone()?)?;
let members: Vec<Member> = room.members.values().cloned().collect();
for member in members.iter() {
account_settings_get_member_info(
self.backend.clone(),
member.uid.clone());
}
None
*/
}
/* this funtion should be moved to the backend */
/*
pub fn account_settings_get_member_info(
backend: Sender<BKCommand>,
sender: String,
) {
let (tx, rx): (Sender<(String, String)>, Receiver<(String, String)>) = channel();
backend
.send(BKCommand::GetUserInfoAsync(sender.clone(), Some(tx)))
.unwrap();
gtk::timeout_add(100, move || match rx.try_recv() {
Err(TryRecvError::Empty) => gtk::Continue(true),
Err(TryRecvError::Disconnected) => gtk::Continue(false),
Ok((_name, _avatar)) => {
/* update UI */
//view.update_members_list(index);
//APPOP!(update_members_list, (sender));
gtk::Continue(false)
}
});
}
*/
......@@ -47,6 +47,7 @@ impl MembersList {
}
/* removes the content of the row with index i */
#[allow(dead_code)]
pub fn update(&self, uid: String) -> Option<()> {
let mut index = None;
for (i, member) in self.members.iter().enumerate() {
......
......@@ -66,12 +66,7 @@ impl RoomSettings {
Some((body, header))
}
/*
pub fn update(&self, i: usize) -> Option<()> {
None
}
*/
#[allow(dead_code)]
pub fn update_members_list(&self, uid: String) -> Option<()> {
self.members_list.clone()?.update(uid);
None
......
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