Skip to content

Commit

Permalink
Show parsed bridge messages (#20058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parveshdhull committed May 27, 2024
1 parent bcd8f3a commit 366fb7b
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 75 deletions.
3 changes: 2 additions & 1 deletion src/legacy/status_im/data_store/messages.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
:deleted :deleted?
:deletedForMe :deleted-for-me?
:communityId :community-id
:albumImagesCount :album-images-count})
:albumImagesCount :album-images-count
:bridgeMessage :bridge-message})
(update :outgoing-status keyword)
(update :command-parameters
set/rename-keys
Expand Down
30 changes: 22 additions & 8 deletions src/status_im/contexts/chat/messenger/composer/reply/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,25 @@
:style style/reply-deleted-message}
(i18n/label :t/message-deleted)]])

(defn- bridge-message-user-name
[user-name]
(when (string? user-name)
(-> user-name
(string/replace "<b>" "")
(string/replace "</b>" ""))))

(defn reply-from
[{:keys [from contact-name current-public-key pin?]}]
(let [[primary-name _] (rf/sub [:contacts/contact-two-names-by-identity from])
photo-path (rf/sub [:chats/photo-path from])]
[{:keys [from contact-name current-public-key pin? bridge-message]}]
(let [{user-name :userName user-avatar :userAvatar} bridge-message
[primary-name _] (rf/sub [:contacts/contact-two-names-by-identity
from])
photo-path (rf/sub [:chats/photo-path from])]
[rn/view {:style style/reply-from}
[quo/user-avatar
{:full-name primary-name
:profile-picture photo-path
{:full-name (if bridge-message
(bridge-message-user-name user-name)
primary-name)
:profile-picture (or user-avatar photo-path)
:status-indicator? false
:size :xxxs
:ring? false}]
Expand All @@ -82,11 +93,13 @@
:size (if pin? :label :paragraph-2)
:number-of-lines 1
:style style/message-author-text}
(format-reply-author from contact-name current-public-key)]]))
(if bridge-message
user-name
(format-reply-author from contact-name current-public-key))]]))

