From 21aacdfe8dab93ebb42bc8cec20fc8322af48175 Mon Sep 17 00:00:00 2001
From: Amin Bandali <amin.bandali@savoirfairelinux.com>
Date: Thu, 3 Dec 2020 13:32:37 -0500
Subject: [PATCH] chatview: use recipient's name in the send message input
 placeholder

Change the message input's placeholder from "Type a message" to
"Write to {0}", where {0} is the name of the message's recipient.

GitLab: #443
Change-Id: I9b849fe4ad8dd42470a998cc4e73d6c9d4ce8a48
---
 src/chatview.cpp               |  2 +-
 src/web-chatview/chatview.html |  2 +-
 src/web-chatview/chatview.js   | 47 +++++++++++++++++++---------------
 3 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/chatview.cpp b/src/chatview.cpp
index 0bc3f20d..4daba7f3 100644
--- a/src/chatview.cpp
+++ b/src/chatview.cpp
@@ -41,7 +41,7 @@ getTranslatedStrings(bool qwebview)
         {"Accept", QObject::tr("Accept")},
         {"Refuse", QObject::tr("Refuse")},
         {"Block", QObject::tr("Block")},
-        {"Type a message", QObject::tr("Type a message")},
+        {"Write to {0}", QObject::tr("Write to {0}")},
         {"Note: an interaction will create a new contact.",
          QObject::tr("Note: an interaction will create a new contact.")},
         {"is not in your contacts", QObject::tr("is not in your contacts")},
diff --git a/src/web-chatview/chatview.html b/src/web-chatview/chatview.html
index a51fe07c..1bd4d905 100644
--- a/src/web-chatview/chatview.html
+++ b/src/web-chatview/chatview.html
@@ -112,7 +112,7 @@
                         <path d="M0 0h24v24H0z" fill="none"/>
                     </svg>
                 </div>
-                <textarea id="message" autofocus placeholder="Type a message" onkeyup="grow_text_area()" onkeydown="process_messagebar_keydown()"
+                <textarea id="message" autofocus onkeyup="grow_text_area()" onkeydown="process_messagebar_keydown()"
                           dir="auto" rows="1"></textarea>
                 <div id="sendButton" class="nav-button action-button" onclick="sendMessage();">
                     <svg class="svgicon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
diff --git a/src/web-chatview/chatview.js b/src/web-chatview/chatview.js
index c6d1dbf1..e0b4d573 100644
--- a/src/web-chatview/chatview.js
+++ b/src/web-chatview/chatview.js
@@ -133,7 +133,7 @@ function init_i18n(data) {
     if (use_qt) {
         window.jsbridge.parseI18nData(function(stringData) {
             i18nStringData = stringData
-            reset_message_bar_input()
+            reset_message_bar_input("")
             set_titles()
         })
     } else {
@@ -151,7 +151,7 @@ function init_i18n(data) {
             }
             i18n = new Jed({ locale_data: { "messages": domain } })
         }
-        reset_message_bar_input()
+        reset_message_bar_input("")
         set_titles()
     }
 }
@@ -190,9 +190,10 @@ function set_titles() {
     }
 }
 
-function reset_message_bar_input() {
+function reset_message_bar_input(name) {
     messageBarInput.placeholder = use_qt ?
-        i18nStringData["Type a message"] : i18n.gettext("Type a message")
+        i18nStringData["Write to {0}"].format(name) :
+        i18n.gettext("Write to {0}").format(name)
 }
 
 function onScrolled_() {
@@ -300,7 +301,7 @@ function update_chatview_frame(accountEnabled, banned, temporary, alias, bestid)
     if (isAccountEnabled !== accountEnabled) {
         isAccountEnabled = accountEnabled
         hideMessageBar(!accountEnabled)
-        hideControls(accountEnabled)
+        hideControls(!accountEnabled)
     }
 
     if (isBanned !== banned) {
@@ -322,10 +323,13 @@ function update_chatview_frame(accountEnabled, banned, temporary, alias, bestid)
                 i18n.gettext("Note: an interaction will create a new contact.")
         } else {
             addToConvButton.style.display = ""
-            reset_message_bar_input()
         }
     }
 
+    if (!temporary) {
+        reset_message_bar_input(alias ? alias : bestid)
+    }
+
     navbar.style.display = ""
 }
 
@@ -406,11 +410,11 @@ function displayRecordControls(isVisible) {
 /**
  * Hide or show message bar, and update body bottom padding accordingly.
  *
- * @param isHidden whether message bar should be displayed or not
+ * @param hide whether message bar should be displayed or not
  */
 /* exported hideMessageBar */
-function hideMessageBar(isHidden) {
-    if (isHidden) {
+function hideMessageBar(hide) {
+    if (hide) {
         messageBar.classList.add("hiddenState")
         document.body.style.setProperty("--messagebar-size", "0")
     } else {
@@ -419,6 +423,19 @@ function hideMessageBar(isHidden) {
     }
 }
 
+/**
+ * Hide or show add to conversations/calls
+ *
+ * @param hide whether the buttons should be hidden
+ */
+function hideControls(hide) {
+    if (hide) {
+        callButtons.style.display = "none"
+    } else {
+        callButtons.style.display = ""
+    }
+}
+
 /* exported setDisplayLinks */
 function setDisplayLinks(display) {
     displayLinksEnabled = display
@@ -818,18 +835,6 @@ function humanFileSize(bytes) {
     return bytes.toFixed(1) + " " + units[u]
 }
 
-/**
- * Hide or show add to conversations/calls whether the account is enabled
- * @param accountEnabled true if account is enabled
- */
-function hideControls(accountEnabled) {
-    if (!accountEnabled) {
-        callButtons.style.display = "none"
-    } else {
-        callButtons.style.display = ""
-    }
-}
-
 /**
  * Change the value of the progress bar.
  *
-- 
GitLab