changeset 2024:01aff34e8873

quick frontends, primitivus: messageState signal handling
author Goffi <goffi@goffi.org>
date Tue, 02 Aug 2016 23:11:44 +0200
parents 224c8b0886bc
children 43516c915ca6
files frontends/src/primitivus/chat.py frontends/src/primitivus/constants.py frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_chat.py
diffstat 4 files changed, 38 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py	Thu Jul 28 19:11:31 2016 +0200
+++ b/frontends/src/primitivus/chat.py	Tue Aug 02 23:11:44 2016 +0200
@@ -81,6 +81,7 @@
 
     def redraw(self):
         self._w.set_text(self.markup)
+        self.mess_data.parent.host.redraw()  # FIXME: should not be necessary
 
     def selectable(self):
         return True
@@ -108,6 +109,14 @@
         d = self.mess_data
         mention = d.mention
 
+        # message status
+        if d.status is None:
+            markup.append(u' ')
+        elif d.status == "delivered":
+            markup.append(('msg_status_received', u'✔'))
+        else:
+            log.warning(u"Unknown status: {}".format(d.status))
+
         # timestamp
         if self.parent.show_timestamp:
             # if the message was sent before today, we print the full date
@@ -134,6 +143,10 @@
 
         return markup
 
+    # events
+    def updated(self, attributes):
+        self.redraw()
+
 @total_ordering
 class OccupantWidget(urwid.WidgetWrap):
 
--- a/frontends/src/primitivus/constants.py	Thu Jul 28 19:11:31 2016 +0200
+++ b/frontends/src/primitivus/constants.py	Tue Aug 02 23:11:44 2016 +0200
@@ -42,6 +42,7 @@
                ('info_msg', 'yellow', 'default', 'bold'),
                ('msg_lang', 'dark cyan', 'default'),
                ('msg_mention', 'dark red, bold', 'default'),
+               ('msg_status_received', 'light green, bold', 'default'),
 
                ('menubar', 'light gray,bold', 'dark red'),
                ('menubar_focus', 'light gray,bold', 'dark green'),
--- a/frontends/src/quick_frontend/quick_app.py	Thu Jul 28 19:11:31 2016 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Tue Aug 02 23:11:44 2016 +0200
@@ -254,6 +254,7 @@
         self.registerSignal("mucRoomUserChangedNick", iface="plugin")
         self.registerSignal("mucRoomNewSubject", iface="plugin")
         self.registerSignal("chatStateReceived", iface="plugin")
+        self.registerSignal("messageState", iface="plugin")
         self.registerSignal("psEvent", iface="plugin")
 
         # FIXME: do it dynamically
@@ -491,6 +492,10 @@
 
         chat_widget.messageNew(uid, timestamp, from_jid, target, msg, subject, type_, extra, profile)
 
+    def messageStateHandler(self, uid, status, profile):
+        for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)):
+            widget.onMessageState(uid, status, profile)
+
     def messageSend(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
         if subject is None:
             subject = {}
--- a/frontends/src/quick_frontend/quick_chat.py	Thu Jul 28 19:11:31 2016 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Tue Aug 02 23:11:44 2016 +0200
@@ -55,6 +55,7 @@
         self.type = type_
         self.extra = extra
         self.nick = self.getNick(from_jid)
+        self._status = None
         # own_mess is True if message was sent by profile's jid
         self.own_mess = (from_jid.resource == self.parent.nick) if self.parent.type == C.CHAT_GROUP else (from_jid.bare == self.host.profiles[profile].whoami.bare)
         # is user mentioned here ?
@@ -112,6 +113,16 @@
             return contact_list.getCache(entity, 'nick') or contact_list.getCache(entity, 'name') or entity.node or entity
         return entity.node or entity
 
+    @property
+    def status(self):
+        return self._status
+
+    @status.setter
+    def status(self, status):
+        self._status = status
+        for w in self.widgets:
+            w.updated(["status"])
+
 
 class Occupant(object):
     """Occupant metadata"""
@@ -468,5 +479,13 @@
                 log.warning(u"{nick} not found in {room}, ignoring new chat state".format(
                     nick=nick, room=self.target.bare))
 
+    def onMessageState(self, uid, status, profile):
+        try:
+            mess_data = self.messages[uid]
+        except KeyError:
+            pass
+        else:
+            mess_data.status = status
+
 
 quick_widgets.register(QuickChat)