[#11212] Mention suggestions based on names parts

This commit is contained in:
Roman Volosovskyi 2020-09-30 14:02:44 +03:00
parent c866082cde
commit 6cf3a6a98e
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
6 changed files with 88 additions and 54 deletions

View File

@ -52,11 +52,13 @@
;; 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)}))
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]

View File

@ -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
(update :users assoc from
(mentions/add-searchable-phrases
{:alias alias
:name (or name alias)
:identicon identicon
:public-key from
:nickname nickname})
:nickname nickname}))
(or (nil? last-clock-value)
(> last-clock-value clock-value))
(assoc :last-clock-value clock-value)

View File

@ -76,14 +76,22 @@
(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
(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 alias name)
(or name alias)
(and alias
(string/starts-with?
@ -94,7 +102,7 @@
(string/starts-with?
(string/lower-case name)
searched-text)
name)]
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]))

View File

@ -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
(mentions/add-searchable-phrases
{:alias alias
:name (or name alias)
:identicon identicon
:public-key from
:nickname nickname})})))
:nickname nickname}))})))
(fx/defn add-received-message
[{:keys [db] :as cofx}

View File

@ -49,7 +49,8 @@
:name "name",
:identicon "identicon",
:public-key "from"
:nickname nil}}}}}}
:nickname nil
:searchable-phrases ["alias" "name"]}}}}}}
(message/add-received-message
cofx
message)))))
@ -72,7 +73,8 @@
:name "name",
:identicon "identicon",
:public-key "from"
:nickname nil}}}}}}
:nickname nil
:searchable-phrases ["alias" "name"]}}}}}}
(message/add-received-message
cofx
message)))))

View File

@ -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
(mentions/add-searchable-phrases
{:alias alias
:name (or name alias)
:identicon identicon
:nickname nickname
:public-key key}))
:public-key key})))
acc))
{}
contacts)))
@ -909,10 +911,11 @@
(apply dissoc
(-> users
(merge contacts)
(assoc public-key {:alias name
(assoc public-key (mentions/add-searchable-phrases
{:alias name
:name (or preferred-name name)
:identicon photo-path
:public-key public-key}))
:public-key public-key})))
blocked)))
(re-frame/reg-sub