2018-07-27 15:46:02 +02:00
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# XEP-0083: Nested Roster Groups
|
|
|
|
|
|
|
|
import nbxmpp
|
|
|
|
|
2019-03-09 23:16:27 +01:00
|
|
|
from gajim.common.modules.base import BaseModule
|
2018-07-27 15:46:02 +02:00
|
|
|
|
|
|
|
|
2019-03-09 23:16:27 +01:00
|
|
|
class Delimiter(BaseModule):
|
2018-07-27 15:46:02 +02:00
|
|
|
def __init__(self, con):
|
2019-03-09 23:16:27 +01:00
|
|
|
BaseModule.__init__(self, con)
|
2018-07-27 15:46:02 +02:00
|
|
|
self.available = False
|
|
|
|
self.delimiter = '::'
|
|
|
|
|
|
|
|
def get_roster_delimiter(self):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Request')
|
2018-07-27 15:46:02 +02:00
|
|
|
node = nbxmpp.Node('storage', attrs={'xmlns': 'roster:delimiter'})
|
|
|
|
iq = nbxmpp.Iq('get', nbxmpp.NS_PRIVATE, payload=node)
|
|
|
|
|
|
|
|
self._con.connection.SendAndCallForResponse(
|
|
|
|
iq, self._delimiter_received)
|
|
|
|
|
|
|
|
def _delimiter_received(self, stanza):
|
|
|
|
if not nbxmpp.isResultNode(stanza):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Request error: %s', stanza.getError())
|
2018-07-27 15:46:02 +02:00
|
|
|
else:
|
|
|
|
delimiter = stanza.getQuery().getTagData('roster')
|
|
|
|
self.available = True
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Delimiter received: %s', delimiter)
|
2018-07-27 15:46:02 +02:00
|
|
|
if delimiter:
|
|
|
|
self.delimiter = delimiter
|
|
|
|
else:
|
|
|
|
self.set_roster_delimiter()
|
|
|
|
|
2018-07-28 13:32:37 +02:00
|
|
|
self._con.connect_machine()
|
2018-07-27 15:46:02 +02:00
|
|
|
|
|
|
|
def set_roster_delimiter(self):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Set delimiter')
|
2018-07-27 15:46:02 +02:00
|
|
|
iq = nbxmpp.Iq('set', nbxmpp.NS_PRIVATE)
|
|
|
|
roster = iq.getQuery().addChild('roster', namespace='roster:delimiter')
|
|
|
|
roster.setData('::')
|
|
|
|
|
|
|
|
self._con.connection.SendAndCallForResponse(
|
|
|
|
iq, self._set_delimiter_response)
|
|
|
|
|
2019-03-09 23:16:27 +01:00
|
|
|
def _set_delimiter_response(self, stanza):
|
2018-07-27 15:46:02 +02:00
|
|
|
if not nbxmpp.isResultNode(stanza):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Store error: %s', stanza.getError())
|
2018-07-27 15:46:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return Delimiter(*args, **kwargs), 'Delimiter'
|