feat: support deleted by xxx (#14768)

This commit is contained in:
yqrashawn 2023-02-01 09:17:57 +08:00 committed by GitHub
parent 1f84128dd7
commit a38ef22ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 86 additions and 37 deletions

View File

@ -64,7 +64,7 @@
(defmulti sm-render :type) (defmulti sm-render :type)
(defmethod sm-render :deleted (defmethod sm-render :deleted
[{:keys [label timestamp-str labels]}] [{:keys [label timestamp-str labels child]}]
[rn/view [rn/view
{:align-items :center {:align-items :center
:justify-content :space-between :justify-content :space-between
@ -77,11 +77,13 @@
{:icon :main-icons/delete {:icon :main-icons/delete
:color :danger :color :danger
:opacity 5}] :opacity 5}]
[text/text (if child
{:size :paragraph-2 child
:style {:color (get-color :text) [text/text
:margin-right 5}} {:size :paragraph-2
(or (get labels label) label (:message-deleted labels))] :style {:color (get-color :text)
:margin-right 5}}
(or (get labels label) label (:message-deleted labels))])
[sm-timestamp timestamp-str]]]) [sm-timestamp timestamp-str]]])
(defmethod sm-render :added (defmethod sm-render :added
@ -185,9 +187,7 @@
1000)) 1000))
[reanimated/touchable-opacity [reanimated/touchable-opacity
{:on-press #(when-not non-pressable? {:on-press #(when-not non-pressable?
(reanimated/set-shared-value (reanimated/set-shared-value sv-color (get-color :bg :pressed type)))
sv-color
(get-color :bg :pressed type)))
:style (reanimated/apply-animations-to-style :style (reanimated/apply-animations-to-style
{:background-color sv-color} {:background-color sv-color}
(merge (merge

View File

@ -88,6 +88,7 @@
(def filter quo2.components.selectors.filter.view/view) (def filter quo2.components.selectors.filter.view/view)
(def skeleton quo2.components.loaders.skeleton/skeleton) (def skeleton quo2.components.loaders.skeleton/skeleton)
(def author quo2.components.messages.author.view/author) (def author quo2.components.messages.author.view/author)
(def display-name quo2.components.messages.author.view/display-name)
;;;; AVATAR ;;;; AVATAR
(def account-avatar quo2.components.avatars.account-avatar/account-avatar) (def account-avatar quo2.components.avatars.account-avatar/account-avatar)

View File

@ -3,16 +3,16 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.chat.models.loading :as chat.loading] [status-im.chat.models.loading :as chat.loading]
[status-im.chat.models.mentions :as mentions] [status-im.chat.models.mentions :as mentions]
[status-im2.contexts.chat.messages.list.events :as message-list]
[status-im.data-store.messages :as data-store.messages] [status-im.data-store.messages :as data-store.messages]
[status-im.transport.message.protocol :as protocol] [status-im.transport.message.protocol :as protocol]
[status-im2.contexts.chat.messages.list.state :as view.state]
[utils.re-frame :as rf]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im2.contexts.chat.messages.delete-message.events :as delete-message] [status-im2.contexts.chat.messages.delete-message.events :as delete-message]
[taoensso.timbre :as log])) [status-im2.contexts.chat.messages.list.events :as message-list]
[status-im2.contexts.chat.messages.list.state :as view.state]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
(defn- message-loaded? (defn- message-loaded?
[db chat-id message-id] [db chat-id message-id]
@ -166,7 +166,9 @@
{:events [::handle-removed-messages]} {:events [::handle-removed-messages]}
[{:keys [db] :as cofx} removed-messages] [{:keys [db] :as cofx} removed-messages]
(let [mark-as-deleted-fx (->> removed-messages (let [mark-as-deleted-fx (->> removed-messages
(map #(assoc % :message-id (:messageId %))) (map #(assoc %
:message-id (:messageId %)
:deleted-by (:deletedBy %)))
(group-by :chatId) (group-by :chatId)
(mapv (fn [[chat-id messages]] (mapv (fn [[chat-id messages]]
(delete-message/delete-messages-localy messages chat-id)))) (delete-message/delete-messages-localy messages chat-id))))

View File

@ -36,6 +36,7 @@
:audioDurationMs :audio-duration-ms :audioDurationMs :audio-duration-ms
:deleted :deleted? :deleted :deleted?
:deletedForMe :deleted-for-me? :deletedForMe :deleted-for-me?
:deletedBy :deleted-by
:albumId :album-id :albumId :album-id
:imageWidth :image-width :imageWidth :image-width
:imageHeight :image-height :imageHeight :image-height

View File

@ -1,16 +1,52 @@
(ns status-im2.contexts.chat.messages.content.deleted.view (ns status-im2.contexts.chat.messages.content.deleted.view
(:require [utils.i18n :as i18n] (:require [quo2.core :as quo]
[quo2.core :as quo])) [react-native.core :as rn]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn user-xxx-deleted-this-message
[{:keys [display-name profile-picture]}]
[rn/view {:style {:flex-direction :row :align-items :center}}
[rn/view {:style {:margin-right 4}}
[quo/user-avatar
{:full-name display-name
:profile-picture profile-picture
:status-indicator? false
:ring? false
:size :xxxs}]]
[quo/display-name
{:profile-name display-name
:text-style {}}]
[quo/text {:style {:margin-left 4} :size :paragraph-2}
(i18n/label :t/deleted-this-message)]])
(defn deleted-by-message
[{:keys [deleted-by deleted-undoable-till timestamp-str deleted-for-me-undoable-till from]}]
(let [;; deleted message with nil deleted-by is deleted by (:from message)
display-name (first (rf/sub [:contacts/contact-two-names-by-identity (or deleted-by from)]))
contact (rf/sub [:contacts/contact-by-address (or deleted-by from)])
photo-path (when-not (empty? (:images contact))
(rf/sub [:chats/photo-path (or deleted-by from)]))]
[quo/system-message
{:type :deleted
:timestamp-str timestamp-str
:child [user-xxx-deleted-this-message
{:display-name display-name :profile-picture photo-path}]
:non-pressable? true
:animate-landing? (or deleted-undoable-till deleted-for-me-undoable-till)}]))
(defn deleted-message (defn deleted-message
[{:keys [deleted? deleted-undoable-till timestamp-str deleted-for-me-undoable-till]}] [{:keys [deleted? deleted-by deleted-undoable-till timestamp-str deleted-for-me-undoable-till from]
[quo/system-message :as message}]
{:type :deleted (let [pub-key (rf/sub [:multiaccount/public-key])
:label (if deleted? :message-deleted :message-deleted-for-you) deleted-by-me? (= (or deleted-by from) pub-key)]
:labels {:pinned-a-message (i18n/label :t/pinned-a-message) (if (not deleted-by-me?)
:message-deleted (i18n/label :t/message-deleted-for-everyone) [deleted-by-message message]
:message-deleted-for-you (i18n/label :t/message-deleted-for-you) [quo/system-message
:added (i18n/label :t/added)} {:type :deleted
:timestamp-str timestamp-str :label (if deleted? :message-deleted :message-deleted-for-you)
:non-pressable? true :labels {:message-deleted (i18n/label :t/message-deleted-for-everyone)
:animate-landing? (or deleted-undoable-till deleted-for-me-undoable-till)}]) :message-deleted-for-you (i18n/label :t/message-deleted-for-you)}
:timestamp-str timestamp-str
:non-pressable? true
:animate-landing? (or deleted-undoable-till deleted-for-me-undoable-till)}])))

View File

@ -17,12 +17,13 @@
(defn- update-db-delete-locally (defn- update-db-delete-locally
"Delete message in re-frame db and set the undo timelimit" "Delete message in re-frame db and set the undo timelimit"
[db chat-id message-id undo-time-limit-ms] [db chat-id message-id undo-time-limit-ms deleted-by]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
(update-in db (update-in db
[:messages chat-id message-id] [:messages chat-id message-id]
assoc assoc
:deleted? true :deleted? true
:deleted-by deleted-by
:deleted-undoable-till (+ (datetime/timestamp) undo-time-limit-ms)))) :deleted-undoable-till (+ (datetime/timestamp) undo-time-limit-ms))))
(defn- update-db-undo-locally (defn- update-db-undo-locally
@ -36,25 +37,29 @@
[:messages chat-id message-id] [:messages chat-id message-id]
dissoc dissoc
:deleted? :deleted?
:deleted-by
:deleted-undoable-till) :deleted-undoable-till)
(update-db-clear-undo-timer db chat-id message-id)))) (update-db-clear-undo-timer db chat-id message-id))))
(defn- update-db-delete-locally-without-time-limit (defn- update-db-delete-locally-without-time-limit
"Delete message in re-frame db, used to handle received removed-messages" "Delete message in re-frame db, used to handle received removed-messages"
[db chat-id message-id] [db chat-id message-id deleted-by]
(when (get-in db [:messages chat-id message-id]) (when (get-in db [:messages chat-id message-id])
(update-in db [:messages chat-id message-id] assoc :deleted? true))) (update-in db [:messages chat-id message-id] assoc :deleted? true :deleted-by deleted-by)))
(rf/defn delete (rf/defn delete
"Delete message now locally and broadcast after undo time limit timeout" "Delete message now locally and broadcast after undo time limit timeout"
{:events [:chat.ui/delete-message]} {:events [:chat.ui/delete-message]}
[{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms] [{:keys [db]} {:keys [chat-id message-id]} undo-time-limit-ms]
(when (get-in db [:messages chat-id message-id]) (when-let [message (get-in db [:messages chat-id message-id])]
;; all delete message toast are the same toast with id :delete-message-for-everyone ;; all delete message toast are the same toast with id :delete-message-for-everyone
;; new delete operation will reset prev pending deletes' undo timelimit ;; new delete operation will reset prev pending deletes' undo timelimit
;; undo will undo all pending deletes ;; undo will undo all pending deletes
;; all pending deletes are stored in toast ;; all pending deletes are stored in toast
(let [existing-undo-toast (get-in db [:toasts :toasts :delete-message-for-everyone]) (let [pub-key (get-in db [:multiaccount :public-key])
message-from (get message :from)
deleted-by (when (not= pub-key message-from) pub-key)
existing-undo-toast (get-in db [:toasts :toasts :delete-message-for-everyone])
toast-count (inc (get existing-undo-toast :message-deleted-for-everyone-count 0)) toast-count (inc (get existing-undo-toast :message-deleted-for-everyone-count 0))
existing-undos (-> existing-undo-toast existing-undos (-> existing-undo-toast
(get :message-deleted-for-everyone-undos []) (get :message-deleted-for-everyone-undos [])
@ -64,7 +69,7 @@
{:db (reduce {:db (reduce
;; sync all pending deletes' undo timelimit, extend to the latest one ;; sync all pending deletes' undo timelimit, extend to the latest one
(fn [db-acc {:keys [chat-id message-id]}] (fn [db-acc {:keys [chat-id message-id]}]
(update-db-delete-locally db-acc chat-id message-id undo-time-limit-ms)) (update-db-delete-locally db-acc chat-id message-id undo-time-limit-ms deleted-by))
db db
existing-undos)} existing-undos)}
chat-id) chat-id)
@ -154,7 +159,10 @@
[{:keys [db]} messages chat-id] [{:keys [db]} messages chat-id]
(let [new-db (->> messages (let [new-db (->> messages
(filter #(get-in db [:messages chat-id (:message-id %)])) (filter #(get-in db [:messages chat-id (:message-id %)]))
(reduce #(update-db-delete-locally-without-time-limit %1 chat-id (:message-id %2)) (reduce #(update-db-delete-locally-without-time-limit %1
chat-id
(:message-id %2)
(:deleted-by %2))
db))] db))]
(when new-db (when new-db
(message-list/rebuild-message-list {:db new-db} chat-id)))) (message-list/rebuild-message-list {:db new-db} chat-id))))

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.126.0", "version": "v0.126.1",
"commit-sha1": "cefa0089dcf24e2f91ebc133ec4994c1f2e128ce", "commit-sha1": "cb624b0cc14d95e46754210c9153f8a0444d2845",
"src-sha256": "00zy4k1200da67dg23r0hvl3dfd9b4pfzsv238islp8pqa869sfi" "src-sha256": "1wrjlzwqj7qzsvh2aba4fjfp29ckx416lkxsk3c7las88ji93wzn"
} }

View File

@ -448,6 +448,7 @@
"delete-profile": "Delete profile", "delete-profile": "Delete profile",
"delete-my-profile": "Delete my profile", "delete-my-profile": "Delete my profile",
"delete-profile-warning": "Warning: If you dont have your seed phrase written down, you will lose access to your funds after you delete your profile", "delete-profile-warning": "Warning: If you dont have your seed phrase written down, you will lose access to your funds after you delete your profile",
"deleted-this-message": "deleted this message",
"enter-channel": "Enter channel", "enter-channel": "Enter channel",
"profile-deleted-title": "Profile deleted", "profile-deleted-title": "Profile deleted",
"profile-deleted-content": "Your profile was successfully deleted", "profile-deleted-content": "Your profile was successfully deleted",