Add desktop msg limit
Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
This commit is contained in:
parent
794313dbee
commit
dfbc0eb435
|
@ -221,6 +221,7 @@
|
||||||
|
|
||||||
(def ^:const lines-collapse-threshold 20)
|
(def ^:const lines-collapse-threshold 20)
|
||||||
(def ^:const chars-collapse-threshold 600)
|
(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-contact-code "contact-code")
|
||||||
(def ^:const dapp-permission-web3 "web3")
|
(def ^:const dapp-permission-web3 "web3")
|
||||||
|
@ -239,4 +240,4 @@
|
||||||
;;ipfs
|
;;ipfs
|
||||||
(def ^:const ipfs-add-url "https://ipfs.infura.io:5001/api/v0/add")
|
(def ^:const ipfs-add-url "https://ipfs.infura.io:5001/api/v0/add")
|
||||||
(def ^:const ipfs-add-param-name "extension.event.edn")
|
(def ^:const ipfs-add-param-name "extension.event.edn")
|
||||||
(def ^:const ipfs-cat-url "https://ipfs.infura.io/ipfs/")
|
(def ^:const ipfs-cat-url "https://ipfs.infura.io/ipfs/")
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
[status-im.utils.platform :as platform]
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
|
[status-im.utils.core :as core-utils]
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.ui.components.colors :as colors]
|
[status-im.ui.components.colors :as colors]
|
||||||
[status-im.utils.http :as http]))
|
[status-im.utils.http :as http]))
|
||||||
|
@ -51,18 +52,25 @@
|
||||||
text-chunk]))
|
text-chunk]))
|
||||||
render-recipe))
|
render-recipe))
|
||||||
|
|
||||||
(defn render-chunks-desktop [render-recipe message]
|
(defn render-chunks-desktop [limit render-recipe message]
|
||||||
"This fn is only need as a temporary hack
|
"This fn is only needed as a temporary hack
|
||||||
until rn-desktop supports text/number-of-lines property"
|
until rn-desktop supports text/number-of-lines property"
|
||||||
(seq (second
|
(->> render-recipe
|
||||||
(reduce (fn [[total-length acc] [idx [text-chunk kind]]]
|
(map vector (range))
|
||||||
(if (< constants/chars-collapse-threshold total-length)
|
(reduce (fn [[total-length acc] [idx [text-chunk kind]]]
|
||||||
(reduced [total-length acc])
|
(if (<= limit total-length)
|
||||||
[(+ total-length (count text-chunk))
|
(reduced [total-length acc])
|
||||||
(conj acc
|
(let [chunk-len (count text-chunk)
|
||||||
(if (= :text kind)
|
cut-chunk-len (min chunk-len (- limit total-length))
|
||||||
text-chunk
|
cut-chunk (if (= chunk-len cut-chunk-len)
|
||||||
[react/text (into {:key idx} (lookup-props text-chunk message kind))
|
text-chunk
|
||||||
text-chunk]))]))
|
(core-utils/truncate-str text-chunk cut-chunk-len))]
|
||||||
[0 []]
|
[(+ total-length cut-chunk-len)
|
||||||
(map vector (range) render-recipe)))))
|
(conj acc
|
||||||
|
(if (= :text kind)
|
||||||
|
cut-chunk
|
||||||
|
[react/text (into {:key idx} (lookup-props text-chunk message kind))
|
||||||
|
cut-chunk]))])))
|
||||||
|
[0 []])
|
||||||
|
second
|
||||||
|
seq))
|
||||||
|
|
|
@ -110,9 +110,9 @@
|
||||||
:on-select #(when (message-sent? user-statuses current-public-key)
|
:on-select #(when (message-sent? user-statuses current-public-key)
|
||||||
(re-frame/dispatch [:chat.ui/reply-to-message message-id old-message-id]))}])))}
|
(re-frame/dispatch [:chat.ui/reply-to-message message-id old-message-id]))}])))}
|
||||||
(let [collapsible? (and (:should-collapse? content) group-chat)
|
(let [collapsible? (and (:should-collapse? content) group-chat)
|
||||||
message-text (cond-> (:text content)
|
char-limit (if (and collapsible? (not expanded?))
|
||||||
(and collapsible? (not expanded?))
|
constants/chars-collapse-threshold constants/desktop-msg-chars-hard-limit)
|
||||||
(core-utils/truncate-str constants/chars-collapse-threshold))]
|
message-text (core-utils/truncate-str (:text content) char-limit)]
|
||||||
[react/view {:style styles/message-container}
|
[react/view {:style styles/message-container}
|
||||||
(when (:response-to content)
|
(when (:response-to content)
|
||||||
[quoted-message (:response-to content) false current-public-key])
|
[quoted-message (:response-to content) false current-public-key])
|
||||||
|
@ -120,11 +120,7 @@
|
||||||
:selectable true
|
:selectable true
|
||||||
:selection-color colors/blue-light}
|
:selection-color colors/blue-light}
|
||||||
(if-let [render-recipe (:render-recipe content)]
|
(if-let [render-recipe (:render-recipe content)]
|
||||||
(apply
|
(chat-utils/render-chunks-desktop char-limit render-recipe message-text)
|
||||||
(if (and collapsible? (not expanded?))
|
|
||||||
chat-utils/render-chunks-desktop
|
|
||||||
chat-utils/render-chunks)
|
|
||||||
render-recipe message-text)
|
|
||||||
message-text)]
|
message-text)]
|
||||||
(when collapsible?
|
(when collapsible?
|
||||||
[message/expand-button expanded? chat-id message-id])])]])
|
[message/expand-button expanded? chat-id message-id])])]])
|
||||||
|
@ -186,8 +182,6 @@
|
||||||
^{:key (str "datemark" message-id)}
|
^{:key (str "datemark" message-id)}
|
||||||
[message.datemark/chat-datemark value]
|
[message.datemark/chat-datemark value]
|
||||||
(when (contains? constants/desktop-content-types content-type)
|
(when (contains? constants/desktop-content-types content-type)
|
||||||
(when (nil? message-id)
|
|
||||||
(log/debug "nil?" message))
|
|
||||||
(reagent.core/create-class
|
(reagent.core/create-class
|
||||||
{:component-did-mount
|
{:component-did-mount
|
||||||
#(when (and message-id
|
#(when (and message-id
|
||||||
|
|
Loading…
Reference in New Issue