From 585baa9d71e05219bbd5ced5c125fff9e6f1b31a Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 20 May 2016 16:36:00 +0300 Subject: [PATCH] Truncate chat name Former-commit-id: c3496957ff93f07bcfaf16d3cf78c866b4c7fe05 --- src/status_im/chat/screen.cljs | 9 +++------ src/status_im/chats_list/views/inner_item.cljs | 3 ++- src/status_im/utils/utils.cljs | 5 +++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index a6020a2fda..8289fe7bb9 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -13,6 +13,7 @@ chat-icon-view-menu-item]] [status-im.chat.styles.screen :as st] [status-im.utils.listview :refer [to-datasource]] + [status-im.utils.utils :refer [truncate-str]] [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] @@ -99,11 +100,7 @@ [chat-icon-view-menu-item chat-id group-chat name color true]) (defn members-text [members] - (let [max 35 - text (str (s/join ", " (map #(:name %) members)) " and you")] - (if (< max (count text)) - (str (subs text 0 (- max 3)) "...") - text))) + (truncate-str (str (s/join ", " (map #(:name %) members)) " and you") 35)) (defn actions-list-view [] (let [{:keys [group-chat chat-id]} @@ -182,7 +179,7 @@ (fn [] [view (st/chat-name-view @show-actions) [text {:style st/chat-name-text} - (or @name "Chat name")] + (truncate-str (or @name "Chat name") 30)] (if @group-chat [view {:flexDirection :row} [icon :group st/group-icon] diff --git a/src/status_im/chats_list/views/inner_item.cljs b/src/status_im/chats_list/views/inner_item.cljs index a0794d5201..e3fc322bb7 100644 --- a/src/status_im/chats_list/views/inner_item.cljs +++ b/src/status_im/chats_list/views/inner_item.cljs @@ -3,6 +3,7 @@ (:require [status-im.components.react :refer [view image icon text]] [status-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]] [status-im.chats-list.styles :as st] + [status-im.utils.utils :refer [truncate-str]] [status-im.utils.datetime :as time])) (defn chat-list-item-inner-view @@ -14,7 +15,7 @@ [chat-icon-view-chat-list chat-id group-chat name color online]] [view st/item-container [view st/name-view - [text {:style st/name-text} name] + [text {:style st/name-text} (truncate-str name 20)] (when group-chat [icon :group st/group-icon]) (when group-chat diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 8a0be411d7..02d54d3f88 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -47,3 +47,8 @@ (.catch (or on-error (fn [error] (toast (str error)))))))) + +(defn truncate-str [s max] + (if (< max (count s)) + (str (subs s 0 (- max 3)) "...") + s))