From 24b77811d824faa2ad2741e617474d1b5e241200 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Mon, 17 Jun 2024 18:25:05 -0300 Subject: [PATCH] fix(profile)_: Fallback to old profile name after migration from v1 (#20412) This is a byproduct of the investigation on issue https://github.com/status-im/status-mobile/issues/20203, more specifically, to double-check if v1 users have their display names shown correctly. Closes https://github.com/status-im/status-mobile/issues/20203 This is the scenario used to reproduce the bugs this PR is solving: 1. Alice creates an account in v1 (branch release/1.20.x). 2. Alice had 1 friend to chat with, Carol. 3. Alice sends and receives at least one message from Carol. 4. Alice installs the new app (latest develop branch suffices). 5. Alice login and try to edit her profile, but her 3-word name is not displayed in the Settings > Edit Profile screen, nor in the Settings > Edit profile > Name input field. 6. Alice also opens her chat with Carol, but her name appears as a public key instead of her 3-word name she identifies herself with. The solution presented here is to just fallback to Alice's 3-word name (name field in the profile/contact app-db instance). Areas that may be impacted - Edit profile name. - Name displayed in chats from the perspective of the sender who migrated from v1. Steps to test In order to test this PR, it's necessary to migrate from v1 to v2 using two separate builds. The v1 build can be obtained in PR https://github.com/status-im/status-mobile/pull/20123. v2 build can be any one from develop from today, for example. --- .../default_sync_period_settings/view.cljs | 2 ++ .../ui/screens/sync_settings/views.cljs | 7 ++++ src/status_im/constants.cljs | 1 + src/status_im/contexts/profile/utils.cljs | 2 +- .../contexts/profile/utils_test.cljs | 19 +++++++++++ src/status_im/subs/contact.cljs | 3 +- src/status_im/subs/contact_test.cljs | 34 +++++++++++++++++++ translations/en.json | 1 + 8 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/status_im/contexts/profile/utils_test.cljs diff --git a/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs b/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs index 02df232fb6..93e56ad0f6 100644 --- a/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs +++ b/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs @@ -13,6 +13,7 @@ constants/one-day (i18n/label :t/one-day) constants/three-days (i18n/label :t/three-days) constants/one-week (i18n/label :t/one-week) + constants/nine-days (i18n/label :t/nine-days) constants/one-month (i18n/label :t/one-month)}) (defn radio-item @@ -34,4 +35,5 @@ [radio-item constants/one-day default-sync-period] [radio-item constants/three-days default-sync-period] [radio-item constants/one-week default-sync-period] + [radio-item constants/nine-days default-sync-period] [radio-item constants/one-month default-sync-period]])) diff --git a/src/legacy/status_im/ui/screens/sync_settings/views.cljs b/src/legacy/status_im/ui/screens/sync_settings/views.cljs index b1772e6a3b..efe1a6d2d4 100644 --- a/src/legacy/status_im/ui/screens/sync_settings/views.cljs +++ b/src/legacy/status_im/ui/screens/sync_settings/views.cljs @@ -57,14 +57,21 @@ :accessory-text (cond (= default-sync-period constants/two-mins) (i18n/label :t/two-minutes) + (or (nil? default-sync-period) (= default-sync-period constants/one-day)) (i18n/label :t/one-day) + (= default-sync-period constants/three-days) (i18n/label :t/three-days) + + (= default-sync-period constants/nine-days) + (i18n/label :t/nine-days) + (= default-sync-period constants/one-week) (i18n/label :t/one-week) + (= default-sync-period constants/one-month) (i18n/label :t/one-month))}] [list.item/list-item diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index ae8854c4c9..be6c66b8a2 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -293,6 +293,7 @@ (def ^:const two-mins (* 2 60)) (def ^:const one-day (* 60 60 24)) (def ^:const three-days (* one-day 3)) +(def ^:const nine-days (* one-day 9)) (def ^:const one-week (* one-day 7)) (def ^:const one-month (* one-day 31)) diff --git a/src/status_im/contexts/profile/utils.cljs b/src/status_im/contexts/profile/utils.cljs index f8ca89994d..d687402ef8 100644 --- a/src/status_im/contexts/profile/utils.cljs +++ b/src/status_im/contexts/profile/utils.cljs @@ -13,7 +13,7 @@ name)] (if (or preferred-name (and ens-verified name)) ens-name - (or display-name primary-name alias)))) + (or display-name primary-name alias name)))) (defn photo [{:keys [images]}] diff --git a/src/status_im/contexts/profile/utils_test.cljs b/src/status_im/contexts/profile/utils_test.cljs new file mode 100644 index 0000000000..b13151a292 --- /dev/null +++ b/src/status_im/contexts/profile/utils_test.cljs @@ -0,0 +1,19 @@ +(ns status-im.contexts.profile.utils-test + (:require + [cljs.test :refer [are deftest]] + [status-im.contexts.profile.utils :as sut])) + +(deftest displayed-name-test + (are [expected arg] (= expected (sut/displayed-name arg)) + "Display Name" {:display-name "Display Name"} + "Primary Name" {:primary-name "Primary Name"} + "Alias" {:alias "Alias"} + "Name" {:name "Name"} + nil {:preferred-name " "} + "Preferred Name" {:preferred-name "Preferred Name"} + "Preferred Name" {:preferred-name "Preferred Name" :display-name "Display Name"} + "Preferred Name" {:preferred-name "Preferred Name" :display-name "Display Name" :name "Name"} + "Display Name" {:ens-verified true :name "Name" :display-name "Display Name"} + "Name" {:ens-verified true :name "Name" :display-name " "} + "Name" {:ens-verified true :name "Name"} + "Name" {:name "Name"})) diff --git a/src/status_im/subs/contact.cljs b/src/status_im/subs/contact.cljs index 20fd37b36d..1a866e1b0f 100644 --- a/src/status_im/subs/contact.cljs +++ b/src/status_im/subs/contact.cljs @@ -258,13 +258,14 @@ [(re-frame/subscribe [:contacts/contact-by-identity contact-identity]) (re-frame/subscribe [:profile/profile])]) (fn [[{:keys [primary-name] :as contact} - {:keys [public-key preferred-name display-name]}] + {:keys [public-key preferred-name display-name name]}] [_ contact-identity]] [(if (= public-key contact-identity) (cond (not (string/blank? preferred-name)) preferred-name (not (string/blank? display-name)) display-name (not (string/blank? primary-name)) primary-name + (not (string/blank? name)) name :else public-key) (profile.utils/displayed-name contact)) (:secondary-name contact)])) diff --git a/src/status_im/subs/contact_test.cljs b/src/status_im/subs/contact_test.cljs index 55a5fbb3e9..f0111ba253 100644 --- a/src/status_im/subs/contact_test.cljs +++ b/src/status_im/subs/contact_test.cljs @@ -174,3 +174,37 @@ (rf/sub [sub-name]))] (is (= expected-sorted-contacts-without-images (mapv remove-contact-images contact-list-without-identicons)))))) + +(h/deftest-sub :contacts/contact-two-names-by-identity + [sub-name] + (testing "contact is current profile" + (let [profile-key "profile-key"] + (swap! rf-db/app-db assoc + :profile/profile + {:public-key profile-key + :display-name "Display Name" + :name "Name" + :preferred-name "Preferred Name"} + + :contacts/contacts + {profile-key {:primary-name "Primary Name"} + "contact-key" {:secondary-name "Secondary Name"}}) + + (is (= ["Preferred Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update :profile/profile dissoc :preferred-name) + (is (= ["Display Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update :profile/profile dissoc :display-name) + (is (= ["Primary Name" nil] (rf/sub [sub-name profile-key]))) + + (swap! rf-db/app-db update-in [:contacts/contacts profile-key] dissoc :primary-name) + (is (= ["Name" nil] (rf/sub [sub-name profile-key]))))) + + (testing "contact is not current profile" + (swap! rf-db/app-db assoc + :profile/profile {:public-key "profile-key"} + :contacts/contacts {"contact-key" {:preferred-name "Preferred Name" + :secondary-name "Secondary Name"}}) + + (is (= ["Preferred Name" "Secondary Name"] (rf/sub [sub-name "contact-key"]))))) diff --git a/translations/en.json b/translations/en.json index a9b88ba050..910053906d 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1863,6 +1863,7 @@ "accept-and-add": "Accept and add", "one-day": "One day", "three-days": "Three days", + "nine-days": "Nine days", "one-week": "One week", "one-month": "One month", "my-profile": "My profile",