Move more MUC methods into muc module
This commit is contained in:
parent
37f7a80396
commit
78858f7c82
|
@ -284,7 +284,8 @@ class StandardGroupChatCommands(CommandContainer):
|
||||||
@doc(_("Display or change a group chat topic"))
|
@doc(_("Display or change a group chat topic"))
|
||||||
def topic(self, new_topic):
|
def topic(self, new_topic):
|
||||||
if new_topic:
|
if new_topic:
|
||||||
self.connection.send_gc_subject(self.room_jid, new_topic)
|
self.connection.get_module('MUC').set_subject(
|
||||||
|
self.room_jid, new_topic)
|
||||||
else:
|
else:
|
||||||
return self.subject
|
return self.subject
|
||||||
|
|
||||||
|
@ -314,18 +315,22 @@ class StandardGroupChatCommands(CommandContainer):
|
||||||
|
|
||||||
If given nickname is not found it will be treated as a JID.
|
If given nickname is not found it will be treated as a JID.
|
||||||
"""))
|
"""))
|
||||||
def ban(self, who, reason):
|
def ban(self, who, reason=''):
|
||||||
if who in app.contacts.get_nick_list(self.account, self.room_jid):
|
if who in app.contacts.get_nick_list(self.account, self.room_jid):
|
||||||
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
||||||
who = contact.jid
|
who = contact.jid
|
||||||
self.connection.gc_set_affiliation(self.room_jid, who, 'outcast', reason or str())
|
self.connection.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{who: {'affiliation': 'outcast',
|
||||||
|
'reason': reason}})
|
||||||
|
|
||||||
@command(raw=True, empty=True)
|
@command(raw=True, empty=True)
|
||||||
@doc(_("Kick user by a nick from a groupchat"))
|
@doc(_("Kick user by a nick from a groupchat"))
|
||||||
def kick(self, who, reason):
|
def kick(self, who, reason):
|
||||||
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
||||||
raise CommandError(_("Nickname not found"))
|
raise CommandError(_("Nickname not found"))
|
||||||
self.connection.gc_set_role(self.room_jid, who, 'none', reason or str())
|
self.connection.get_module('MUC').set_role(
|
||||||
|
self.room_jid, who, 'none', reason or str())
|
||||||
|
|
||||||
@command(raw=True)
|
@command(raw=True)
|
||||||
#Do not translate moderator, participant, visitor, none
|
#Do not translate moderator, participant, visitor, none
|
||||||
|
@ -337,7 +342,7 @@ class StandardGroupChatCommands(CommandContainer):
|
||||||
raise CommandError(_("Invalid role given"))
|
raise CommandError(_("Invalid role given"))
|
||||||
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
||||||
raise CommandError(_("Nickname not found"))
|
raise CommandError(_("Nickname not found"))
|
||||||
self.connection.gc_set_role(self.room_jid, who, role)
|
self.connection.get_module('MUC').set_role(self.room_jid, who, role)
|
||||||
|
|
||||||
@command(raw=True)
|
@command(raw=True)
|
||||||
#Do not translate owner, admin, member, outcast, none
|
#Do not translate owner, admin, member, outcast, none
|
||||||
|
@ -347,11 +352,13 @@ class StandardGroupChatCommands(CommandContainer):
|
||||||
def affiliate(self, who, affiliation):
|
def affiliate(self, who, affiliation):
|
||||||
if affiliation not in ('owner', 'admin', 'member', 'outcast', 'none'):
|
if affiliation not in ('owner', 'admin', 'member', 'outcast', 'none'):
|
||||||
raise CommandError(_("Invalid affiliation given"))
|
raise CommandError(_("Invalid affiliation given"))
|
||||||
if not who in app.contacts.get_nick_list(self.account, self.room_jid):
|
if who not in app.contacts.get_nick_list(self.account, self.room_jid):
|
||||||
raise CommandError(_("Nickname not found"))
|
raise CommandError(_("Nickname not found"))
|
||||||
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
contact = app.contacts.get_gc_contact(self.account, self.room_jid, who)
|
||||||
self.connection.gc_set_affiliation(self.room_jid, contact.jid,
|
|
||||||
affiliation)
|
self.connection.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{contact.jid: {'affiliation': affiliation}})
|
||||||
|
|
||||||
@command
|
@command
|
||||||
@doc(_("Display names of all group chat occupants"))
|
@doc(_("Display names of all group chat occupants"))
|
||||||
|
|
|
@ -2143,46 +2143,6 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
chatstate=None, automatic_message=obj.automatic_message,
|
chatstate=None, automatic_message=obj.automatic_message,
|
||||||
stanza_id=obj.stanza_id, additional_data=obj.additional_data))
|
stanza_id=obj.stanza_id, additional_data=obj.additional_data))
|
||||||
|
|
||||||
def send_gc_subject(self, jid, subject):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
msg_iq = nbxmpp.Message(jid, typ='groupchat', subject=subject)
|
|
||||||
self.connection.send(msg_iq)
|
|
||||||
|
|
||||||
def request_gc_config(self, room_jid):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='get', queryNS=nbxmpp.NS_MUC_OWNER,
|
|
||||||
to=room_jid)
|
|
||||||
self.add_lang(iq)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def cancel_gc_config(self, room_jid):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
cancel = nbxmpp.Node(tag='x', attrs={'xmlns': nbxmpp.NS_DATA,
|
|
||||||
'type': 'cancel'})
|
|
||||||
iq = nbxmpp.Iq(typ='set',
|
|
||||||
queryNS=nbxmpp.NS_MUC_OWNER,
|
|
||||||
payload=cancel,
|
|
||||||
to=room_jid)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def destroy_gc_room(self, room_jid, reason = '', jid = ''):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='set', queryNS=nbxmpp.NS_MUC_OWNER,
|
|
||||||
to=room_jid)
|
|
||||||
destroy = iq.setQuery().setTag('destroy')
|
|
||||||
if reason:
|
|
||||||
destroy.setTagData('reason', reason)
|
|
||||||
if jid:
|
|
||||||
destroy.setAttr('jid', jid)
|
|
||||||
self.connection.send(iq)
|
|
||||||
i = 0
|
|
||||||
self.get_module('Bookmarks').bookmarks.pop(jid, None)
|
|
||||||
self.get_module('Bookmarks').store_bookmarks()
|
|
||||||
|
|
||||||
def send_gc_status(self, nick, jid, show, status, auto=False):
|
def send_gc_status(self, nick, jid, show, status, auto=False):
|
||||||
if not app.account_is_connected(self.name):
|
if not app.account_is_connected(self.name):
|
||||||
return
|
return
|
||||||
|
@ -2213,63 +2173,6 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
# disconnect from jabber server
|
# disconnect from jabber server
|
||||||
self.connection.send(p)
|
self.connection.send(p)
|
||||||
|
|
||||||
def gc_set_role(self, room_jid, nick, role, reason=''):
|
|
||||||
"""
|
|
||||||
Role is for all the life of the room so it's based on nick
|
|
||||||
"""
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
|
||||||
item = iq.setQuery().setTag('item')
|
|
||||||
item.setAttr('nick', nick)
|
|
||||||
item.setAttr('role', role)
|
|
||||||
if reason:
|
|
||||||
item.addChild(name='reason', payload=reason)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def gc_set_affiliation(self, room_jid, jid, affiliation, reason = ''):
|
|
||||||
"""
|
|
||||||
Affiliation is for all the life of the room so it's based on jid
|
|
||||||
"""
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
|
||||||
item = iq.setQuery().setTag('item')
|
|
||||||
item.setAttr('jid', jid)
|
|
||||||
item.setAttr('affiliation', affiliation)
|
|
||||||
if reason:
|
|
||||||
item.addChild(name = 'reason', payload = reason)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def send_gc_affiliation_list(self, room_jid, users_dict):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
|
||||||
item = iq.setQuery()
|
|
||||||
for jid in users_dict:
|
|
||||||
item_tag = item.addChild('item', {'jid': jid,
|
|
||||||
'affiliation': users_dict[jid]['affiliation']})
|
|
||||||
if 'reason' in users_dict[jid] and users_dict[jid]['reason']:
|
|
||||||
item_tag.setTagData('reason', users_dict[jid]['reason'])
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def get_affiliation_list(self, room_jid, affiliation):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='get', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
|
||||||
item = iq.setQuery().setTag('item')
|
|
||||||
item.setAttr('affiliation', affiliation)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def send_gc_config(self, room_jid, form):
|
|
||||||
if not app.account_is_connected(self.name):
|
|
||||||
return
|
|
||||||
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_OWNER)
|
|
||||||
query = iq.setQuery()
|
|
||||||
form.setAttr('type', 'submit')
|
|
||||||
query.addChild(node = form)
|
|
||||||
self.connection.send(iq)
|
|
||||||
|
|
||||||
def change_password(self, password):
|
def change_password(self, password):
|
||||||
if not app.account_is_connected(self.name):
|
if not app.account_is_connected(self.name):
|
||||||
return
|
return
|
||||||
|
|
|
@ -998,16 +998,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream, ConnectionDisco,
|
||||||
# This way we'll really remove it
|
# This way we'll really remove it
|
||||||
app.to_be_removed[self.name].remove(jid)
|
app.to_be_removed[self.name].remove(jid)
|
||||||
|
|
||||||
def _MucOwnerCB(self, con, iq_obj):
|
|
||||||
log.debug('MucOwnerCB')
|
|
||||||
app.nec.push_incoming_event(MucOwnerReceivedEvent(None, conn=self,
|
|
||||||
stanza=iq_obj))
|
|
||||||
|
|
||||||
def _MucAdminCB(self, con, iq_obj):
|
|
||||||
log.debug('MucAdminCB')
|
|
||||||
app.nec.push_incoming_event(MucAdminReceivedEvent(None, conn=self,
|
|
||||||
stanza=iq_obj))
|
|
||||||
|
|
||||||
def _getRoster(self):
|
def _getRoster(self):
|
||||||
log.debug('getRosterCB')
|
log.debug('getRosterCB')
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -1179,10 +1169,6 @@ class ConnectionHandlers(ConnectionSocks5Bytestream, ConnectionDisco,
|
||||||
nbxmpp.NS_DISCO_INFO)
|
nbxmpp.NS_DISCO_INFO)
|
||||||
con.RegisterHandler('iq', self._DiscoverInfoErrorCB, 'error',
|
con.RegisterHandler('iq', self._DiscoverInfoErrorCB, 'error',
|
||||||
nbxmpp.NS_DISCO_INFO)
|
nbxmpp.NS_DISCO_INFO)
|
||||||
con.RegisterHandler('iq', self._MucOwnerCB, 'result',
|
|
||||||
nbxmpp.NS_MUC_OWNER)
|
|
||||||
con.RegisterHandler('iq', self._MucAdminCB, 'result',
|
|
||||||
nbxmpp.NS_MUC_ADMIN)
|
|
||||||
con.RegisterHandler('iq', self._SecLabelCB, 'result',
|
con.RegisterHandler('iq', self._SecLabelCB, 'result',
|
||||||
nbxmpp.NS_SECLABEL_CATALOG)
|
nbxmpp.NS_SECLABEL_CATALOG)
|
||||||
con.RegisterHandler('iq', self._DiscoverInfoGetCB, 'get',
|
con.RegisterHandler('iq', self._DiscoverInfoGetCB, 'get',
|
||||||
|
|
|
@ -267,48 +267,6 @@ class RosterInfoEvent(nec.NetworkIncomingEvent):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.avatar_sha = None
|
self.avatar_sha = None
|
||||||
|
|
||||||
class MucOwnerReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
||||||
name = 'muc-owner-received'
|
|
||||||
base_network_events = []
|
|
||||||
|
|
||||||
def generate(self):
|
|
||||||
self.get_jid_resource()
|
|
||||||
qp = self.stanza.getQueryPayload()
|
|
||||||
self.form_node = None
|
|
||||||
for q in qp:
|
|
||||||
if q.getNamespace() == nbxmpp.NS_DATA:
|
|
||||||
self.form_node = q
|
|
||||||
self.dataform = dataforms.ExtendForm(node=self.form_node)
|
|
||||||
return True
|
|
||||||
|
|
||||||
class MucAdminReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|
||||||
name = 'muc-admin-received'
|
|
||||||
base_network_events = []
|
|
||||||
|
|
||||||
def generate(self):
|
|
||||||
self.get_jid_resource()
|
|
||||||
items = self.stanza.getTag('query',
|
|
||||||
namespace=nbxmpp.NS_MUC_ADMIN).getTags('item')
|
|
||||||
self.users_dict = {}
|
|
||||||
for item in items:
|
|
||||||
if item.has_attr('jid') and item.has_attr('affiliation'):
|
|
||||||
try:
|
|
||||||
jid = helpers.parse_jid(item.getAttr('jid'))
|
|
||||||
except helpers.InvalidFormat:
|
|
||||||
log.warning('Invalid JID: %s, ignoring it' % \
|
|
||||||
item.getAttr('jid'))
|
|
||||||
continue
|
|
||||||
affiliation = item.getAttr('affiliation')
|
|
||||||
self.users_dict[jid] = {'affiliation': affiliation}
|
|
||||||
if item.has_attr('nick'):
|
|
||||||
self.users_dict[jid]['nick'] = item.getAttr('nick')
|
|
||||||
if item.has_attr('role'):
|
|
||||||
self.users_dict[jid]['role'] = item.getAttr('role')
|
|
||||||
reason = item.getTagData('reason')
|
|
||||||
if reason:
|
|
||||||
self.users_dict[jid]['reason'] = reason
|
|
||||||
return True
|
|
||||||
|
|
||||||
class IqErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
class IqErrorReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||||
name = 'iq-error-received'
|
name = 'iq-error-received'
|
||||||
base_network_events = []
|
base_network_events = []
|
||||||
|
|
|
@ -19,6 +19,8 @@ import logging
|
||||||
|
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
|
|
||||||
|
from gajim.common import i18n
|
||||||
|
from gajim.common import dataforms
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
from gajim.common.nec import NetworkIncomingEvent
|
from gajim.common.nec import NetworkIncomingEvent
|
||||||
|
@ -36,6 +38,152 @@ class MUC:
|
||||||
('message', self._direct_invite, '', nbxmpp.NS_CONFERENCE),
|
('message', self._direct_invite, '', nbxmpp.NS_CONFERENCE),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def set_subject(self, room_jid, subject):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
message = nbxmpp.Message(room_jid, typ='groupchat', subject=subject)
|
||||||
|
log.info('Set subject for %s', room_jid)
|
||||||
|
self._con.connection.send(message)
|
||||||
|
|
||||||
|
def request_config(self, room_jid):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='get',
|
||||||
|
queryNS=nbxmpp.NS_MUC_OWNER,
|
||||||
|
to=room_jid)
|
||||||
|
iq.setAttr('xml:lang', i18n.LANG)
|
||||||
|
log.info('Request config for %s', room_jid)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._config_received)
|
||||||
|
|
||||||
|
def _config_received(self, stanza):
|
||||||
|
if not nbxmpp.isResultNode(stanza):
|
||||||
|
log.info('Error: %s', stanza.getError())
|
||||||
|
return
|
||||||
|
|
||||||
|
room_jid = stanza.getFrom().getStripped()
|
||||||
|
payload = stanza.getQueryPayload()
|
||||||
|
|
||||||
|
for form in payload:
|
||||||
|
if form.getNamespace() == nbxmpp.NS_DATA:
|
||||||
|
dataform = dataforms.ExtendForm(node=form)
|
||||||
|
log.info('Config form received for %s', room_jid)
|
||||||
|
app.nec.push_incoming_event(MucOwnerReceivedEvent(
|
||||||
|
None,
|
||||||
|
conn=self._con,
|
||||||
|
form_node=form,
|
||||||
|
dataform=dataform,
|
||||||
|
jid=room_jid))
|
||||||
|
break
|
||||||
|
|
||||||
|
def cancel_config(self, room_jid):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
cancel = nbxmpp.Node(tag='x', attrs={'xmlns': nbxmpp.NS_DATA,
|
||||||
|
'type': 'cancel'})
|
||||||
|
iq = nbxmpp.Iq(typ='set',
|
||||||
|
queryNS=nbxmpp.NS_MUC_OWNER,
|
||||||
|
payload=cancel,
|
||||||
|
to=room_jid)
|
||||||
|
log.info('Cancel config for %s', room_jid)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._default_response, {})
|
||||||
|
|
||||||
|
def destroy(self, room_jid, reason='', jid=''):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='set',
|
||||||
|
queryNS=nbxmpp.NS_MUC_OWNER,
|
||||||
|
to=room_jid)
|
||||||
|
destroy = iq.setQuery().setTag('destroy')
|
||||||
|
if reason:
|
||||||
|
destroy.setTagData('reason', reason)
|
||||||
|
if jid:
|
||||||
|
destroy.setAttr('jid', jid)
|
||||||
|
log.info('Destroy room: %s, reason: %s, alternate: %s',
|
||||||
|
room_jid, reason, jid)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._default_response, {})
|
||||||
|
|
||||||
|
def set_config(self, room_jid, form):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_OWNER)
|
||||||
|
query = iq.setQuery()
|
||||||
|
form.setAttr('type', 'submit')
|
||||||
|
query.addChild(node=form)
|
||||||
|
log.info('Set config for %s', room_jid)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._default_response, {})
|
||||||
|
|
||||||
|
def set_affiliation(self, room_jid, users_dict):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
||||||
|
item = iq.setQuery()
|
||||||
|
for jid in users_dict:
|
||||||
|
affiliation = users_dict[jid].get('affiliation')
|
||||||
|
reason = users_dict[jid].get('reason') or None
|
||||||
|
item_tag = item.addChild('item', {'jid': jid,
|
||||||
|
'affiliation': affiliation})
|
||||||
|
if reason is not None:
|
||||||
|
item_tag.setTagData('reason', reason)
|
||||||
|
log.info('Set affiliation for %s: %s', room_jid, users_dict)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._default_response, {})
|
||||||
|
|
||||||
|
def get_affiliation(self, room_jid, affiliation):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='get', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
||||||
|
item = iq.setQuery().setTag('item')
|
||||||
|
item.setAttr('affiliation', affiliation)
|
||||||
|
log.info('Get affiliation %s for %s', affiliation, room_jid)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._affiliation_received)
|
||||||
|
|
||||||
|
def _affiliation_received(self, stanza):
|
||||||
|
if not nbxmpp.isResultNode(stanza):
|
||||||
|
log.info('Error: %s', stanza.getError())
|
||||||
|
return
|
||||||
|
|
||||||
|
room_jid = stanza.getFrom().getStripped()
|
||||||
|
query = stanza.getTag('query', namespace=nbxmpp.NS_MUC_ADMIN)
|
||||||
|
items = query.getTags('item')
|
||||||
|
users_dict = {}
|
||||||
|
for item in items:
|
||||||
|
try:
|
||||||
|
jid = helpers.parse_jid(item.getAttr('jid'))
|
||||||
|
except helpers.InvalidFormat:
|
||||||
|
log.warning('Invalid JID: %s, ignoring it',
|
||||||
|
item.getAttr('jid'))
|
||||||
|
continue
|
||||||
|
affiliation = item.getAttr('affiliation')
|
||||||
|
users_dict[jid] = {'affiliation': affiliation}
|
||||||
|
if item.has_attr('nick'):
|
||||||
|
users_dict[jid]['nick'] = item.getAttr('nick')
|
||||||
|
if item.has_attr('role'):
|
||||||
|
users_dict[jid]['role'] = item.getAttr('role')
|
||||||
|
reason = item.getTagData('reason')
|
||||||
|
if reason:
|
||||||
|
users_dict[jid]['reason'] = reason
|
||||||
|
log.info('Affiliations received from %s: %s', room_jid, users_dict)
|
||||||
|
app.nec.push_incoming_event(MucAdminReceivedEvent(
|
||||||
|
None, conn=self._con, room_jid=room_jid, users_dict=users_dict))
|
||||||
|
|
||||||
|
def set_role(self, room_jid, nick, role, reason=''):
|
||||||
|
if not app.account_is_connected(self._account):
|
||||||
|
return
|
||||||
|
iq = nbxmpp.Iq(typ='set', to=room_jid, queryNS=nbxmpp.NS_MUC_ADMIN)
|
||||||
|
item = iq.setQuery().setTag('item')
|
||||||
|
item.setAttr('nick', nick)
|
||||||
|
item.setAttr('role', role)
|
||||||
|
if reason:
|
||||||
|
item.addChild(name='reason', payload=reason)
|
||||||
|
log.info('Set role for %s: %s %s %s', room_jid, nick, role, reason)
|
||||||
|
self._con.connection.SendAndCallForResponse(
|
||||||
|
iq, self._default_response, {})
|
||||||
|
|
||||||
def _mediated_invite(self, con, stanza):
|
def _mediated_invite(self, con, stanza):
|
||||||
muc_user = stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER)
|
muc_user = stanza.getTag('x', namespace=nbxmpp.NS_MUC_USER)
|
||||||
if muc_user is None:
|
if muc_user is None:
|
||||||
|
@ -192,6 +340,10 @@ class MUC:
|
||||||
message.addChild(node=x)
|
message.addChild(node=x)
|
||||||
self._con.connection.send(message)
|
self._con.connection.send(message)
|
||||||
|
|
||||||
|
def _default_response(self, conn, stanza, **kwargs):
|
||||||
|
if not nbxmpp.isResultNode(stanza):
|
||||||
|
log.info('Error: %s', stanza.getError())
|
||||||
|
|
||||||
|
|
||||||
class GcInvitationReceived(NetworkIncomingEvent):
|
class GcInvitationReceived(NetworkIncomingEvent):
|
||||||
name = 'gc-invitation-received'
|
name = 'gc-invitation-received'
|
||||||
|
@ -201,5 +353,13 @@ class GcDeclineReceived(NetworkIncomingEvent):
|
||||||
name = 'gc-decline-received'
|
name = 'gc-decline-received'
|
||||||
|
|
||||||
|
|
||||||
|
class MucAdminReceivedEvent(NetworkIncomingEvent):
|
||||||
|
name = 'muc-admin-received'
|
||||||
|
|
||||||
|
|
||||||
|
class MucOwnerReceivedEvent(NetworkIncomingEvent):
|
||||||
|
name = 'muc-owner-received'
|
||||||
|
|
||||||
|
|
||||||
def get_instance(*args, **kwargs):
|
def get_instance(*args, **kwargs):
|
||||||
return MUC(*args, **kwargs), 'MUC'
|
return MUC(*args, **kwargs), 'MUC'
|
||||||
|
|
|
@ -1644,8 +1644,8 @@ class GroupchatConfigWindow:
|
||||||
sw = Gtk.ScrolledWindow()
|
sw = Gtk.ScrolledWindow()
|
||||||
sw.add(self.affiliation_treeview[affiliation])
|
sw.add(self.affiliation_treeview[affiliation])
|
||||||
add_on_vbox.pack_start(sw, True, True, 0)
|
add_on_vbox.pack_start(sw, True, True, 0)
|
||||||
app.connections[self.account].get_affiliation_list(self.room_jid,
|
con = app.connections[self.account]
|
||||||
affiliation)
|
con.get_module('MUC').get_affiliation(self.room_jid, affiliation)
|
||||||
|
|
||||||
self.xml.connect_signals(self)
|
self.xml.connect_signals(self)
|
||||||
self.window.connect('delete-event', self.on_cancel_button_clicked)
|
self.window.connect('delete-event', self.on_cancel_button_clicked)
|
||||||
|
@ -1653,7 +1653,8 @@ class GroupchatConfigWindow:
|
||||||
|
|
||||||
def on_cancel_button_clicked(self, *args):
|
def on_cancel_button_clicked(self, *args):
|
||||||
if self.form:
|
if self.form:
|
||||||
app.connections[self.account].cancel_gc_config(self.room_jid)
|
con = app.connections[self.account]
|
||||||
|
con.get_module('MUC').cancel_config(self.room_jid)
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
def on_cell_edited(self, cell, path, new_text):
|
def on_cell_edited(self, cell, path, new_text):
|
||||||
|
@ -1728,7 +1729,8 @@ class GroupchatConfigWindow:
|
||||||
def on_ok_button_clicked(self, widget):
|
def on_ok_button_clicked(self, widget):
|
||||||
if self.form:
|
if self.form:
|
||||||
form = self.data_form_widget.data_form
|
form = self.data_form_widget.data_form
|
||||||
app.connections[self.account].send_gc_config(self.room_jid, form)
|
con = app.connections[self.account]
|
||||||
|
con.get_module('MUC').set_config(self.room_jid, form)
|
||||||
for affiliation in self.affiliation_labels.keys():
|
for affiliation in self.affiliation_labels.keys():
|
||||||
users_dict = {}
|
users_dict = {}
|
||||||
actual_jid_list = []
|
actual_jid_list = []
|
||||||
|
@ -1751,7 +1753,8 @@ class GroupchatConfigWindow:
|
||||||
if jid not in actual_jid_list:
|
if jid not in actual_jid_list:
|
||||||
users_dict[jid] = {'affiliation': 'none'}
|
users_dict[jid] = {'affiliation': 'none'}
|
||||||
if users_dict:
|
if users_dict:
|
||||||
app.connections[self.account].send_gc_affiliation_list(
|
con = app.connections[self.account]
|
||||||
|
con.get_module('MUC').set_affiliation(
|
||||||
self.room_jid, users_dict)
|
self.room_jid, users_dict)
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
|
|
||||||
|
|
|
@ -649,8 +649,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
def on_ok(subject):
|
def on_ok(subject):
|
||||||
# Note, we don't update self.subject since we don't know whether it
|
# Note, we don't update self.subject since we don't know whether it
|
||||||
# will work yet
|
# will work yet
|
||||||
app.connections[self.account].send_gc_subject(
|
con = app.connections[self.account]
|
||||||
self.room_jid, subject)
|
con.get_module('MUC').set_subject(self.room_jid, subject)
|
||||||
|
|
||||||
InputTextDialog(_('Changing Subject'),
|
InputTextDialog(_('Changing Subject'),
|
||||||
_('Please specify the new subject:'), input_str=self.subject,
|
_('Please specify the new subject:'), input_str=self.subject,
|
||||||
|
@ -678,11 +678,14 @@ class GroupchatControl(ChatControlBase):
|
||||||
try:
|
try:
|
||||||
jid = helpers.parse_jid(jid)
|
jid = helpers.parse_jid(jid)
|
||||||
except Exception:
|
except Exception:
|
||||||
ErrorDialog(_('Invalid group chat JID'),
|
ErrorDialog(
|
||||||
|
_('Invalid group chat JID'),
|
||||||
_('The group chat JID has not allowed characters.'))
|
_('The group chat JID has not allowed characters.'))
|
||||||
return
|
return
|
||||||
app.connections[self.account].destroy_gc_room(
|
con = app.connections[self.account]
|
||||||
self.room_jid, reason, jid)
|
con.get_module('MUC').destroy(self.room_jid, reason, jid)
|
||||||
|
con.get_module('Bookmarks').bookmarks.pop(self.room_jid, None)
|
||||||
|
con.get_module('Bookmarks').store_bookmarks()
|
||||||
gui_menu_builder.build_bookmark_menu(self.account)
|
gui_menu_builder.build_bookmark_menu(self.account)
|
||||||
self.force_non_minimizable = True
|
self.force_non_minimizable = True
|
||||||
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND)
|
self.parent_win.remove_tab(self, self.parent_win.CLOSE_COMMAND)
|
||||||
|
@ -699,7 +702,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
c = app.contacts.get_gc_contact(
|
c = app.contacts.get_gc_contact(
|
||||||
self.account, self.room_jid, self.nick)
|
self.account, self.room_jid, self.nick)
|
||||||
if c.affiliation == 'owner':
|
if c.affiliation == 'owner':
|
||||||
app.connections[self.account].request_gc_config(self.room_jid)
|
con = app.connections[self.account]
|
||||||
|
con.get_module('MUC').request_config(self.room_jid)
|
||||||
elif c.affiliation == 'admin':
|
elif c.affiliation == 'admin':
|
||||||
if self.room_jid not in app.interface.instances[self.account][
|
if self.room_jid not in app.interface.instances[self.account][
|
||||||
'gc_config']:
|
'gc_config']:
|
||||||
|
@ -1797,8 +1801,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
# We need to configure the room if it's a new one.
|
# We need to configure the room if it's a new one.
|
||||||
# We cannot know it's a new one. Status 201 is not
|
# We cannot know it's a new one. Status 201 is not
|
||||||
# sent by all servers.
|
# sent by all servers.
|
||||||
app.connections[self.account].request_gc_config(
|
con = app.connections[self.account]
|
||||||
self.room_jid)
|
con.get_module('MUC').request_config(self.room_jid)
|
||||||
elif 'continue_tag' in app.automatic_rooms[
|
elif 'continue_tag' in app.automatic_rooms[
|
||||||
self.account][self.room_jid]:
|
self.account][self.room_jid]:
|
||||||
# We just need to invite contacts
|
# We just need to invite contacts
|
||||||
|
@ -1932,8 +1936,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
self.draw_all_roles()
|
self.draw_all_roles()
|
||||||
if obj.status_code and '201' in obj.status_code:
|
if obj.status_code and '201' in obj.status_code:
|
||||||
# We just created the room
|
# We just created the room
|
||||||
app.connections[self.account].request_gc_config(
|
con = app.connections[self.account]
|
||||||
self.room_jid)
|
con.get_module('MUC').request_config(self.room_jid)
|
||||||
else:
|
else:
|
||||||
gc_c = app.contacts.get_gc_contact(self.account,
|
gc_c = app.contacts.get_gc_contact(self.account,
|
||||||
self.room_jid, obj.nick)
|
self.room_jid, obj.nick)
|
||||||
|
@ -2382,8 +2386,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
def on_ok(subject):
|
def on_ok(subject):
|
||||||
# Note, we don't update self.subject since we don't know whether it
|
# Note, we don't update self.subject since we don't know whether it
|
||||||
# will work yet
|
# will work yet
|
||||||
app.connections[self.account].send_gc_subject(self.room_jid,
|
con = app.connections[self.account]
|
||||||
subject)
|
con.get_module('MUC').set_subject(self.room_jid, subject)
|
||||||
|
|
||||||
InputTextDialog(_('Changing Subject'),
|
InputTextDialog(_('Changing Subject'),
|
||||||
_('Please specify the new subject:'), input_str=self.subject,
|
_('Please specify the new subject:'), input_str=self.subject,
|
||||||
|
@ -2562,8 +2566,8 @@ class GroupchatControl(ChatControlBase):
|
||||||
Kick a user
|
Kick a user
|
||||||
"""
|
"""
|
||||||
def on_ok(reason):
|
def on_ok(reason):
|
||||||
app.connections[self.account].gc_set_role(self.room_jid, nick,
|
con = app.connections[self.account]
|
||||||
'none', reason)
|
con.get_module('MUC').set_role(self.room_jid, nick, 'none', reason)
|
||||||
|
|
||||||
# ask for reason
|
# ask for reason
|
||||||
InputDialog(_('Kicking %s') % nick,
|
InputDialog(_('Kicking %s') % nick,
|
||||||
|
@ -2828,37 +2832,40 @@ class GroupchatControl(ChatControlBase):
|
||||||
"""
|
"""
|
||||||
Grant voice privilege to a user
|
Grant voice privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_role(self.room_jid, nick,
|
con = app.connections[self.account]
|
||||||
'participant')
|
con.get_module('MUC').set_role(self.room_jid, nick, 'participant')
|
||||||
|
|
||||||
def revoke_voice(self, widget, nick):
|
def revoke_voice(self, widget, nick):
|
||||||
"""
|
"""
|
||||||
Revoke voice privilege to a user
|
Revoke voice privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_role(self.room_jid, nick,
|
con = app.connections[self.account]
|
||||||
'visitor')
|
con.get_module('MUC').set_role(self.room_jid, nick, 'visitor')
|
||||||
|
|
||||||
def grant_moderator(self, widget, nick):
|
def grant_moderator(self, widget, nick):
|
||||||
"""
|
"""
|
||||||
Grant moderator privilege to a user
|
Grant moderator privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_role(self.room_jid, nick,
|
con = app.connections[self.account]
|
||||||
'moderator')
|
con.get_module('MUC').set_role(self.room_jid, nick, 'moderator')
|
||||||
|
|
||||||
def revoke_moderator(self, widget, nick):
|
def revoke_moderator(self, widget, nick):
|
||||||
"""
|
"""
|
||||||
Revoke moderator privilege to a user
|
Revoke moderator privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_role(self.room_jid, nick,
|
con = app.connections[self.account]
|
||||||
'participant')
|
con.get_module('MUC').set_role(self.room_jid, nick, 'participant')
|
||||||
|
|
||||||
def ban(self, widget, jid):
|
def ban(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Ban a user
|
Ban a user
|
||||||
"""
|
"""
|
||||||
def on_ok(reason):
|
def on_ok(reason):
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid,
|
con = app.connections[self.account]
|
||||||
jid, 'outcast', reason)
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'outcast',
|
||||||
|
'reason': reason}})
|
||||||
|
|
||||||
# to ban we know the real jid. so jid is not fakejid
|
# to ban we know the real jid. so jid is not fakejid
|
||||||
nick = app.get_nick_from_jid(jid)
|
nick = app.get_nick_from_jid(jid)
|
||||||
|
@ -2871,43 +2878,55 @@ class GroupchatControl(ChatControlBase):
|
||||||
"""
|
"""
|
||||||
Grant membership privilege to a user
|
Grant membership privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'member')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'member'}})
|
||||||
|
|
||||||
def revoke_membership(self, widget, jid):
|
def revoke_membership(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Revoke membership privilege to a user
|
Revoke membership privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'none')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'none'}})
|
||||||
|
|
||||||
def grant_admin(self, widget, jid):
|
def grant_admin(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Grant administrative privilege to a user
|
Grant administrative privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'admin')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'admin'}})
|
||||||
|
|
||||||
def revoke_admin(self, widget, jid):
|
def revoke_admin(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Revoke administrative privilege to a user
|
Revoke administrative privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'member')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'member'}})
|
||||||
|
|
||||||
def grant_owner(self, widget, jid):
|
def grant_owner(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Grant owner privilege to a user
|
Grant owner privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'owner')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'owner'}})
|
||||||
|
|
||||||
def revoke_owner(self, widget, jid):
|
def revoke_owner(self, widget, jid):
|
||||||
"""
|
"""
|
||||||
Revoke owner privilege to a user
|
Revoke owner privilege to a user
|
||||||
"""
|
"""
|
||||||
app.connections[self.account].gc_set_affiliation(self.room_jid, jid,
|
con = app.connections[self.account]
|
||||||
'admin')
|
con.get_module('MUC').set_affiliation(
|
||||||
|
self.room_jid,
|
||||||
|
{jid: {'affiliation': 'admin'}})
|
||||||
|
|
||||||
def on_info(self, widget, nick):
|
def on_info(self, widget, nick):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -606,14 +606,14 @@ class Interface:
|
||||||
f.value = True
|
f.value = True
|
||||||
elif f.var == 'public_list':
|
elif f.var == 'public_list':
|
||||||
f.value = False
|
f.value = False
|
||||||
obj.conn.send_gc_config(obj.jid, obj.dataform.get_purged())
|
obj.conn.get_module('MUC').set_config(obj.jid, obj.dataform.get_purged())
|
||||||
user_list = {}
|
user_list = {}
|
||||||
for jid in app.automatic_rooms[account][obj.jid]['invities']:
|
for jid in app.automatic_rooms[account][obj.jid]['invities']:
|
||||||
user_list[jid] = {'affiliation': 'member'}
|
user_list[jid] = {'affiliation': 'member'}
|
||||||
obj.conn.send_gc_affiliation_list(obj.jid, user_list)
|
obj.conn.get_module('MUC').set_affiliation(obj.jid, user_list)
|
||||||
else:
|
else:
|
||||||
# use default configuration
|
# use default configuration
|
||||||
obj.conn.send_gc_config(obj.jid, obj.form_node)
|
obj.conn.get_module('MUC').set_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
|
||||||
|
@ -637,8 +637,8 @@ class Interface:
|
||||||
def handle_event_gc_affiliation(self, obj):
|
def handle_event_gc_affiliation(self, obj):
|
||||||
#('GC_AFFILIATION', account, (room_jid, users_dict))
|
#('GC_AFFILIATION', account, (room_jid, users_dict))
|
||||||
account = obj.conn.name
|
account = obj.conn.name
|
||||||
if obj.jid in self.instances[account]['gc_config']:
|
if obj.room_jid in self.instances[account]['gc_config']:
|
||||||
self.instances[account]['gc_config'][obj.jid].\
|
self.instances[account]['gc_config'][obj.room_jid].\
|
||||||
affiliation_list_received(obj.users_dict)
|
affiliation_list_received(obj.users_dict)
|
||||||
|
|
||||||
def handle_event_gc_decline(self, obj):
|
def handle_event_gc_decline(self, obj):
|
||||||
|
|
Loading…
Reference in New Issue