[#8854] Finish "Show my ENS name in chat" setting in user profile

This commit is contained in:
Andrey Shovkoplyas 2019-11-12 11:55:45 +01:00
parent ad80d4b0fd
commit ec04709495
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
9 changed files with 97 additions and 84 deletions

View File

@ -1,6 +1,6 @@
(ns status-im.group-chats.db
(:require [status-im.chat.models :as models.chat]
[status-im.utils.gfycat.core :as gfycat]))
[status-im.multiaccounts.core :as multiaccounts]))
(defn unwrap-events
"Flatten all events, denormalizing from field"
@ -36,15 +36,12 @@
(invited? my-public-key chat)
(not (joined? my-public-key chat)))
(let [inviter-pk (get-inviter-pk my-public-key chat)]
(get-in contacts [inviter-pk :name]
(gfycat/generate-gfy inviter-pk)))))
(multiaccounts/displayed-name (or (get contacts inviter-pk) {:public-key inviter-pk})))))
(defn get-inviter-name
"when the chat is a private group chat in which the user has been
invited and didn't accept the invitation yet, return inviter-name"
[contacts chat my-public-key]
(when (and (models.chat/group-chat? chat)
(joined? my-public-key chat))
(when (models.chat/group-chat? chat)
(let [inviter-pk (get-inviter-pk my-public-key chat)]
(get-in contacts [inviter-pk :name]
(gfycat/generate-gfy inviter-pk)))))
(multiaccounts/displayed-name (or (get contacts inviter-pk) {:public-key inviter-pk})))))

View File

