« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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 => {