use NEC to handle private storage stanza
This commit is contained in:
parent
f93dca04f3
commit
cb0f30f4b4
|
@ -1091,6 +1091,15 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
ged.CORE, self._nec_time_revised_request_received)
|
||||
gajim.ged.register_event_handler('roster-set-received',
|
||||
ged.CORE, self._nec_roster_set_received)
|
||||
gajim.nec.register_incoming_event(PrivateStorageBookmarksReceivedEvent)
|
||||
gajim.ged.register_event_handler('private-storage-bookmarks-received',
|
||||
ged.CORE, self._nec_private_storate_bookmarks_received)
|
||||
gajim.nec.register_incoming_event(BookmarksReceivedEvent)
|
||||
gajim.nec.register_incoming_event(
|
||||
PrivateStorageRosternotesReceivedEvent)
|
||||
gajim.ged.register_event_handler('private-storage-rosternotes-received',
|
||||
ged.CORE, self._nec_private_storate_rosternotes_received)
|
||||
gajim.nec.register_incoming_event(RosternotesReceivedEvent)
|
||||
|
||||
def build_http_auth_answer(self, iq_obj, answer):
|
||||
if not self.connection or self.connected < 2:
|
||||
|
@ -1137,34 +1146,28 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
errcode = iq_obj.getErrorCode()
|
||||
self.dispatch('ERROR_ANSWER', (id_, jid_from, errmsg, errcode))
|
||||
|
||||
def _nec_private_storate_bookmarks_received(self, obj):
|
||||
resend_to_pubsub = False
|
||||
bm_jids = [b['jid'] for b in self.bookmarks]
|
||||
for bm in obj.bookmarks:
|
||||
if bm['jid'] not in bm_jids:
|
||||
self.bookmarks.append(bm)
|
||||
# We got a bookmark that was not in pubsub
|
||||
resend_to_pubsub = True
|
||||
if self.pubsub_supported and resend_to_pubsub:
|
||||
self.store_bookmarks('pubsub')
|
||||
|
||||
def _nec_private_storate_rosternotes_received(self, obj):
|
||||
for jid in obj.annotations:
|
||||
self.annotations[jid] = obj.annotations[jid]
|
||||
|
||||
def _PrivateCB(self, con, iq_obj):
|
||||
"""
|
||||
Private Data (XEP 048 and 049)
|
||||
"""
|
||||
log.debug('PrivateCB')
|
||||
query = iq_obj.getTag('query')
|
||||
storage = query.getTag('storage')
|
||||
if storage:
|
||||
ns = storage.getNamespace()
|
||||
if ns == 'storage:bookmarks':
|
||||
self._parse_bookmarks(storage, 'xml')
|
||||
elif ns == 'gajim:prefs':
|
||||
# Preferences data
|
||||
# http://www.xmpp.org/extensions/xep-0049.html
|
||||
#TODO: implement this
|
||||
pass
|
||||
elif ns == 'storage:rosternotes':
|
||||
# Annotations
|
||||
# http://www.xmpp.org/extensions/xep-0145.html
|
||||
notes = storage.getTags('note')
|
||||
for note in notes:
|
||||
try:
|
||||
jid = helpers.parse_jid(note.getAttr('jid'))
|
||||
except common.helpers.InvalidFormat:
|
||||
log.warn('Invalid JID: %s, ignoring it' % note.getAttr('jid'))
|
||||
continue
|
||||
annotation = note.getData()
|
||||
self.annotations[jid] = annotation
|
||||
gajim.nec.push_incoming_event(PrivateStorageReceivedEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
|
||||
def _SecLabelCB(self, con, iq_obj):
|
||||
"""
|
||||
|
@ -1264,7 +1267,7 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
gajim.nec.push_incoming_event(VersionRequestEvent(None,
|
||||
conn=self, iq_obj=iq_obj))
|
||||
raise common.xmpp.NodeProcessed
|
||||
|
||||
|
||||
def _nec_version_request_received(self, obj):
|
||||
if obj.conn.name != self.name:
|
||||
return
|
||||
|
@ -2434,7 +2437,7 @@ class HttpAuthReceivedEvent(nec.NetworkIncomingEvent):
|
|||
class LastResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'last-result-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
def generate(self):
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
|
@ -2460,7 +2463,7 @@ class LastResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
class VersionResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'version-result-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
def generate(self):
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
|
@ -2594,7 +2597,7 @@ class GMailQueryReceivedEvent(nec.NetworkIncomingEvent):
|
|||
class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent):
|
||||
name = 'roster-item-exchange-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
def generate(self):
|
||||
self.get_id()
|
||||
self.get_jid_resource()
|
||||
|
@ -2639,11 +2642,11 @@ class RosterItemExchangeEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
class VersionRequestEvent(nec.NetworkIncomingEvent):
|
||||
name = 'version-request-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
class LastRequestEvent(nec.NetworkIncomingEvent):
|
||||
name = 'last-request-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
class TimeRequestEvent(nec.NetworkIncomingEvent):
|
||||
name = 'time-request-received'
|
||||
base_network_events = []
|
||||
|
@ -2725,3 +2728,97 @@ class MucAdminReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
|
|||
if reason:
|
||||
self.users_dict[jid]['reason'] = reason
|
||||
return True
|
||||
|
||||
class PrivateStorageReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'private-storage-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
query = self.iq_obj.getTag('query')
|
||||
self.storage_node = query.getTag('storage')
|
||||
if self.storage_node:
|
||||
self.namespace = self.storage_node.getNamespace()
|
||||
return True
|
||||
|
||||
class BookmarksHelper:
|
||||
def parse_bookmarks(self):
|
||||
self.bookmarks = []
|
||||
confs = self.base_event.storage_node.getTags('conference')
|
||||
for conf in confs:
|
||||
autojoin_val = conf.getAttr('autojoin')
|
||||
if autojoin_val is None: # not there (it's optional)
|
||||
autojoin_val = False
|
||||
minimize_val = conf.getAttr('minimize')
|
||||
if minimize_val is None: # not there (it's optional)
|
||||
minimize_val = False
|
||||
print_status = conf.getTagData('print_status')
|
||||
if not print_status:
|
||||
print_status = conf.getTagData('show_status')
|
||||
try:
|
||||
jid = helpers.parse_jid(conf.getAttr('jid'))
|
||||
except common.helpers.InvalidFormat:
|
||||
log.warn('Invalid JID: %s, ignoring it' % conf.getAttr('jid'))
|
||||
continue
|
||||
bm = {'name': conf.getAttr('name'),
|
||||
'jid': jid,
|
||||
'autojoin': autojoin_val,
|
||||
'minimize': minimize_val,
|
||||
'password': conf.getTagData('password'),
|
||||
'nick': conf.getTagData('nick'),
|
||||
'print_status': print_status}
|
||||
|
||||
|
||||
bm_jids = [b['jid'] for b in self.bookmarks]
|
||||
if bm['jid'] not in bm_jids:
|
||||
self.bookmarks.append(bm)
|
||||
|
||||
class PrivateStorageBookmarksReceivedEvent(nec.NetworkIncomingEvent,
|
||||
BookmarksHelper):
|
||||
name = 'private-storage-bookmarks-received'
|
||||
base_network_events = ['private-storage-received']
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
if self.base_event.namespace != 'storage:bookmarks':
|
||||
return
|
||||
self.parse_bookmarks()
|
||||
return True
|
||||
|
||||
class BookmarksReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'bookmarks-received'
|
||||
base_network_events = ['private-storage-bookmarks-received']
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
self.bookmarks = self.base_event.bookmarks
|
||||
return True
|
||||
|
||||
class PrivateStorageRosternotesReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'private-storage-rosternotes-received'
|
||||
base_network_events = ['private-storage-received']
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
if self.base_event.namespace != 'storage:rosternotes':
|
||||
return
|
||||
notes = self.base_event.storage_node.getTags('note')
|
||||
self.annotations = {}
|
||||
for note in notes:
|
||||
try:
|
||||
jid = helpers.parse_jid(note.getAttr('jid'))
|
||||
except common.helpers.InvalidFormat:
|
||||
log.warn('Invalid JID: %s, ignoring it' % note.getAttr('jid'))
|
||||
continue
|
||||
annotation = note.getData()
|
||||
self.annotations[jid] = annotation
|
||||
if self.annotations:
|
||||
return True
|
||||
|
||||
class RosternotesReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'rosternotes-received'
|
||||
base_network_events = ['private-storage-rosternotes-received']
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.base_event.conn
|
||||
self.annotations = self.base_event.annotations
|
||||
return True
|
|
@ -1008,12 +1008,10 @@ class Interface:
|
|||
f.value = True
|
||||
elif f.var == 'public_list':
|
||||
f.value = False
|
||||
gajim.connections[account].send_gc_config(obj.jid,
|
||||
obj.dataform.get_purged())
|
||||
obj.conn.send_gc_config(obj.jid, obj.dataform.get_purged())
|
||||
else:
|
||||
# use default configuration
|
||||
gajim.connections[account].send_gc_config(obj.jid,
|
||||
obj.form_node)
|
||||
obj.conn.send_gc_config(obj.jid, obj.form_node)
|
||||
# invite contacts
|
||||
# check if it is necessary to add <continue />
|
||||
continue_tag = False
|
||||
|
@ -1021,7 +1019,7 @@ class Interface:
|
|||
continue_tag = True
|
||||
if 'invities' in gajim.automatic_rooms[account][obj.jid]:
|
||||
for jid in gajim.automatic_rooms[account][obj.jid]['invities']:
|
||||
gajim.connections[account].send_invite(obj.jid, jid,
|
||||
obj.conn.send_invite(obj.jid, jid,
|
||||
continue_tag=continue_tag)
|
||||
del gajim.automatic_rooms[account][obj.jid]
|
||||
elif obj.jid not in self.instances[account]['gc_config']:
|
||||
|
@ -1254,7 +1252,7 @@ class Interface:
|
|||
self.roster.draw_group(group, account)
|
||||
self.roster.draw_contact(obj.jid, account)
|
||||
|
||||
def handle_event_bookmarks(self, account, bms):
|
||||
def handle_event_bookmarks(self, obj):
|
||||
# ('BOOKMARKS', account, [{name,jid,autojoin,password,nick}, {}])
|
||||
# We received a bookmark item from the server (JEP48)
|
||||
# Auto join GC windows if neccessary
|
||||
|
@ -1262,10 +1260,10 @@ class Interface:
|
|||
self.roster.set_actions_menu_needs_rebuild()
|
||||
invisible_show = gajim.SHOW_LIST.index('invisible')
|
||||
# do not autojoin if we are invisible
|
||||
if gajim.connections[account].connected == invisible_show:
|
||||
if obj.conn.connected == invisible_show:
|
||||
return
|
||||
|
||||
self.auto_join_bookmarks(account)
|
||||
self.auto_join_bookmarks(obj.conn.name)
|
||||
|
||||
def handle_event_file_send_error(self, account, array):
|
||||
jid = array[0]
|
||||
|
@ -2110,7 +2108,6 @@ class Interface:
|
|||
'GC_PASSWORD_REQUIRED': [self.handle_event_gc_password_required],
|
||||
'GC_ERROR': [self.handle_event_gc_error],
|
||||
'BAD_PASSPHRASE': [self.handle_event_bad_passphrase],
|
||||
'BOOKMARKS': [self.handle_event_bookmarks],
|
||||
'CON_TYPE': [self.handle_event_con_type],
|
||||
'CONNECTION_LOST': [self.handle_event_connection_lost],
|
||||
'FILE_REQUEST': [self.handle_event_file_request],
|
||||
|
@ -2160,6 +2157,7 @@ class Interface:
|
|||
'CAPS_RECEIVED': [self.handle_event_caps_received],
|
||||
'ARCHIVING_CHANGED': [self.handle_event_archiving_changed],
|
||||
'ARCHIVING_ERROR': [self.handle_event_archiving_error],
|
||||
'bookmarks-received': [self.handle_event_bookmarks],
|
||||
'gmail-notify': [self.handle_event_gmail_notify],
|
||||
'http-auth-received': [self.handle_event_http_auth],
|
||||
'last-result-received': [self.handle_event_last_status_time],
|
||||
|
|
Loading…
Reference in New Issue