@ -15,20 +15,13 @@
[status-im.utils.platform :as platform]
[status-im.utils.utils :as utils]))
; Whether we should be strict about verifying ens, currently disabled as
; status-go can't be upgrade because of geth 1.9 incompatibility
(def only-verified-ens false)
(defn displayed-name
"Use preferred name, name or alias in that order"
[{:keys [name preferred-name alias public-key ens-verified]}]
(let [ens-name (or preferred-name
name)]
;; Preferred name is our own
;; otherwise we make sure is verified
(if (or preferred-name
(and only-verified-ens
ens-verified
name))
;; Preferred name is our own otherwise we make sure it's verified
(if (or preferred-name (and ens-verified name))
(let [username (stateofus/username ens-name)]
(str "@" (or username ens-name)))
(or alias (gfycat/generate-gfy public-key)))))

View File

@ -1657,7 +1657,8 @@
:<- [:contacts/contacts]
:<- [:multiaccount]
(fn [[{:keys [contacts admins]} all-contacts current-multiaccount]]
(contact.db/get-all-contacts-in-group-chat contacts admins all-contacts current-multiaccount)))
(map #(assoc % :name (multiaccounts/displayed-name %))
(contact.db/get-all-contacts-in-group-chat contacts admins all-contacts current-multiaccount))))
(re-frame/reg-sub
:contacts/contacts-by-chat

View File

@ -192,7 +192,7 @@
(defview message-author-name [from alias]
(letsubs [{:keys [ens-name]} [:contacts/contact-name-by-identity from]]
(chat.utils/format-author alias style/message-author-name ens-name)))
(chat.utils/format-author alias style/message-author-name-container ens-name)))
(defn message-body
[{:keys [alias

View File

@ -180,6 +180,13 @@
:margin-right 12
:text-align-vertical :center})
(def message-author-name-container
{:padding-top 6
:padding-left 12
:padding-right 16
:margin-right 12
:text-align-vertical :center})
(defn quoted-message-container [outgoing]
{:margin-bottom 6
:padding-bottom 6

View File

@ -19,7 +19,10 @@
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.screens.chat.message.message :as message]
[status-im.ui.screens.profile.components.views :as profile.components]
[status-im.utils.navigation :as navigation])
[status-im.utils.navigation :as navigation]
[status-im.ui.components.list-item.views :as list-item]
[status-im.ui.screens.chat.photos :as photos]
[status-im.multiaccounts.core :as multiaccounts])
(:require-macros [status-im.utils.views :as views]))
(defn- button
@ -582,14 +585,15 @@
[button {:on-press #(re-frame/dispatch [::ens/get-started-pressed])
:label (i18n/label :t/get-started)}]]])
(defn- name-item [{:keys [name action hide-chevron?]}]
(defn- name-item [{:keys [name action]}]
(let [stateofus-username (stateofus/username name)
s (or stateofus-username name)]
[list/big-list-item {:text s
:subtext (when stateofus-username stateofus/domain)
:action-fn action
[list-item/list-item
{:title s
:subtitle (when stateofus-username stateofus/domain)
:on-press action
:icon :main-icons/username
:hide-chevron? hide-chevron?}]))
:accessories [:chevron]}]))
(defn- name-list [names preferred-name]
[react/view {:style {:flex 1 :margin-top 16}}
@ -612,12 +616,14 @@
[name-item {:name name :hide-chevron? true :action action}]]
[radio/radio (= name preferred-name)]]]))]]]])
(defn- registered [names {:keys [preferred-name address public-key name]} show?]
(defn- registered [names {:keys [preferred-name public-key name] :as account} show?]
[react/view {:style {:flex 1}}
[react/scroll-view
[react/view {:style {:margin-top 8}}
[list/big-list-item {:text (i18n/label :t/ens-add-username)
:action-fn #(re-frame/dispatch [::ens/add-username-pressed])
[list-item/list-item
{:title (i18n/label :t/ens-add-username)
:theme :action
:on-press #(re-frame/dispatch [::ens/add-username-pressed])
:icon :main-icons/add}]]
[react/view {:style {:margin-top 22 :margin-bottom 8}}
[react/text {:style {:color colors/gray :margin-horizontal 16}}
@ -645,22 +651,23 @@
{:label-kw :ens-show-username
:action-fn #(re-frame/dispatch [::ens/switch-show-username])
:value show?}]]
(let [message (merge {:from public-key
:last-in-group? true
:display-username? true
:display-photo? true
:alias name
:content {:text (i18n/label :t/ens-test-message)
:name (when show? preferred-name)}
(let [message (merge {:content {:text (i18n/label :t/ens-test-message)}
:content-type "text/plain"
:timestamp-str "9:41 AM"}
(when show?
{:name preferred-name}))]
[message/message-body message
[message/text-message message]])]])
:timestamp-str "9:41 AM"})]
[react/view
[react/view {:padding-left 60}
(if show?
^{:key "ens-name"}
[message/message-author-name public-key]
^{:key "generated"}
[message/message-author-name nil name])]
[react/view {:flex-direction :row}
[react/view {:padding-left 16 :padding-right 8 :padding-top 4}
[photos/photo (multiaccounts/displayed-photo account) {:size 36}]]
[message/text-message message]]])]])
(views/defview main []
(views/letsubs [{:keys [names multiaccount preferred-name show?]} [:ens.main/screen]]
(views/letsubs [{:keys [names multiaccount show?]} [:ens.main/screen]]
[react/keyboard-avoiding-view {:style {:flex 1}}
[status-bar/status-bar {:type :main}]
[toolbar/simple-toolbar

View File

@ -44,6 +44,13 @@
:number-of-lines 1}
generated-name])]))
(defn- group-name [name]
[react/view styles/profile-header-name-container
[react/text {:style styles/profile-name-text
:number-of-lines 2
:ellipsize-mode :tail}
name]])
(defn- profile-header-display [{:keys [name public-key] :as contact}
allow-icon-change? include-remove-action?]
[react/view (merge styles/profile-header-display {:padding-horizontal 16})
@ -85,6 +92,11 @@
:edit? false}])
[names contact]])
(defn group-header-display [{:keys [chat-name color]}]
[react/view (merge styles/profile-header-display {:padding-horizontal 16})
[chat-icon.screen/profile-icon-view nil chat-name color nil 64 nil]
[group-name chat-name]])
(defn profile-header
[{:keys [contact allow-icon-change? include-remove-action?]}]
[profile-header-display contact allow-icon-change? include-remove-action?])

View File

