Fix incoming muc voice request notification

This commit is contained in:
fiaxh 2020-11-11 11:27:31 +01:00
parent b2c7e9dfff
commit 10adf716f3
5 changed files with 27 additions and 19 deletions

View file

@ -14,7 +14,7 @@ public class MucManager : StreamInteractionModule, Object {
public signal void room_info_updated(Account account, Jid muc_jid);
public signal void private_room_occupant_updated(Account account, Jid room, Jid occupant);
public signal void invite_received(Account account, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void voice_request_received(Account account, Jid room_jid, Jid from_jid, string? nick, string? role, string? label);
public signal void voice_request_received(Account account, Jid room_jid, Jid from_jid, string nick);
public signal void received_occupant_role(Account account, Jid jid, Xep.Muc.Role? role);
public signal void bookmarks_updated(Account account, Set<Conference> conferences);
public signal void conference_added(Account account, Conference conference);
@ -364,8 +364,8 @@ public class MucManager : StreamInteractionModule, Object {
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).invite_received.connect( (stream, room_jid, from_jid, password, reason) => {
invite_received(account, room_jid, from_jid, password, reason);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).voice_request_received.connect( (stream, room_jid, from_jid, nick, role, label) => {
voice_request_received(account, room_jid, from_jid, nick, role, label);
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).voice_request_received.connect( (stream, room_jid, from_jid, nick) => {
voice_request_received(account, room_jid, from_jid, nick);
});
stream_interactor.module_manager.get_module(account, Xep.Muc.Module.IDENTITY).received_occupant_role.connect( (stream, from_jid, role) => {
received_occupant_role(account, from_jid, role);

View file

@ -13,7 +13,7 @@ public class NotificationEvents : StreamInteractionModule, Object {
public signal void notify_subscription_request(Conversation conversation);
public signal void notify_connection_error(Account account, ConnectionManager.ConnectionError error);
public signal void notify_muc_invite(Account account, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void notify_voice_request(Account account, Jid room_jid, Jid from_jid, string? nick, string? role, string? label);
public signal void notify_voice_request(Account account, Jid room_jid, Jid from_jid, string nick);
private StreamInteractor stream_interactor;
@ -28,7 +28,7 @@ public class NotificationEvents : StreamInteractionModule, Object {
stream_interactor.get_module(ContentItemStore.IDENTITY).new_item.connect(on_content_item_received);
stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request);
stream_interactor.get_module(MucManager.IDENTITY).invite_received.connect((account, room_jid, from_jid, password, reason) => notify_muc_invite(account, room_jid, from_jid, password, reason));
stream_interactor.get_module(MucManager.IDENTITY).voice_request_received.connect((account, room_jid, from_jid, nick, role, label) => notify_voice_request(account, room_jid, from_jid, nick, role, label));
stream_interactor.get_module(MucManager.IDENTITY).voice_request_received.connect((account, room_jid, from_jid, nick) => notify_voice_request(account, room_jid, from_jid, nick));
stream_interactor.connection_manager.connection_error.connect((account, error) => notify_connection_error(account, error));
}

View file

@ -138,11 +138,14 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application {
});
add_action(accept_muc_invite_action);
SimpleAction accept_voice_request_action = new SimpleAction("accept-voice-request", VariantType.INT32);
SimpleAction accept_voice_request_action = new SimpleAction("accept-voice-request", new VariantType.tuple(new VariantType[]{VariantType.INT32, VariantType.STRING}));
accept_voice_request_action.activate.connect((variant) => {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_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;
stream_interactor.get_module(MucManager.IDENTITY).change_role(conversation.account, conversation.counterpart, conversation.nickname, "participant");
string nick = variant.get_child_value(1).get_string();
stream_interactor.get_module(MucManager.IDENTITY).change_role(conversation.account, conversation.counterpart, nick, "participant");
});
add_action(accept_voice_request_action);

View file

@ -141,7 +141,7 @@ public class Notifications : Object {
GLib.Application.get_default().send_notification(null, notification);
}
private async void on_voice_request_received(Account account, Jid room_jid, Jid from_jid, string? nick, string? role, string? label) {
private async void on_voice_request_received(Account account, Jid room_jid, Jid from_jid, string nick) {
Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation(room_jid, account, Conversation.Type.GROUPCHAT);
if (conversation == null) return;
@ -156,9 +156,10 @@ public class Notifications : Object {
notification.set_icon(get_pixbuf_icon(jid_avatar));
} catch (Error e) { }
notification.set_default_action_and_target_value("app.accept-voice-request", new Variant.int32(conversation.id));
Variant variant = new Variant.tuple(new Variant[] {new Variant.int32(conversation.id), new Variant.string(nick)});
notification.set_default_action_and_target_value("app.accept-voice-request", variant);
notification.add_button_with_target_value(_("Deny"), "app.deny-voice-request", conversation.id);
notification.add_button_with_target_value(_("Accept"), "app.accept-voice-request", conversation.id);
notification.add_button_with_target_value(_("Accept"), "app.accept-voice-request", variant);
GLib.Application.get_default().send_notification(null, notification);
}

View file

@ -69,7 +69,7 @@ public class Module : XmppStreamModule {
public signal void received_occupant_role(XmppStream stream, Jid jid, Role? role);
public signal void subject_set(XmppStream stream, string? subject, Jid jid);
public signal void invite_received(XmppStream stream, Jid room_jid, Jid from_jid, string? password, string? reason);
public signal void voice_request_received(XmppStream stream, Jid room_jid, Jid from_jid, string? nick, string? role, string? label);
public signal void voice_request_received(XmppStream stream, Jid room_jid, Jid from_jid, string nick);
public signal void room_info_updated(XmppStream stream, Jid muc_jid);
public signal void self_removed_from_room(XmppStream stream, Jid jid, StatusCode code);
@ -559,8 +559,6 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
Gee.List<StanzaNode>? fields = x_field_node.get_subnodes("field", DataForms.NS_URI);
Jid? from_jid = null;
string? nick = null;
string? role = null;
string? label = null;
if (fields.size!=0){
foreach (var field_node in fields){
@ -579,13 +577,19 @@ public class ReceivedPipelineListener : StanzaListener<MessageStanza> {
}
else if (var_ == "muc#role"){
StanzaNode? value_node = field_node.get_subnode("value", DataForms.NS_URI);
if (value_node != null) role = value_node.get_string_content();
}
else if (var_ == "muc#request_allow"){
label = field_node.get_attribute("label");
if (value_node != null) {
if (value_node.get_string_content() != "participant") {
warning("Voice request with role other than participant");
}
}
outer.voice_request_received(stream, message.from, from_jid, nick, role, label);
}
}
if (from_jid == null || nick == null) {
warning("Voice request without from_jid or nick");
return false;
}
outer.voice_request_received(stream, message.from, from_jid, nick);
return true;
}
}