Commit f4da6bb4 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Invite: Remove member from list when their pill is deleted

See #78
parent e869de07
......@@ -44,6 +44,12 @@ impl App {
let invite = self.ui.builder
.get_object::<gtk::Button>("invite_button")
.expect("Can't find invite_button in ui file.");
let to_chat_textview = self.ui.builder
.get_object::<gtk::TextView>("to_chat_textview")
.expect("Can't find to_chat_textview in ui file.");
let invite_textview = self.ui.builder
.get_object::<gtk::TextView>("invite_textview")
.expect("Can't find invite_textview in ui file.");
let entry = self.ui.builder
.get_object::<gtk::Entry>("invite_entry")
.expect("Can't find invite_entry in ui file.");
......@@ -72,6 +78,24 @@ impl App {
glib::signal::Inhibit(false)
}));
if let Some(buffer) = to_chat_textview.get_buffer() {
buffer.connect_delete_range(clone!( op => move |_, _, _| {
gtk::idle_add(clone!(op => move || {
op.lock().unwrap().detect_removed_invite();
Continue(false)
}));
}));
}
if let Some(buffer) = invite_textview.get_buffer() {
buffer.connect_delete_range(clone!( op => move |_, _, _| {
gtk::idle_add(clone!(op => move || {
op.lock().unwrap().detect_removed_invite();
Continue(false)
}));
}));
}
dialog.connect_delete_event(clone!(op => move |_, _| {
op.lock().unwrap().close_invite_dialog();
glib::signal::Inhibit(true)
......
......@@ -32,11 +32,11 @@ impl AppOp {
.get_object::<gtk::ListBox>(listboxid)
.expect("Can't find to_invite in ui file.");
if self.invite_list.contains(&u) {
let to_invite_textview = self.ui.builder
.get_object::<gtk::TextView>(textviewid)
.expect("Can't find to_invite_textview in ui file.");
if self.invite_list.iter().any(|(mem, _)| *mem == u) {
return;
}
......@@ -132,7 +132,7 @@ impl AppOp {
.get_object::<gtk::Dialog>(dialogid)
.expect("Can’t find invite_user_dialog in ui file.");
let idx = self.invite_list.iter().position(|x| x.uid == uid);
let idx = self.invite_list.iter().position(|x| x.0.uid == uid);
if let Some(i) = idx {
self.invite_list.remove(i);
if let Some(r) = to_invite.get_row_at_index(i as i32) {
......@@ -153,6 +153,17 @@ impl AppOp {
dialog.resize(300, 200);
}
pub fn detect_removed_invite(&self) {
for (member, anchor) in self.invite_list.clone() {
if anchor.get_deleted() {
let tx = self.internal.clone();
let uid = member.uid.clone();
tx.send(InternalCommand::RmInvite(uid)).unwrap();
}
}
}
pub fn show_invite_user_dialog(&mut self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("invite_user_dialog")
......@@ -181,7 +192,7 @@ impl AppOp {
pub fn invite(&mut self) {
if let &Some(ref r) = &self.active_room {
for user in &self.invite_list {
self.backend.send(BKCommand::Invite(r.clone(), user.uid.clone())).unwrap();
self.backend.send(BKCommand::Invite(r.clone(), user.0.uid.clone())).unwrap();
}
}
self.close_invite_dialog();
......
......@@ -91,7 +91,7 @@ pub struct AppOp {
pub invitation_roomid: Option<String>,
pub md_enabled: bool,
invite_list: Vec<Member>,
pub invite_list: Vec<(Member, gtk::TextChildAnchor)>,
search_type: SearchType,
pub stickers: Vec<StickerGroup>,
......
......@@ -22,10 +22,10 @@ impl AppOp {
let user = self.invite_list[0].clone();
let internal_id: String = thread_rng().sample_iter(&Alphanumeric).take(10).collect();
self.backend.send(BKCommand::DirectChat(user.clone(), internal_id.clone())).unwrap();
self.backend.send(BKCommand::DirectChat(user.0.clone(), internal_id.clone())).unwrap();
self.close_direct_chat_dialog();
let mut fakeroom = Room::new(internal_id.clone(), user.alias.clone());
let mut fakeroom = Room::new(internal_id.clone(), user.0.alias.clone());
fakeroom.direct = true;
self.new_room(fakeroom, 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