@ -54,9 +54,9 @@
; :content-height 150}
; contact])
(defn render-detail [{:keys [name public-key] :as detail}]
(defn render-detail [{:keys [alias public-key] :as detail}]
[list-item/list-item
{:title name
{:title alias
:subtitle (utils/get-shortened-address public-key)
:icon [chat-icon/contact-icon-contacts-tab detail]
:accessibility-label :profile-public-key
@ -118,10 +118,12 @@
;;TO-DO Rework generate-view to use 3 functions from large-toolbar
(views/defview profile []
(views/letsubs [list-ref (reagent/atom nil)
contact [:contacts/current-contact]]
{:keys [ens-verified name] :as contact} [:contacts/current-contact]]
(when contact
(let [header-in-toolbar (header-in-toolbar contact)
header (header contact)
header (header (cond-> contact
(and ens-verified name)
(assoc :usernames [name])))
content
[[list/action-list (actions contact)
{:container-style styles/action-container

View File

@ -14,7 +14,8 @@
[re-frame.core :as re-frame]
[status-im.ui.components.common.styles :as common.styles]
[status-im.i18n :as i18n]
[status-im.utils.utils :as utils]))
[status-im.utils.utils :as utils]
[status-im.ui.components.list-item.views :as list-item]))
(defn group-chat-profile-toolbar [admin?]
[toolbar/toolbar {}
@ -33,21 +34,6 @@
:accessibility-label :done-button}
(i18n/label :t/done)]])
(defn actions [allow-adding-members? chat-id]
(concat
(when allow-adding-members?
[{:label (i18n/label :add-members)
:icon :main-icons/add
:action #(re-frame/dispatch [:navigate-to :add-participants-toggle-list])}])
[{:label (i18n/label :t/clear-history)
:icon :main-icons/close
:action #(re-frame/dispatch [:chat.ui/clear-history-pressed])
:accessibility-label :clear-history-button}
{:label (i18n/label :t/delete-chat)
:icon :main-icons/arrow-left
:action #(re-frame/dispatch [:group-chats.ui/remove-chat-pressed chat-id])
:accessibility-label :delete-chat-button}]))
(defn member-actions [chat-id member us-admin?]
(concat
[{:action #(re-frame/dispatch [(if platform/desktop? :show-profile-desktop :chat.ui/show-profile) (:public-key member)])
@ -61,7 +47,7 @@
:label (i18n/label :t/make-admin)}])))
(defn render-member [chat-id {:keys [name public-key] :as member} admin? current-user-identity]
[react/view
[react/view {:padding-vertical 10}
[contact/contact-view
{:contact member
:extend-options (member-actions chat-id member admin?)
@ -78,15 +64,13 @@
(defview chat-group-members-view [chat-id admin? current-user-identity]
(letsubs [members [:contacts/current-chat-contacts]]
(when (seq members)
[react/view
[list/flat-list {:data members
:separator list/default-separator
:key-fn :address
:render-fn #(render-member chat-id % admin? current-user-identity)}]])))
:render-fn #(render-member chat-id % admin? current-user-identity)}])))
(defn members-list [chat-id admin? current-user-identity]
[react/view
[profile.components/settings-title (i18n/label :t/members-title)]
[list-item/list-item {:title :t/members-title :type :section-header}]
[chat-group-members-view chat-id admin? current-user-identity]])
(defview group-chat-profile []
@ -102,20 +86,30 @@
(< (count members) constants/max-group-chat-participants))]
[react/view profile.components.styles/profile
[status-bar/status-bar]
(if editing?
[group-chat-profile-edit-toolbar]
[group-chat-profile-toolbar admin?])
;;TODO doesn't work, needs to be fixed
;(if editing?
;[group-chat-profile-edit-toolbar]
[group-chat-profile-toolbar false];admin?]
[react/scroll-view
[react/view profile.components.styles/profile-form
[profile.components/profile-header
{:contact shown-chat
:editing? editing?
:allow-icon-change? false
:on-change-text-event :group-chats.ui/name-changed}]
[list/action-list (actions allow-adding-members? chat-id)
{:container-style styles/action-container
:action-style styles/action
:action-label-style styles/action-label
:action-separator-style styles/action-separator
:icon-opts styles/action-icon-opts}]
[profile.components/group-header-display shown-chat]
[react/view {:height 20}]
(when allow-adding-members?
[list-item/list-item
{:title :t/add-members
:icon :main-icons/add
:theme :action
:on-press #(re-frame/dispatch [:navigate-to :add-participants-toggle-list])}])
[list-item/list-item
{:title :t/clear-history
:icon :main-icons/close
:theme :action
:on-press #(re-frame/dispatch [:chat.ui/clear-history-pressed])
:accessibility-label :clear-history-button}]
[list-item/list-item
{:title :t/delete-chat
:icon :main-icons/arrow-left
:theme :action
:on-press #(re-frame/dispatch [:group-chats.ui/remove-chat-pressed chat-id])
:accessibility-label :delete-chat-button}]
[members-list chat-id admin? (first admins) current-pk]]]]))))