diff cagou/plugins/plugin_wid_chat.py @ 289:717c6c368f70

chat: merge user moved info messages: - MessageWidget now inheriates from the new quick_chat.MessageWidget - MessageWidget.message is now an AliasProperty - new message_widgets_rev property implemented - new handleUserMoved method is used
author Goffi <goffi@goffi.org>
date Thu, 28 Mar 2019 08:44:03 +0100
parents 5d96bcd3bfec
children fdbb07f1e373
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.py	Thu Mar 28 08:42:11 2019 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Thu Mar 28 08:44:03 2019 +0100
@@ -73,7 +73,7 @@
     pass
 
 
-class MessageWidget(BoxLayout):
+class MessageWidget(BoxLayout, quick_chat.MessageWidget):
     mess_data = properties.ObjectProperty()
     mess_xhtml = properties.ObjectProperty()
     mess_padding = (dp(5), dp(5))
@@ -94,16 +94,27 @@
         """return parent Chat instance"""
         return self.mess_data.parent
 
-    @property
-    def message(self):
+    def _get_message(self):
         """Return currently displayed message"""
         return self.mess_data.main_message
 
+    def _set_message(self, message):
+        if message == self.mess_data.message.get(u""):
+            return False
+        self.mess_data.message = {u"": message}
+        return True
+
+    message = properties.AliasProperty(_get_message, _set_message)
+
     @property
     def message_xhtml(self):
         """Return currently displayed message"""
         return self.mess_data.main_message_xhtml
 
+    @property
+    def info_type(self):
+        return self.mess_data.info_type
+
     def widthAdjust(self):
         """this widget grows up with its children"""
         pass
@@ -437,6 +448,10 @@
                                                 on_existing_widget=G.host.getOrClone,
                                                 profiles=profiles)
 
+    @property
+    def message_widgets_rev(self):
+        return self.messages_widget.children
+
     ## header ##
 
     def changeWidget(self, jid_):
@@ -547,6 +562,12 @@
         self.appendMessage(message)
 
     def appendMessage(self, mess_data):
+        """Append a message Widget to the history
+
+        @param mess_data(quick_chat.Message): message data
+        """
+        if self.handleUserMoved(mess_data):
+            return
         self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
         self.notify(mess_data)