frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster

This commit is contained in:
souliane 2014-05-29 14:34:01 +02:00
commit f09fb76752
7 changed files with 49 additions and 30 deletions

View file

@ -75,3 +75,6 @@ class Const(constants.Const):
"composing": u'✎', "composing": u'✎',
"paused": u"⦷" "paused": u"⦷"
} }
# Roster
GROUP_NOT_IN_ROSTER = D_('Not in roster')

View file

@ -25,7 +25,7 @@ from sat_frontends.quick_frontend.quick_chat import QuickChat
from sat_frontends.primitivus.card_game import CardGame from sat_frontends.primitivus.card_game import CardGame
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
from sat_frontends.primitivus.xmlui import XMLUI from sat_frontends.primitivus.xmlui import XMLUI
from sat_frontends.primitivus.constants import Const from sat_frontends.primitivus.constants import Const as C
import time import time
from sat.tools.jid import JID from sat.tools.jid import JID
@ -179,18 +179,18 @@ class Chat(urwid.WidgetWrap, QuickChat):
def updateChatState(self, state, nick=None): def updateChatState(self, state, nick=None):
"""Set the chat state (XEP-0085) of the contact. Leave nick to None """Set the chat state (XEP-0085) of the contact. Leave nick to None
to set the state for a one2one conversation, or give a nickname or to set the state for a one2one conversation, or give a nickname or
Const.ALL_OCCUPANTS to set the state of a participant within a MUC. C.ALL_OCCUPANTS to set the state of a participant within a MUC.
@param state: the new chat state @param state: the new chat state
@param nick: None for one2one, the MUC user nick or Const.ALL_OCCUPANTS @param nick: None for one2one, the MUC user nick or C.ALL_OCCUPANTS
""" """
if nick: if nick:
assert(self.type == 'group') assert(self.type == 'group')
occupants = self.occupants if nick == Const.ALL_OCCUPANTS else [nick] occupants = self.occupants if nick == C.ALL_OCCUPANTS else [nick]
options = self.present_wid.getAllValues() options = self.present_wid.getAllValues()
for index in xrange(0, len(options)): for index in xrange(0, len(options)):
nick = options[index].value nick = options[index].value
if nick in occupants: if nick in occupants:
options[index] = (nick, '%s %s' % (Const.MUC_USER_STATES[state], nick)) options[index] = (nick, '%s %s' % (C.MUC_USER_STATES[state], nick))
self.present_wid.changeValues(options) self.present_wid.changeValues(options)
self.host.redraw() self.host.redraw()
else: else:
@ -209,7 +209,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
full_jid = JID("%s/%s" % (self.target.bare, nick)) full_jid = JID("%s/%s" % (self.target.bare, nick))
new_jid = escapePrivate(full_jid) new_jid = escapePrivate(full_jid)
if new_jid not in self.host.contact_list: if new_jid not in self.host.contact_list:
self.host.contact_list.add(new_jid) self.host.contact_list.add(new_jid, [C.GROUP_NOT_IN_ROSTER])
#now we select the new window #now we select the new window
self.host.contact_list.setFocus(full_jid, True) self.host.contact_list.setFocus(full_jid, True)

View file

