« get me outta code hell

simplify log message text construction - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-03-15 21:57:34 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-03-15 21:57:34 -0300
commit6bc0f9a8d544f458baad84973740591ddb8702d5 (patch)
treebf5a516677d93fab1428953b4cba4f99b9645aa8
parent609690e36a57fb7f6a1f272ede80e3714237c1e4 (diff)
simplify log message text construction
-rw-r--r--socket.js12
1 files changed, 5 insertions, 7 deletions
diff --git a/socket.js b/socket.js
index 69cadeb..efe3d07 100644
--- a/socket.js
+++ b/socket.js
@@ -419,7 +419,7 @@ function attachBackendToSocketClient(backend, client, {
   function logCommand(command) {
     const nickToMessage = nickname => `\x1b[32;1m${nickname}\x1b[0m`
     const itemToMessage = item => `\x1b[32m"${item.name}"\x1b[0m`
-    let fullmsg = '' // may be overridden
+    let senderNickname = command.sender === 'server' ? 'the server' : command.senderNickname
     let actionmsg = `sent ${command.code} (no action message specified)`
     let isVerbose = false
     switch (command.code) {
@@ -461,7 +461,8 @@ function attachBackendToSocketClient(backend, client, {
         actionmsg = `seeked to ${getTimeStringsFromSec(command.time, command.time).timeDone}`
         break
       case 'set-nickname':
-        fullmsg = `${nickToMessage(command.nickname)} updated their nickname (from ${nickToMessage(command.oldNickname)})`
+        actionmsg = `updated their nickname (from ${nickToMessage(command.oldNickname)})`
+        senderNickname = command.nickname
         break
       case 'set-pause':
         if (command.paused) {
@@ -494,11 +495,8 @@ function attachBackendToSocketClient(backend, client, {
         }
         break
     }
-    if (!fullmsg) {
-      const nickname = command.sender === 'server' ? 'the server' : command.senderNickname
-      fullmsg = `${nickToMessage(nickname)} ${actionmsg}`
-    }
-    backend.showLogMessage(fullmsg, isVerbose)
+    const text = `${nickToMessage(senderNickname)} ${actionmsg}`
+    backend.showLogMessage(text, isVerbose)
   }
 
   client.on('sent-command', command => {