|
| 1 | +(ns status-im2.contexts.chat.bottom-sheet-composer.reply.view |
| 2 | + (:require [clojure.string :as string] |
| 3 | + [react-native.core :as rn] |
| 4 | + [react-native.reanimated :as reanimated] |
| 5 | + [status-im2.contexts.chat.bottom-sheet-composer.constants :as constants] |
| 6 | + [utils.i18n :as i18n] |
| 7 | + [quo2.core :as quo] |
| 8 | + [quo2.foundations.colors :as colors] |
| 9 | + [status-im2.constants :as constant] |
| 10 | + [status-im.ethereum.stateofus :as stateofus] |
| 11 | + [utils.re-frame :as rf] |
| 12 | + [status-im2.contexts.chat.bottom-sheet-composer.reply.style :as style] |
| 13 | + [react-native.linear-gradient :as linear-gradient])) |
| 14 | + |
| 15 | +(defn get-quoted-text-with-mentions |
| 16 | + [parsed-text] |
| 17 | + (string/join |
| 18 | + (mapv (fn [{:keys [type literal children]}] |
| 19 | + (cond |
| 20 | + (= type "paragraph") |
| 21 | + (get-quoted-text-with-mentions children) |
| 22 | + |
| 23 | + (= type "mention") |
| 24 | + (rf/sub [:messages/resolve-mention literal]) |
| 25 | + |
| 26 | + (seq children) |
| 27 | + (get-quoted-text-with-mentions children) |
| 28 | + |
| 29 | + :else |
| 30 | + literal)) |
| 31 | + parsed-text))) |
| 32 | + |
| 33 | +(defn format-author |
| 34 | + [contact-name] |
| 35 | + (let [author (if (or (= (first contact-name) "@") |
| 36 | + ;; in case of replies |
| 37 | + (= (second contact-name) "@")) |
| 38 | + (or (stateofus/username contact-name) |
| 39 | + (subs contact-name 0 81)) |
| 40 | + contact-name)] |
| 41 | + author)) |
| 42 | + |
| 43 | +(defn format-reply-author |
| 44 | + [from username current-public-key] |
| 45 | + (or (and (= from current-public-key) |
| 46 | + (i18n/label :t/You)) |
| 47 | + (when username (format-author username)))) |
| 48 | + |
| 49 | +(defn reply-deleted-message |
| 50 | + [] |
| 51 | + [rn/view |
| 52 | + {:style {:flex-direction :row |
| 53 | + :align-items :center}} |
| 54 | + [quo/icon :i/sad-face {:size 16}] |
| 55 | + [quo/text |
| 56 | + {:number-of-lines 1 |
| 57 | + :size :label |
| 58 | + :weight :regular |
| 59 | + :accessibility-label :quoted-message |
| 60 | + :style style/reply-deleted-message} |
| 61 | + (i18n/label :t/message-deleted)]]) |
| 62 | + |
| 63 | +(defn reply-from |
| 64 | + [{:keys [from contact-name current-public-key]}] |
| 65 | + (let [display-name (first (rf/sub [:contacts/contact-two-names-by-identity from])) |
| 66 | + contact (rf/sub [:contacts/contact-by-address from]) |
| 67 | + photo-path (when-not (empty? (:images contact)) (rf/sub [:chats/photo-path from]))] |
| 68 | + [rn/view {:style style/reply-from} |
| 69 | + [quo/user-avatar |
| 70 | + {:full-name display-name |
| 71 | + :profile-picture photo-path |
| 72 | + :status-indicator? false |
| 73 | + :size :xxxs}] |
| 74 | + [quo/text |
| 75 | + {:weight :semi-bold |
| 76 | + :size :paragraph-2 |
| 77 | + :number-of-lines 1 |
| 78 | + :style style/message-author-text} |
| 79 | + (format-reply-author from contact-name current-public-key)]])) |
| 80 | + |
| 81 | +(defn reply-message |
| 82 | + [{:keys [from identicon content-type contentType parsed-text content deleted? deleted-for-me? |
| 83 | + album-images-count]} |
| 84 | + in-chat-input? pin? recording-audio?] |
| 85 | + (let [contact-name (rf/sub [:contacts/contact-name-by-identity from]) |
| 86 | + current-public-key (rf/sub [:multiaccount/public-key]) |
| 87 | + content-type (or content-type contentType)] |
| 88 | + [rn/view |
| 89 | + {:style {:flex-direction :row |
| 90 | + :height (when-not pin? 24) |
| 91 | + :accessibility-label :reply-message}} |
| 92 | + [rn/view {:style (style/reply-content pin?)} |
| 93 | + (when-not pin? |
| 94 | + [quo/icon :i/connector |
| 95 | + {:size 16 |
| 96 | + :color (colors/theme-colors colors/neutral-40 colors/neutral-60) |
| 97 | + :container-style {:position :absolute :left 0 :bottom -4 :width 16 :height 16}}]) |
| 98 | + (if (or deleted? deleted-for-me?) |
| 99 | + [rn/view {:style (style/quoted-message pin?)} |
| 100 | + [reply-deleted-message]] |
| 101 | + [rn/view {:style (style/quoted-message pin?)} |
| 102 | + [reply-from |
| 103 | + {:from from |
| 104 | + :identicon identicon |
| 105 | + :contact-name contact-name |
| 106 | + :current-public-key current-public-key}] |
| 107 | + [quo/text |
| 108 | + {:number-of-lines 1 |
| 109 | + :size :label |
| 110 | + :weight :regular |
| 111 | + :accessibility-label :quoted-message |
| 112 | + :ellipsize-mode :tail |
| 113 | + :style (merge |
| 114 | + style/message-text |
| 115 | + (when (or (= constant/content-type-image content-type) |
| 116 | + (= constant/content-type-sticker content-type) |
| 117 | + (= constant/content-type-audio content-type)) |
| 118 | + {:color (colors/theme-colors colors/neutral-50 colors/neutral-40)}))} |
| 119 | + (case (or content-type contentType) |
| 120 | + constant/content-type-image (if album-images-count |
| 121 | + (i18n/label :t/images-albums-count |
| 122 | + {:album-images-count album-images-count}) |
| 123 | + (i18n/label :t/image)) |
| 124 | + constant/content-type-sticker (i18n/label :t/sticker) |
| 125 | + constant/content-type-audio (i18n/label :t/audio) |
| 126 | + (get-quoted-text-with-mentions (or parsed-text (:parsed-text content))))]])] |
| 127 | + (when (and in-chat-input? (not recording-audio?)) |
| 128 | + [quo/button |
| 129 | + {:icon true |
| 130 | + :type :outline |
| 131 | + :size 24 |
| 132 | + :on-press #(rf/dispatch [:chat.ui/cancel-message-reply])} |
| 133 | + :i/close]) |
| 134 | + (when (and in-chat-input? recording-audio?) |
| 135 | + [linear-gradient/linear-gradient |
| 136 | + {:colors [(colors/theme-colors colors/white-opa-0 colors/neutral-90-opa-0) |
| 137 | + (colors/theme-colors colors/white colors/neutral-90)] |
| 138 | + :start {:x 0 :y 0} |
| 139 | + :end {:x 0.7 :y 0} |
| 140 | + :style style/gradient}])])) |
| 141 | + |
| 142 | +(defn- f-view |
| 143 | + [] |
| 144 | + (let [reply (rf/sub [:chats/reply-message]) |
| 145 | + height (reanimated/use-shared-value (if reply constants/reply-container-height 0))] |
| 146 | + (rn/use-effect #(reanimated/animate height (if reply constants/reply-container-height 0)) [reply]) |
| 147 | + [reanimated/view {:style (reanimated/apply-animations-to-style {:height height} {})} |
| 148 | + (when reply [reply-message reply true false false])])) |
| 149 | + |
| 150 | +(defn view |
| 151 | + [] |
| 152 | + [:f> f-view]) |
0 commit comments