[#11212] Mention suggestions based on names parts
This commit is contained in:
parent
c866082cde
commit
6cf3a6a98e
|
@ -51,12 +51,14 @@
|
|||
;; NOTE(roman): on-text-input event is not dispatched when we change input
|
||||
;; programmatically, so we have to call `on-text-input` manually
|
||||
(mentions/on-text-input
|
||||
(let [match-len (count match)
|
||||
searched-text-len (count searched-text)]
|
||||
{:new-text (subs match searched-text-len)
|
||||
:previous-text ""
|
||||
:start (+ at-sign-idx searched-text-len 1)
|
||||
:end (+ at-sign-idx match-len 1)}))
|
||||
(let [match-len (count match)
|
||||
searched-text-len (count searched-text)
|
||||
start (inc at-sign-idx)
|
||||
end (+ start match-len)]
|
||||
{:new-text match
|
||||
:previous-text searched-text
|
||||
:start start
|
||||
:end end}))
|
||||
(mentions/recheck-at-idxs {alias user}))))
|
||||
|
||||
(defn- start-cooldown [{:keys [db]} cooldowns]
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[status-im.chat.models.reactions :as reactions]
|
||||
[status-im.chat.models.message-list :as message-list]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.chat.models.message-seen :as message-seen]))
|
||||
[status-im.chat.models.message-seen :as message-seen]
|
||||
[status-im.chat.models.mentions :as mentions]))
|
||||
|
||||
(defn cursor->clock-value
|
||||
[^js cursor]
|
||||
|
@ -95,11 +96,13 @@
|
|||
(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})
|
||||
(update :users assoc from
|
||||
(mentions/add-searchable-phrases
|
||||
{: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)
|
||||
|
|
|
@ -76,25 +76,33 @@
|
|||
|
||||
(defn get-suggestions [users searched-text]
|
||||
(reduce
|
||||
(fn [acc [k {:keys [alias name nickname] :as user}]]
|
||||
(fn [acc [k {:keys [alias name nickname searchable-phrases] :as user}]]
|
||||
(if-let [match
|
||||
(cond
|
||||
(and nickname
|
||||
(string/starts-with?
|
||||
(string/lower-case nickname)
|
||||
searched-text))
|
||||
(or alias name)
|
||||
(if (seq searchable-phrases)
|
||||
(when (some
|
||||
(fn [s]
|
||||
(string/starts-with?
|
||||
(string/lower-case s)
|
||||
searched-text))
|
||||
searchable-phrases)
|
||||
(or name alias))
|
||||
(cond
|
||||
(and nickname
|
||||
(string/starts-with?
|
||||
(string/lower-case nickname)
|
||||
searched-text))
|
||||
(or name alias)
|
||||
|
||||
(and alias
|
||||
(string/starts-with?
|
||||
(string/lower-case alias)
|
||||
searched-text))
|
||||
alias
|
||||
(and alias
|
||||
(string/starts-with?
|
||||
(string/lower-case alias)
|
||||
searched-text))
|
||||
alias
|
||||
|
||||
(string/starts-with?
|
||||
(string/lower-case name)
|
||||
searched-text)
|
||||
name)]
|
||||
(string/starts-with?
|
||||
(string/lower-case name)
|
||||
searched-text)
|
||||
name))]
|
||||
(assoc acc k (assoc user
|
||||
:match match
|
||||
:searched-text searched-text))
|
||||
|
@ -465,3 +473,17 @@
|
|||
(fx/defn reset-text-input-cursor
|
||||
[_ ref cursor]
|
||||
{::reset-text-input-cursor [ref cursor]})
|
||||
|
||||
(defn add-searchable-phrases
|
||||
[{:keys [alias name nickname] :as user}]
|
||||
(reduce
|
||||
(fn [user s]
|
||||
(if (nil? s)
|
||||
user
|
||||
(let [new-words (concat
|
||||
[s]
|
||||
(rest (string/split s " ")))]
|
||||
(update user :searchable-phrases (fnil concat []) new-words))))
|
||||
user
|
||||
[alias name nickname]))
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
[status-im.transport.message.protocol :as protocol]
|
||||
[status-im.ui.screens.chat.state :as view.state]
|
||||
[status-im.utils.fx :as fx]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.chat.models.mentions :as mentions]))
|
||||
|
||||
(defn- prepare-message
|
||||
[message current-chat?]
|
||||
|
@ -67,11 +68,12 @@
|
|||
(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})})))
|
||||
(mentions/add-searchable-phrases
|
||||
{:alias alias
|
||||
:name (or name alias)
|
||||
:identicon identicon
|
||||
:public-key from
|
||||
:nickname nickname}))})))
|
||||
|
||||
(fx/defn add-received-message
|
||||
[{:keys [db] :as cofx}
|
||||
|
|
|
@ -45,11 +45,12 @@
|
|||
"00000000000000000000000000000000000000000000000000090x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
:cursor-clock-value 9,
|
||||
:users
|
||||
{"from" {:alias "alias",
|
||||
:name "name",
|
||||
:identicon "identicon",
|
||||
:public-key "from"
|
||||
:nickname nil}}}}}}
|
||||
{"from" {:alias "alias",
|
||||
:name "name",
|
||||
:identicon "identicon",
|
||||
:public-key "from"
|
||||
:nickname nil
|
||||
:searchable-phrases ["alias" "name"]}}}}}}
|
||||
(message/add-received-message
|
||||
cofx
|
||||
message)))))
|
||||
|
@ -68,11 +69,12 @@
|
|||
"00000000000000000000000000000000000000000000000000090x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
:cursor-clock-value 9,
|
||||
:users
|
||||
{"from" {:alias "alias",
|
||||
:name "name",
|
||||
:identicon "identicon",
|
||||
:public-key "from"
|
||||
:nickname nil}}}}}}
|
||||
{"from" {:alias "alias",
|
||||
:name "name",
|
||||
:identicon "identicon",
|
||||
:public-key "from"
|
||||
:nickname nil
|
||||
:searchable-phrases ["alias" "name"]}}}}}}
|
||||
(message/add-received-message
|
||||
cofx
|
||||
message)))))
|
||||
|
|
|
@ -42,7 +42,8 @@
|
|||
status-im.ui.screens.keycard.subs
|
||||
status-im.ui.screens.keycard.settings.subs
|
||||
status-im.ui.screens.keycard.pin.subs
|
||||
status-im.ui.screens.keycard.setup.subs))
|
||||
status-im.ui.screens.keycard.setup.subs
|
||||
[status-im.chat.models.mentions :as mentions]))
|
||||
|
||||
;; TOP LEVEL ===========================================================================================================
|
||||
|
||||
|
@ -890,11 +891,12 @@
|
|||
(not (contact.db/blocked? contact)))
|
||||
(let [name (utils/safe-replace name ".stateofus.eth" "")]
|
||||
(assoc acc public-key
|
||||
{:alias alias
|
||||
:name (or name alias)
|
||||
:identicon identicon
|
||||
:nickname nickname
|
||||
:public-key key}))
|
||||
(mentions/add-searchable-phrases
|
||||
{:alias alias
|
||||
:name (or name alias)
|
||||
:identicon identicon
|
||||
:nickname nickname
|
||||
:public-key key})))
|
||||
acc))
|
||||
{}
|
||||
contacts)))
|
||||
|
@ -909,10 +911,11 @@
|
|||
(apply dissoc
|
||||
(-> users
|
||||
(merge contacts)
|
||||
(assoc public-key {:alias name
|
||||
:name (or preferred-name name)
|
||||
:identicon photo-path
|
||||
:public-key public-key}))
|
||||
(assoc public-key (mentions/add-searchable-phrases
|
||||
{:alias name
|
||||
:name (or preferred-name name)
|
||||
:identicon photo-path
|
||||
:public-key public-key})))
|
||||
blocked)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
|
|
Loading…
Reference in New Issue