From 26d10d1dcb95f11b65611473c9840e13683cb5ec Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 4 Nov 2021 17:33:08 +0100 Subject: Add multiparty call support to libdino and xmpp-vala --- libdino/src/service/call_state.vala | 302 ++++++++++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 libdino/src/service/call_state.vala (limited to 'libdino/src/service/call_state.vala') diff --git a/libdino/src/service/call_state.vala b/libdino/src/service/call_state.vala new file mode 100644 index 00000000..385cf9dc --- /dev/null +++ b/libdino/src/service/call_state.vala @@ -0,0 +1,302 @@ +using Dino.Entities; +using Gee; +using Xmpp; + +public class Dino.CallState : Object { + + public signal void terminated(Jid who_terminated, string? reason_name, string? reason_text); + public signal void peer_joined(Jid jid, PeerState peer_state); + public signal void peer_left(Jid jid, PeerState peer_state, string? reason_name, string? reason_text); + + public StreamInteractor stream_interactor; + public Call call; + public Xep.Muji.GroupCall? group_call { get; set; } + public Jid? invited_to_group_call = null; + public Jid? group_call_inviter = null; + public bool accepted { get; private set; default=false; } + + public bool we_should_send_audio { get; set; default=false; } + public bool we_should_send_video { get; set; default=false; } + public HashMap peers = new HashMap(Jid.hash_func, Jid.equals_func); + + public CallState(Call call, StreamInteractor stream_interactor) { + this.call = call; + this.stream_interactor = stream_interactor; + + if (call.direction == Call.DIRECTION_OUTGOING) { + accepted = true; + + Timeout.add_seconds(30, () => { + if (this == null) return false; // TODO enough? + if (call.state == Call.State.ESTABLISHING) { + call.state = Call.State.MISSED; + terminated(call.account.bare_jid, null, null); + } + return false; + }); + } + } + + internal PeerState set_first_peer(Jid peer) { + var peer_state = new PeerState(peer, call, stream_interactor); + peer_state.first_peer = true; + add_peer(peer_state); + return peer_state; + } + + internal void add_peer(PeerState peer) { + call.add_peer(peer.jid.bare_jid); + connect_peer_signals(peer); + peer_joined(peer.jid, peer); + } + + public void accept() { + accepted = true; + call.state = Call.State.ESTABLISHING; + + if (invited_to_group_call != null) { + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_accept_to_peer(stream, group_call_inviter, invited_to_group_call); + join_group_call.begin(invited_to_group_call); + } else { + foreach (PeerState peer in peers.values) { + peer.accept(); + } + } + } + + public void reject() { + call.state = Call.State.DECLINED; + + if (invited_to_group_call != null) { + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_reject_to_self(stream, invited_to_group_call); + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_reject_to_peer(stream, group_call_inviter, invited_to_group_call); + } + var peers_cpy = new ArrayList(); + peers_cpy.add_all(peers.values); + foreach (PeerState peer in peers_cpy) { + peer.reject(); + } + terminated(call.account.bare_jid, null, null); + } + + public void end() { + var peers_cpy = new ArrayList(); + peers_cpy.add_all(peers.values); + + if (call.state == Call.State.IN_PROGRESS || call.state == Call.State.ESTABLISHING) { + foreach (PeerState peer in peers_cpy) { + peer.end(Xep.Jingle.ReasonElement.SUCCESS); + } + call.state = Call.State.ENDED; + } else if (call.state == Call.State.RINGING) { + foreach (PeerState peer in peers_cpy) { + peer.end(Xep.Jingle.ReasonElement.CANCEL); + } + call.state = Call.State.MISSED; + } else { + return; + } + + call.end_time = new DateTime.now_utc(); + + terminated(call.account.bare_jid, null, null); + } + + public void mute_own_audio(bool mute) { + we_should_send_audio = !mute; + foreach (PeerState peer in peers.values) { + peer.mute_own_audio(mute); + } + } + + public void mute_own_video(bool mute) { + we_should_send_video = !mute; + foreach (PeerState peer in peers.values) { + peer.mute_own_video(mute); + } + } + + public bool should_we_send_video() { + return we_should_send_video; + } + + public async void invite_to_call(Jid invitee) { + if (this.group_call == null) yield convert_into_group_call(); + if (this.group_call == null) return; + + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + + debug("[%s] Inviting to muji call %s", call.account.bare_jid.to_string(), invitee.to_string()); + yield stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation(stream, group_call.muc_jid, invitee, null, "owner"); + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite(stream, invitee, group_call.muc_jid, we_should_send_video); + + // If the peer hasn't accepted within a minute, retract the invite + Timeout.add_seconds(60, () => { + if (this == null) return false; + + bool contains_peer = false; + foreach (Jid peer in peers.keys) { + if (peer.equals_bare(invitee)) { + contains_peer = true; + } + } + + if (!contains_peer) { + debug("[%s] Retracting invite to %s from %s", call.account.bare_jid.to_string(), group_call.muc_jid.to_string(), invitee.to_string()); + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_retract_to_peer(stream, invitee, group_call.muc_jid); + stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation.begin(stream, group_call.muc_jid, invitee, null, "none"); + } + return false; + }); + } + + internal void rename_peer(Jid from_jid, Jid to_jid) { + debug("[%s] Renaming %s to %s exists %b", call.account.bare_jid.to_string(), from_jid.to_string(), to_jid.to_string(), peers.has_key(from_jid)); + PeerState? peer_state = peers[from_jid]; + if (peer_state == null) return; + + // Adjust the internal mapping of this `PeerState` object + peers.unset(from_jid); + peers[to_jid] = peer_state; + peer_state.jid = to_jid; + } + + private void on_call_terminated(Jid who_terminated, bool we_terminated, string? reason_name, string? reason_text) { + if (call.state == Call.State.RINGING || call.state == Call.State.IN_PROGRESS || call.state == Call.State.ESTABLISHING) { + call.end_time = new DateTime.now_utc(); + } + if (call.state == Call.State.IN_PROGRESS) { + call.state = Call.State.ENDED; + } else if (call.state == Call.State.RINGING || call.state == Call.State.ESTABLISHING) { + if (reason_name == Xep.Jingle.ReasonElement.DECLINE) { + call.state = Call.State.DECLINED; + } else { + call.state = Call.State.FAILED; + } + } + + terminated(who_terminated, reason_name, reason_text); + } + + private void connect_peer_signals(PeerState peer_state) { + peers[peer_state.jid] = peer_state; + + this.bind_property("we-should-send-audio", peer_state, "we-should-send-audio", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + this.bind_property("we-should-send-video", peer_state, "we-should-send-video", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + this.bind_property("group-call", peer_state, "group-call", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + + peer_state.session_terminated.connect((we_terminated, reason_name, reason_text) => { + peers.unset(peer_state.jid); + debug("[%s] Peer left %s left %i", call.account.bare_jid.to_string(), peer_state.jid.to_string(), peers.size); + + if (peers.is_empty) { + if (group_call != null) group_call.leave(stream_interactor.get_stream(call.account)); + on_call_terminated(peer_state.jid, we_terminated, reason_name, reason_text); + } else { + peer_left(peer_state.jid, peer_state, reason_name, reason_text); + } + }); + } + + public async void convert_into_group_call() { + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + + Jid muc_jid = stream_interactor.get_module(MucManager.IDENTITY).default_muc_server[call.account] ?? new Jid("chat.jabberfr.org"); + muc_jid = new Jid("%08x@".printf(Random.next_int()) + muc_jid.to_string()); // TODO longer? + + debug("[%s] Converting call to groupcall %s", call.account.bare_jid.to_string(), muc_jid.to_string()); + yield join_group_call(muc_jid); + + Xep.DataForms.DataForm? data_form = yield stream_interactor.get_module(MucManager.IDENTITY).get_config_form(call.account, muc_jid); + if (data_form == null) return; + + foreach (Xep.DataForms.DataForm.Field field in data_form.fields) { + switch (field.var) { + case "muc#roomconfig_allowinvites": + if (field.type_ == Xep.DataForms.DataForm.Type.BOOLEAN) { + ((Xep.DataForms.DataForm.BooleanField) field).value = true; + } + break; + case "muc#roomconfig_persistentroom": + if (field.type_ == Xep.DataForms.DataForm.Type.BOOLEAN) { + ((Xep.DataForms.DataForm.BooleanField) field).value = false; + } + break; + case "muc#roomconfig_membersonly": + if (field.type_ == Xep.DataForms.DataForm.Type.BOOLEAN) { + ((Xep.DataForms.DataForm.BooleanField) field).value = true; + } + break; + case "muc#roomconfig_whois": + if (field.type_ == Xep.DataForms.DataForm.Type.LIST_SINGLE) { + ((Xep.DataForms.DataForm.ListSingleField) field).value = "anyone"; + } + break; + } + } + yield stream_interactor.get_module(MucManager.IDENTITY).set_config_form(call.account, muc_jid, data_form); + + foreach (Jid peer_jid in peers.keys) { + debug("[%s] Group call inviting %s", call.account.bare_jid.to_string(), peer_jid.to_string()); + yield invite_to_call(peer_jid); + } + } + + public async void join_group_call(Jid muc_jid) { + debug("[%s] Joining group call %s", call.account.bare_jid.to_string(), muc_jid.to_string()); + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + + this.group_call = yield stream.get_module(Xep.Muji.Module.IDENTITY).join_call(stream, muc_jid, we_should_send_video); + if (this.group_call == null) { + warning("[%s] Couldn't join MUJI MUC", call.account.bare_jid.to_string()); + return; + } + + this.group_call.peer_joined.connect((jid) => { + debug("[%s] Group call peer joined: %s", call.account.bare_jid.to_string(), jid.to_string()); + + // Newly joined peers have to call us, not the other way round + // Maybe they called us already. Accept the call. + // (Except for the first peer, we already have a connection to that one.) + if (peers.has_key(jid)) { + if (!peers[jid].first_peer) { + peers[jid].accept(); + } + // else: Connection to first peer already active + } else { + var peer_state = new PeerState(jid, call, stream_interactor); + peer_state.waiting_for_inbound_muji_connection = true; + debug("[%s] Waiting for call from %s", call.account.bare_jid.to_string(), jid.to_string()); + add_peer(peer_state); + } + }); + + this.group_call.peer_left.connect((jid) => { + debug("[%s] Group call peer left: %s", call.account.bare_jid.to_string(), jid.to_string()); + if (!peers.has_key(jid)) return; + // end() will in the end cause a `peer_left` signal and removal from `peers` + peers[jid].end(Xep.Jingle.ReasonElement.CANCEL, "Peer left the MUJI MUC"); + }); + + // Call all peers that are in the room already + foreach (Jid peer_jid in group_call.peers_to_connect_to) { + // Don't establish connection if we have one already (the person that invited us to the call) + if (peers.has_key(peer_jid)) continue; + + debug("[%s] Calling %s because they were in the MUC already", call.account.bare_jid.to_string(), peer_jid.to_string()); + + PeerState peer_state = new PeerState(peer_jid, call, stream_interactor); + add_peer(peer_state); + peer_state.call_resource.begin(peer_jid); + } + + debug("[%s] Finished joining MUJI muc %s", call.account.bare_jid.to_string(), muc_jid.to_string()); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 78bb2bbddaf587de77f67c404e8ed5083f16bf8a Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 18 Dec 2021 21:34:39 +0100 Subject: Add calls in private MUCs via a MUJI MUC --- libdino/src/entity/call.vala | 13 +++-- libdino/src/service/call_state.vala | 39 +++++++++++++- libdino/src/service/calls.vala | 62 +++++++++++++++++------ main/src/ui/conversation_titlebar/call_entry.vala | 18 +++---- xmpp-vala/src/module/xep/muji_meta.vala | 36 ++++++------- 5 files changed, 116 insertions(+), 52 deletions(-) (limited to 'libdino/src/service/call_state.vala') diff --git a/libdino/src/entity/call.vala b/libdino/src/entity/call.vala index 5221a807..3b48f664 100644 --- a/libdino/src/entity/call.vala +++ b/libdino/src/entity/call.vala @@ -39,11 +39,6 @@ namespace Dino.Entities { id = row[db.call.id]; account = db.get_account_by_id(row[db.call.account_id]); - counterpart = db.get_jid_by_id(row[db.call.counterpart_id]); - string counterpart_resource = row[db.call.counterpart_resource]; - if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); - counterparts.add(counterpart); - string our_resource = row[db.call.our_resource]; if (our_resource != null) { ourpart = account.bare_jid.with_resource(our_resource); @@ -66,6 +61,14 @@ namespace Dino.Entities { if (counterpart == null) counterpart = peer; } + counterpart = db.get_jid_by_id(row[db.call.counterpart_id]); + string counterpart_resource = row[db.call.counterpart_resource]; + if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); + if (counterparts.is_empty) { + counterparts.add(counterpart); + counterpart = counterpart; + } + notify.connect(on_update); } diff --git a/libdino/src/service/call_state.vala b/libdino/src/service/call_state.vala index 385cf9dc..51563552 100644 --- a/libdino/src/service/call_state.vala +++ b/libdino/src/service/call_state.vala @@ -11,6 +11,7 @@ public class Dino.CallState : Object { public StreamInteractor stream_interactor; public Call call; public Xep.Muji.GroupCall? group_call { get; set; } + public Jid? parent_muc { get; set; } public Jid? invited_to_group_call = null; public Jid? group_call_inviter = null; public bool accepted { get; private set; default=false; } @@ -19,6 +20,8 @@ public class Dino.CallState : Object { public bool we_should_send_video { get; set; default=false; } public HashMap peers = new HashMap(Jid.hash_func, Jid.equals_func); + private string message_type = Xmpp.MessageStanza.TYPE_CHAT; + public CallState(Call call, StreamInteractor stream_interactor) { this.call = call; this.stream_interactor = stream_interactor; @@ -37,6 +40,29 @@ public class Dino.CallState : Object { } } + internal async void initiate_groupchat_call(Jid muc) { + parent_muc = muc; + message_type = Xmpp.MessageStanza.TYPE_GROUPCHAT; + + if (this.group_call == null) yield convert_into_group_call(); + if (this.group_call == null) return; + // The user might have retracted the call in the meanwhile + if (this.call.state != Call.State.RINGING) return; + + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + + Gee.List occupants = stream_interactor.get_module(MucManager.IDENTITY).get_other_occupants(muc, call.account); + foreach (Jid occupant in occupants) { + Jid? real_jid = stream_interactor.get_module(MucManager.IDENTITY).get_real_jid(occupant, call.account); + if (real_jid == null) continue; + debug(@"Adding MUC member as MUJI MUC owner %s", real_jid.bare_jid.to_string()); + yield stream.get_module(Xep.Muc.Module.IDENTITY).change_affiliation(stream, group_call.muc_jid, real_jid.bare_jid, null, "owner"); + } + + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite(stream, muc, group_call.muc_jid, we_should_send_video, message_type); + } + internal PeerState set_first_peer(Jid peer) { var peer_state = new PeerState(peer, call, stream_interactor); peer_state.first_peer = true; @@ -57,7 +83,7 @@ public class Dino.CallState : Object { if (invited_to_group_call != null) { XmppStream stream = stream_interactor.get_stream(call.account); if (stream == null) return; - stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_accept_to_peer(stream, group_call_inviter, invited_to_group_call); + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_accept_to_peer(stream, group_call_inviter, invited_to_group_call, message_type); join_group_call.begin(invited_to_group_call); } else { foreach (PeerState peer in peers.values) { @@ -73,7 +99,7 @@ public class Dino.CallState : Object { XmppStream stream = stream_interactor.get_stream(call.account); if (stream == null) return; stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_reject_to_self(stream, invited_to_group_call); - stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_reject_to_peer(stream, group_call_inviter, invited_to_group_call); + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_reject_to_peer(stream, group_call_inviter, invited_to_group_call, message_type); } var peers_cpy = new ArrayList(); peers_cpy.add_all(peers.values); @@ -87,6 +113,10 @@ public class Dino.CallState : Object { var peers_cpy = new ArrayList(); peers_cpy.add_all(peers.values); + if (group_call != null) { + stream_interactor.get_module(MucManager.IDENTITY).part(call.account, group_call.muc_jid); + } + if (call.state == Call.State.IN_PROGRESS || call.state == Call.State.ESTABLISHING) { foreach (PeerState peer in peers_cpy) { peer.end(Xep.Jingle.ReasonElement.SUCCESS); @@ -96,6 +126,11 @@ public class Dino.CallState : Object { foreach (PeerState peer in peers_cpy) { peer.end(Xep.Jingle.ReasonElement.CANCEL); } + if (parent_muc != null) { + XmppStream stream = stream_interactor.get_stream(call.account); + if (stream == null) return; + stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_retract_to_peer(stream, parent_muc, group_call.muc_jid, message_type); + } call.state = Call.State.MISSED; } else { return; diff --git a/libdino/src/service/calls.vala b/libdino/src/service/calls.vala index 3d1ed7e8..629d8074 100644 --- a/libdino/src/service/calls.vala +++ b/libdino/src/service/calls.vala @@ -39,7 +39,8 @@ namespace Dino { Call call = new Call(); call.direction = Call.DIRECTION_OUTGOING; call.account = conversation.account; - call.add_peer(conversation.counterpart); + // TODO we should only do that for Conversation.Type.CHAT, but the database currently requires a counterpart from the start + call.counterpart = conversation.counterpart; call.ourpart = conversation.account.full_jid; call.time = call.local_time = call.end_time = new DateTime.now_utc(); call.state = Call.State.RINGING; @@ -50,9 +51,14 @@ namespace Dino { call_state.we_should_send_video = video; call_state.we_should_send_audio = true; connect_call_state_signals(call_state); - PeerState peer_state = call_state.set_first_peer(conversation.counterpart); - yield peer_state.initiate_call(conversation.counterpart); + if (conversation.type_ == Conversation.Type.CHAT) { + call.add_peer(conversation.counterpart); + PeerState peer_state = call_state.set_first_peer(conversation.counterpart); + yield peer_state.initiate_call(conversation.counterpart); + } else { + call_state.initiate_groupchat_call(conversation.counterpart); + } conversation.last_active = call.time; @@ -63,7 +69,12 @@ namespace Dino { public async bool can_do_audio_calls_async(Conversation conversation) { if (!can_do_audio_calls()) return false; - return (yield get_call_resources(conversation.account, conversation.counterpart)).size > 0 || has_jmi_resources(conversation.counterpart); + + if (conversation.type_ == Conversation.Type.CHAT) { + return (yield get_call_resources(conversation.account, conversation.counterpart)).size > 0 || has_jmi_resources(conversation.counterpart); + } else { + return stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart); + } } private bool can_do_audio_calls() { @@ -75,7 +86,12 @@ namespace Dino { public async bool can_do_video_calls_async(Conversation conversation) { if (!can_do_video_calls()) return false; - return (yield get_call_resources(conversation.account, conversation.counterpart)).size > 0 || has_jmi_resources(conversation.counterpart); + + if (conversation.type_ == Conversation.Type.CHAT) { + return (yield get_call_resources(conversation.account, conversation.counterpart)).size > 0 || has_jmi_resources(conversation.counterpart); + } else { + return stream_interactor.get_module(MucManager.IDENTITY).is_private_room(conversation.account, conversation.counterpart); + } } private bool can_do_video_calls() { @@ -237,17 +253,24 @@ namespace Dino { private CallState? get_call_state_for_groupcall(Account account, Jid muc_jid) { foreach (CallState call_state in call_states.values) { - if (call_state.group_call != null && call_state.call.account.equals(account) && call_state.group_call.muc_jid.equals(muc_jid)) { - return call_state; - } + if (!call_state.call.account.equals(account)) continue; + + if (call_state.group_call != null && call_state.group_call.muc_jid.equals(muc_jid)) return call_state; + if (call_state.invited_to_group_call != null && call_state.invited_to_group_call.equals(muc_jid)) return call_state; } return null; } - private async void on_muji_call_received(Account account, Jid inviter_jid, Jid muc_jid, Gee.List descriptions) { - debug("[%s] on_muji_call_received", account.bare_jid.to_string()); + private async void on_muji_call_received(Account account, Jid inviter_jid, Jid muc_jid, Gee.List descriptions, string message_type) { + debug("[%s] Muji call received from %s for MUC %s, type %s", account.bare_jid.to_string(), inviter_jid.to_string(), muc_jid.to_string(), message_type); + foreach (Call call in call_states.keys) { - if (call.account.equals(account) && call.counterparts.contains(inviter_jid) && call_states[call].accepted) { + if (!call.account.equals(account)) return; + + // We already know the call; this is a reflection of our own invite + if (call_states[call].parent_muc.equals_bare(inviter_jid)) return; + + if (call.counterparts.contains(inviter_jid) && call_states[call].accepted) { // A call is converted into a group call. yield call_states[call].join_group_call(muc_jid); return; @@ -373,11 +396,11 @@ namespace Dino { }); Xep.MujiMeta.Module muji_meta_module = stream_interactor.module_manager.get_module(account, Xep.MujiMeta.Module.IDENTITY); - muji_meta_module.call_proposed.connect((inviter_jid, to, muc_jid, descriptions) => { + muji_meta_module.call_proposed.connect((inviter_jid, to, muc_jid, descriptions, message_type) => { if (inviter_jid.equals_bare(account.bare_jid)) return; - on_muji_call_received.begin(account, inviter_jid, muc_jid, descriptions); + on_muji_call_received.begin(account, inviter_jid, muc_jid, descriptions, message_type); }); - muji_meta_module.call_accepted.connect((from_jid, muc_jid) => { + muji_meta_module.call_accepted.connect((from_jid, muc_jid, message_type) => { if (!from_jid.equals_bare(account.bare_jid)) return; // We accepted the call from another device @@ -387,17 +410,24 @@ namespace Dino { call_state.call.state = Call.State.OTHER_DEVICE; remove_call_from_datastructures(call_state.call); }); - muji_meta_module.call_retracted.connect((from_jid, muc_jid) => { + muji_meta_module.call_retracted.connect((from_jid, to_jid, muc_jid, message_type) => { if (from_jid.equals_bare(account.bare_jid)) return; // The call was retracted by the counterpart CallState? call_state = get_call_state_for_groupcall(account, muc_jid); if (call_state == null) return; + if (call_state.call.state != Call.State.RINGING) { + debug("%s tried to retract a call that's in state %s. Ignoring.", from_jid.to_string(), call_state.call.state.to_string()); + return; + } + + // TODO prevent other MUC occupants from retracting a call + call_state.call.state = Call.State.MISSED; remove_call_from_datastructures(call_state.call); }); - muji_meta_module.call_rejected.connect((from_jid, to_jid, muc_jid) => { + muji_meta_module.call_rejected.connect((from_jid, to_jid, muc_jid, message_type) => { if (from_jid.equals_bare(account.bare_jid)) return; debug(@"[%s] rejected our MUJI invite to %s", account.bare_jid.to_string(), from_jid.to_string(), muc_jid.to_string()); }); diff --git a/main/src/ui/conversation_titlebar/call_entry.vala b/main/src/ui/conversation_titlebar/call_entry.vala index 3b3a5b39..3fa399a6 100644 --- a/main/src/ui/conversation_titlebar/call_entry.vala +++ b/main/src/ui/conversation_titlebar/call_entry.vala @@ -115,17 +115,13 @@ namespace Dino.Ui { return; } - if (conversation.type_ == Conversation.Type.CHAT) { - Conversation conv_bak = conversation; - bool audio_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_audio_calls_async(conversation); - bool video_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_video_calls_async(conversation); - if (conv_bak != conversation) return; - - visible = audio_works; - video_button.visible = video_works; - } else { - visible = false; - } + Conversation conv_bak = conversation; + bool audio_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_audio_calls_async(conversation); + bool video_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_video_calls_async(conversation); + if (conv_bak != conversation) return; + + visible = audio_works; + video_button.visible = video_works; } public new void unset_conversation() { } diff --git a/xmpp-vala/src/module/xep/muji_meta.vala b/xmpp-vala/src/module/xep/muji_meta.vala index 4452e611..89a0e8de 100644 --- a/xmpp-vala/src/module/xep/muji_meta.vala +++ b/xmpp-vala/src/module/xep/muji_meta.vala @@ -6,48 +6,48 @@ namespace Xmpp.Xep.MujiMeta { public class Module : XmppStreamModule { public static ModuleIdentity IDENTITY = new ModuleIdentity(NS_URI, "muji_meta"); - public signal void call_proposed(Jid from, Jid to, Jid muc_jid, Gee.List descriptions); - public signal void call_retracted(Jid from, Jid to, Jid muc_jid); - public signal void call_accepted(Jid from, Jid muc_jid); - public signal void call_rejected(Jid from, Jid to, Jid muc_jid); + public signal void call_proposed(Jid from, Jid to, Jid muc_jid, Gee.List descriptions, string message_type); + public signal void call_retracted(Jid from, Jid to, Jid muc_jid, string message_type); + public signal void call_accepted(Jid from, Jid muc_jid, string message_type); + public signal void call_rejected(Jid from, Jid to, Jid muc_jid, string message_type); - public void send_invite(XmppStream stream, Jid invitee, Jid muc_jid, bool video) { + public void send_invite(XmppStream stream, Jid invitee, Jid muc_jid, bool video, string? message_type = null) { var invite_node = new StanzaNode.build("propose", NS_URI).put_attribute("muc", muc_jid.to_string()); invite_node.put_node(new StanzaNode.build("description", Xep.JingleRtp.NS_URI).add_self_xmlns().put_attribute("media", "audio")); if (video) { invite_node.put_node(new StanzaNode.build("description", Xep.JingleRtp.NS_URI).add_self_xmlns().put_attribute("media", "video")); } var muji_node = new StanzaNode.build("muji", NS_URI).add_self_xmlns().put_node(invite_node); - MessageStanza invite_message = new MessageStanza() { to=invitee, type_=MessageStanza.TYPE_CHAT }; + MessageStanza invite_message = new MessageStanza() { to=invitee, type_=message_type }; invite_message.stanza.put_node(muji_node); stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message); } - public void send_invite_retract_to_peer(XmppStream stream, Jid invitee, Jid muc_jid) { - send_jmi_message(stream, "retract", invitee, muc_jid); + public void send_invite_retract_to_peer(XmppStream stream, Jid invitee, Jid muc_jid, string? message_type = null) { + send_jmi_message(stream, "retract", invitee, muc_jid, message_type); } - public void send_invite_accept_to_peer(XmppStream stream, Jid invitor, Jid muc_jid) { - send_jmi_message(stream, "accept", invitor, muc_jid); + public void send_invite_accept_to_peer(XmppStream stream, Jid invitor, Jid muc_jid, string? message_type = null) { + send_jmi_message(stream, "accept", invitor, muc_jid, message_type); } public void send_invite_accept_to_self(XmppStream stream, Jid muc_jid) { send_jmi_message(stream, "accept", Bind.Flag.get_my_jid(stream).bare_jid, muc_jid); } - public void send_invite_reject_to_peer(XmppStream stream, Jid invitor, Jid muc_jid) { - send_jmi_message(stream, "reject", invitor, muc_jid); + public void send_invite_reject_to_peer(XmppStream stream, Jid invitor, Jid muc_jid, string? message_type = null) { + send_jmi_message(stream, "reject", invitor, muc_jid, message_type); } public void send_invite_reject_to_self(XmppStream stream, Jid muc_jid) { send_jmi_message(stream, "reject", Bind.Flag.get_my_jid(stream).bare_jid, muc_jid); } - private void send_jmi_message(XmppStream stream, string name, Jid to, Jid muc) { + private void send_jmi_message(XmppStream stream, string name, Jid to, Jid muc, string? message_type = null) { var jmi_node = new StanzaNode.build(name, NS_URI).add_self_xmlns().put_attribute("muc", muc.to_string()); var muji_node = new StanzaNode.build("muji", NS_URI).add_self_xmlns().put_node(jmi_node); - MessageStanza accepted_message = new MessageStanza() { to=to, type_=MessageStanza.TYPE_CHAT }; + MessageStanza accepted_message = new MessageStanza() { to=to, type_= message_type ?? MessageStanza.TYPE_CHAT }; accepted_message.stanza.put_node(muji_node); stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, accepted_message); } @@ -80,7 +80,7 @@ namespace Xmpp.Xep.MujiMeta { switch (mi_node.name) { case "accept": case "proceed": - call_accepted(message.from, muc_jid); + call_accepted(message.from, muc_jid, message.type_); break; case "propose": ArrayList descriptions = new ArrayList(); @@ -91,14 +91,14 @@ namespace Xmpp.Xep.MujiMeta { } if (descriptions.size > 0) { - call_proposed(message.from, message.to, muc_jid, descriptions); + call_proposed(message.from, message.to, muc_jid, descriptions, message.type_); } break; case "retract": - call_retracted(message.from, message.to, muc_jid); + call_retracted(message.from, message.to, muc_jid, message.type_); break; case "reject": - call_rejected(message.from, message.to, muc_jid); + call_rejected(message.from, message.to, muc_jid, message.type_); break; } } -- cgit v1.2.3-54-g00ecf From f0c7dd0682fec8d72c644d8e54896de7bdc40ddb Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 20 Dec 2021 00:15:05 +0100 Subject: UI + libdino: Improve MUJI calls from MUC - Move calls from ICE-thead onto main thread - Identify Call.ourpart as MUC nick if in MUC - Keep track of the initiator of a call --- libdino/src/entity/call.vala | 9 ++++---- libdino/src/service/call_peer_state.vala | 14 +++++++++---- libdino/src/service/call_state.vala | 9 ++++++-- libdino/src/service/call_store.vala | 9 +++++--- libdino/src/service/calls.vala | 24 ++++++++++++---------- libdino/src/service/content_item_store.vala | 4 ++-- libdino/src/service/muc_manager.vala | 2 +- main/data/call_widget.ui | 2 +- main/src/ui/application.vala | 18 ++++++++++++---- main/src/ui/call_window/call_window.vala | 2 +- .../ui/conversation_content_view/call_widget.vala | 2 +- main/src/ui/conversation_titlebar/call_entry.vala | 18 +++++++++------- main/src/ui/notifier_freedesktop.vala | 6 ++++-- 13 files changed, 75 insertions(+), 44 deletions(-) (limited to 'libdino/src/service/call_state.vala') diff --git a/libdino/src/entity/call.vala b/libdino/src/entity/call.vala index 3b48f664..8e5bc246 100644 --- a/libdino/src/entity/call.vala +++ b/libdino/src/entity/call.vala @@ -20,9 +20,12 @@ namespace Dino.Entities { public int id { get; set; default=-1; } public Account account { get; set; } - public Jid counterpart { get; set; } // For backwards compatibility with db version 21. Not to be used anymore. + public Jid counterpart { get; set; } public Gee.List counterparts = new Gee.ArrayList(Jid.equals_bare_func); public Jid ourpart { get; set; } + public Jid proposer { + get { return direction == DIRECTION_OUTGOING ? ourpart : counterpart; } + } public bool direction { get; set; } public DateTime time { get; set; } public DateTime local_time { get; set; } @@ -58,7 +61,6 @@ namespace Dino.Entities { if (!counterparts.contains(peer)) { // Legacy: The first peer is also in the `call` table. Don't add twice. counterparts.add(peer); } - if (counterpart == null) counterpart = peer; } counterpart = db.get_jid_by_id(row[db.call.counterpart_id]); @@ -66,7 +68,6 @@ namespace Dino.Entities { if (counterpart_resource != null) counterpart = counterpart.with_resource(counterpart_resource); if (counterparts.is_empty) { counterparts.add(counterpart); - counterpart = counterpart; } notify.connect(on_update); @@ -107,8 +108,6 @@ namespace Dino.Entities { } public void add_peer(Jid peer) { - if (counterpart == null) counterpart = peer; - if (counterparts.contains(peer)) return; counterparts.add(peer); diff --git a/libdino/src/service/call_peer_state.vala b/libdino/src/service/call_peer_state.vala index 8c4b0930..09440371 100644 --- a/libdino/src/service/call_peer_state.vala +++ b/libdino/src/service/call_peer_state.vala @@ -127,8 +127,6 @@ public class Dino.PeerState : Object { } public void reject() { - call.state = Call.State.DECLINED; - if (session != null) { foreach (Xep.Jingle.Content content in session.contents) { content.reject(); @@ -299,7 +297,12 @@ public class Dino.PeerState : Object { debug(@"[%s] %s connecting content signals %s", call.account.bare_jid.to_string(), jid.to_string(), rtp_content_parameter.media); rtp_content_parameter.stream_created.connect((stream) => on_stream_created(rtp_content_parameter.media, stream)); - rtp_content_parameter.connection_ready.connect((status) => on_connection_ready(content, rtp_content_parameter.media)); + rtp_content_parameter.connection_ready.connect((status) => { + Idle.add(() => { + on_connection_ready(content, rtp_content_parameter.media); + return false; + }); + }); content.senders_modify_incoming.connect((content, proposed_senders) => { if (content.session.senders_include_us(content.senders) != content.session.senders_include_us(proposed_senders)) { @@ -342,7 +345,10 @@ public class Dino.PeerState : Object { if (media == "video" && stream.receiving) { counterpart_sends_video = true; video_content_parameter.connection_ready.connect((status) => { - counterpart_sends_video_updated(false); + Idle.add(() => { + counterpart_sends_video_updated(false); + return false; + }); }); } diff --git a/libdino/src/service/call_state.vala b/libdino/src/service/call_state.vala index 51563552..188a8321 100644 --- a/libdino/src/service/call_state.vala +++ b/libdino/src/service/call_state.vala @@ -126,7 +126,7 @@ public class Dino.CallState : Object { foreach (PeerState peer in peers_cpy) { peer.end(Xep.Jingle.ReasonElement.CANCEL); } - if (parent_muc != null) { + if (parent_muc != null && group_call != null) { XmppStream stream = stream_interactor.get_stream(call.account); if (stream == null) return; stream.get_module(Xep.MujiMeta.Module.IDENTITY).send_invite_retract_to_peer(stream, parent_muc, group_call.muc_jid, message_type); @@ -242,7 +242,12 @@ public class Dino.CallState : Object { XmppStream stream = stream_interactor.get_stream(call.account); if (stream == null) return; - Jid muc_jid = stream_interactor.get_module(MucManager.IDENTITY).default_muc_server[call.account] ?? new Jid("chat.jabberfr.org"); + Jid? muc_jid = null; + if (muc_jid == null) { + warning("Failed to initiate group call: MUC server not known."); + return; + } + muc_jid = new Jid("%08x@".printf(Random.next_int()) + muc_jid.to_string()); // TODO longer? debug("[%s] Converting call to groupcall %s", call.account.bare_jid.to_string(), muc_jid.to_string()); diff --git a/libdino/src/service/call_store.vala b/libdino/src/service/call_store.vala index fa6e63ee..bfc8255f 100644 --- a/libdino/src/service/call_store.vala +++ b/libdino/src/service/call_store.vala @@ -30,7 +30,7 @@ namespace Dino { cache_call(call); } - public Call? get_call_by_id(int id) { + public Call? get_call_by_id(int id, Conversation conversation) { Call? call = calls_by_db_id[id]; if (call != null) { return call; @@ -38,14 +38,17 @@ namespace Dino { RowOption row_option = db.call.select().with(db.call.id, "=", id).row(); - return create_call_from_row_opt(row_option); + return create_call_from_row_opt(row_option, conversation); } - private Call? create_call_from_row_opt(RowOption row_opt) { + private Call? create_call_from_row_opt(RowOption row_opt, Conversation conversation) { if (!row_opt.is_present()) return null; try { Call call = new Call.from_row(db, row_opt.inner); + if (conversation.type_.is_muc_semantic()) { + call.ourpart = conversation.counterpart.with_resource(call.ourpart.resourcepart); + } cache_call(call); return call; } catch (InvalidJidError e) { diff --git a/libdino/src/service/calls.vala b/libdino/src/service/calls.vala index 629d8074..3e2181a5 100644 --- a/libdino/src/service/calls.vala +++ b/libdino/src/service/calls.vala @@ -39,9 +39,8 @@ namespace Dino { Call call = new Call(); call.direction = Call.DIRECTION_OUTGOING; call.account = conversation.account; - // TODO we should only do that for Conversation.Type.CHAT, but the database currently requires a counterpart from the start call.counterpart = conversation.counterpart; - call.ourpart = conversation.account.full_jid; + call.ourpart = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account) ?? conversation.account.full_jid; call.time = call.local_time = call.end_time = new DateTime.now_utc(); call.state = Call.State.RINGING; @@ -57,7 +56,7 @@ namespace Dino { PeerState peer_state = call_state.set_first_peer(conversation.counterpart); yield peer_state.initiate_call(conversation.counterpart); } else { - call_state.initiate_groupchat_call(conversation.counterpart); + call_state.initiate_groupchat_call.begin(conversation.counterpart); } conversation.last_active = call.time; @@ -213,24 +212,23 @@ namespace Dino { private PeerState create_received_call(Account account, Jid from, Jid to, bool video_requested) { Call call = new Call(); - Jid counterpart = null; if (from.equals_bare(account.bare_jid)) { // Call requested by another of our devices call.direction = Call.DIRECTION_OUTGOING; call.ourpart = from; call.state = Call.State.OTHER_DEVICE; - counterpart = to; + call.counterpart = to; } else { call.direction = Call.DIRECTION_INCOMING; call.ourpart = account.full_jid; call.state = Call.State.RINGING; - counterpart = from; + call.counterpart = from; } - call.add_peer(counterpart); + call.add_peer(call.counterpart); call.account = account; call.time = call.local_time = call.end_time = new DateTime.now_utc(); - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(counterpart.bare_jid, account, Conversation.Type.CHAT); + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(call.counterpart.bare_jid, account, Conversation.Type.CHAT); stream_interactor.get_module(CallStore.IDENTITY).add_call(call, conversation); @@ -238,7 +236,7 @@ namespace Dino { var call_state = new CallState(call, stream_interactor); connect_call_state_signals(call_state); - PeerState peer_state = call_state.set_first_peer(counterpart); + PeerState peer_state = call_state.set_first_peer(call.counterpart); call_state.we_should_send_video = video_requested; call_state.we_should_send_audio = true; @@ -283,7 +281,7 @@ namespace Dino { Call call = new Call(); call.direction = Call.DIRECTION_INCOMING; call.ourpart = account.full_jid; - call.add_peer(inviter_jid); // not rly + call.counterpart = inviter_jid; call.account = account; call.time = call.local_time = call.end_time = new DateTime.now_utc(); call.state = Call.State.RINGING; @@ -361,13 +359,14 @@ namespace Dino { if (from.equals(account.full_jid)) return; Call call = current_jmi_request_peer[account].call; + call.ourpart = from; call.state = Call.State.OTHER_DEVICE; remove_call_from_datastructures(call); } else if (from.equals_bare(current_jmi_request_peer[account].jid) && to.equals(account.full_jid)) { // Message from our peer // We proposed the call // We know the full jid of our peer now current_jmi_request_call[account].rename_peer(current_jmi_request_peer[account].jid, from); - current_jmi_request_peer[account].call_resource(from); + current_jmi_request_peer[account].call_resource.begin(from); } }); mi_module.session_rejected.connect((from, to, sid) => { @@ -378,6 +377,9 @@ namespace Dino { bool incoming_reject = call.direction == Call.DIRECTION_INCOMING && from.equals_bare(account.bare_jid); if (!outgoing_reject && !incoming_reject) return; + // We don't care if a single person in a group call rejected the call + if (incoming_reject && call_states[call].group_call != null) return; + call.state = Call.State.DECLINED; call_states[call].terminated(from, Xep.Jingle.ReasonElement.DECLINE, "JMI reject"); remove_call_from_datastructures(call); diff --git a/libdino/src/service/content_item_store.vala b/libdino/src/service/content_item_store.vala index e0102d24..7a8e38b8 100644 --- a/libdino/src/service/content_item_store.vala +++ b/libdino/src/service/content_item_store.vala @@ -69,7 +69,7 @@ public class ContentItemStore : StreamInteractionModule, Object { } break; case 3: - Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(foreign_id); + Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(foreign_id, conversation); if (call != null) { var call_item = new CallItem(call, conversation, row[db.content_item.id]); items.add(call_item); @@ -321,7 +321,7 @@ public class CallItem : ContentItem { public Conversation conversation; public CallItem(Call call, Conversation conversation, int id) { - base(id, TYPE, call.direction == Call.DIRECTION_OUTGOING ? conversation.account.bare_jid : conversation.counterpart, call.time, call.encryption, Message.Marked.NONE); + base(id, TYPE, call.proposer, call.time, call.encryption, Message.Marked.NONE); this.call = call; this.conversation = conversation; diff --git a/libdino/src/service/muc_manager.vala b/libdino/src/service/muc_manager.vala index 8a317a08..05473647 100644 --- a/libdino/src/service/muc_manager.vala +++ b/libdino/src/service/muc_manager.vala @@ -424,7 +424,7 @@ public class MucManager : StreamInteractionModule, Object { foreach (Xep.ServiceDiscovery.Identity identity in identities) { if (identity.category == Xep.ServiceDiscovery.Identity.CATEGORY_CONFERENCE) { default_muc_server[account] = item.jid; - print(@"$(account.bare_jid) Default MUC: $(item.jid)\n"); + debug("[%s] Default MUC: %s", account.bare_jid.to_string(), item.jid.to_string()); return; } } diff --git a/main/data/call_widget.ui b/main/data/call_widget.ui index 8e2ee36c..0c5d8bfa 100644 --- a/main/data/call_widget.ui +++ b/main/data/call_widget.ui @@ -98,7 +98,7 @@ 10 - 5 + 7 True diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 9f48caec..ecbea85e 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -206,9 +206,14 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { }); add_action(open_shortcuts_action); - SimpleAction accept_call_action = new SimpleAction("accept-call", VariantType.INT32); + SimpleAction accept_call_action = new SimpleAction("accept-call", new VariantType.tuple(new VariantType[]{VariantType.INT32, VariantType.INT32})); accept_call_action.activate.connect((variant) => { - Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(variant.get_int32()); + int conversation_id = variant.get_child_value(0).get_int32(); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(conversation_id); + if (conversation == null) return; + + int call_id = variant.get_child_value(1).get_int32(); + Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(call_id, conversation); CallState? call_state = stream_interactor.get_module(Calls.IDENTITY).call_states[call]; if (call_state == null) return; @@ -220,9 +225,14 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { }); add_action(accept_call_action); - SimpleAction deny_call_action = new SimpleAction("reject-call", VariantType.INT32); + SimpleAction deny_call_action = new SimpleAction("reject-call", new VariantType.tuple(new VariantType[]{VariantType.INT32, VariantType.INT32})); deny_call_action.activate.connect((variant) => { - Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(variant.get_int32()); + int conversation_id = variant.get_child_value(0).get_int32(); + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(conversation_id); + if (conversation == null) return; + + int call_id = variant.get_child_value(1).get_int32(); + Call? call = stream_interactor.get_module(CallStore.IDENTITY).get_call_by_id(call_id, conversation); CallState? call_state = stream_interactor.get_module(Calls.IDENTITY).call_states[call]; if (call_state == null) return; diff --git a/main/src/ui/call_window/call_window.vala b/main/src/ui/call_window/call_window.vala index fab424bf..c610444f 100644 --- a/main/src/ui/call_window/call_window.vala +++ b/main/src/ui/call_window/call_window.vala @@ -20,7 +20,7 @@ namespace Dino.Ui { public Revealer header_bar_revealer = new Revealer() { halign=Align.END, valign=Align.START, transition_type=RevealerTransitionType.CROSSFADE, transition_duration=200, visible=true }; public Box own_video_box = new Box(Orientation.HORIZONTAL, 0) { halign=Align.END, valign=Align.END, visible=true }; public Revealer invite_button_revealer = new Revealer() { margin_top=50, margin_right=30, halign=Align.END, valign=Align.START, transition_type=RevealerTransitionType.CROSSFADE, transition_duration=200 }; - public Button invite_button = new Button.from_icon_name("dino-account-plus") { relief=ReliefStyle.NONE }; + public Button invite_button = new Button.from_icon_name("dino-account-plus") { relief=ReliefStyle.NONE, visible=false }; private Widget? own_video = null; private HashMap participant_widgets = new HashMap(); private ArrayList participants = new ArrayList(); diff --git a/main/src/ui/conversation_content_view/call_widget.vala b/main/src/ui/conversation_content_view/call_widget.vala index a7d37afd..a2c8c0c2 100644 --- a/main/src/ui/conversation_content_view/call_widget.vala +++ b/main/src/ui/conversation_content_view/call_widget.vala @@ -86,7 +86,7 @@ namespace Dino.Ui { private void update_counterparts() { if (call.state != Call.State.IN_PROGRESS && call.state != Call.State.ENDED) return; - if (call.counterparts.size <= 1) return; + if (call.counterparts.size <= 1 && conversation.type_ == Conversation.Type.CHAT) return; multiparty_peer_box.foreach((widget) => { multiparty_peer_box.remove(widget); }); diff --git a/main/src/ui/conversation_titlebar/call_entry.vala b/main/src/ui/conversation_titlebar/call_entry.vala index 3fa399a6..3b3a5b39 100644 --- a/main/src/ui/conversation_titlebar/call_entry.vala +++ b/main/src/ui/conversation_titlebar/call_entry.vala @@ -115,13 +115,17 @@ namespace Dino.Ui { return; } - Conversation conv_bak = conversation; - bool audio_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_audio_calls_async(conversation); - bool video_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_video_calls_async(conversation); - if (conv_bak != conversation) return; - - visible = audio_works; - video_button.visible = video_works; + if (conversation.type_ == Conversation.Type.CHAT) { + Conversation conv_bak = conversation; + bool audio_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_audio_calls_async(conversation); + bool video_works = yield stream_interactor.get_module(Calls.IDENTITY).can_do_video_calls_async(conversation); + if (conv_bak != conversation) return; + + visible = audio_works; + video_button.visible = video_works; + } else { + visible = false; + } } public new void unset_conversation() { } diff --git a/main/src/ui/notifier_freedesktop.vala b/main/src/ui/notifier_freedesktop.vala index 83e9bf57..e8e2ba1d 100644 --- a/main/src/ui/notifier_freedesktop.vala +++ b/main/src/ui/notifier_freedesktop.vala @@ -141,10 +141,12 @@ public class Dino.Ui.FreeDesktopNotifier : NotificationProvider, Object { GLib.Application.get_default().activate_action("open-conversation", new Variant.int32(conversation.id)); }); add_action_listener(notification_id, "reject", () => { - GLib.Application.get_default().activate_action("reject-call", new Variant.int32(call.id)); + var variant = new Variant.tuple(new Variant[] {new Variant.int32(conversation.id), new Variant.int32(call.id)}); + GLib.Application.get_default().activate_action("reject-call", variant); }); add_action_listener(notification_id, "accept", () => { - GLib.Application.get_default().activate_action("accept-call", new Variant.int32(call.id)); + var variant = new Variant.tuple(new Variant[] {new Variant.int32(conversation.id), new Variant.int32(call.id)}); + GLib.Application.get_default().activate_action("accept-call", variant); }); } catch (Error e) { warning("Failed showing subscription request notification: %s", e.message); -- cgit v1.2.3-54-g00ecf