Commit d7b877c9 authored by Daniel García Moreno's avatar Daniel García Moreno

Accept and reject invitation working

parent 45a37dda
......@@ -198,6 +198,14 @@ impl Backend {
let r = room::search(self, roomid, term);
bkerror!(r, tx, BKResponse::SearchError);
}
Ok(BKCommand::AcceptInv(roomid)) => {
let r = room::join_room(self, roomid);
bkerror!(r, tx, BKResponse::AcceptInvError);
}
Ok(BKCommand::RejectInv(roomid)) => {
let r = room::leave_room(self, roomid);
bkerror!(r, tx, BKResponse::RejectInvError);
}
// Media module
......
......@@ -47,6 +47,8 @@ pub enum BKCommand {
Search(String, Option<String>),
NewRoom(String, RoomType),
AddToFav(String, bool),
AcceptInv(String),
RejectInv(String),
}
#[derive(Debug)]
......@@ -111,6 +113,8 @@ pub enum BKResponse {
SearchError(Error),
NewRoomError(Error),
AddToFavError(Error),
AcceptInvError(Error),
RejectInvError(Error),
}
#[derive(Debug)]
......
use std::collections::HashMap;
use model::message::Message;
use model::member::MemberList;
use model::member::Member;
#[derive(Debug, Serialize, Deserialize)]
pub struct Room {
......@@ -17,8 +18,9 @@ pub struct Room {
pub highlight: i32,
pub messages: Vec<Message>,
pub fav: bool,
pub inv: bool,
pub left: bool,
pub inv: bool,
pub inv_sender: Option<Member>,
}
impl Room {
......@@ -37,8 +39,9 @@ impl Room {
messages: vec![],
members: HashMap::new(),
fav: false,
inv: false,
left: false,
inv: false,
inv_sender: None,
}
}
}
......@@ -59,8 +62,9 @@ impl Clone for Room {
messages: self.messages.iter().cloned().collect(),
members: self.members.clone(),
fav: self.fav,
inv: self.inv,
left: self.left,
inv: self.inv,
inv_sender: self.inv_sender.clone(),
}
}
}
......
......@@ -274,6 +274,21 @@ pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<V
r.alias = Some(evc(stevents, "m.room.canonical_alias", "alias"));
r.topic = Some(evc(stevents, "m.room.topic", "topic"));
if let Some(arr) = stevents.as_array() {
if let Some(ev) = arr.iter()
.find(|x| x["membership"] == "invite" && x["state_key"] == userid) {
if let Ok((alias, avatar)) = get_user_avatar(baseu, ev["sender"].as_str().unwrap_or_default()) {
r.inv_sender = Some(
Member {
alias: Some(alias),
avatar: Some(avatar),
uid: strn!(userid),
}
);
}
}
}
rooms.push(r);
}
......
......@@ -19,6 +19,76 @@
<mime-type>image/gif</mime-type>
</mime-types>
</object>
<object class="GtkMessageDialog" id="invite_dialog">
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="urgency_hint">True</property>
<property name="deletable">False</property>
<property name="gravity">center</property>
<property name="transient_for">main_window</property>
<property name="attached_to">main_window</property>
<property name="message_type">question</property>
<property name="text" translatable="yes">Invitation</property>
<property name="secondary_text" translatable="yes">You've been invited to join to "", you can accept or reject</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
<property name="layout_style">expand</property>
<child>
<object class="GtkButton" id="invite_accept">
<property name="label" translatable="yes">Accept</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="invite_reject">
<property name="label" translatable="yes">Reject</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<style>
<class name="destructive-action"/>
</style>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<child>
<placeholder/>
</child>
<style>
<class name="leave-room"/>
</style>
</object>
<object class="GtkPopoverMenu" id="members_popover">
<property name="can_focus">False</property>
<child>
......
......@@ -671,8 +671,7 @@ impl AppOp {
if let Some(r) = room {
if r.inv {
//TODO: show invitation accept/reject dialog
println!("INVITATION: {}, {:?}", r.id, r.name);
self.show_inv_dialog(&r);
return;
}
......@@ -680,6 +679,55 @@ impl AppOp {
}
}
pub fn show_inv_dialog(&self, r: &Room) {
let dialog = self.gtk_builder
.get_object::<gtk::MessageDialog>("invite_dialog")
.expect("Can't find invite_dialog in ui file.");
let room_name = r.name.clone().unwrap_or_default();
let title = format!("Join to {}?", room_name);
let secondary;
if let Some(ref sender) = r.inv_sender {
let sender_name = sender.get_alias().unwrap_or(sender.uid.clone());
secondary = format!("You've been invited to join to \"{}\" room by \"{}\"",
room_name, sender_name);
} else {
secondary = format!("You've been invited to join to \"{}\"", room_name);
}
dialog.set_property_text(Some(&title));
dialog.set_property_secondary_text(Some(&secondary));
let accept = self.gtk_builder
.get_object::<gtk::Button>("invite_accept")
.expect("Can't find invite_accept in ui file.");
let reject = self.gtk_builder
.get_object::<gtk::Button>("invite_reject")
.expect("Can't find invite_reject in ui file.");
let bk = self.backend.clone();
let rid = r.id.clone();
let internal = self.internal.clone();
reject.connect_clicked(clone!(dialog, rid, bk, internal => move |_| {
bk.send(BKCommand::RejectInv(rid.clone())).unwrap();
internal.send(InternalCommand::RemoveInv(rid.clone())).unwrap();
dialog.hide();
}));
accept.connect_clicked(clone!(dialog, rid, bk, internal => move |_| {
bk.send(BKCommand::AcceptInv(rid.clone())).unwrap();
internal.send(InternalCommand::RemoveInv(rid.clone())).unwrap();
dialog.hide();
}));
dialog.present();
}
pub fn remove_inv(&mut self, roomid: String) {
self.rooms.remove(&roomid);
self.roomlist.remove_room(roomid);
}
pub fn set_active_room(&mut self, room: &Room) {
self.member_limit = 50;
self.room_panel(RoomPanel::Loading);
......@@ -2375,6 +2423,7 @@ pub enum InternalCommand {
NotifyClicked(Message),
SelectRoom(Room),
LoadMoreNormal,
RemoveInv(String),
}
......@@ -2399,6 +2448,9 @@ fn appop_loop(rx: Receiver<InternalCommand>) {
Ok(InternalCommand::LoadMoreNormal) => {
APPOP!(load_more_normal);
}
Ok(InternalCommand::RemoveInv(rid)) => {
APPOP!(remove_inv, (rid));
}
Err(_) => {
break;
}
......
......@@ -481,6 +481,7 @@ impl RoomList {
pub fn remove_room(&mut self, room: String) -> Option<RoomUpdated> {
run_in_group!(self, &room, remove_room, room)
self.show_and_hide();
}
pub fn set_bold(&mut self, room: String, bold: bool) {
......
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