[#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}
{: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

View File

@ -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)))))

View File

@ -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}

View File

@ -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)))))

View File

@ -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))))

View File

@ -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))
{}

View File

@ -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))