quick frontend, primitivus, wix: MUC private messages management
/!\ not fully finished, backend part is not done yet /!\
- as resources are discarded to manage chat windows lists, a pretty dirty hack is done to work around this:
full jid is escaped using a prefix (it becomes invalid and resource is preserved).
- new quick_utils module, with helper methods. escapePrivate and unescapePrivate implementations
- MUC private messages are not managed in Wix yet
This commit is contained in:
parent
4225b694d0
commit
8ad8ca1933
3 changed files with 163 additions and 77 deletions
|
|
@ -22,9 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from urwid_satext.files_management import FileDialog
|
||||
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
|
||||
from sat_frontends.quick_frontend.quick_chat import QuickChat
|
||||
from sat_frontends.primitivus.card_game import CardGame
|
||||
from sat_frontends.quick_frontend.quick_utils import unescapePrivate
|
||||
import time
|
||||
from sat.tools.jid import JID
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
|
|||
self.__appendPresentPanel()
|
||||
|
||||
def __getDecoration(self, widget):
|
||||
return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(self.target)))
|
||||
return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(unescapePrivate(self.target))))
|
||||
|
||||
def showDecoration(self, show=True):
|
||||
"""Show/Hide the decoration around the chat window"""
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
|
||||
from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
|
||||
from sat.tools.jid import JID
|
||||
|
||||
|
||||
|
|
@ -29,10 +30,10 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
signals = ['click','change']
|
||||
|
||||
def __init__(self, host, on_click=None, on_change=None, user_data=None):
|
||||
QuickContactList.__init__(self)
|
||||
self.host = host
|
||||
self.selected = None
|
||||
self.groups={}
|
||||
self.special={}
|
||||
self.alert_jid=set()
|
||||
self.show_status = False
|
||||
self.show_disconnected = False
|
||||
|
|
@ -45,7 +46,6 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
urwid.connect_signal(self, 'click', on_click, user_data)
|
||||
if on_change:
|
||||
urwid.connect_signal(self, 'change', on_change, user_data)
|
||||
QuickContactList.__init__(self)
|
||||
|
||||
def update(self):
|
||||
"""Update display, keep focus"""
|
||||
|
|
@ -115,18 +115,23 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
widgets = [] #list of built widgets
|
||||
|
||||
for contact in contacts:
|
||||
jid=JID(contact)
|
||||
name = self.getCache(jid, 'name')
|
||||
nick = self.getCache(jid, 'nick')
|
||||
status = self.getCache(jid, 'status')
|
||||
show = self.getCache(jid, 'show')
|
||||
if show == None:
|
||||
show = "unavailable"
|
||||
if (not self.show_disconnected and show == "unavailable"
|
||||
and not contact in self.alert_jid and contact != self.selected):
|
||||
continue
|
||||
show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
|
||||
contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short)
|
||||
if contact.startswith(const_PRIVATE_PREFIX):
|
||||
contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact))
|
||||
show_icon = ''
|
||||
status = ''
|
||||
else:
|
||||
jid=JID(contact)
|
||||
name = self.getCache(jid, 'name')
|
||||
nick = self.getCache(jid, 'nick')
|
||||
status = self.getCache(jid, 'status')
|
||||
show = self.getCache(jid, 'show')
|
||||
if show == None:
|
||||
show = "unavailable"
|
||||
if (not self.show_disconnected and show == "unavailable"
|
||||
and not contact in self.alert_jid and contact != self.selected):
|
||||
continue
|
||||
show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
|
||||
contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short)
|
||||
display = [ show_icon + " " , contact_disp]
|
||||
if self.show_status:
|
||||
status_disp = ('status',"\n " + status) if status else ""
|
||||
|
|
@ -147,7 +152,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
|
||||
def __buildSpecials(self, content):
|
||||
"""Build the special entities"""
|
||||
specials = self.special.keys()
|
||||
specials = self.specials.keys()
|
||||
specials.sort()
|
||||
for special in specials:
|
||||
jid=JID(special)
|
||||
|
|
@ -168,7 +173,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
content = urwid.SimpleListWalker([])
|
||||
|
||||
self.__buildSpecials(content)
|
||||
if self.special:
|
||||
if self.specials:
|
||||
content.append(urwid.Divider('='))
|
||||
|
||||
group_keys = self.groups.keys()
|
||||
|
|
@ -198,6 +203,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
|
||||
def clearContacts(self):
|
||||
"""clear all the contact list"""
|
||||
QuickContactList.clearContacts(self)
|
||||
self.groups={}
|
||||
self.selected = None
|
||||
self.unselectAll()
|
||||
|
|
@ -205,7 +211,8 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
|
||||
def replace(self, jid, groups=None, attributes=None):
|
||||
"""add a contact to the list if doesn't exist, else update it"""
|
||||
if jid.short in self.special:
|
||||
QuickContactList.replace(self, jid, groups, attributes)
|
||||
if jid.short in self.specials:
|
||||
return
|
||||
if not groups:
|
||||
groups = [None]
|
||||
|
|
@ -227,10 +234,10 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
self.list_wid.changeValues(contacts)
|
||||
self._emit('change')"""
|
||||
|
||||
def remove(self, param_jid):
|
||||
def remove(self, jid):
|
||||
"""remove a contact from the list"""
|
||||
QuickContactList.remove(self, jid)
|
||||
groups_to_remove = []
|
||||
jid = JID(param_jid)
|
||||
for group in self.groups:
|
||||
contacts = self.groups[group][1]
|
||||
if jid.short in contacts:
|
||||
|
|
@ -239,10 +246,6 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
groups_to_remove.append(group)
|
||||
for group in groups_to_remove:
|
||||
del self.groups[group]
|
||||
try:
|
||||
del self.special[jid.short]
|
||||
except KeyError:
|
||||
pass
|
||||
self.update()
|
||||
|
||||
def add(self, jid, param_groups=[None]):
|
||||
|
|
@ -254,7 +257,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
@param jid: jid of the entity
|
||||
@param _type: special type (e.g.: "MUC")
|
||||
"""
|
||||
self.special[special_jid.short] = special_type
|
||||
QuickContactList.setSpecial(self, special_jid, special_type)
|
||||
if None in self.groups:
|
||||
folded,group_jids = self.groups[None]
|
||||
for group_jid in group_jids:
|
||||
|
|
@ -265,5 +268,5 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
|
|||
|
||||
def updatePresence(self, jid, show, priority, statuses):
|
||||
#XXX: for the moment, we ignore presence updates for special entities
|
||||
if jid.short not in self.special:
|
||||
if jid.short not in self.specials:
|
||||
QuickContactList.updatePresence(self, jid, show, priority, statuses)
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@ import urwid
|
|||
from urwid_satext import sat_widgets
|
||||
from sat_frontends.quick_frontend.quick_app import QuickApp
|
||||
from sat_frontends.quick_frontend.quick_chat_list import QuickChatList
|
||||
from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
|
||||
from sat_frontends.quick_frontend.quick_contact_management import QuickContactManagement
|
||||
from sat_frontends.primitivus.profile_manager import ProfileManager
|
||||
from sat_frontends.primitivus.contact_list import ContactList
|
||||
from sat_frontends.primitivus.chat import Chat
|
||||
|
|
@ -47,9 +45,6 @@ logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages
|
|||
class ChatList(QuickChatList):
|
||||
"""This class manage the list of chat windows"""
|
||||
|
||||
def __init__(self, host):
|
||||
QuickChatList.__init__(self, host)
|
||||
|
||||
def createChat(self, target):
|
||||
return Chat(target, self.host)
|
||||
|
||||
|
|
@ -300,7 +295,7 @@ class PrimitivusApp(QuickApp):
|
|||
if contact:
|
||||
chat = self.chat_wins[contact]
|
||||
try:
|
||||
self.bridge.sendMessage(contact,
|
||||
self.sendMessage(contact,
|
||||
editBar.get_edit_text(),
|
||||
mess_type = "groupchat" if chat.type == 'group' else "chat",
|
||||
profile_key=self.profile)
|
||||
|
|
@ -308,18 +303,17 @@ class PrimitivusApp(QuickApp):
|
|||
self.notify(_("Error while sending message"))
|
||||
editBar.set_edit_text('')
|
||||
|
||||
def newMessage(self, from_jid, msg, type, to_jid, profile):
|
||||
if not self.check_profile(profile):
|
||||
return
|
||||
sender = JID(from_jid)
|
||||
if not sender in self.contact_list and sender.short != self.profiles[profile]['whoami'].short:
|
||||
def newMessage(self, from_jid, to_jid, msg, _type, profile):
|
||||
QuickApp.newMessage(self, from_jid, to_jid, msg, _type, profile)
|
||||
|
||||
if not from_jid in self.contact_list and from_jid.short != self.profiles[profile]['whoami'].short:
|
||||
#XXX: needed to show entities which haven't sent any
|
||||
# presence information and which are not in roster
|
||||
#TODO: put these entities in a "not in roster" list
|
||||
self.contact_list.replace(sender)
|
||||
QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
|
||||
if JID(self.contact_list.selected).short != sender.short:
|
||||
self.contact_list.putAlert(sender)
|
||||
self.contact_list.replace(from_jid)
|
||||
|
||||
if JID(self.contact_list.selected).short != from_jid.short:
|
||||
self.contact_list.putAlert(from_jid)
|
||||
|
||||
def _dialogOkCb(self, widget, data):
|
||||
self.removePopUp()
|
||||
|
|
|
|||
Loading…
Reference in a new issue