[android, ios] render markdown-ish formatting in chat messages natively.
use patched RN to make sure that heavily-formatted messages don't slow our chats down. Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
ae52fd07f4
commit
79454938bc
|
@ -116,6 +116,7 @@
|
||||||
(defn prepare-nested-text-props [props]
|
(defn prepare-nested-text-props [props]
|
||||||
(-> props
|
(-> props
|
||||||
(update :style typography/get-nested-style)
|
(update :style typography/get-nested-style)
|
||||||
|
(assoc :parseBasicMarkdown true)
|
||||||
(assoc :nested? true)))
|
(assoc :nested? true)))
|
||||||
|
|
||||||
;; Accessor methods for React Components
|
;; Accessor methods for React Components
|
||||||
|
|
|
@ -54,8 +54,8 @@ PODS:
|
||||||
- nanopb/decode (0.3.8)
|
- nanopb/decode (0.3.8)
|
||||||
- nanopb/encode (0.3.8)
|
- nanopb/encode (0.3.8)
|
||||||
- Protobuf (3.6.1)
|
- Protobuf (3.6.1)
|
||||||
- React (0.59.3):
|
- React (0.59.9):
|
||||||
- React/Core (= 0.59.3)
|
- React/Core (= 0.59.9)
|
||||||
- react-native-background-timer (2.1.0-alpha.6):
|
- react-native-background-timer (2.1.0-alpha.6):
|
||||||
- React
|
- React
|
||||||
- react-native-camera (1.1.5):
|
- react-native-camera (1.1.5):
|
||||||
|
@ -68,8 +68,8 @@ PODS:
|
||||||
- React
|
- React
|
||||||
- react-native-webview (5.2.1):
|
- react-native-webview (5.2.1):
|
||||||
- React
|
- React
|
||||||
- React/Core (0.59.3):
|
- React/Core (0.59.9):
|
||||||
- yoga (= 0.59.3.React)
|
- yoga (= 0.59.9.React)
|
||||||
- RNKeychain (3.0.0-rc.3):
|
- RNKeychain (3.0.0-rc.3):
|
||||||
- React
|
- React
|
||||||
- SQLCipher (3.4.2):
|
- SQLCipher (3.4.2):
|
||||||
|
@ -80,7 +80,7 @@ PODS:
|
||||||
- SSZipArchive (2.1.4)
|
- SSZipArchive (2.1.4)
|
||||||
- TouchID (4.4.1):
|
- TouchID (4.4.1):
|
||||||
- React
|
- React
|
||||||
- yoga (0.59.3.React)
|
- yoga (0.59.9.React)
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- Firebase/Core
|
- Firebase/Core
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"querystring-es3": "0.2.1",
|
"querystring-es3": "0.2.1",
|
||||||
"react": "16.8.3",
|
"react": "16.8.3",
|
||||||
"react-dom": "16.4.2",
|
"react-dom": "16.4.2",
|
||||||
"react-native": "git+https://github.com/status-im/react-native.git#status-v0.59.3",
|
"react-native": "git+https://github.com/status-im/react-native.git#status-0.59.9",
|
||||||
"react-native-background-timer": "2.1.0-alpha.6",
|
"react-native-background-timer": "2.1.0-alpha.6",
|
||||||
"react-native-camera": "git+https://github.com/status-im/react-native-camera.git#v1.1.5-1-status",
|
"react-native-camera": "git+https://github.com/status-im/react-native-camera.git#v1.1.5-1-status",
|
||||||
"react-native-config": "git+https://github.com/status-im/react-native-config.git#0.11.2-1",
|
"react-native-config": "git+https://github.com/status-im/react-native-config.git#0.11.2-1",
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,6 @@
|
||||||
(ns status-im.chat.models.message-content
|
(ns status-im.chat.models.message-content
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.constants :as constants]))
|
[status-im.constants :as constants]))
|
||||||
|
|
||||||
(def stylings [[:bold constants/regx-bold]
|
(def stylings [[:bold constants/regx-bold]
|
||||||
|
@ -92,7 +93,9 @@
|
||||||
[(clear-ranges matches text) (assoc metadata type matches)]
|
[(clear-ranges matches text) (assoc metadata type matches)]
|
||||||
[text metadata]))
|
[text metadata]))
|
||||||
[text {}]
|
[text {}]
|
||||||
(into stylings actions))]
|
(if platform/desktop?
|
||||||
|
(into stylings actions)
|
||||||
|
actions))]
|
||||||
(cond-> content
|
(cond-> content
|
||||||
(seq metadata) (as-> content
|
(seq metadata) (as-> content
|
||||||
(assoc content :metadata metadata)
|
(assoc content :metadata metadata)
|
||||||
|
|
|
@ -92,7 +92,11 @@
|
||||||
[quoted-message (:response-to content) outgoing current-public-key])
|
[quoted-message (:response-to content) outgoing current-public-key])
|
||||||
(apply react/nested-text
|
(apply react/nested-text
|
||||||
(cond-> {:style (style/text-message collapsible? outgoing)
|
(cond-> {:style (style/text-message collapsible? outgoing)
|
||||||
:text-break-strategy :balanced}
|
:text-break-strategy :balanced
|
||||||
|
:parseBasicMarkdown true
|
||||||
|
:markdownCodeBackgroundColor colors/black
|
||||||
|
:markdownCodeForegroundColor colors/green}
|
||||||
|
|
||||||
(and collapsible? (not expanded?))
|
(and collapsible? (not expanded?))
|
||||||
(assoc :number-of-lines constants/lines-collapse-threshold))
|
(assoc :number-of-lines constants/lines-collapse-threshold))
|
||||||
(conj (if-let [render-recipe (:render-recipe content)]
|
(conj (if-let [render-recipe (:render-recipe content)]
|
||||||
|
|
|
@ -366,7 +366,6 @@
|
||||||
:row message
|
:row message
|
||||||
:idx idx
|
:idx idx
|
||||||
:list-ref messages-list-ref}])
|
:list-ref messages-list-ref}])
|
||||||
:initialNumToRender 6
|
|
||||||
:inverted true
|
:inverted true
|
||||||
:onEndReached #(re-frame/dispatch [:chat.ui/load-more-messages])
|
:onEndReached #(re-frame/dispatch [:chat.ui/load-more-messages])
|
||||||
:keyboardShouldPersistTaps :handled}
|
:keyboardShouldPersistTaps :handled}
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
(ns status-im.test.chat.models.message-content
|
(ns status-im.test.chat.models.message-content
|
||||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||||
|
[status-im.utils.platform :as platform]
|
||||||
[status-im.chat.models.message-content :as message-content]))
|
[status-im.chat.models.message-content :as message-content]))
|
||||||
|
|
||||||
(deftest enrich-string-content-test
|
(deftest enrich-string-content-test
|
||||||
(testing "Text content of the message is enriched correctly"
|
(if platform/desktop?
|
||||||
(is (not (:metadata (message-content/enrich-content {:text "Plain message"}))))
|
(testing "Text content of the message is enriched correctly"
|
||||||
(is (= {:bold [[5 14]]}
|
(is (not (:metadata (message-content/enrich-content {:text "Plain message"}))))
|
||||||
(:metadata (message-content/enrich-content {:text "Some *styling* present"}))))
|
(is (= {:bold [[5 14]]}
|
||||||
(is (= {:bold [[5 14]]
|
(:metadata (message-content/enrich-content {:text "Some *styling* present"}))))
|
||||||
:tag [[28 33] [38 43]]}
|
(is (= {:bold [[5 14]]
|
||||||
(:metadata (message-content/enrich-content {:text "Some *styling* present with #tag1 and #tag2 as well"})))))
|
:tag [[28 33] [38 43]]}
|
||||||
|
(:metadata (message-content/enrich-content {:text "Some *styling* present with #tag1 and #tag2 as well"}))))))
|
||||||
|
|
||||||
(testing "right to left is correctly identified"
|
(testing "right to left is correctly identified"
|
||||||
(is (not (:rtl? (message-content/enrich-content {:text "You are lucky today!"}))))
|
(is (not (:rtl? (message-content/enrich-content {:text "You are lucky today!"}))))
|
||||||
(is (not (:rtl? (message-content/enrich-content {:text "42"}))))
|
(is (not (:rtl? (message-content/enrich-content {:text "42"}))))
|
||||||
|
@ -23,10 +26,20 @@
|
||||||
(deftest build-render-recipe-test
|
(deftest build-render-recipe-test
|
||||||
(testing "Render tree is build from text"
|
(testing "Render tree is build from text"
|
||||||
(is (not (:render-recipe (message-content/enrich-content {:text "Plain message"}))))
|
(is (not (:render-recipe (message-content/enrich-content {:text "Plain message"}))))
|
||||||
(is (= '(["Test " :text]
|
(is (= (if platform/desktop?
|
||||||
["#status" :tag]
|
'(["Test " :text]
|
||||||
[" one three " :text]
|
["#status" :tag]
|
||||||
["#core-chat (@developer)!" :bold]
|
[" one three " :text]
|
||||||
[" By the way, " :text]
|
["#core-chat (@developer)!" :bold]
|
||||||
["nice link(https://link.com)" :italic])
|
[" By the way, " :text]
|
||||||
|
["nice link(https://link.com)" :italic])
|
||||||
|
'(["Test " :text]
|
||||||
|
["#status" :tag]
|
||||||
|
[" one three *" :text]
|
||||||
|
["#core-chat" :tag]
|
||||||
|
[" (" :text]
|
||||||
|
["@developer" :mention]
|
||||||
|
[")!* By the way, ~nice link(" :text]
|
||||||
|
["https://link.com" :link]
|
||||||
|
[")~" :text]))
|
||||||
(:render-recipe (message-content/enrich-content {:text "Test #status one three *#core-chat (@developer)!* By the way, ~nice link(https://link.com)~"}))))))
|
(:render-recipe (message-content/enrich-content {:text "Test #status one three *#core-chat (@developer)!* By the way, ~nice link(https://link.com)~"}))))))
|
||||||
|
|
Loading…
Reference in New Issue