Refactor voice approval
This commit is contained in:
parent
8b5adb06da
commit
c614ac69df
|
@ -402,15 +402,6 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|||
self.nick = ''
|
||||
|
||||
if not self.stanza.getTag('body'): # no <body>
|
||||
if self.msg_obj.form_node:
|
||||
# It could be a voice request. See
|
||||
# http://www.xmpp.org/extensions/xep-0045.html#voiceapprove
|
||||
from gajim.gtk.single_message import SingleMessageWindow
|
||||
SingleMessageWindow(
|
||||
self.conn.name, self.fjid,
|
||||
action='receive', from_whom=self.fjid,
|
||||
subject='', message='', resource='', session=None,
|
||||
form_node=self.msg_obj.form_node)
|
||||
return
|
||||
|
||||
from gajim.common.modules.security_labels import parse_securitylabel
|
||||
|
|
|
@ -43,6 +43,7 @@ class MUC:
|
|||
('message', self._mediated_invite, 'normal', nbxmpp.NS_MUC_USER),
|
||||
('message', self._direct_invite, '', nbxmpp.NS_CONFERENCE),
|
||||
('message', self._on_captcha_challenge, '', nbxmpp.NS_CAPTCHA),
|
||||
('message', self._on_voice_request, '', nbxmpp.NS_DATA, 45),
|
||||
]
|
||||
|
||||
def pass_disco(self, from_, identities, features, _data, _node):
|
||||
|
@ -114,6 +115,33 @@ class MUC:
|
|||
log.info('Set subject for %s', room_jid)
|
||||
self._con.connection.send(message)
|
||||
|
||||
def _on_voice_request(self, _con, stanza):
|
||||
data_form = stanza.getTag('x', namespace=nbxmpp.NS_DATA)
|
||||
if data_form is None:
|
||||
return
|
||||
|
||||
if stanza.getBody():
|
||||
return
|
||||
|
||||
room_jid = str(stanza.getFrom())
|
||||
contact = app.contacts.get_groupchat_contact(self._account, room_jid)
|
||||
if contact is None:
|
||||
return
|
||||
|
||||
data_form = dataforms.extend_form(data_form)
|
||||
try:
|
||||
if data_form['FORM_TYPE'].value != nbxmpp.NS_MUC_REQUEST:
|
||||
return
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
app.nec.push_incoming_event(
|
||||
NetworkEvent('voice-approval',
|
||||
account=self._account,
|
||||
room_jid=room_jid,
|
||||
form=data_form))
|
||||
raise nbxmpp.NodeProcessed
|
||||
|
||||
def _on_captcha_challenge(self, _con, stanza):
|
||||
captcha = stanza.getTag('captcha', namespace=nbxmpp.NS_CAPTCHA)
|
||||
if captcha is None:
|
||||
|
|
|
@ -70,6 +70,7 @@ from gajim.gtk.dialogs import ConfirmationDialogCheck
|
|||
from gajim.gtk.dialogs import DoubleInputDialog
|
||||
from gajim.gtk.dialogs import InputDialog
|
||||
from gajim.gtk.dialogs import ChangeNickDialog
|
||||
from gajim.gtk.single_message import SingleMessageWindow
|
||||
from gajim.gtk.filechoosers import AvatarChooserDialog
|
||||
from gajim.gtk.add_contact import AddNewContactWindow
|
||||
from gajim.gtk.tooltips import GCTooltip
|
||||
|
@ -331,6 +332,8 @@ class GroupchatControl(ChatControlBase):
|
|||
self._message_sent)
|
||||
app.ged.register_event_handler('captcha-challenge', ged.GUI1,
|
||||
self._on_captcha_challenge)
|
||||
app.ged.register_event_handler('voice-approval', ged.GUI1,
|
||||
self._on_voice_approval)
|
||||
self.is_connected = False
|
||||
# disable win, we are not connected yet
|
||||
ChatControlBase.got_disconnected(self)
|
||||
|
@ -1074,6 +1077,17 @@ class GroupchatControl(ChatControlBase):
|
|||
return
|
||||
self._update_banner_state_image()
|
||||
|
||||
def _on_voice_approval(self, event):
|
||||
if event.account != self.account:
|
||||
return
|
||||
if event.room_jid != self.room_jid:
|
||||
return
|
||||
SingleMessageWindow(self.account,
|
||||
self.room_jid,
|
||||
action='receive',
|
||||
from_whom=self.room_jid,
|
||||
form_node=event.form)
|
||||
|
||||
def _on_captcha_challenge(self, event):
|
||||
if event.account != self.account:
|
||||
return
|
||||
|
@ -2179,6 +2193,8 @@ class GroupchatControl(ChatControlBase):
|
|||
self._message_sent)
|
||||
app.ged.remove_event_handler('captcha-challenge', ged.GUI1,
|
||||
self._on_captcha_challenge)
|
||||
app.ged.remove_event_handler('voice-approval', ged.GUI1,
|
||||
self._on_voice_approval)
|
||||
|
||||
if self.is_connected:
|
||||
app.connections[self.account].send_gc_status(self.nick,
|
||||
|
|
|
@ -20,12 +20,11 @@ from gi.repository import GLib
|
|||
from gajim.common import app
|
||||
from gajim.common import helpers
|
||||
from gajim.common.i18n import _
|
||||
from gajim.common.modules import dataforms
|
||||
from gajim.common.connection_handlers_events import MessageOutgoingEvent
|
||||
|
||||
from gajim.dataforms_widget import DataFormWidget
|
||||
from gajim.conversation_textview import ConversationTextview
|
||||
|
||||
from gajim.gtk.dataform import DataFormWidget
|
||||
from gajim.gtk.dialogs import ErrorDialog
|
||||
from gajim.gtk.dialogs import AspellDictError
|
||||
from gajim.gtk.util import get_builder
|
||||
|
@ -83,9 +82,7 @@ class SingleMessageWindow:
|
|||
parent_box = self.xml.get_object('conversation_scrolledwindow').\
|
||||
get_parent()
|
||||
if form_node:
|
||||
dataform = dataforms.extend_form(node=form_node)
|
||||
dataform.type_ = 'submit'
|
||||
self.form_widget = DataFormWidget(dataform)
|
||||
self.form_widget = DataFormWidget(form_node)
|
||||
self.form_widget.show_all()
|
||||
parent_box.add(self.form_widget)
|
||||
parent_box.child_set_property(self.form_widget, 'position',
|
||||
|
@ -282,7 +279,7 @@ class SingleMessageWindow:
|
|||
message = self.message_tv_buffer.get_text(begin, end, True)
|
||||
|
||||
if self.form_widget:
|
||||
form_node = self.form_widget.data_form
|
||||
form_node = self.form_widget.get_submit_form()
|
||||
else:
|
||||
form_node = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue