use NEC to handle muc config event

This commit is contained in:
Yann Leboulanger 2010-08-24 09:15:42 +02:00
parent a067cf552a
commit ff66a095a6
3 changed files with 41 additions and 32 deletions

View File

@ -46,6 +46,7 @@ import common.caps_cache as capscache
from common import helpers from common import helpers
from common import gajim from common import gajim
from common import exceptions from common import exceptions
from common import dataforms
from common.commands import ConnectionCommands from common.commands import ConnectionCommands
from common.pubsub import ConnectionPubSub from common.pubsub import ConnectionPubSub
from common.pep import ConnectionPEP from common.pep import ConnectionPEP
@ -2103,14 +2104,8 @@ ConnectionJingle, ConnectionIBBytestream):
def _MucOwnerCB(self, con, iq_obj): def _MucOwnerCB(self, con, iq_obj):
log.debug('MucOwnerCB') log.debug('MucOwnerCB')
qp = iq_obj.getQueryPayload() gajim.nec.push_incoming_event(MucOwnerReceivedEvent(None,
node = None conn=self, iq_obj=iq_obj))
for q in qp:
if q.getNamespace() == common.xmpp.NS_DATA:
node = q
if not node:
return
self.dispatch('GC_CONFIG', (helpers.get_full_jid_from_iq(iq_obj), node))
def _MucAdminCB(self, con, iq_obj): def _MucAdminCB(self, con, iq_obj):
log.debug('MucAdminCB') log.debug('MucAdminCB')
@ -2433,7 +2428,7 @@ ConnectionJingle, ConnectionIBBytestream):
class HelperEvent: class HelperEvent:
def get_jid_resource(self): def get_jid_resource(self):
if self.id_ in self.conn.groupchat_jids: if hasattr(self, 'id_') and self.id_ in self.conn.groupchat_jids:
self.fjid = self.conn.groupchat_jids[self.id_] self.fjid = self.conn.groupchat_jids[self.id_]
del self.conn.groupchat_jids[self.id_] del self.conn.groupchat_jids[self.id_]
else: else:
@ -2708,3 +2703,17 @@ class RosterSetReceivedEvent(nec.NetworkIncomingEvent):
class RosterInfoEvent(nec.NetworkIncomingEvent): class RosterInfoEvent(nec.NetworkIncomingEvent):
name = 'roster-info' name = 'roster-info'
base_network_events = [] base_network_events = []
class MucOwnerReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
name = 'muc-owner-received'
base_network_events = []
def generate(self):
self.get_jid_resource()
qp = self.iq_obj.getQueryPayload()
self.form_node = None
for q in qp:
if q.getNamespace() == common.xmpp.NS_DATA:
self.form_node = q
self.dataform = dataforms.ExtendForm(node=self.form_node)
return True

View File

@ -2701,7 +2701,7 @@ class ServiceRegistrationWindow:
class GroupchatConfigWindow: class GroupchatConfigWindow:
def __init__(self, account, room_jid, form = None): def __init__(self, account, room_jid, form=None):
self.account = account self.account = account
self.room_jid = room_jid self.room_jid = room_jid
self.form = form self.form = form
@ -2719,8 +2719,7 @@ class GroupchatConfigWindow:
if self.form: if self.form:
config_vbox = self.xml.get_object('config_vbox') config_vbox = self.xml.get_object('config_vbox')
dataform = dataforms.ExtendForm(node = self.form) self.data_form_widget = dataforms_widget.DataFormWidget(self.form)
self.data_form_widget = dataforms_widget.DataFormWidget(dataform)
# hide scrollbar of this data_form_widget, we already have in this # hide scrollbar of this data_form_widget, we already have in this
# widget # widget
sw = self.data_form_widget.xml.get_object('single_form_scrolledwindow') sw = self.data_form_widget.xml.get_object('single_form_scrolledwindow')

View File

@ -993,14 +993,13 @@ class Interface:
else: else:
gc_control.print_conversation(text) gc_control.print_conversation(text)
def handle_event_gc_config(self, account, array): def handle_event_gc_config(self, obj):
#('GC_CONFIG', account, (jid, form)) config is a dict #('GC_CONFIG', account, (jid, form_node)) config is a dict
room_jid = array[0].split('/')[0] account = obj.conn.name
if room_jid in gajim.automatic_rooms[account]: if obj.jid in gajim.automatic_rooms[account]:
if 'continue_tag' in gajim.automatic_rooms[account][room_jid]: if 'continue_tag' in gajim.automatic_rooms[account][obj.jid]:
# We're converting chat to muc. allow participants to invite # We're converting chat to muc. allow participants to invite
form = dataforms.ExtendForm(node = array[1]) for f in obj.dataform.iter_fields():
for f in form.iter_fields():
if f.var == 'muc#roomconfig_allowinvites': if f.var == 'muc#roomconfig_allowinvites':
f.value = True f.value = True
elif f.var == 'muc#roomconfig_publicroom': elif f.var == 'muc#roomconfig_publicroom':
@ -1009,23 +1008,25 @@ class Interface:
f.value = True f.value = True
elif f.var == 'public_list': elif f.var == 'public_list':
f.value = False f.value = False
gajim.connections[account].send_gc_config(room_jid, form) gajim.connections[account].send_gc_config(obj.jid,
obj.dataform.get_purged())
else: else:
# use default configuration # use default configuration
gajim.connections[account].send_gc_config(room_jid, array[1]) gajim.connections[account].send_gc_config(obj.jid,
obj.form_node)
# invite contacts # invite contacts
# check if it is necessary to add <continue /> # check if it is necessary to add <continue />
continue_tag = False continue_tag = False
if 'continue_tag' in gajim.automatic_rooms[account][room_jid]: if 'continue_tag' in gajim.automatic_rooms[account][obj.jid]:
continue_tag = True continue_tag = True
if 'invities' in gajim.automatic_rooms[account][room_jid]: if 'invities' in gajim.automatic_rooms[account][obj.jid]:
for jid in gajim.automatic_rooms[account][room_jid]['invities']: for jid in gajim.automatic_rooms[account][obj.jid]['invities']:
gajim.connections[account].send_invite(room_jid, jid, gajim.connections[account].send_invite(obj.jid, jid,
continue_tag=continue_tag) continue_tag=continue_tag)
del gajim.automatic_rooms[account][room_jid] del gajim.automatic_rooms[account][obj.jid]
elif room_jid not in self.instances[account]['gc_config']: elif obj.jid not in self.instances[account]['gc_config']:
self.instances[account]['gc_config'][room_jid] = \ self.instances[account]['gc_config'][obj.jid] = \
config.GroupchatConfigWindow(account, room_jid, array[1]) config.GroupchatConfigWindow(account, obj.jid, obj.dataform)
def handle_event_gc_config_change(self, account, array): def handle_event_gc_config_change(self, account, array):
#('GC_CONFIG_CHANGE', account, (jid, statusCode)) statuscode is a list #('GC_CONFIG_CHANGE', account, (jid, statusCode)) statuscode is a list
@ -2104,7 +2105,6 @@ class Interface:
'GC_NOTIFY': [self.handle_event_gc_notify], 'GC_NOTIFY': [self.handle_event_gc_notify],
'GC_MSG': [self.handle_event_gc_msg], 'GC_MSG': [self.handle_event_gc_msg],
'GC_SUBJECT': [self.handle_event_gc_subject], 'GC_SUBJECT': [self.handle_event_gc_subject],
'GC_CONFIG': [self.handle_event_gc_config],
'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change], 'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change],
'GC_INVITATION': [self.handle_event_gc_invitation], 'GC_INVITATION': [self.handle_event_gc_invitation],
'GC_AFFILIATION': [self.handle_event_gc_affiliation], 'GC_AFFILIATION': [self.handle_event_gc_affiliation],
@ -2164,9 +2164,10 @@ class Interface:
'gmail-notify': [self.handle_event_gmail_notify], 'gmail-notify': [self.handle_event_gmail_notify],
'http-auth-received': [self.handle_event_http_auth], 'http-auth-received': [self.handle_event_http_auth],
'last-result-received': [self.handle_event_last_status_time], 'last-result-received': [self.handle_event_last_status_time],
'muc-owner-received': [self.handle_event_gc_config],
'roster-info': [self.handle_event_roster_info],
'roster-item-exchange-received': \ 'roster-item-exchange-received': \
[self.handle_event_roster_item_exchange], [self.handle_event_roster_item_exchange],
'roster-info': [self.handle_event_roster_info],
} }
def register_core_handlers(self): def register_core_handlers(self):