Add desktop msg limit

Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
This commit is contained in:
Vitaliy Vlasov 2018-12-21 13:29:33 +02:00
parent 794313dbee
commit dfbc0eb435
No known key found for this signature in database
GPG Key ID: A7D57C347F2B2964
3 changed files with 29 additions and 26 deletions

View File

@ -221,6 +221,7 @@
(def ^:const lines-collapse-threshold 20)
(def ^:const chars-collapse-threshold 600)
(def ^:const desktop-msg-chars-hard-limit 10000)
(def ^:const dapp-permission-contact-code "contact-code")
(def ^:const dapp-permission-web3 "web3")

View File

@ -4,6 +4,7 @@
[status-im.utils.platform :as platform]
[status-im.i18n :as i18n]
[status-im.constants :as constants]
[status-im.utils.core :as core-utils]
[status-im.ui.components.react :as react]
[status-im.ui.components.colors :as colors]
[status-im.utils.http :as http]))
@ -51,18 +52,25 @@
text-chunk]))
render-recipe))
(defn render-chunks-desktop [render-recipe message]
"This fn is only need as a temporary hack
(defn render-chunks-desktop [limit render-recipe message]
"This fn is only needed as a temporary hack
until rn-desktop supports text/number-of-lines property"
(seq (second
(->> render-recipe
(map vector (range))
(reduce (fn [[total-length acc] [idx [text-chunk kind]]]
(if (< constants/chars-collapse-threshold total-length)
(if (<= limit total-length)
(reduced [total-length acc])
[(+ total-length (count text-chunk))
(let [chunk-len (count text-chunk)
cut-chunk-len (min chunk-len (- limit total-length))
cut-chunk (if (= chunk-len cut-chunk-len)
text-chunk
(core-utils/truncate-str text-chunk cut-chunk-len))]
[(+ total-length cut-chunk-len)
(conj acc
(if (= :text kind)
text-chunk
cut-chunk
[react/text (into {:key idx} (lookup-props text-chunk message kind))
text-chunk]))]))
[0 []]
(map vector (range) render-recipe)))))
cut-chunk]))])))
[0 []])
second
seq))

View File

@ -110,9 +110,9 @@
:on-select #(when (message-sent? user-statuses current-public-key)
(re-frame/dispatch [:chat.ui/reply-to-message message-id old-message-id]))}])))}
(let [collapsible? (and (:should-collapse? content) group-chat)
message-text (cond-> (:text content)
(and collapsible? (not expanded?))
(core-utils/truncate-str constants/chars-collapse-threshold))]
char-limit (if (and collapsible? (not expanded?))
constants/chars-collapse-threshold constants/desktop-msg-chars-hard-limit)
message-text (core-utils/truncate-str (:text content) char-limit)]
[react/view {:style styles/message-container}
(when (:response-to content)
[quoted-message (:response-to content) false current-public-key])
@ -120,11 +120,7 @@
:selectable true
:selection-color colors/blue-light}
(if-let [render-recipe (:render-recipe content)]
(apply
(if (and collapsible? (not expanded?))
chat-utils/render-chunks-desktop
chat-utils/render-chunks)
render-recipe message-text)
(chat-utils/render-chunks-desktop char-limit render-recipe message-text)
message-text)]
(when collapsible?
[message/expand-button expanded? chat-id message-id])])]])
@ -186,8 +182,6 @@
^{:key (str "datemark" message-id)}
[message.datemark/chat-datemark value]
(when (contains? constants/desktop-content-types content-type)
(when (nil? message-id)
(log/debug "nil?" message))
(reagent.core/create-class
{:component-did-mount
#(when (and message-id