feat: edit/delete/reply for emoji/sticker/audio (#13808)

* feat: edit/delete/reply, fixed unnecessary changes
This commit is contained in:
Omar Basem 2022-10-18 17:20:27 +04:00 committed by GitHub
parent c6ac899b44
commit 3aaa7e4c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 66 deletions

View File

@ -252,11 +252,15 @@
:pack (int (if (string/blank? packID) pack packID))}
:text (i18n/label :t/update-to-see-sticker {"locale" "en"})})))
(fx/defn send-edited-message [{:keys [db] :as cofx} text {:keys [message-id]}]
(fx/defn send-edited-message [{:keys [db] :as cofx} text {:keys [message-id quoted-message]}]
(fx/merge
cofx
{::json-rpc/call [{:method "wakuext_editMessage"
:params [{:id message-id :text text}]
:params [{:id message-id
:text text
:content-type (if (message-content/emoji-only-content? {:text text :response-to quoted-message})
constants/content-type-emoji
constants/content-type-text)}]
:js-response true
:on-error #(log/error "failed to edit message " %)
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]}

View File

@ -86,9 +86,10 @@
:accessibility-label :message-timestamp}
timestamp-str]])))
(defview quoted-message
[_ {:keys [from parsed-text image]} outgoing current-public-key public? pinned]
(letsubs [contact-name [:contacts/contact-name-by-identity from]]
(defn quoted-message
[_ {:keys [from parsed-text image audio sticker id] :as message} outgoing current-public-key public? pinned chat-id]
(let [contact-name [:contacts/contact-name-by-identity from]
replied-message (get @(re-frame/subscribe [:chats/chat-messages chat-id]) id)] ;; the message replied to
[react/view {:style (style/quoted-message-container (and outgoing (not pinned)))}
[react/view {:style style/quoted-message-author-container}
[chat.utils/format-reply-author
@ -97,15 +98,29 @@
current-public-key
(partial style/quoted-message-author (and outgoing (not pinned)))
(and outgoing (not pinned))]]
(if (and image
;; Disabling images for public-chats
(not public?))
(cond
(and image (not public?)) ;; Disabling images for public-chats
[fast-image/fast-image {:style {:width 56
:height 56
:background-color :black
:border-radius 4}
:source {:uri image}}]
[react/text {:style (style/quoted-message-text (and outgoing (not pinned)))
(and audio (not public?)) ;; Disabling audio for public-chats
[react/view {:style (style/message-view message) :accessibility-label :audio-message}
[react/view {:style (style/message-view-content)}
[react/view {:style (style/style-message-text outgoing)}
[message.audio/message-content message]
[message-status message]]]]
sticker
(if replied-message
[fast-image/fast-image {:style {:margin 4 :width 56 :height 56}
;; Get sticker url of the message replied to
:source {:uri (((replied-message :content) :sticker) :url)}}]
;; Let the user know if the message was deleted
[react/text {:style (style/quoted-message-text (and outgoing (not pinned)))}
;; This hardcorded text can be modified to come from the parsed-text. Also, translations can be added.
"This message was deleted!"])
:else [react/text {:style (style/quoted-message-text (and outgoing (not pinned)))
:number-of-lines 5}
(components.reply/get-quoted-text-with-mentions parsed-text)])]))
@ -447,7 +462,7 @@
(let [collapsed? (reagent/atom false)
collapsible? (reagent/atom false)
show-timestamp? (reagent/atom false)]
(fn [{:keys [content outgoing current-public-key public? pinned in-popover?] :as message} on-long-press modal]
(fn [{:keys [content outgoing current-public-key public? pinned in-popover? chat-id] :as message} on-long-press modal]
(let [max-height (when-not (or outgoing modal)
(if @collapsible?
(if @collapsed? message-height-px nil)
@ -478,7 +493,7 @@
(reset! collapsed? true)
(reset! collapsible? true))}
(when (and (seq response-to) (:quoted-message message))
[quoted-message response-to (:quoted-message message) outgoing current-public-key public? pinned])
[quoted-message response-to (:quoted-message message) outgoing current-public-key public? pinned chat-id])
[render-parsed-text-with-message-status message (:parsed-text content)]])
(when-not @collapsible? [message-status message])
(when (and @collapsible? (not modal))
@ -522,10 +537,15 @@
(defmethod ->message constants/content-type-emoji []
(let [show-timestamp? (reagent/atom false)]
(fn [{:keys [content current-public-key outgoing public? pinned in-popover? message-pin-enabled] :as message}
(fn [{:keys [content current-public-key outgoing edit-enabled public? pinned in-popover? message-pin-enabled content-type edited-at] :as message}
{:keys [on-long-press modal]
:as reaction-picker}]
;; Makes sure to render a text-messsage and not an emoji-message if it has been edited with text
(if (= content-type constants/content-type-text)
[message-content-wrapper message
[collapsible-text-message message on-long-press modal] reaction-picker]
(let [response-to (:response-to content)]
(println "outgoing" outgoing edit-enabled)
[message-content-wrapper message
[react/touchable-highlight (when-not modal
{:disabled in-popover?
@ -536,6 +556,10 @@
:on-long-press (fn []
(on-long-press
(concat
(when (and outgoing edit-enabled)
[{:on-press #(re-frame/dispatch [:chat.ui/edit-message message])
:label (i18n/label :t/edit)
:id :edit}])
[{:on-press #(re-frame/dispatch [:chat.ui/reply-to-message message])
:id :reply
:label (i18n/label :t/message-reply)}
@ -543,7 +567,11 @@
:id :copy
:label (i18n/label :t/sharing-copy-to-clipboard)}]
(when message-pin-enabled [{:on-press #(pin-message message)
:label (if pinned (i18n/label :t/unpin) (i18n/label :t/pin))}]))))})
:label (if pinned (i18n/label :t/unpin) (i18n/label :t/pin))}])
(when (and outgoing config/delete-message-enabled?)
[{:on-press #(re-frame/dispatch [:chat.ui/soft-delete-message message])
:label (i18n/label :t/delete)
:id :delete}]))))})
[react/view (style/message-view-wrapper outgoing)
[message-timestamp message show-timestamp?]
[react/view (style/message-view message)
@ -552,9 +580,9 @@
(when (and (seq response-to) (:quoted-message message))
[quoted-message response-to (:quoted-message message) outgoing current-public-key public? pinned])
[react/text {:style (style/emoji-message message)}
(:text content)]]
(if edited-at (str (content :text) " ") (str (content :text)))]]
[message-status message]]]]]
reaction-picker]))))
reaction-picker])))))
(defmethod ->message constants/content-type-sticker
[{:keys [content from outgoing in-popover?]
@ -573,10 +601,19 @@
:delay-long-press 100
:on-long-press (fn []
(on-long-press
(concat
(when-not outgoing
[{:on-press #(when pack
(re-frame/dispatch [:chat.ui/show-profile from]))
:label (i18n/label :t/view-details)}])))})
:label (i18n/label :t/view-details)}])
[{:on-press #(re-frame/dispatch [:chat.ui/reply-to-message message])
:id :reply
:label (i18n/label :t/message-reply)}]
(if (and outgoing config/delete-message-enabled?)
[{:on-press #(re-frame/dispatch [:chat.ui/soft-delete-message message])
:label (i18n/label :t/delete)
:id :delete}]
[]))))})
[fast-image/fast-image {:style {:margin 10 :width 140 :height 140}
:source {:uri (str (-> content :sticker :url) "&download=true")}}]]
reaction-picker]))
@ -617,10 +654,16 @@
[react/touchable-highlight
(when-not modal
{:on-long-press
(fn [] (on-long-press (if (and outgoing config/delete-message-enabled?)
(fn []
(on-long-press
(concat
[{:on-press #(re-frame/dispatch [:chat.ui/reply-to-message message])
:id :reply
:label (i18n/label :t/message-reply)}]
(when (and outgoing config/delete-message-enabled?)
[{:on-press #(re-frame/dispatch [:chat.ui/soft-delete-message message])
:label (i18n/label :t/delete)
:id :delete}]
:id :delete}])
[])))
:on-press (fn []
(reset! show-timestamp? true))})

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "f47cb8572de921fb4cff5d0f8d87b7b92386a226",
"commit-sha1": "f47cb8572de921fb4cff5d0f8d87b7b92386a226",
"src-sha256": "0wbiwq6dh531crqsij836bdkggn8f1z9f121aqpyxwdgp1njzxjk"
"version": "938e7987ca4f7d4e5fadcd7f32306bfc3e1f6736",
"commit-sha1": "938e7987ca4f7d4e5fadcd7f32306bfc3e1f6736",
"src-sha256": "0h3gp4lf3ak0z7cqp088s8n6y1jf7xbjya2xc4xb4rv1i6ijz00d"
}