@ -236,30 +236,36 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def replace(self, jid, groups=None, attributes=None): def replace(self, jid, groups=None, attributes=None):
"""Add a contact to the list if doesn't exist, else update it. """Add a contact to the list if doesn't exist, else update it.
This method can be called with groups=None for the purpose of updating
the contact's attributes (e.g. nickname). In that case, the groups
attribute must not be set to the default group but ignored. If not,
you may move your contact from its actual group(s) to the default one.
None value for 'groups' has a different meaning than [None] which is for the default group.
@param jid (JID) @param jid (JID)
@param groups (list): list of groups or None to ignore the groups membership. @param groups (list): list of groups or None to ignore the groups membership.
@param attributes (dict) @param attributes (dict)
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
""" """
QuickContactList.replace(self, jid, groups, attributes) QuickContactList.replace(self, jid, groups, attributes) # eventually change the nickname
if jid.bare in self.specials: if jid.bare in self.specials:
return return
if not attributes: if groups is None:
attributes = {} self.update()
return
assert isinstance(jid, JID) assert isinstance(jid, JID)
if groups is not None: assert isinstance(groups, list)
if not groups: if groups == []:
groups = [None] groups = [None] # [None] is the default group
for group in [group for group in self.groups if group not in groups]: for group in [group for group in self.groups if group not in groups]:
try: # remove the contact from a previous group try: # remove the contact from a previous group
self.groups[group][1].remove(jid.bare) self.groups[group][1].remove(jid.bare)
except KeyError: except KeyError:
pass pass
for group in groups: for group in groups:
if group not in self.groups: if group not in self.groups:
self.groups[group] = [True, set()] # [unfold, list_of_contacts] self.groups[group] = [True, set()] # [unfold, list_of_contacts]
self.groups[group][1].add(jid.bare) self.groups[group][1].add(jid.bare)
self.update() self.update()
def remove(self, jid): def remove(self, jid):
@ -278,7 +284,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def add(self, jid, param_groups=None): def add(self, jid, param_groups=None):
"""add a contact to the list""" """add a contact to the list"""
self.replace(jid, param_groups) self.replace(jid, param_groups if param_groups else [None])
def setSpecial(self, special_jid, special_type, show=False): def setSpecial(self, special_jid, special_type, show=False):
"""Set entity as a special """Set entity as a special

View file

@ -388,7 +388,7 @@ class PrimitivusApp(QuickApp, InputHistory):
if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare: if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare:
#XXX: needed to show entities which haven't sent any #XXX: needed to show entities which haven't sent any
# presence information and which are not in roster # presence information and which are not in roster
self.contact_list.replace(from_jid, ['Not in roster']) self.contact_list.replace(from_jid, [C.GROUP_NOT_IN_ROSTER])
if JID(self.contact_list.selected).bare != from_jid.bare: if JID(self.contact_list.selected).bare != from_jid.bare:
self.contact_list.putAlert(from_jid) self.contact_list.putAlert(from_jid)

View file

@ -269,7 +269,7 @@ class QuickApp(object):
else: else:
from_jid = new_jid from_jid = new_jid
if new_jid not in self.contact_list: if new_jid not in self.contact_list:
self.contact_list.add(new_jid) self.contact_list.add(new_jid, [C.GROUP_NOT_IN_ROSTER])
self.newMessage(from_jid, to_jid, msg, _type, extra, profile) self.newMessage(from_jid, to_jid, msg, _type, extra, profile)

View file

@ -57,11 +57,16 @@ class QuickContactList(object):
def replace(self, jid, groups=None, attributes=None): def replace(self, jid, groups=None, attributes=None):
"""Add a contact to the list if doesn't exist, else update it. """Add a contact to the list if doesn't exist, else update it.
This method can be called with groups=None for the purpose of updating
the contact's attributes (e.g. nickname). In that case, the groups
attribute must not be set to the default group but ignored. If not,
you may move your contact from its actual group(s) to the default one.
None value for 'groups' has a different meaning than [None] which is for the default group.
@param jid (JID) @param jid (JID)
@param groups (list): list of groups or None to ignore the groups membership. @param groups (list): list of groups or None to ignore the groups membership.
@param attributes (dict) @param attributes (dict)
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
""" """
if attributes and 'name' in attributes: if attributes and 'name' in attributes:
self.setCache(jid, 'name', attributes['name']) self.setCache(jid, 'name', attributes['name'])

View file

@ -79,11 +79,16 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
def replace(self, contact, groups=None, attributes=None): def replace(self, contact, groups=None, attributes=None):
"""Add a contact to the list if doesn't exist, else update it. """Add a contact to the list if doesn't exist, else update it.
This method can be called with groups=None for the purpose of updating
the contact's attributes (e.g. nickname). In that case, the groups
attribute must not be set to the default group but ignored. If not,
you may move your contact from its actual group(s) to the default one.
None value for 'groups' has a different meaning than [None] which is for the default group.
@param jid (JID) @param jid (JID)
@param groups (list): list of groups or None to ignore the groups membership. @param groups (list): list of groups or None to ignore the groups membership.
@param attributes (dict) @param attributes (dict)
XXX: None value for 'groups' has a different meaning than [None] which is for the default group.
""" """
log.debug(_("update %s") % contact) log.debug(_("update %s") % contact)
if not self.__find_idx(contact): if not self.__find_idx(contact):