diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 97ffc9b7b6..b831acd406 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -92,24 +92,26 @@ (reduce (fn [{:keys [last-clock-value all-messages users] :as acc} {:keys [clock-value seen message-id alias name identicon from] :as message}] - (cond-> acc - (and alias (not= alias "")) - (update :users assoc from {:alias alias - :name (or name alias) - :identicon identicon - :public-key from}) - (or (nil? last-clock-value) - (> last-clock-value clock-value)) - (assoc :last-clock-value clock-value) + (let [nickname (get-in db [:contacts/contacts from :nickname])] + (cond-> acc + (and alias (not= alias "")) + (update :users assoc from {:alias alias + :name (or name alias) + :identicon identicon + :public-key from + :nickname nickname}) + (or (nil? last-clock-value) + (> last-clock-value clock-value)) + (assoc :last-clock-value clock-value) - (not seen) - (update :unviewed-message-ids conj message-id) + (not seen) + (update :unviewed-message-ids conj message-id) - (nil? (get all-messages message-id)) - (update :new-messages conj message) + (nil? (get all-messages message-id)) + (update :new-messages conj message) - :always - (update :all-messages assoc message-id message))) + :always + (update :all-messages assoc message-id message)))) {:all-messages already-loaded-messages :unviewed-message-ids loaded-unviewed-messages-ids :users users diff --git a/src/status_im/chat/models/mentions.cljs b/src/status_im/chat/models/mentions.cljs index bdcf974d4e..89f8af7c2e 100644 --- a/src/status_im/chat/models/mentions.cljs +++ b/src/status_im/chat/models/mentions.cljs @@ -72,9 +72,15 @@ (defn get-suggestions [users searched-text] (reduce - (fn [acc [k {:keys [alias name] :as user}]] + (fn [acc [k {:keys [alias name nickname] :as user}]] (if-let [match (cond + (and nickname + (string/starts-with? + (string/lower-case nickname) + searched-text)) + (or alias name) + (and alias (string/starts-with? (string/lower-case alias) @@ -330,7 +336,7 @@ :at-idxs new-at-idxs) (assoc-in [:chats/input-with-mentions chat-id] calculated-input))})) -(fx/defn calculate-suggestion +(fx/defn calculate-suggestions {:events [::calculate-suggestions]} [{:keys [db] :as cofx} mentionable-users] (let [chat-id (:current-chat-id db) @@ -441,6 +447,6 @@ :start end :end end :new-text "")} - (calculate-suggestion mentionable-users)) + (calculate-suggestions mentionable-users)) (clear-suggestions cofx))))) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index cec965a248..16f6676e22 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -64,12 +64,14 @@ (fx/defn add-sender-to-chat-users [{:keys [db]} {:keys [chat-id alias name identicon from]}] (when (and alias (not= alias "")) - {:db (update-in db [:chats chat-id :users] assoc - from - {:alias alias - :name (or name alias) - :identicon identicon - :public-key from})})) + (let [nickname (get-in db [:contacts/contacts from :nickname])] + {:db (update-in db [:chats chat-id :users] assoc + from + {:alias alias + :name (or name alias) + :identicon identicon + :public-key from + :nickname nickname})}))) (fx/defn add-received-message [{:keys [db] :as cofx} diff --git a/src/status_im/chat/models/message_test.cljs b/src/status_im/chat/models/message_test.cljs index 6c7fbef49c..a48047facc 100644 --- a/src/status_im/chat/models/message_test.cljs +++ b/src/status_im/chat/models/message_test.cljs @@ -48,7 +48,8 @@ {"from" {:alias "alias", :name "name", :identicon "identicon", - :public-key "from"}}}}}} + :public-key "from" + :nickname nil}}}}}} (message/add-received-message cofx message))))) @@ -70,7 +71,8 @@ {"from" {:alias "alias", :name "name", :identicon "identicon", - :public-key "from"}}}}}} + :public-key "from" + :nickname nil}}}}}} (message/add-received-message cofx message))))) diff --git a/src/status_im/contact/core.cljs b/src/status_im/contact/core.cljs index 325f37e32f..a68d09fb41 100644 --- a/src/status_im/contact/core.cljs +++ b/src/status_im/contact/core.cljs @@ -87,7 +87,7 @@ (when (not= (get-in db [:multiaccount :public-key]) public-key) (let [contact (cond-> (get-in db [:contacts/contacts public-key] (build-contact cofx public-key)) - nickname + (and nickname (not (string/blank? nickname))) (assoc :nickname nickname) :else (update :system-tags @@ -187,9 +187,12 @@ (fx/defn update-nickname {:events [:contacts/update-nickname]} [{:keys [db] :as cofx} public-key nickname] - (fx/merge cofx - {:db (if (string/blank? nickname) - (update-in db [:contacts/contacts public-key] dissoc :nickname) - (assoc-in db [:contacts/contacts public-key :nickname] nickname))} - (upsert-contact {:public-key public-key}) - (navigation/navigate-back))) + (let [contact (-> (build-contact cofx public-key) + (merge (get-in db [:contacts/contacts public-key])))] + (fx/merge cofx + {:db (assoc-in db [:contacts/contacts public-key] + (if (string/blank? nickname) + (dissoc contact :nickname) + (assoc contact :nickname nickname)))} + (upsert-contact {:public-key public-key}) + (navigation/navigate-back)))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index dacfc624c8..ffdc8e17c0 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -884,7 +884,7 @@ :<- [:contacts/contacts] (fn [contacts] (reduce - (fn [acc [key {:keys [alias name identicon public-key] :as contact}]] + (fn [acc [key {:keys [alias name identicon public-key nickname] :as contact}]] (if (and alias (not= alias "") (not (contact.db/blocked? contact))) @@ -893,6 +893,7 @@ {:alias alias :name (or name alias) :identicon identicon + :nickname nickname :public-key key})) acc)) {} diff --git a/src/status_im/ui/screens/chat/components/input.cljs b/src/status_im/ui/screens/chat/components/input.cljs index 20aa1ebee2..21d781d350 100644 --- a/src/status_im/ui/screens/chat/components/input.cljs +++ b/src/status_im/ui/screens/chat/components/input.cljs @@ -3,6 +3,7 @@ [quo.react-native :as rn] [quo.react :as react] [quo.platform :as platform] + [quo.components.text :as text] [quo.design-system.colors :as colors] [status-im.ui.screens.chat.components.style :as styles] [status-im.ui.screens.chat.components.reply :as reply] @@ -196,9 +197,8 @@ input-with-mentions)]])) (defn mention-item - [[_ {:keys [identicon alias name] :as user}]] - (let [title name - subtitle? (not= alias name)] + [[_ {:keys [identicon alias name nickname] :as user}]] + (let [ens-name? (not= alias name)] [list-item/list-item (cond-> {:icon [rn/view {:style {}} @@ -211,13 +211,31 @@ :icon-container-style {} :size :small :text-size :small - :title title + :title + [text/text + {:weight :medium + :ellipsize-mode :tail + :number-of-lines 1 + :size :small} + (if nickname + nickname + name) + (when nickname + [text/text + {:weight :regular + :color :secondary + :ellipsize-mode :tail + :size :small} + " " + (when ens-name? + "@") + name])] :title-text-weight :medium :on-press (fn [] (re-frame/dispatch [:chat.ui/select-mention user]))} - subtitle? + ens-name? (assoc :subtitle alias))])) (def chat-input-height (reagent/atom nil))