* now we handle result for archiving preferences request and also all changes that come from server
This commit is contained in:
parent
649aa1ed55
commit
66e7ea153e
|
@ -1032,6 +1032,13 @@ class Connection(ConnectionHandlers):
|
||||||
self.connection.set_send_timeout(self.keepalives, self.send_keepalive)
|
self.connection.set_send_timeout(self.keepalives, self.send_keepalive)
|
||||||
self.connection.set_send_timeout2(self.pingalives, self.sendPing)
|
self.connection.set_send_timeout2(self.pingalives, self.sendPing)
|
||||||
self.connection.onreceive(None)
|
self.connection.onreceive(None)
|
||||||
|
|
||||||
|
# Request message archiving preferences
|
||||||
|
iq = common.xmpp.Iq('get')
|
||||||
|
iq.setTag('pref', namespace=common.xmpp.NS_ARCHIVE)
|
||||||
|
self.connection.send(iq)
|
||||||
|
|
||||||
|
# Request privacy list
|
||||||
iq = common.xmpp.Iq('get', common.xmpp.NS_PRIVACY, xmlns = '')
|
iq = common.xmpp.Iq('get', common.xmpp.NS_PRIVACY, xmlns = '')
|
||||||
id_ = self.connection.getAnID()
|
id_ = self.connection.getAnID()
|
||||||
iq.setID(id_)
|
iq.setID(id_)
|
||||||
|
|
|
@ -51,6 +51,7 @@ from common import exceptions
|
||||||
from common.commands import ConnectionCommands
|
from common.commands import ConnectionCommands
|
||||||
from common.pubsub import ConnectionPubSub
|
from common.pubsub import ConnectionPubSub
|
||||||
from common.caps import ConnectionCaps
|
from common.caps import ConnectionCaps
|
||||||
|
from common.message_archiving import ConnectionArchive
|
||||||
|
|
||||||
from common import dbus_support
|
from common import dbus_support
|
||||||
if dbus_support.supported:
|
if dbus_support.supported:
|
||||||
|
@ -1433,8 +1434,9 @@ sent a message to.'''
|
||||||
|
|
||||||
return sess
|
return sess
|
||||||
|
|
||||||
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase):
|
class ConnectionHandlers(ConnectionArchive, ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
ConnectionArchive.__init__(self)
|
||||||
ConnectionVcard.__init__(self)
|
ConnectionVcard.__init__(self)
|
||||||
ConnectionBytestream.__init__(self)
|
ConnectionBytestream.__init__(self)
|
||||||
ConnectionCommands.__init__(self)
|
ConnectionCommands.__init__(self)
|
||||||
|
@ -2739,6 +2741,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
common.xmpp.NS_SEARCH)
|
common.xmpp.NS_SEARCH)
|
||||||
con.RegisterHandler('iq', self._PrivacySetCB, 'set',
|
con.RegisterHandler('iq', self._PrivacySetCB, 'set',
|
||||||
common.xmpp.NS_PRIVACY)
|
common.xmpp.NS_PRIVACY)
|
||||||
|
con.RegisterHandler('iq', self._ArchiveCB, ns=common.xmpp.NS_ARCHIVE)
|
||||||
con.RegisterHandler('iq', self._PubSubCB, 'result')
|
con.RegisterHandler('iq', self._PubSubCB, 'result')
|
||||||
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
con.RegisterHandler('iq', self._ErrorCB, 'error')
|
||||||
con.RegisterHandler('iq', self._IqCB)
|
con.RegisterHandler('iq', self._IqCB)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|
||||||
class ArchivingPreferences:
|
class ConnectionArchive:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.auto_save = None
|
self.auto_save = None
|
||||||
self.method_auto = None
|
self.method_auto = None
|
||||||
|
@ -28,17 +28,53 @@ class ArchivingPreferences:
|
||||||
self.default = None
|
self.default = None
|
||||||
self.items = {}
|
self.items = {}
|
||||||
|
|
||||||
def set(self, auto_save, method_auto, method_local, method_manual):
|
|
||||||
self.auto_save = auto_save
|
|
||||||
self.method_auto = method_auto
|
|
||||||
self.method_local = method_local
|
|
||||||
self.method_manual = method_manual
|
|
||||||
|
|
||||||
def set_default(self, otr, save, expire=None, unset=False):
|
def set_default(self, otr, save, expire=None, unset=False):
|
||||||
self.default = {'expire': expire, 'otr': otr, 'save': save, 'unset': unset}
|
self.default = {'expire': expire, 'otr': otr, 'save': save,
|
||||||
|
'unset': unset}
|
||||||
|
|
||||||
def append_or_update_item(self, jid, expire, otr, save):
|
def append_or_update_item(self, jid, expire, otr, save):
|
||||||
self.items[jid] = {'expire': expire, 'otr': otr, 'save': save}
|
self.items[jid] = {'expire': expire, 'otr': otr, 'save': save}
|
||||||
|
|
||||||
def remove_item(self, jid):
|
def remove_item(self, jid):
|
||||||
del self.items[jid]
|
del self.items[jid]
|
||||||
|
|
||||||
|
def _ArchiveCB(self, con, iq_obj):
|
||||||
|
print '_ArchiveCB', iq_obj.getType()
|
||||||
|
if iq_obj.getType() not in ('result', 'set'):
|
||||||
|
return
|
||||||
|
if iq_obj.getTag('pref'):
|
||||||
|
pref = iq_obj.getTag('pref')
|
||||||
|
|
||||||
|
if pref.getTag('auto'):
|
||||||
|
self.auto_save = pref.getTagAttr('auto', 'save')
|
||||||
|
print 'auto_save:', self.auto_save
|
||||||
|
|
||||||
|
method_auto = pref.getTag('method', attrs={'type': 'auto'})
|
||||||
|
if method_auto:
|
||||||
|
self.method_auto = method_auto.getAttr('use')
|
||||||
|
|
||||||
|
method_local = pref.getTag('method', attrs={'type': 'local'})
|
||||||
|
if method_local:
|
||||||
|
self.method_local = method_local.getAttr('use')
|
||||||
|
|
||||||
|
method_manual = pref.getTag('method', attrs={'type': 'manual'})
|
||||||
|
if method_manual:
|
||||||
|
self.method_manual = method_manual.getAttr('use')
|
||||||
|
|
||||||
|
print 'method alm:', self.method_auto, self.method_local, self.method_manual
|
||||||
|
|
||||||
|
if pref.getTag('default'):
|
||||||
|
default = pref.getTag('default')
|
||||||
|
print 'default oseu:', default.getAttr('otr'), default.getAttr('save'), default.getAttr('expire'), default.getAttr('unset')
|
||||||
|
self.set_default(default.getAttr('otr'),
|
||||||
|
default.getAttr('save'), default.getAttr('expire'),
|
||||||
|
default.getAttr('unset'))
|
||||||
|
for item in pref.getTags('item'):
|
||||||
|
print item.getAttr('jid'), item.getAttr('otr'), item.getAttr('save'), item.getAttr('expire')
|
||||||
|
self.append_or_update_item(item.getAttr('jid'),
|
||||||
|
item.getAttr('otr'), item.getAttr('save'),
|
||||||
|
item.getAttr('expire'))
|
||||||
|
elif iq_obj.getTag('itemremove'):
|
||||||
|
for item in pref.getTags('item'):
|
||||||
|
print 'del', item.getAttr('jid')
|
||||||
|
self.remove_item(item.getAttr('jid'))
|
||||||
|
|
Loading…
Reference in New Issue