comparison 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
comparison
equal deleted inserted replaced
288:44752e8031f8 289:717c6c368f70
71 71
72 class MessAvatar(Image): 72 class MessAvatar(Image):
73 pass 73 pass
74 74
75 75
76 class MessageWidget(BoxLayout): 76 class MessageWidget(BoxLayout, quick_chat.MessageWidget):
77 mess_data = properties.ObjectProperty() 77 mess_data = properties.ObjectProperty()
78 mess_xhtml = properties.ObjectProperty() 78 mess_xhtml = properties.ObjectProperty()
79 mess_padding = (dp(5), dp(5)) 79 mess_padding = (dp(5), dp(5))
80 avatar = properties.ObjectProperty() 80 avatar = properties.ObjectProperty()
81 delivery = properties.ObjectProperty() 81 delivery = properties.ObjectProperty()
92 @property 92 @property
93 def chat(self): 93 def chat(self):
94 """return parent Chat instance""" 94 """return parent Chat instance"""
95 return self.mess_data.parent 95 return self.mess_data.parent
96 96
97 @property 97 def _get_message(self):
98 def message(self):
99 """Return currently displayed message""" 98 """Return currently displayed message"""
100 return self.mess_data.main_message 99 return self.mess_data.main_message
100
101 def _set_message(self, message):
102 if message == self.mess_data.message.get(u""):
103 return False
104 self.mess_data.message = {u"": message}
105 return True
106
107 message = properties.AliasProperty(_get_message, _set_message)
101 108
102 @property 109 @property
103 def message_xhtml(self): 110 def message_xhtml(self):
104 """Return currently displayed message""" 111 """Return currently displayed message"""
105 return self.mess_data.main_message_xhtml 112 return self.mess_data.main_message_xhtml
113
114 @property
115 def info_type(self):
116 return self.mess_data.info_type
106 117
107 def widthAdjust(self): 118 def widthAdjust(self):
108 """this widget grows up with its children""" 119 """this widget grows up with its children"""
109 pass 120 pass
110 # parent = self.mess_xhtml.parent 121 # parent = self.mess_xhtml.parent
435 target = G.host.profiles[profiles[0]].whoami 446 target = G.host.profiles[profiles[0]].whoami
436 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, 447 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None,
437 on_existing_widget=G.host.getOrClone, 448 on_existing_widget=G.host.getOrClone,
438 profiles=profiles) 449 profiles=profiles)
439 450
451 @property
452 def message_widgets_rev(self):
453 return self.messages_widget.children
454
440 ## header ## 455 ## header ##
441 456
442 def changeWidget(self, jid_): 457 def changeWidget(self, jid_):
443 """change current widget for a new one with given jid 458 """change current widget for a new one with given jid
444 459
545 560
546 def createMessage(self, message): 561 def createMessage(self, message):
547 self.appendMessage(message) 562 self.appendMessage(message)
548 563
549 def appendMessage(self, mess_data): 564 def appendMessage(self, mess_data):
565 """Append a message Widget to the history
566
567 @param mess_data(quick_chat.Message): message data
568 """
569 if self.handleUserMoved(mess_data):
570 return
550 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) 571 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
551 self.notify(mess_data) 572 self.notify(mess_data)
552 573
553 def _get_notif_msg(self, mess_data): 574 def _get_notif_msg(self, mess_data):
554 return _(u"{nick}: {message}").format( 575 return _(u"{nick}: {message}").format(