[#11179] Nicknames in mention suggestions

This commit is contained in:
Roman Volosovskyi 2020-09-22 17:14:45 +03:00
parent b8298dce44
commit 345ae359aa
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 73 additions and 39 deletions

View File

@ -92,24 +92,26 @@
(reduce (fn [{:keys [last-clock-value all-messages users] :as acc} (reduce (fn [{:keys [last-clock-value all-messages users] :as acc}
{:keys [clock-value seen message-id alias name identicon from] {:keys [clock-value seen message-id alias name identicon from]
:as message}] :as message}]
(cond-> acc (let [nickname (get-in db [:contacts/contacts from :nickname])]
(and alias (not= alias "")) (cond-> acc
(update :users assoc from {:alias alias (and alias (not= alias ""))
:name (or name alias) (update :users assoc from {:alias alias
:identicon identicon :name (or name alias)
:public-key from}) :identicon identicon
(or (nil? last-clock-value) :public-key from
(> last-clock-value clock-value)) :nickname nickname})
(assoc :last-clock-value clock-value) (or (nil? last-clock-value)
(> last-clock-value clock-value))
(assoc :last-clock-value clock-value)
(not seen) (not seen)
(update :unviewed-message-ids conj message-id) (update :unviewed-message-ids conj message-id)
(nil? (get all-messages message-id)) (nil? (get all-messages message-id))
(update :new-messages conj message) (update :new-messages conj message)
:always :always
(update :all-messages assoc message-id message))) (update :all-messages assoc message-id message))))
{:all-messages already-loaded-messages {:all-messages already-loaded-messages
:unviewed-message-ids loaded-unviewed-messages-ids :unviewed-message-ids loaded-unviewed-messages-ids
:users users :users users

View File

@ -72,9 +72,15 @@
(defn get-suggestions [users searched-text] (defn get-suggestions [users searched-text]
(reduce (reduce
(fn [acc [k {:keys [alias name] :as user}]] (fn [acc [k {:keys [alias name nickname] :as user}]]
(if-let [match (if-let [match
(cond (cond
(and nickname
(string/starts-with?
(string/lower-case nickname)
searched-text))
(or alias name)
(and alias (and alias
(string/starts-with? (string/starts-with?
(string/lower-case alias) (string/lower-case alias)
@ -330,7 +336,7 @@
:at-idxs new-at-idxs) :at-idxs new-at-idxs)
(assoc-in [:chats/input-with-mentions chat-id] calculated-input))})) (assoc-in [:chats/input-with-mentions chat-id] calculated-input))}))
(fx/defn calculate-suggestion (fx/defn calculate-suggestions
{:events [::calculate-suggestions]} {:events [::calculate-suggestions]}
[{:keys [db] :as cofx} mentionable-users] [{:keys [db] :as cofx} mentionable-users]
(let [chat-id (:current-chat-id db) (let [chat-id (:current-chat-id db)
@ -441,6 +447,6 @@
:start end :start end
:end end :end end
:new-text "")} :new-text "")}
(calculate-suggestion mentionable-users)) (calculate-suggestions mentionable-users))
(clear-suggestions cofx))))) (clear-suggestions cofx)))))

View File

@ -64,12 +64,14 @@
(fx/defn add-sender-to-chat-users (fx/defn add-sender-to-chat-users
[{:keys [db]} {:keys [chat-id alias name identicon from]}] [{:keys [db]} {:keys [chat-id alias name identicon from]}]
(when (and alias (not= alias "")) (when (and alias (not= alias ""))
{:db (update-in db [:chats chat-id :users] assoc (let [nickname (get-in db [:contacts/contacts from :nickname])]
from {:db (update-in db [:chats chat-id :users] assoc
{:alias alias from
:name (or name alias) {:alias alias
:identicon identicon :name (or name alias)
:public-key from})})) :identicon identicon
:public-key from
:nickname nickname})})))
(fx/defn add-received-message (fx/defn add-received-message
[{:keys [db] :as cofx} [{:keys [db] :as cofx}

View File

@ -48,7 +48,8 @@
{"from" {:alias "alias", {"from" {:alias "alias",
:name "name", :name "name",
:identicon "identicon", :identicon "identicon",
:public-key "from"}}}}}} :public-key "from"
:nickname nil}}}}}}
(message/add-received-message (message/add-received-message
cofx cofx
message))))) message)))))
@ -70,7 +71,8 @@
{"from" {:alias "alias", {"from" {:alias "alias",
:name "name", :name "name",
:identicon "identicon", :identicon "identicon",
:public-key "from"}}}}}} :public-key "from"
:nickname nil}}}}}}
(message/add-received-message (message/add-received-message
cofx cofx
message))))) message)))))

