Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/quo/components/text_combinations/username/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
:color (colors/resolve-color color theme)}]))

(defn status-icon
[{:keys [theme name-type status]
[{:keys [name-type status]
:or {name-type :default}}]
[rn/view {:style (style/status-icon-container name-type status)}
(case status
:verified [icon-20 :i/verified theme :success]
:contact [icon-20 :i/contact theme :blue]
:untrustworthy [icon-20 :i/untrustworthy theme :danger]
:blocked [icon-20 :i/block theme :danger]
:verified [icon-20 :i/verified :success]
:contact [icon-20 :i/contact :blue]
:untrustworthy [icon-20 :i/untrustworthy :danger]
:blocked [icon-20 :i/block :danger]
:untrustworthy-contact [:<>
[icon-20 :i/untrustworthy theme :danger]
[icon-20 :i/contact theme :blue]]
[icon-20 :i/untrustworthy :danger]
[icon-20 :i/contact :blue]]
nil)])

(defn view
Expand Down
19 changes: 5 additions & 14 deletions src/status_im/common/confirmation_drawer/style.cljs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
(ns status-im.common.confirmation-drawer.style
(:require
[quo.foundations.colors :as colors]))

(defn context-container
[theme]
{:flex-direction :row
:background-color (colors/theme-colors colors/neutral-10 colors/neutral-80 theme)
:border-radius 20
:align-items :center
:align-self :flex-start
:padding 2
:margin-top 4
:margin-bottom 16})
(ns status-im.common.confirmation-drawer.style)

(def buttons-container
{:flex-direction :row
:justify-content :space-between
:margin-top 25})

(def context-tag
{:margin-bottom 12
:margin-top 4})
27 changes: 8 additions & 19 deletions src/status_im/common/confirmation_drawer/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn avatar
[group-chat color display-name photo-path]
(if group-chat
[quo/group-avatar
{:customization-color color
:size :size-20}]
[quo/user-avatar
{:full-name display-name
:profile-picture photo-path
:size :xxs
:status-indicator? false}]))

(defn extra-action-view
[extra-action extra-text extra-action-selected?]
(when extra-action
Expand All @@ -38,7 +26,6 @@
(let [{:keys [group-chat chat-id public-key color chat-type
profile-picture name]} context
id (or chat-id public-key)
theme (quo.context/use-theme)
[primary-name _] (when-not (or group-chat
(= chat-type constants/public-chat-type))
(rf/sub [:contacts/contact-two-names-by-identity id]))
Expand All @@ -56,12 +43,14 @@
[quo/text
{:weight :semi-bold
:size :heading-2} title]
[rn/view {:style (style/context-container theme)}
[avatar group-chat color display-name photo-path]
[quo/text
{:weight :medium
:size :paragraph-2
:style {:margin-left 4}} display-name]]
[quo/context-tag
{:type (if group-chat :group :default)
:profile-picture photo-path
:full-name display-name
:group-name display-name
:customization-color color
:container-style style/context-tag
:size 24}]
[quo/text description]
[extra-action-view extra-action extra-text extra-action-selected?]
[rn/view {:style style/buttons-container}
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/common/contact_list_item/view.cljs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
(ns status-im.common.contact-list-item.view
(:require
[quo.core :as quo]
[status-im.constants :as constants]
[utils.address :as address]
[utils.re-frame :as rf]))

(defn contact-list-item
[{:keys [on-press on-long-press accessory allow-multiple-presses? disabled?]}
{:keys [primary-name secondary-name public-key compressed-key ens-verified added?
container-style]}
container-style trust-status]}
theme]
(let [photo-path (rf/sub [:chats/photo-path public-key])
online? (rf/sub [:visibility-status-updates/online? public-key])
untrustworthy? (= constants/contact-trust-status-untrustworthy trust-status)
customization-color (rf/sub [:profile/customization-color])]
[quo/user
{:customization-color customization-color
Expand All @@ -23,6 +25,7 @@
:online? online?
:verified? ens-verified
:contact? added?
:untrustworthy? untrustworthy?
:on-press on-press
:on-long-press on-long-press
:accessory accessory
Expand Down
34 changes: 22 additions & 12 deletions src/status_im/common/home/actions/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[status-im.contexts.chat.actions.view :as chat-actions]
[status-im.contexts.chat.contacts.drawers.nickname-drawer.view :as nickname-drawer]
[status-im.contexts.communities.actions.chat.view :as communities-chat-actions]
[status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

Expand Down Expand Up @@ -130,6 +131,14 @@
:on-press #(hide-sheet-and-dispatch [:contact/block-contact
public-key])}])}]))