(defn quoted-message
[{:keys [from content-type contentType parsed-text content deleted? deleted-for-me?
album-images-count]}
album-images-count bridge-message]}
in-chat-input? pin? recording-audio? input-ref]
(let [[primary-name _] (rf/sub [:contacts/contact-two-names-by-identity from])
current-public-key (rf/sub [:multiaccount/public-key])
Expand All @@ -110,7 +123,8 @@
{:pin? pin?
:from from
:contact-name primary-name
:current-public-key current-public-key}]
:current-public-key current-public-key
:bridge-message bridge-message}]
(when (not-empty text)
[quo/text
{:number-of-lines 1
Expand Down
124 changes: 68 additions & 56 deletions src/status_im/contexts/chat/messenger/messages/content/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,54 @@
[status-im.contexts.chat.messenger.messages.drawers.view :as drawers]
[utils.address :as address]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(def delivery-state-showing-time-ms 3000)

(defn- bridge-message-user-name
[user-name]
(when (string? user-name)
(-> user-name
(string/replace "<b>" "")
(string/replace "</b>" ""))))

(defn avatar-container
[{:keys [content last-in-group? pinned-by quoted-message from]} hide-reactions?
in-reaction-or-action-menu? show-user-info? in-pinned-view?]
(if (or (and (seq (:response-to content))
quoted-message)
last-in-group?
show-user-info?
pinned-by
hide-reactions?
in-reaction-or-action-menu?)
[{:keys [content last-in-group? pinned-by quoted-message from bridge-message]}
hide-reactions? in-reaction-or-action-menu? show-user-info? in-pinned-view?]
(cond
(:user-avatar bridge-message)
[fast-image/fast-image
{:source {:uri (:user-avatar bridge-message)}
:fallback-content [quo/user-avatar
{:full-name (bridge-message-user-name (:user-name bridge-message))
:ring? false
:online? false
:status-indicator? false
:size :small}]
:style {:width 32
:margin-top 4
:border-radius 16
:height 32}}]

(or (and (seq (:response-to content))
quoted-message)
last-in-group?
show-user-info?
pinned-by
hide-reactions?
in-reaction-or-action-menu?)
[avatar/avatar
{:public-key from
:size :small
:hide-ring? (or in-pinned-view? in-reaction-or-action-menu?)}]

:else
[rn/view {:padding-top 4 :width 32}]))

(defn author
[{:keys [content
[{:keys [bridge-message
content
compressed-key
last-in-group?
pinned-by
Expand All @@ -62,20 +88,27 @@
in-reaction-or-action-menu?
show-user-info?]
(when (or (and (seq (:response-to content)) quoted-message)
(seq bridge-message)
last-in-group?
pinned-by
show-user-info?
hide-reactions?
in-reaction-or-action-menu?)
(let [[primary-name secondary-name] (rf/sub [:contacts/contact-two-names-by-identity from])
{:keys [ens-verified added?]} (rf/sub [:contacts/contact-by-address from])]
(let [{:keys [user-name bridge-name]} bridge-message
[primary-name secondary-name] (when-not bridge-message
(rf/sub [:contacts/contact-two-names-by-identity from]))
{:keys [ens-verified added?]} (when-not bridge-message
(rf/sub [:contacts/contact-by-address from]))
user-name (bridge-message-user-name user-name)]
[quo/author
{:primary-name primary-name
{:primary-name (or user-name primary-name)
:secondary-name secondary-name
:short-chat-key (address/get-shortened-compressed-key (or compressed-key from))
:short-chat-key (if bridge-message
(i18n/label :t/bridge-from {:bridge-name bridge-name})
(address/get-shortened-compressed-key (or compressed-key from)))
:time-str (datetime/timestamp->time timestamp)
:contact? added?
:verified? ens-verified}])))
:contact? (when-not bridge-message added?)
:verified? (when-not bridge-message ens-verified)}])))

(defn system-message-contact-request
[{:keys [chat-id timestamp-str from]} type]
Expand Down Expand Up @@ -118,50 +151,23 @@
constants/content-type-system-message-mutual-event-sent
[system-message-contact-request message-data :contact-request])))

(defn bridge-message-content
[{:keys [bridge-message timestamp]}]
(let [{:keys [user-avatar user-name
bridge-name content]} bridge-message
user-name (when (string? user-name)
(-> user-name
(string/replace "<b>" "")
(string/replace "</b>" "")))]
(when (and user-name content)
[rn/view
{:style {:flex-direction :row
:padding-horizontal 12
:padding-top 4}}
[fast-image/fast-image
{:source {:uri user-avatar}
:fallback-content [quo/user-avatar
{:full-name user-name
:ring? false
:online? false
:status-indicator? false
:size :small}]
:style {:width 32
:margin-top 4
:border-radius 16
:height 32}}]
[rn/view {:margin-left 8 :flex 1}
[quo/author
{:primary-name (str user-name)
:short-chat-key (str "Bridged from " bridge-name)
:time-str (datetime/timestamp->time timestamp)}]
[quo/text
{:size :paragraph-1
:style {:line-height 22.75}}
content]]])))

(declare on-long-press)

(defn- bridge-message-content
[content]
[quo/text
{:size :paragraph-1
:style {:line-height 22.75}}
content])

(defn user-message-content
[]
(let [show-delivery-state? (reagent/atom false)]
(fn [{:keys [message-data context keyboard-shown? hide-reactions?
in-reaction-or-action-menu? show-user-info?]}]
(let [theme (quo.theme/use-theme)
{:keys [content-type quoted-message content outgoing outgoing-status pinned-by pinned
bridge-message
last-in-group? message-id chat-id]} message-data
{:keys [disable-message-long-press?]} context
first-image (first (:album message-data))
Expand Down Expand Up @@ -191,7 +197,13 @@
chat-id])
six-reactions? (-> reactions
count
(= 6))]
(= 6))
content-type (if (and
(= content-type
constants/content-type-bridge-message)
(seq (:parsed-text content)))
constants/content-type-text
content-type)]
[rn/touchable-highlight
{:accessibility-label (if (and outgoing (= outgoing-status :sending))
:message-sending
Expand Down Expand Up @@ -237,9 +249,13 @@
:max-height (when hide-reactions? (* 0.4 height))}}
[author message-data hide-reactions? in-reaction-or-action-menu? show-user-info?]
(condp = content-type

constants/content-type-text
[content.text/text-content message-data context]

constants/content-type-bridge-message
[bridge-message-content (:content bridge-message)]

constants/content-type-contact-request
[content.text/text-content message-data context]

Expand Down Expand Up @@ -340,10 +356,6 @@
keyboard-shown?))
context]


(= content-type constants/content-type-bridge-message)
[bridge-message-content message-data]

:else
[user-message-content
{:message-data message-data
Expand Down
16 changes: 9 additions & 7 deletions src/status_im/contexts/chat/messenger/messages/drawers/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
(assoc message-data :pinned message-not-pinned?)]))))

(defn get-actions
[{:keys [outgoing content pinned-by outgoing-status deleted? deleted-for-me? content-type]
[{:keys [outgoing content pinned-by outgoing-status deleted? deleted-for-me? content-type
bridge-message]
:as message-data}
{:keys [able-to-send-message? community? can-delete-message-for-everyone?
message-pin-enabled group-chat group-admin?]}]
Expand Down Expand Up @@ -139,7 +140,7 @@
:accessibility-label (if pinned-by :unpin-message :pin-message)
:icon :i/pin
:id (if pinned-by :unpin :pin)}])
(when-not (or deleted? deleted-for-me?)
(when-not (or deleted? deleted-for-me? bridge-message)
[{:type :danger
:on-press (fn []
(rf/dispatch
Expand All @@ -152,11 +153,12 @@
:icon :i/delete
:id :delete-for-me}])
(when (cond
deleted? false
outgoing true
community? can-delete-message-for-everyone?
group-chat group-admin?
:else false)
deleted? false
outgoing true
community? can-delete-message-for-everyone?
group-chat group-admin?
bridge-message false
:else false)
[{:type :danger
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet])
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.179.20",
"commit-sha1": "92ef58d4202d151d44015c37d6c1ea45d8a8d8b3",
"src-sha256": "05vqn5zy7fd4abq4d0r5191w2f3dzv9j5s6gmvqsis2r1y4njj7p"
"version": "v0.179.22",
"commit-sha1": "2b1bcb48c60bb40da1f1e3e9249a53dd57434b82",
"src-sha256": "1fn6gwayb5ir1ym196qh774l315hccg6gkvhav3zlkdcvwfqny6i"
}
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,7 @@
"empty-tab-description": "C'mon do something...",
"buy": "Buy",
"bridge": "Bridge",
"bridge-from": "Bridge from {{bridge-name}}",
"bridge-to": "Bridge {{name}} to",
"on-device": "On device",
"on-keycard": "On Keycard",
Expand Down

0 comments on commit 366fb7b

Please sign in to comment.