View File

@ -87,7 +87,7 @@
(when (not= (get-in db [:multiaccount :public-key]) public-key) (when (not= (get-in db [:multiaccount :public-key]) public-key)
(let [contact (cond-> (get-in db [:contacts/contacts public-key] (let [contact (cond-> (get-in db [:contacts/contacts public-key]
(build-contact cofx public-key)) (build-contact cofx public-key))
nickname (and nickname (not (string/blank? nickname)))
(assoc :nickname nickname) (assoc :nickname nickname)
:else :else
(update :system-tags (update :system-tags
@ -187,9 +187,12 @@
(fx/defn update-nickname (fx/defn update-nickname
{:events [:contacts/update-nickname]} {:events [:contacts/update-nickname]}
[{:keys [db] :as cofx} public-key nickname] [{:keys [db] :as cofx} public-key nickname]
(fx/merge cofx (let [contact (-> (build-contact cofx public-key)
{:db (if (string/blank? nickname) (merge (get-in db [:contacts/contacts public-key])))]
(update-in db [:contacts/contacts public-key] dissoc :nickname) (fx/merge cofx
(assoc-in db [:contacts/contacts public-key :nickname] nickname))} {:db (assoc-in db [:contacts/contacts public-key]
(upsert-contact {:public-key public-key}) (if (string/blank? nickname)
(navigation/navigate-back))) (dissoc contact :nickname)
(assoc contact :nickname nickname)))}
(upsert-contact {:public-key public-key})
(navigation/navigate-back))))

View File

@ -884,7 +884,7 @@
:<- [:contacts/contacts] :<- [:contacts/contacts]
(fn [contacts] (fn [contacts]
(reduce (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 (if (and alias
(not= alias "") (not= alias "")
(not (contact.db/blocked? contact))) (not (contact.db/blocked? contact)))
@ -893,6 +893,7 @@
{:alias alias {:alias alias
:name (or name alias) :name (or name alias)
:identicon identicon :identicon identicon
:nickname nickname
:public-key key})) :public-key key}))
acc)) acc))
{} {}

View File

@ -3,6 +3,7 @@
[quo.react-native :as rn] [quo.react-native :as rn]
[quo.react :as react] [quo.react :as react]
[quo.platform :as platform] [quo.platform :as platform]
[quo.components.text :as text]
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[status-im.ui.screens.chat.components.style :as styles] [status-im.ui.screens.chat.components.style :as styles]
[status-im.ui.screens.chat.components.reply :as reply] [status-im.ui.screens.chat.components.reply :as reply]
@ -196,9 +197,8 @@
input-with-mentions)]])) input-with-mentions)]]))
(defn mention-item (defn mention-item
[[_ {:keys [identicon alias name] :as user}]] [[_ {:keys [identicon alias name nickname] :as user}]]
(let [title name (let [ens-name? (not= alias name)]
subtitle? (not= alias name)]
[list-item/list-item [list-item/list-item
(cond-> {:icon (cond-> {:icon
[rn/view {:style {}} [rn/view {:style {}}
@ -211,13 +211,31 @@
:icon-container-style {} :icon-container-style {}
:size :small :size :small
:text-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 :title-text-weight :medium
:on-press :on-press
(fn [] (fn []
(re-frame/dispatch [:chat.ui/select-mention user]))} (re-frame/dispatch [:chat.ui/select-mention user]))}
subtitle? ens-name?
(assoc :subtitle alias))])) (assoc :subtitle alias))]))
(def chat-input-height (reagent/atom nil)) (def chat-input-height (reagent/atom nil))