(defn handle-trust-mark-action
[{:keys [public-key trust-status] :as item}]
(hide-sheet-and-dispatch
(if (= trust-status
constants/contact-trust-status-untrustworthy)
[:contact/remove-trust-status public-key (profile.utils/displayed-name item)]
[:contact/mark-as-untrusted-sheet item])))

(defn mute-chat-entry
[chat-id chat-type muted-till]
(let [muted? (rf/sub [:chats/muted chat-id])]
Expand Down Expand Up @@ -260,7 +269,7 @@
(entry {:icon :i/remove-user
:label (i18n/label :t/remove-from-contacts)
:on-press #(hide-sheet-and-dispatch [:contact.ui/remove-contact-pressed contact])
:danger? false
:danger? true
:accessibility-label :remove-from-contacts
:sub-label nil
:chevron? false}))
Expand Down Expand Up @@ -300,17 +309,19 @@
:sub-label nil
:chevron? false}))

;; TODO(OmarBasem): Requires status-go impl.
(defn mark-untrustworthy-entry
[]
(entry {:icon :i/alert
:label (i18n/label :t/mark-untrustworthy)
:on-press #(js/alert "TODO: to be implemented, requires status-go impl.")
(defn change-trust-status-entry
[{:keys [trust-status] :as item}]
(entry {:icon :i/untrustworthy
:label (i18n/label (if (= trust-status
constants/contact-trust-status-untrustworthy)
:t/remove-untrusted-mark
:t/mark-as-untrusted))
:on-press #(handle-trust-mark-action item)
:danger? true
:accessibility-label :mark-untrustworthy
:add-divider? true
:accessibility-label :mark-as-untrusted
:sub-label nil
:chevron? false
:add-divider? true}))
:chevron? false}))

