From 2190fa3be469f2d7991e2e776b276a6b904a7828 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 2 Nov 2016 13:29:43 +0200 Subject: [PATCH] fixes #399 Former-commit-id: 50c877eee843a125214c2c8234949ed1bd602fe4 --- src/status_im/chat/views/response.cljs | 18 ++++++----- src/status_im/chat/views/toolbar_content.cljs | 2 +- src/status_im/utils/name.cljs | 30 +++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 src/status_im/utils/name.cljs diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index b496391457..53190036d6 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -24,7 +24,8 @@ [status-im.components.webview-bridge :refer [webview-bridge]] [status-im.i18n :refer [label]] [status-im.utils.datetime :as dt] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [status-im.utils.name :refer [shortened-name]])) (defn drag-icon [] [view st/drag-container @@ -44,13 +45,14 @@ [text {:style st/command-name} (str (:description command) " " (label :t/request))] (when added - [text {:style st/message-info} - (str "By " (or name chat-id) ", " - (dt/format-date "MMM" added) - " " - (dt/get-ordinal-date added) - " at " - (dt/format-date "HH:mm" added))])]) + (let [name' (shortened-name (or name chat-id) 20)] + [text {:style st/message-info} + (str "By " name' ", " + (dt/format-date "MMM" added) + " " + (dt/get-ordinal-date added) + " at " + (dt/format-date "HH:mm" added))]))]) (defn request-info [response-height] (let [layout-height (subscribe [:max-layout-height :default]) diff --git a/src/status_im/chat/views/toolbar_content.cljs b/src/status_im/chat/views/toolbar_content.cljs index bf8eec45ed..87e3de7d78 100644 --- a/src/status_im/chat/views/toolbar_content.cljs +++ b/src/status_im/chat/views/toolbar_content.cljs @@ -67,4 +67,4 @@ [group-last-activity {:contacts @contacts :sync-state @sync-state}] [last-activity {:online-text (online-text @contact @chat-id) - :sync-state @sync-state}])]))) \ No newline at end of file + :sync-state @sync-state}])]))) diff --git a/src/status_im/utils/name.cljs b/src/status_im/utils/name.cljs new file mode 100644 index 0000000000..cc55d74d09 --- /dev/null +++ b/src/status_im/utils/name.cljs @@ -0,0 +1,30 @@ +(ns status-im.utils.name + (:require [clojure.string :as str])) + +(defn too-long? [name max-len] + (> (count name) max-len)) + +(defn max-name + [name max-len] + (let [names (str/split name " ")] + (first + (reduce (fn [[name done] next-name] + (if done + name + (let [new-name (str/join " " [name next-name])] + (if (too-long? new-name max-len) + (let [new-name' (str name " " (first next-name) ".")] + (if (too-long? new-name' max-len) + [name true] + [new-name' true])) + [new-name])))) + [(first names)] + (rest names))))) + +(defn shortened-name [name max-len] + (if (> (count name) max-len) + (let [name' (max-name name max-len)] + (if (too-long? name' max-len) + (str (str/trim (subs name 0 max-len)) "...") + name')) + name))