Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_chat.py @ 1290:faa1129559b8 frontends_multi_profiles
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
/!\ not finished, everything is still instable !
- bridge: DBus bridge has been modified to allow blocking call to be called in the same way as asynchronous calls
- bridge: calls with a callback and no errback are now possible, default errback log the error
- constants: removed hack to manage presence without OrderedDict, as an OrderedDict like class has been implemented in Libervia
- core: getLastResource has been removed and replaced by getMainResource (there is a global better management of resources)
- various style improvments: use of constants when possible, fixed variable overlaps, import of module instead of direct class import
- frontends: printInfo and printMessage methods in (Quick)Chat are more generic (use of extra instead of timestamp)
- frontends: bridge creation and option parsing (command line arguments) are now specified by the frontend in QuickApp __init__
- frontends: ProfileManager manage a more complete plug sequence (some stuff formerly manage in contact_list have moved to ProfileManager)
- quick_frontend (quick_widgets): QuickWidgetsManager is now iterable (all widgets are then returned), or can return an iterator on a specific class (return all widgets of this class) with getWidgets
- frontends: tools.jid can now be used in Pyjamas, with some care
- frontends (XMLUI): profile is now managed
- core (memory): big improvment on entities cache management (and specially resource management)
- core (params/exceptions): added PermissionError
- various fixes and improvments, check diff for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 24 Jan 2015 01:00:29 +0100 |
parents | e3a9ea76de35 |
children | ebf72fe68d1c |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py Sat Jan 24 00:15:01 2015 +0100 +++ b/frontends/src/quick_frontend/quick_chat.py Sat Jan 24 01:00:29 2015 +0100 @@ -20,11 +20,18 @@ from sat.core.i18n import _ from sat.core.log import getLogger log = getLogger(__name__) -from sat_frontends.tools.jid import JID +from sat_frontends.tools import jid from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend.constants import Const as C +try: + # FIXME: to be removed when an acceptable solution is here + unicode('') # XXX: unicode doesn't exist in pyjamas +except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options + unicode = lambda x: str(x) + + class QuickChat(quick_widgets.QuickWidget): def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): @@ -153,11 +160,11 @@ def onHistory(history): for line in history: - timestamp, from_jid, to_jid, message, _type, extra = line - if ((self.type == C.CHAT_GROUP and _type != C.MESS_TYPE_GROUPCHAT) or - (self.type == C.CHAT_ONE2ONE and _type == C.MESS_TYPE_GROUPCHAT)): + timestamp, from_jid, to_jid, message, type_, extra = line # FIXME: extra is unused ! + if ((self.type == C.CHAT_GROUP and type_ != C.MESS_TYPE_GROUPCHAT) or + (self.type == C.CHAT_ONE2ONE and type_ == C.MESS_TYPE_GROUPCHAT)): continue - self.printMessage(JID(from_jid), message, profile, timestamp) + self.printMessage(jid.JID(from_jid), message, {'timestamp':timestamp}, profile) self.afterHistoryPrint() def onHistoryError(err): @@ -165,7 +172,7 @@ target = self.target.bare - return self.host.bridge.getHistory(self.host.profiles[profile].whoami.bare, target, size, search=search, profile=profile, callback=onHistory, errback=onHistoryError) + self.host.bridge.getHistory(unicode(self.host.profiles[profile].whoami.bare), unicode(target), size, True, search, profile, callback=onHistory, errback=onHistoryError) def _get_nick(self, entity): """Return nick of this entity when possible""" @@ -193,29 +200,27 @@ chat_widget = self.getOrCreatePrivateWidget(target) chat_widget.newMessage(from_jid, target, msg, type_, extra, profile) else: - timestamp = extra.get('archive') if type_ == C.MESS_TYPE_INFO: - self.printInfo(msg, timestamp=float(timestamp) if timestamp else None) + self.printInfo(msg, extra=extra) else: - self.printMessage(from_jid, msg, profile, float(timestamp) if timestamp else None) + self.printMessage(from_jid, msg, extra, profile) - def printMessage(self, from_jid, msg, profile, timestamp=None): + def printMessage(self, from_jid, msg, extra=None, profile=C.PROF_KEY_NONE): """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 == C.CHAT_GROUP else (jid.bare == self.host.profiles[profile].whoami.bare) #mymess = True if message comes from local user + nick = self._get_nick(from_jid) + mymess = (from_jid.resource == self.nick) if self.type == C.CHAT_GROUP else (from_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) + self.printInfo('* %s %s' % (nick, msg[4:]), type_='me', extra=extra) return - return jid, nick, mymess + return nick, mymess - def printInfo(self, msg, type_='normal', timestamp=None): + def printInfo(self, msg, type_='normal', extra=None): """Print general info @param msg: message to print @type_: one of: normal: general info like "toto has joined the room" me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" - @param timestamp (float): number of seconds since epoch + @param extra (dict): message data """ raise NotImplementedError