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

View File

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

View File

@ -3,16 +3,16 @@
[re-frame.core :as re-frame]
[status-im.chat.models.loading :as chat.loading]
[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.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.platform :as platform]
[status-im.utils.types :as types]
[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?
[db chat-id message-id]
@ -166,7 +166,9 @@
{:events [::handle-removed-messages]}
[{:keys [db] :as cofx} 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)
(mapv (fn [[chat-id messages]]
(delete-message/delete-messages-localy messages chat-id))))

View File

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

View File

@ -1,16 +1,52 @@
(ns status-im2.contexts.chat.messages.content.deleted.view
(:require [utils.i18n :as i18n]
[quo2.core :as quo]))
(:require [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
[{: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]
:as message}]
(let [pub-key (rf/sub [:multiaccount/public-key])
deleted-by-me? (= (or deleted-by from) pub-key)]
(if (not deleted-by-me?)
[deleted-by-message message]
[quo/system-message
{:type :deleted
:label (if deleted? :message-deleted :message-deleted-for-you)
:labels {:pinned-a-message (i18n/label :t/pinned-a-message)
:message-deleted (i18n/label :t/message-deleted-for-everyone)
:message-deleted-for-you (i18n/label :t/message-deleted-for-you)
:added (i18n/label :t/added)}
:labels {:message-deleted (i18n/label :t/message-deleted-for-everyone)
: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)}])
:animate-landing? (or deleted-undoable-till deleted-for-me-undoable-till)}])))

View File

@ -17,12 +17,13 @@
(defn- update-db-delete-locally
"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])
(update-in db
[:messages chat-id message-id]
assoc
:deleted? true
:deleted-by deleted-by
:deleted-undoable-till (+ (datetime/timestamp) undo-time-limit-ms))))
(defn- update-db-undo-locally
@ -36,25 +37,29 @@
[:messages chat-id message-id]
dissoc
:deleted?
:deleted-by
:deleted-undoable-till)
(update-db-clear-undo-timer db chat-id message-id))))
(defn- update-db-delete-locally-without-time-limit
"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])
(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
"Delete message now locally and broadcast after undo time limit timeout"
{:events [:chat.ui/delete-message]}
[{: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
;; new delete operation will reset prev pending deletes' undo timelimit
;; undo will undo all pending deletes
;; 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))
existing-undos (-> existing-undo-toast
(get :message-deleted-for-everyone-undos [])
@ -64,7 +69,7 @@
{:db (reduce
;; sync all pending deletes' undo timelimit, extend to the latest one
(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
existing-undos)}
chat-id)
@ -154,7 +159,10 @@
[{:keys [db]} messages chat-id]
(let [new-db (->> messages
(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))]
(when new-db
(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>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.126.0",
"commit-sha1": "cefa0089dcf24e2f91ebc133ec4994c1f2e128ce",
"src-sha256": "00zy4k1200da67dg23r0hvl3dfd9b4pfzsv238islp8pqa869sfi"
"version": "v0.126.1",
"commit-sha1": "cb624b0cc14d95e46754210c9153f8a0444d2845",
"src-sha256": "1wrjlzwqj7qzsvh2aba4fjfp29ckx416lkxsk3c7las88ji93wzn"
}

View File

@ -448,6 +448,7 @@
"delete-profile": "Delete 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",
"deleted-this-message": "deleted this message",
"enter-channel": "Enter channel",
"profile-deleted-title": "Profile deleted",
"profile-deleted-content": "Your profile was successfully deleted",