* now we handle result for archiving preferences request and also all changes that come from server

This commit is contained in:
Anaël Verrier 2009-07-15 15:13:12 +02:00
parent 649aa1ed55
commit 66e7ea153e
3 changed files with 55 additions and 9 deletions

View File

@ -1032,6 +1032,13 @@ class Connection(ConnectionHandlers):
self.connection.set_send_timeout(self.keepalives, self.send_keepalive)
self.connection.set_send_timeout2(self.pingalives, self.sendPing)
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 = '')
id_ = self.connection.getAnID()
iq.setID(id_)

View File

@ -51,6 +51,7 @@ from common import exceptions
from common.commands import ConnectionCommands
from common.pubsub import ConnectionPubSub
from common.caps import ConnectionCaps
from common.message_archiving import ConnectionArchive
from common import dbus_support
if dbus_support.supported:
@ -1433,8 +1434,9 @@ sent a message to.'''
return sess
class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase):
class ConnectionHandlers(ConnectionArchive, ConnectionVcard, ConnectionBytestream, ConnectionDisco, ConnectionCommands, ConnectionPubSub, ConnectionCaps, ConnectionHandlersBase):
def __init__(self):
ConnectionArchive.__init__(self)
ConnectionVcard.__init__(self)
ConnectionBytestream.__init__(self)
ConnectionCommands.__init__(self)
@ -2739,6 +2741,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
common.xmpp.NS_SEARCH)
con.RegisterHandler('iq', self._PrivacySetCB, 'set',
common.xmpp.NS_PRIVACY)
con.RegisterHandler('iq', self._ArchiveCB, ns=common.xmpp.NS_ARCHIVE)
con.RegisterHandler('iq', self._PubSubCB, 'result')
con.RegisterHandler('iq', self._ErrorCB, 'error')
con.RegisterHandler('iq', self._IqCB)

View File

@ -19,7 +19,7 @@
##
class ArchivingPreferences:
class ConnectionArchive:
def __init__(self):
self.auto_save = None
self.method_auto = None
@ -28,17 +28,53 @@ class ArchivingPreferences:
self.default = None
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):
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):
self.items[jid] = {'expire': expire, 'otr': otr, 'save': save}
def remove_item(self, 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'))