-
Notifications
You must be signed in to change notification settings - Fork 992
/
Copy pathlegacy_view.cljs
240 lines (210 loc) · 7.56 KB
/
legacy_view.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
(ns legacy.status-im.ui.screens.chat.message.legacy-view
(:require
[legacy.status-im.react-native.resources :as resources]
[legacy.status-im.ui.components.colors :as quo.colors]
[legacy.status-im.ui.screens.chat.message.legacy-style :as style]
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.foundations.typography :as typography]
[react-native.core :as rn]
[status-im.constants :as constants]
[status-im.contexts.chat.messenger.messages.delete-message-for-me.events]
[status-im.contexts.chat.messenger.messages.delete-message.events]
[utils.i18n :as i18n]
[utils.re-frame :as rf])
(:require-macros [legacy.status-im.utils.views :refer [defview letsubs]]))
(defn system-text?
[content-type]
(or
(= content-type constants/content-type-system-text)
(= content-type constants/content-type-system-pinned-message)))
(defn mention-element
[from]
(rf/sub [:messages/resolve-mention from]))
(defn render-inline
[_message-text content-type acc {:keys [type literal destination]}
community-id]
(case type
""
(conj acc literal)
"code"
(conj acc [rn/text literal])
"emph"
(conj acc [rn/text (style/emph-style) literal])
"strong"
(conj acc [rn/text (style/strong-style) literal])
"strong-emph"
(conj acc [quo/text (style/strong-emph-style) literal])
"del"
(conj acc [rn/text (style/strikethrough-style) literal])
"link"
(conj acc
[rn/text
{:style {:color (colors/theme-colors colors/primary-50 colors/primary-60)
:text-decoration-line :underline}
:on-press #(rf/dispatch [:browser.ui/message-link-pressed destination])}
destination])
"mention"
(conj
acc
[rn/view
{:style {:background-color colors/primary-50-opa-10 :border-radius 6 :padding-horizontal 3}}
[rn/text
{:style (merge {:color (if (system-text? content-type) quo.colors/black colors/primary-50)}
(if (system-text? content-type) typography/font-regular typography/font-medium))
:on-press (when-not (system-text? content-type)
#(rf/dispatch [:chat.ui/show-profile literal]))}
[mention-element literal]]])
"status-tag"
(conj acc
[rn/text
(when community-id
{:style {:color (colors/theme-colors colors/primary-50 colors/primary-60)
:text-decoration-line :underline}
:on-press #(rf/dispatch [:communities/status-tag-pressed community-id literal])})
"#"
literal])
"edited"
(conj acc [rn/text (style/edited-style) (str " (" (i18n/label :t/edited) ")")])
(conj acc literal)))
;; TEXT
(defn render-block
[{:keys [content content-type edited-at in-popover?]} acc
{:keys [type ^js literal children]}
community-id]
(case type
"paragraph"
(conj acc
(reduce
(fn [acc e]
(render-inline (:text content)
content-type
acc
e
community-id))
[rn/text (style/text-style content-type in-popover?)]
(conj
children
(when edited-at
{:type "edited"}))))
"blockquote"
(conj acc
[rn/view (style/blockquote-style)
[rn/text (style/blockquote-text-style)
(.substring literal 0 (.-length literal))]])
"codeblock"
(conj acc
[rn/view {:style style/codeblock-style}
[rn/text (.substring literal 0 (dec (.-length literal)))]])
acc))
(defn render-parsed-text
[{:keys [content chat-id]
:as message-data}]
(let [community-id (rf/sub [:community-id-by-chat-id chat-id])]
(reduce (fn [acc e]
(render-block message-data
acc
e
community-id))
[:<>]
(:parsed-text content))))
(defmulti ->message :content-type)
(defmethod ->message constants/content-type-gap
[_]
[rn/view])
;; STATUS ? whats that ?
(defmethod ->message constants/content-type-status
[{:keys [content content-type]}]
[rn/view style/status-container
[rn/text {:style (style/status-text)}
(reduce
(fn [acc e] (render-inline (:text content) content-type acc e nil))
[rn/text {:style (style/status-text)}]
(-> content :parsed-text peek :children))]])
(defn contact-request-status-pending
[]
[rn/view {:style {:flex-direction :row}}
[quo/text
{:style {:margin-right 5.27}
:weight :medium
:color :secondary}
(i18n/label :t/contact-request-pending)]
[rn/activity-indicator
{:animating true
:size :small
:color quo.colors/gray}]])
(defn contact-request-status-accepted
[]
[quo/text
{:style {:color quo.colors/green}
:weight :medium}
(i18n/label :t/contact-request-accepted)])
(defn contact-request-status-declined
[]
[quo/text
{:style {:color quo.colors/red}
:weight :medium}
(i18n/label :t/contact-request-declined)])
(defn contact-request-status-label
[state]
[rn/view {:style (style/contact-request-status-label state)}
(condp = state
constants/contact-request-message-state-pending [contact-request-status-pending]
constants/contact-request-message-state-accepted [contact-request-status-accepted]
constants/contact-request-message-state-declined [contact-request-status-declined]
nil)])
;;;; SYSTEM
;; CONTACT REQUEST (like system message ? ) no wrapper
(defn system-contact-request
[message _]
[rn/view {:style (style/content-type-contact-request)}
[rn/image
{:source (resources/get-image :hand-wave)
:style {:width 112
:height 97}}]
[quo/text
{:style {:margin-top 6}
:weight :bold
:size :heading-2}
(i18n/label :t/contact-request)]
[rn/view {:style {:padding-horizontal 16}}
[quo/text
{:style {:margin-top 2
:margin-bottom 14}}
(get-in message [:content :text])]]
[contact-request-status-label (:contact-request-state message)]])
(defview community-content
[{:keys [community-id] :as message}]
(letsubs [{:keys [name description verified] :as community} [:communities/community community-id]]
(when community
[rn/view
{:style (assoc (style/message-wrapper message)
:margin-vertical 10
:margin-left 8
:width 271)}
(when verified
[rn/view (style/community-verified)
[rn/text
{:style {:font-size 13
:color quo.colors/blue}} (i18n/label :t/communities-verified)]])
[rn/view (style/community-message verified)
[rn/view
{:width 62
:padding-left 14}]
[rn/view {:padding-right 14 :flex 1}
[rn/text {:style {:font-weight "700" :font-size 17 :color quo.colors/black}}
name]
[rn/text {:style {:color quo.colors/black}} description]]]
[rn/view (style/community-view-button)
[rn/touchable-opacity
{:on-press #(do
(rf/dispatch [:pop-to-root :shell-stack])
(rf/dispatch [:communities/navigate-to-community-overview (:id community)])
(rf/dispatch [:chat/close]))}
[rn/text
{:style {:text-align :center
:color quo.colors/blue}} (i18n/label :t/view)]]]])))
;; COMMUNITY (like system ? ) no wrapper
(defn community
[message]
[community-content message])