changeset 367:abb57182ebfb

chat: prepend nick to message input when occupant avatar is touched on group chat.
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:08 +0100
parents 58e395c0777e
children 7fd138c12506
files cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.kv	Mon Jan 27 21:17:08 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Mon Jan 27 21:17:08 2020 +0100
@@ -58,6 +58,7 @@
         MessAvatar:
             id: avatar
             source: (root.mess_data.avatar or '') if root.mess_data else ''
+            on_press: root.chat.addNick(root.nick)
         Widget:
             # use to push the avatar on the top
             size_hint: 1, 1
--- a/cagou/plugins/plugin_wid_chat.py	Mon Jan 27 21:17:08 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Mon Jan 27 21:17:08 2020 +0100
@@ -24,6 +24,7 @@
 from kivy.uix.textinput import TextInput
 from kivy.uix.screenmanager import Screen, NoTransition
 from kivy.uix import screenmanager
+from kivy.uix.behaviors import ButtonBehavior
 from kivy.metrics import sp, dp
 from kivy.clock import Clock
 from kivy import properties
@@ -73,7 +74,7 @@
 INFINITE_SCROLL_LIMIT = dp(600)
 
 
-class MessAvatar(Image):
+class MessAvatar(ButtonBehavior, Image):
     pass
 
 
@@ -455,6 +456,7 @@
         return self.messages_widget.children
 
     ## keyboard ##
+
     def key_input(self, window, key, scancode, codepoint, modifier):
         if key == 27:
             screen_manager = self.screen_manager
@@ -650,6 +652,13 @@
                             room_jid=self.target)
                         )
 
+    # message input
+
+    def addNick(self, nick):
+        """Add a nickname to message_input if suitable"""
+        if (self.type == C.CHAT_GROUP and not self.message_input.text.startswith(nick)):
+            self.message_input.text = f'{nick}: {self.message_input.text}'
+
     def onSend(self, input_widget):
         G.host.messageSend(
             self.target,