we not send sha of our VCARD (JEP 153) in every presences
This commit is contained in:
parent
8c86a126cc
commit
a7572c4352
3 changed files with 58 additions and 18 deletions
|
@ -19,6 +19,7 @@
|
||||||
##
|
##
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import sha
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import sre
|
import sre
|
||||||
|
@ -134,6 +135,7 @@ class Connection:
|
||||||
self.connected = 0 # offline
|
self.connected = 0 # offline
|
||||||
self.connection = None # xmpppy instance
|
self.connection = None # xmpppy instance
|
||||||
self.gpg = None
|
self.gpg = None
|
||||||
|
self.vcard_sha = None
|
||||||
self.status = ''
|
self.status = ''
|
||||||
self.myVCardID = []
|
self.myVCardID = []
|
||||||
self.new_account_info = None
|
self.new_account_info = None
|
||||||
|
@ -161,6 +163,12 @@ class Connection:
|
||||||
for handler in self.handlers[event]:
|
for handler in self.handlers[event]:
|
||||||
handler(self.name, data)
|
handler(self.name, data)
|
||||||
|
|
||||||
|
def add_sha(self, p):
|
||||||
|
c = p.setTag('x', namespace = common.xmpp.NS_VCARD_UPDATE)
|
||||||
|
if self.vcard_sha is not None:
|
||||||
|
c.setTagData('photo', self.vcard_sha)
|
||||||
|
return p
|
||||||
|
|
||||||
# this is in features.py but it is blocking
|
# this is in features.py but it is blocking
|
||||||
def _discover(self, ns, jid, node = None):
|
def _discover(self, ns, jid, node = None):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -213,9 +221,20 @@ class Connection:
|
||||||
vcard[name] = {}
|
vcard[name] = {}
|
||||||
for c in info.getChildren():
|
for c in info.getChildren():
|
||||||
vcard[name][c.getName()] = c.getData()
|
vcard[name][c.getName()] = c.getData()
|
||||||
if vc.getID() in self.myVCardID:
|
if int(vc.getID()) in self.myVCardID:
|
||||||
self.myVCardID.remove(vc.getID())
|
self.myVCardID.remove(int(vc.getID()))
|
||||||
|
if vcard.has_key('PHOTO') and type(vcard['PHOTO']) == type({}) and \
|
||||||
|
vcard['PHOTO'].has_key('BINVAL'):
|
||||||
|
photo = vcard['PHOTO']['BINVAL']
|
||||||
|
self.vcard_sha = sha.sha(photo).hexdigest()
|
||||||
|
else:
|
||||||
|
self.vcard_sha = ''
|
||||||
self.dispatch('MYVCARD', vcard)
|
self.dispatch('MYVCARD', vcard)
|
||||||
|
#we re-send our presence with sha
|
||||||
|
sshow = STATUS_LIST[self.connected]
|
||||||
|
p = common.xmpp.Presence(typ = None, show = sshow)
|
||||||
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
else:
|
else:
|
||||||
self.dispatch('VCARD', vcard)
|
self.dispatch('VCARD', vcard)
|
||||||
|
|
||||||
|
@ -319,8 +338,9 @@ class Connection:
|
||||||
gajim.log.debug('subscribe request from %s' % who)
|
gajim.log.debug('subscribe request from %s' % who)
|
||||||
if gajim.config.get('alwaysauth') or who.find("@") <= 0:
|
if gajim.config.get('alwaysauth') or who.find("@") <= 0:
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.to_be_sent.append(common.xmpp.Presence(who,
|
p = common.xmpp.Presence(who, 'subscribed')
|
||||||
'subscribed'))
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
if who.find("@") <= 0:
|
if who.find("@") <= 0:
|
||||||
self.dispatch('NOTIFY',
|
self.dispatch('NOTIFY',
|
||||||
(prs.getFrom().getStripped().encode('utf8'), 'offline',
|
(prs.getFrom().getStripped().encode('utf8'), 'offline',
|
||||||
|
@ -1309,6 +1329,7 @@ class Connection:
|
||||||
self.activate_privacy_rule('invisible')
|
self.activate_privacy_rule('invisible')
|
||||||
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
||||||
p = common.xmpp.Presence(typ = ptype, priority = prio, show = show)
|
p = common.xmpp.Presence(typ = ptype, priority = prio, show = show)
|
||||||
|
p = self.add_sha(p)
|
||||||
if msg:
|
if msg:
|
||||||
p.setStatus(msg)
|
p.setStatus(msg)
|
||||||
if signed:
|
if signed:
|
||||||
|
@ -1358,12 +1379,12 @@ class Connection:
|
||||||
if self.connected == 2:
|
if self.connected == 2:
|
||||||
self.connected = STATUS_LIST.index(show)
|
self.connected = STATUS_LIST.index(show)
|
||||||
#send our presence
|
#send our presence
|
||||||
ptype = None
|
|
||||||
if show == 'invisible':
|
if show == 'invisible':
|
||||||
self.send_invisible_presence(msg, signed, True)
|
self.send_invisible_presence(msg, signed, True)
|
||||||
return
|
return
|
||||||
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
||||||
p = common.xmpp.Presence(typ = ptype, priority = prio, show = sshow)
|
p = common.xmpp.Presence(typ = None, priority = prio, show = sshow)
|
||||||
|
p = self.add_sha(p)
|
||||||
if msg:
|
if msg:
|
||||||
p.setStatus(msg)
|
p.setStatus(msg)
|
||||||
if signed:
|
if signed:
|
||||||
|
@ -1384,6 +1405,7 @@ class Connection:
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.on_purpose = True
|
self.on_purpose = True
|
||||||
p = common.xmpp.Presence(typ = 'unavailable')
|
p = common.xmpp.Presence(typ = 'unavailable')
|
||||||
|
p = self.add_sha(p)
|
||||||
if msg:
|
if msg:
|
||||||
p.setStatus(msg)
|
p.setStatus(msg)
|
||||||
if self.connection:
|
if self.connection:
|
||||||
|
@ -1397,7 +1419,6 @@ class Connection:
|
||||||
elif show != 'offline' and self.connected:
|
elif show != 'offline' and self.connected:
|
||||||
was_invisible = self.connected == STATUS_LIST.index('invisible')
|
was_invisible = self.connected == STATUS_LIST.index('invisible')
|
||||||
self.connected = STATUS_LIST.index(show)
|
self.connected = STATUS_LIST.index(show)
|
||||||
ptype = None
|
|
||||||
if show == 'invisible':
|
if show == 'invisible':
|
||||||
self.send_invisible_presence(msg, signed)
|
self.send_invisible_presence(msg, signed)
|
||||||
return
|
return
|
||||||
|
@ -1406,7 +1427,8 @@ class Connection:
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
self.activate_privacy_rule('visible')
|
self.activate_privacy_rule('visible')
|
||||||
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
prio = str(gajim.config.get_per('accounts', self.name, 'priority'))
|
||||||
p = common.xmpp.Presence(typ = ptype, priority = prio, show = sshow)
|
p = common.xmpp.Presence(typ = None, priority = prio, show = sshow)
|
||||||
|
p = self.add_sha(p)
|
||||||
if msg:
|
if msg:
|
||||||
p.setStatus(msg)
|
p.setStatus(msg)
|
||||||
if signed:
|
if signed:
|
||||||
|
@ -1470,21 +1492,26 @@ class Connection:
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
gajim.log.debug('subscription request for %s' % jid)
|
gajim.log.debug('subscription request for %s' % jid)
|
||||||
pres = common.xmpp.Presence(jid, 'subscribe')
|
p = common.xmpp.Presence(jid, 'subscribe')
|
||||||
|
p = self.add_sha(p)
|
||||||
if not msg:
|
if not msg:
|
||||||
msg = _('I would like to add you to my roster.')
|
msg = _('I would like to add you to my roster.')
|
||||||
pres.setStatus(msg)
|
p.setStatus(msg)
|
||||||
self.to_be_sent.append(pres)
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def send_authorization(self, jid):
|
def send_authorization(self, jid):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
self.to_be_sent.append(common.xmpp.Presence(jid, 'subscribed'))
|
p = common.xmpp.Presence(jid, 'subscribed')
|
||||||
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def refuse_authorization(self, jid):
|
def refuse_authorization(self, jid):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
self.to_be_sent.append(common.xmpp.Presence(jid, 'unsubscribed'))
|
p = common.xmpp.Presence(jid, 'unsubscribed')
|
||||||
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def unsubscribe(self, jid):
|
def unsubscribe(self, jid):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -1603,6 +1630,8 @@ class Connection:
|
||||||
if jid:
|
if jid:
|
||||||
iq.setTo(jid)
|
iq.setTo(jid)
|
||||||
iq.setTag(common.xmpp.NS_VCARD + ' vCard')
|
iq.setTag(common.xmpp.NS_VCARD + ' vCard')
|
||||||
|
id = self.connection.getAnID()
|
||||||
|
iq.setID(id)
|
||||||
self.to_be_sent.append(iq)
|
self.to_be_sent.append(iq)
|
||||||
return iq
|
return iq
|
||||||
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
#('VCARD', {entry1: data, entry2: {entry21: data, ...}, ...})
|
||||||
|
@ -1667,6 +1696,7 @@ class Connection:
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
p = common.xmpp.Presence(to = agent, typ = ptype)
|
p = common.xmpp.Presence(to = agent, typ = ptype)
|
||||||
|
p = self.add_sha(p)
|
||||||
self.to_be_sent.append(p)
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def join_gc(self, nick, room, server, password):
|
def join_gc(self, nick, room, server, password):
|
||||||
|
@ -1678,6 +1708,7 @@ class Connection:
|
||||||
show = None
|
show = None
|
||||||
p = common.xmpp.Presence(to = '%s@%s/%s' % (room, server, nick),
|
p = common.xmpp.Presence(to = '%s@%s/%s' % (room, server, nick),
|
||||||
show = show, status = self.status)
|
show = show, status = self.status)
|
||||||
|
p = self.add_sha(p)
|
||||||
t = p.setTag(common.xmpp.NS_MUC + ' x')
|
t = p.setTag(common.xmpp.NS_MUC + ' x')
|
||||||
if password:
|
if password:
|
||||||
t.setTagData('password', password)
|
t.setTagData('password', password)
|
||||||
|
@ -1704,8 +1735,9 @@ class Connection:
|
||||||
def change_gc_nick(self, room_jid, nick):
|
def change_gc_nick(self, room_jid, nick):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
self.to_be_sent.append(common.xmpp.Presence(to = '%s/%s' % (room_jid,
|
p = common.xmpp.Presence(to = '%s/%s' % (room_jid, nick))
|
||||||
nick)))
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def send_gc_status(self, nick, jid, show, status):
|
def send_gc_status(self, nick, jid, show, status):
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
|
@ -1716,8 +1748,10 @@ class Connection:
|
||||||
show = None
|
show = None
|
||||||
if show == 'online':
|
if show == 'online':
|
||||||
show = None
|
show = None
|
||||||
self.to_be_sent.append(common.xmpp.Presence(to = '%s/%s' % (jid, nick),
|
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
|
||||||
typ = ptype, show = show, status = status))
|
show = show, status = status)
|
||||||
|
p = self.add_sha(p)
|
||||||
|
self.to_be_sent.append(p)
|
||||||
|
|
||||||
def gc_set_role(self, room_jid, nick, role, reason = ''):
|
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'''
|
'''role is for all the life of the room so it's based on nick'''
|
||||||
|
|
|
@ -43,7 +43,12 @@ class Dispatcher(PlugIn):
|
||||||
self.RegisterEventHandler,self.UnregisterCycleHandler,self.RegisterCycleHandler,\
|
self.RegisterEventHandler,self.UnregisterCycleHandler,self.RegisterCycleHandler,\
|
||||||
self.RegisterHandlerOnce,self.UnregisterHandler,self.RegisterProtocol,\
|
self.RegisterHandlerOnce,self.UnregisterHandler,self.RegisterProtocol,\
|
||||||
self.WaitForResponse,self.SendAndWaitForResponse,self.send,self.disconnect,\
|
self.WaitForResponse,self.SendAndWaitForResponse,self.send,self.disconnect,\
|
||||||
self.SendAndCallForResponse, ]
|
self.SendAndCallForResponse, self.getAnID]
|
||||||
|
|
||||||
|
def getAnID(self):
|
||||||
|
global ID
|
||||||
|
ID+=1
|
||||||
|
return ID
|
||||||
|
|
||||||
def dumpHandlers(self):
|
def dumpHandlers(self):
|
||||||
""" Return set of user-registered callbacks in it's internal format.
|
""" Return set of user-registered callbacks in it's internal format.
|
||||||
|
|
|
@ -62,6 +62,7 @@ NS_TIME ='jabber:iq:time'
|
||||||
NS_TLS ='urn:ietf:params:xml:ns:xmpp-tls'
|
NS_TLS ='urn:ietf:params:xml:ns:xmpp-tls'
|
||||||
NS_VACATION ='http://jabber.org/protocol/vacation'
|
NS_VACATION ='http://jabber.org/protocol/vacation'
|
||||||
NS_VCARD ='vcard-temp'
|
NS_VCARD ='vcard-temp'
|
||||||
|
NS_VCARD_UPDATE =NS_VCARD+':x:update'
|
||||||
NS_VERSION ='jabber:iq:version'
|
NS_VERSION ='jabber:iq:version'
|
||||||
NS_ENCRYPTED ='jabber:x:encrypted' # JEP-0027
|
NS_ENCRYPTED ='jabber:x:encrypted' # JEP-0027
|
||||||
NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams'
|
NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams'
|
||||||
|
|
Loading…
Add table
Reference in a new issue