(defn block-user-entry
[item]
Expand Down Expand Up @@ -445,8 +456,7 @@
(show-qr-entry public-key)
(share-profile-entry public-key)]
[(when-not (= current-pub-key public-key)
(when config/show-not-implemented-features?
(mark-untrustworthy-entry)))
(change-trust-status-entry contact))
(when added? (remove-from-contacts-entry contact))
(when-not (= current-pub-key public-key) (block-user-entry contact))]
(when (and admin? chat-id)
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,8 @@
;; Community help links
(def ^:const create-community-help-url
"https://status.app/help/communities/create-a-status-community#create-a-status-community")

;; Contact trust status
(def ^:const contact-trust-status-unknown 0)
(def ^:const contact-trust-status-trusted 1)
(def ^:const contact-trust-status-untrustworthy 2)
1 change: 1 addition & 0 deletions src/status_im/contexts/chat/contacts/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:last-updated (oops/oget js-contact "lastUpdated")
:active? (oops/oget js-contact "active")
:blocked? (oops/oget js-contact "blocked")
:trust-status (oops/oget js-contact "trustStatus")
:added? (oops/oget js-contact "added")
:has-added-us? (oops/oget js-contact "hasAddedUs")
:mutual? (oops/oget js-contact "mutual")
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/contexts/chat/home/chat_list_item/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@
(rf/sub [:contacts/contact-two-names-by-identity chat-id]))
{:keys [ens-verified added?] :as contact} (when-not group-chat
(rf/sub [:contacts/contact-by-address chat-id]))
unread-messages? (pos? unviewed-messages-count)]
unread-messages? (pos? unviewed-messages-count)
trust-status (rf/sub [:contacts/contact-trust-status chat-id])
untrustworthy? (= constants/contact-trust-status-untrustworthy trust-status)]
[rn/view {:style {:flex-direction :row}}
[avatar-view
{:contact contact
Expand All @@ -266,6 +268,7 @@
:verified? ens-verified
:contact? added?
:muted? muted
:untrustworthy? untrustworthy?
:time-str (datetime/to-short-str timestamp)
:style {:flex-shrink 1}}]
[last-message-preview group-chat last-message muted unread-messages?]]]
Expand Down
96 changes: 96 additions & 0 deletions src/status_im/contexts/contact/trust/events.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
(ns status-im.contexts.contact.trust.events
(:require
[status-im.common.confirmation-drawer.view :as confirmation-drawer]
[status-im.constants :as constants]
[status-im.contexts.profile.utils :as profile.utils]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(rf/reg-event-fx :contact/mark-as-untrusted-success
(fn [{:keys [db]} [contact-id]]
{:db (update-in db
[:contacts/contacts contact-id]
assoc
:trust-status
constants/contact-trust-status-untrustworthy)
:fx [[:dispatch
[:toasts/upsert
{:type :positive
:text (i18n/label :t/marked-as-untrusted)}]]]}))

(rf/reg-event-fx :contact/mark-as-untrusted
(fn [_ [contact-id name]]
{:json-rpc/call
[{:method "wakuext_markAsUntrustworthy"
:params [contact-id]
:on-success [:contact/mark-as-untrusted-success contact-id name]
:on-error #(log/error "failed mark contact as untrusted"
{:event :contact/mark-as-untrusted
:contact-id contact-id
:error %})}]}))

(rf/reg-event-fx :contact/remove-trust-status-success
(fn [{:keys [db]} [contact-id]]
{:db (update-in db
[:contacts/contacts contact-id]
assoc
:trust-status
constants/contact-trust-status-unknown)
:fx [[:dispatch
[:toasts/upsert
{:type :positive
:text (i18n/label :t/untrusted-mark-removed)}]]]}))

(rf/reg-event-fx :contact/remove-trust-status
(fn [_ [contact-id name]]
{:json-rpc/call
[{:method "wakuext_removeTrustStatus"
:params [contact-id]
:on-success [:contact/remove-trust-status-success contact-id name]
:on-error #(log/error "failed remove contact trust status"
{:event :contact/remove-trust-status
:contact-id contact-id
:error %})}]}))

(defn pending-contact-request-from-contact-id
[db contact-id]
(->> (get-in db [:activity-center :contact-requests])
(filter #(= contact-id (:author %)))
first))

(rf/reg-event-fx :contact/mark-as-untrusted-sheet
(fn [{:keys [db]} [{:keys [public-key contact-request-state] :as contact}]]
(let [name (profile.utils/displayed-name contact)
contact? (= contact-request-state
constants/contact-request-state-mutual)
request? (= contact-request-state
constants/contact-request-state-received)
contact-request (when request?
(pending-contact-request-from-contact-id db public-key))]
{:fx [[:dispatch
[:show-bottom-sheet
{:content (fn []
[confirmation-drawer/confirmation-drawer
(cond-> {:title (i18n/label :t/mark-as-untrusted)
:description (i18n/label :t/mark-as-untrusted-description
{:username (:primary-name contact)})
:context contact
:accessibility-label :mark-as-untrustworthy
:button-text (i18n/label :t/mark-as-untrusted-button)
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch
[:contact/mark-as-untrusted
public-key name]))}
contact?
(assoc :extra-action (fn []
(rf/dispatch [:contact.ui/remove-contact-pressed
contact]))
:extra-text (i18n/label :t/remove-contact))
request?
(assoc :extra-action (fn []
(rf/dispatch
[:activity-center.contact-requests/decline
(:id contact-request)]))
:extra-text (i18n/label :t/decline-contact-request)))])}]]]})))
Loading