tools: renamed tools.jid.JID attribute "short" to "bare"
This commit is contained in:
parent
a154d9acbb
commit
36cea6fc91
6 changed files with 94 additions and 94 deletions
|
|
@ -254,7 +254,7 @@ class QuickApp(object):
|
|||
from_jid = JID(from_jid_s)
|
||||
to_jid = JID(to_jid_s)
|
||||
|
||||
from_me = from_jid.short == self.profiles[profile]['whoami'].short
|
||||
from_me = from_jid.bare == self.profiles[profile]['whoami'].bare
|
||||
win = to_jid if from_me else from_jid
|
||||
|
||||
if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC":
|
||||
|
|
@ -273,14 +273,14 @@ class QuickApp(object):
|
|||
self.newMessage(from_jid, to_jid, msg, _type, extra, profile)
|
||||
|
||||
def newMessage(self, from_jid, to_jid, msg, _type, extra, profile):
|
||||
from_me = from_jid.short == self.profiles[profile]['whoami'].short
|
||||
from_me = from_jid.bare == self.profiles[profile]['whoami'].bare
|
||||
win = to_jid if from_me else from_jid
|
||||
|
||||
self.current_action_ids = set()
|
||||
self.current_action_ids_cb = {}
|
||||
|
||||
timestamp = extra.get('archive')
|
||||
self.chat_wins[win.short].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
|
||||
self.chat_wins[win.bare].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
|
||||
|
||||
def sendMessage(self, to_jid, message, subject='', mess_type="auto", options={}, profile_key="@NONE@"):
|
||||
if to_jid.startswith(const_PRIVATE_PREFIX):
|
||||
|
|
@ -303,9 +303,9 @@ class QuickApp(object):
|
|||
return
|
||||
debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile})
|
||||
from_jid=JID(jabber_id)
|
||||
debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short})
|
||||
debug ("from_jid.bare=%(from_jid)s whoami.bare=%(whoami)s" % {'from_jid':from_jid.bare, 'whoami':self.profiles[profile]['whoami'].bare})
|
||||
|
||||
if from_jid.short==self.profiles[profile]['whoami'].short:
|
||||
if from_jid.bare==self.profiles[profile]['whoami'].bare:
|
||||
if not type:
|
||||
self.setStatusOnline(True)
|
||||
elif type=="unavailable":
|
||||
|
|
@ -317,8 +317,8 @@ class QuickApp(object):
|
|||
if show != 'unavailable':
|
||||
|
||||
#FIXME: must be moved in a plugin
|
||||
if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
|
||||
self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
|
||||
if from_jid.bare in self.profiles[profile]['watched'] and not from_jid.bare in self.profiles[profile]['onlineContact']:
|
||||
self.showAlert(_("Watched jid [%s] is connected !") % from_jid.bare)
|
||||
|
||||
self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
|
||||
|
||||
|
|
@ -498,9 +498,9 @@ class QuickApp(object):
|
|||
def _subscribe_cb(self, answer, data):
|
||||
entity, profile = data
|
||||
if answer:
|
||||
self.bridge.subscription("subscribed", entity.short, profile_key = profile)
|
||||
self.bridge.subscription("subscribed", entity.bare, profile_key = profile)
|
||||
else:
|
||||
self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
|
||||
self.bridge.subscription("unsubscribed", entity.bare, profile_key = profile)
|
||||
|
||||
def subscribe(self, type, raw_jid, profile):
|
||||
"""Called when a subsciption management signal is received"""
|
||||
|
|
@ -509,13 +509,13 @@ class QuickApp(object):
|
|||
entity = JID(raw_jid)
|
||||
if type=="subscribed":
|
||||
# this is a subscription confirmation, we just have to inform user
|
||||
self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation'))
|
||||
self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation'))
|
||||
elif type=="unsubscribed":
|
||||
# this is a subscription refusal, we just have to inform user
|
||||
self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error')
|
||||
self.showDialog(_("The contact %s has refused your subscription") % entity.bare, _('Subscription refusal'), 'error')
|
||||
elif type=="subscribe":
|
||||
# this is a subscriptionn request, we have to ask for user confirmation
|
||||
answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile))
|
||||
answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.bare, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile))
|
||||
|
||||
def showDialog(self, message, title, type="info", answer_cb = None):
|
||||
raise NotImplementedError
|
||||
|
|
@ -539,7 +539,7 @@ class QuickApp(object):
|
|||
target = JID(jid)
|
||||
self.contact_list.remove(target)
|
||||
try:
|
||||
self.profiles[profile]['onlineContact'].remove(target.short)
|
||||
self.profiles[profile]['onlineContact'].remove(target.bare)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -110,15 +110,15 @@ class QuickChat(object):
|
|||
if self.target.startswith(const_PRIVATE_PREFIX):
|
||||
target = unescapePrivate(self.target)
|
||||
else:
|
||||
target = self.target.short
|
||||
target = self.target.bare
|
||||
|
||||
self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].short, target, 20, profile=profile, callback=onHistory, errback=onHistoryError)
|
||||
self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError)
|
||||
|
||||
def _get_nick(self, jid):
|
||||
"""Return nick of this jid when possible"""
|
||||
if self.target.startswith(const_PRIVATE_PREFIX):
|
||||
unescaped = unescapePrivate(self.target)
|
||||
if jid.startswith(const_PRIVATE_PREFIX) or unescaped.short == jid.short:
|
||||
if jid.startswith(const_PRIVATE_PREFIX) or unescaped.bare == jid.bare:
|
||||
return unescaped.resource
|
||||
return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node)
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ class QuickChat(object):
|
|||
"""Print message in chat window. Must be implemented by child class"""
|
||||
jid=JID(from_jid)
|
||||
nick = self._get_nick(jid)
|
||||
mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user
|
||||
mymess = (jid.resource == self.nick) if self.type == "group" else (jid.bare == self.host.profiles[profile]['whoami'].bare) #mymess = True if message comes from local user
|
||||
if msg.startswith('/me '):
|
||||
self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ class QuickChatList(dict):
|
|||
|
||||
def __getitem__(self, to_jid):
|
||||
target = JID(to_jid)
|
||||
if not target.short in self:
|
||||
if not target.bare in self:
|
||||
#we have to create the chat win
|
||||
self[target.short] = self.createChat(target)
|
||||
return dict.__getitem__(self, target.short)
|
||||
self[target.bare] = self.createChat(target)
|
||||
return dict.__getitem__(self, target.bare)
|
||||
|
||||
def createChat(self, target):
|
||||
raise NotImplementedError
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class QuickContactList(object):
|
|||
|
||||
def getCache(self, jid, name):
|
||||
try:
|
||||
jid_cache = self._cache[jid.short]
|
||||
jid_cache = self._cache[jid.bare]
|
||||
if name == 'status': #XXX: we get the first status for 'status' key
|
||||
return jid_cache['statuses'].get('default','')
|
||||
return jid_cache[name]
|
||||
|
|
@ -42,7 +42,7 @@ class QuickContactList(object):
|
|||
return None
|
||||
|
||||
def setCache(self, jid, name, value):
|
||||
jid_cache = self._cache.setdefault(jid.short, {})
|
||||
jid_cache = self._cache.setdefault(jid.bare, {})
|
||||
jid_cache[name] = value
|
||||
|
||||
def __contains__(self, jid):
|
||||
|
|
@ -60,7 +60,7 @@ class QuickContactList(object):
|
|||
def remove(self, jid):
|
||||
"""remove a contact from the list"""
|
||||
try:
|
||||
del self.specials[jid.short]
|
||||
del self.specials[jid.bare]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ class QuickContactList(object):
|
|||
|
||||
def getSpecial(self, jid):
|
||||
"""Return special type of jid, or None if it's not special"""
|
||||
return self.specials.get(jid.short)
|
||||
return self.specials.get(jid.bare)
|
||||
|
||||
def setSpecial(self, jid, _type, show=False):
|
||||
"""Set entity as a special
|
||||
|
|
@ -78,7 +78,7 @@ class QuickContactList(object):
|
|||
@param _type: special type (e.g.: "MUC")
|
||||
@param show: True to display the dialog to chat with this entity
|
||||
"""
|
||||
self.specials[jid.short] = _type
|
||||
self.specials[jid.bare] = _type
|
||||
|
||||
def updatePresence(self, jid, show, priority, statuses):
|
||||
"""Update entity's presence status
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class QuickContactManagement(object):
|
|||
self.__contactlist = {}
|
||||
|
||||
def __contains__(self, entity):
|
||||
return entity.short in self.__contactlist
|
||||
return entity.bare in self.__contactlist
|
||||
|
||||
def clear(self):
|
||||
"""Clear all the contact list"""
|
||||
|
|
@ -38,13 +38,13 @@ class QuickContactManagement(object):
|
|||
|
||||
def add(self, entity):
|
||||
"""Add contact to the list, update resources"""
|
||||
if not self.__contactlist.has_key(entity.short):
|
||||
self.__contactlist[entity.short] = {'resources':[]}
|
||||
if not self.__contactlist.has_key(entity.bare):
|
||||
self.__contactlist[entity.bare] = {'resources':[]}
|
||||
if not entity.resource:
|
||||
return
|
||||
if entity.resource in self.__contactlist[entity.short]['resources']:
|
||||
self.__contactlist[entity.short]['resources'].remove(entity.resource)
|
||||
self.__contactlist[entity.short]['resources'].append(entity.resource)
|
||||
if entity.resource in self.__contactlist[entity.bare]['resources']:
|
||||
self.__contactlist[entity.bare]['resources'].remove(entity.resource)
|
||||
self.__contactlist[entity.bare]['resources'].append(entity.resource)
|
||||
|
||||
def getContFromGroup(self, group):
|
||||
"""Return all contacts which are in given group"""
|
||||
|
|
@ -60,28 +60,28 @@ class QuickContactManagement(object):
|
|||
@param entity: jid of the contact
|
||||
@param name: name of the attribute
|
||||
@return: asked attribute"""
|
||||
if self.__contactlist.has_key(entity.short):
|
||||
if self.__contactlist.has_key(entity.bare):
|
||||
if name == 'status': #FIXME: for the moment, we only use the first status
|
||||
if self.__contactlist[entity.short]['statuses']:
|
||||
return self.__contactlist[entity.short]['statuses'].values()[0]
|
||||
if self.__contactlist[entity.short].has_key(name):
|
||||
return self.__contactlist[entity.short][name]
|
||||
if self.__contactlist[entity.bare]['statuses']:
|
||||
return self.__contactlist[entity.bare]['statuses'].values()[0]
|
||||
if self.__contactlist[entity.bare].has_key(name):
|
||||
return self.__contactlist[entity.bare][name]
|
||||
else:
|
||||
debug(_('Trying to get attribute for an unknown contact'))
|
||||
return None
|
||||
|
||||
def isConnected(self, entity):
|
||||
"""Tell if the contact is online"""
|
||||
return self.__contactlist.has_key(entity.short)
|
||||
return self.__contactlist.has_key(entity.bare)
|
||||
|
||||
def remove(self, entity):
|
||||
"""remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
|
||||
try:
|
||||
if entity.resource:
|
||||
self.__contactlist[entity.short]['resources'].remove(entity.resource)
|
||||
if not entity.resource or not self.__contactlist[entity.short]['resources']:
|
||||
self.__contactlist[entity.bare]['resources'].remove(entity.resource)
|
||||
if not entity.resource or not self.__contactlist[entity.bare]['resources']:
|
||||
#no more resource available: the contact seems really disconnected
|
||||
del self.__contactlist[entity.short]
|
||||
del self.__contactlist[entity.bare]
|
||||
except KeyError:
|
||||
error(_('INTERNAL ERROR: Key error'))
|
||||
raise
|
||||
|
|
@ -92,11 +92,11 @@ class QuickContactManagement(object):
|
|||
@param key: name of the attribute
|
||||
@param value: value of the attribute
|
||||
"""
|
||||
if self.__contactlist.has_key(entity.short):
|
||||
self.__contactlist[entity.short][key] = value
|
||||
if self.__contactlist.has_key(entity.bare):
|
||||
self.__contactlist[entity.bare][key] = value
|
||||
else:
|
||||
debug (_('Trying to update an unknown contact: %s'), entity.short)
|
||||
debug (_('Trying to update an unknown contact: %s'), entity.bare)
|
||||
|
||||
def get_full(self, entity):
|
||||
return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1]
|
||||
return entity.bare+'/'+self.__contactlist[entity.bare]['resources'][-1]
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from os.path import exists, splitext
|
|||
|
||||
def escapePrivate(ori_jid):
|
||||
"""Escape a private jid"""
|
||||
return JID(const_PRIVATE_PREFIX + ori_jid.short + '@' + ori_jid.resource)
|
||||
return JID(const_PRIVATE_PREFIX + ori_jid.bare + '@' + ori_jid.resource)
|
||||
|
||||
def unescapePrivate(escaped_jid):
|
||||
if not escaped_jid.startswith(const_PRIVATE_PREFIX):
|
||||
|
|
|
|||
Loading…
Reference in a new issue