Add community members to mentionable list (#12926)
This commit is contained in:
parent
29a7e4dc1c
commit
edbb06a7c3
|
@ -9,7 +9,8 @@
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
[quo.react-native :as rn]
|
[quo.react-native :as rn]
|
||||||
[quo.react :as react]))
|
[quo.react :as react]
|
||||||
|
[status-im.multiaccounts.core :as multiaccounts]))
|
||||||
|
|
||||||
(def at-sign "@")
|
(def at-sign "@")
|
||||||
|
|
||||||
|
@ -170,11 +171,55 @@
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(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]))
|
||||||
|
|
||||||
|
(defn add-searchable-phrases-to-contact
|
||||||
|
[{:keys [alias name added? blocked? identicon public-key nickname]} community-chat?]
|
||||||
|
(when (and alias
|
||||||
|
(not (string/blank? alias))
|
||||||
|
(or name
|
||||||
|
nickname
|
||||||
|
added?
|
||||||
|
community-chat?)
|
||||||
|
(not blocked?))
|
||||||
|
(add-searchable-phrases
|
||||||
|
{:alias alias
|
||||||
|
:name (or (utils/safe-replace name ".stateofus.eth" "") alias)
|
||||||
|
:identicon identicon
|
||||||
|
:nickname nickname
|
||||||
|
:public-key public-key})))
|
||||||
|
|
||||||
|
(defn mentionable-commmunity-members [contacts my-public-key community-members]
|
||||||
|
(reduce (fn [acc identity]
|
||||||
|
(let [contact (multiaccounts/contact-by-identity
|
||||||
|
contacts identity)
|
||||||
|
contact (if (string/blank? (:alias contact))
|
||||||
|
(assoc contact :alias
|
||||||
|
(get-in contact [:names :three-words-name]))
|
||||||
|
contact)
|
||||||
|
mentionable-contact (add-searchable-phrases-to-contact
|
||||||
|
contact true)]
|
||||||
|
(if (nil? mentionable-contact) acc
|
||||||
|
(assoc acc identity mentionable-contact))))
|
||||||
|
{}
|
||||||
|
(keys (dissoc community-members my-public-key))))
|
||||||
|
|
||||||
(defn get-mentionable-users
|
(defn get-mentionable-users
|
||||||
[{{:keys [current-chat-id]
|
[{{:keys [current-chat-id]
|
||||||
:contacts/keys [contacts] :as db} :db}]
|
:contacts/keys [contacts] :as db} :db}]
|
||||||
(let [{:keys [chat-type users] :as chat}
|
(let [{:keys [chat-type community-id users] :as chat} (get-in db [:chats current-chat-id])
|
||||||
(get-in db [:chats current-chat-id])
|
{:keys [name preferred-name public-key]} (:multiaccount db)
|
||||||
chat-specific-suggestions
|
chat-specific-suggestions
|
||||||
(cond
|
(cond
|
||||||
(= chat-type constants/private-group-chat-type)
|
(= chat-type constants/private-group-chat-type)
|
||||||
|
@ -200,9 +245,12 @@
|
||||||
current-chat-id
|
current-chat-id
|
||||||
(contact.db/public-key->contact contacts current-chat-id))
|
(contact.db/public-key->contact contacts current-chat-id))
|
||||||
|
|
||||||
:else users)
|
(= chat-type constants/community-chat-type)
|
||||||
{:keys [name preferred-name public-key]}
|
(merge users (mentionable-commmunity-members
|
||||||
(:multiaccount db)]
|
contacts public-key
|
||||||
|
(get-in db [:communities community-id :members])))
|
||||||
|
|
||||||
|
:else users)]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [key {:keys [alias name identicon]}]]
|
(fn [acc [key {:keys [alias name identicon]}]]
|
||||||
(let [name (utils/safe-replace name ".stateofus.eth" "")]
|
(let [name (utils/safe-replace name ".stateofus.eth" "")]
|
||||||
|
@ -634,19 +682,6 @@
|
||||||
[_ ref cursor]
|
[_ ref cursor]
|
||||||
{::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]))
|
|
||||||
|
|
||||||
(defn is-valid-terminating-character? [c]
|
(defn is-valid-terminating-character? [c]
|
||||||
(case c
|
(case c
|
||||||
"\t" true ; tab
|
"\t" true ; tab
|
||||||
|
|
|
@ -19,15 +19,16 @@
|
||||||
{:unread-count (get db :activity.center/notifications-count 0)
|
{:unread-count (get db :activity.center/notifications-count 0)
|
||||||
:notifications (get-in db [:activity.center/notifications :notifications])}
|
:notifications (get-in db [:activity.center/notifications :notifications])}
|
||||||
activities)]
|
activities)]
|
||||||
|
(merge
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-in [:activity.center/notifications :notifications] notifications)
|
(assoc-in [:activity.center/notifications :notifications] notifications)
|
||||||
(assoc :activity.center/notifications-count (max 0 unread-count)))
|
(assoc :activity.center/notifications-count (max 0 unread-count)))}
|
||||||
:dispatch (cond
|
(cond
|
||||||
(= (:view-id db) :notifications-center)
|
(= (:view-id db) :notifications-center)
|
||||||
[:mark-all-activity-center-notifications-as-read]
|
{:dispatch [:mark-all-activity-center-notifications-as-read]}
|
||||||
|
|
||||||
(= (:view-id db) :chat)
|
(= (:view-id db) :chat)
|
||||||
[:accept-all-activity-center-notifications-from-chat (:current-chat-id db)])}))
|
{:dispatch [:accept-all-activity-center-notifications-from-chat (:current-chat-id db)]}))))
|
||||||
|
|
||||||
(fx/defn get-activity-center-notifications-count
|
(fx/defn get-activity-center-notifications-count
|
||||||
{:events [:get-activity-center-notifications-count]}
|
{:events [:get-activity-center-notifications-count]}
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
[status-im.utils.security :as security]
|
[status-im.utils.security :as security]
|
||||||
[status-im.wallet.db :as wallet.db]
|
[status-im.wallet.db :as wallet.db]
|
||||||
[status-im.wallet.utils :as wallet.utils]
|
[status-im.wallet.utils :as wallet.utils]
|
||||||
[status-im.utils.utils :as utils]
|
|
||||||
status-im.ui.screens.keycard.subs
|
status-im.ui.screens.keycard.subs
|
||||||
[status-im.chat.models.mentions :as mentions]
|
[status-im.chat.models.mentions :as mentions]
|
||||||
[status-im.notifications.core :as notifications]
|
[status-im.notifications.core :as notifications]
|
||||||
|
@ -1400,22 +1399,11 @@
|
||||||
:<- [:contacts/contacts]
|
:<- [:contacts/contacts]
|
||||||
(fn [contacts]
|
(fn [contacts]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [acc [key {:keys [alias name added? blocked? identicon public-key nickname]}]]
|
(fn [acc [key contact]]
|
||||||
(if (and alias
|
(let [mentionable-contact (mentions/add-searchable-phrases-to-contact
|
||||||
(not= alias "")
|
contact false)]
|
||||||
(or name
|
(if (nil? mentionable-contact) acc
|
||||||
nickname
|
(assoc acc key mentionable-contact))))
|
||||||
added?)
|
|
||||||
(not blocked?))
|
|
||||||
(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})))
|
|
||||||
acc))
|
|
||||||
{}
|
{}
|
||||||
contacts)))
|
contacts)))
|
||||||
|
|
||||||
|
@ -1425,7 +1413,9 @@
|
||||||
:<- [:chats/mentionable-contacts]
|
:<- [:chats/mentionable-contacts]
|
||||||
:<- [:contacts/blocked-set]
|
:<- [:contacts/blocked-set]
|
||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
(fn [[{:keys [chat-id users contacts community-id chat-type] :as chat} mentionable-contacts blocked {:keys [name preferred-name public-key]}]]
|
:<- [:contacts/contacts]
|
||||||
|
(fn [[{:keys [chat-id users contacts community-id chat-type] :as chat}
|
||||||
|
mentionable-contacts blocked {:keys [public-key]} my-contacts]]
|
||||||
(let [community-members @(re-frame/subscribe [:communities/community-members
|
(let [community-members @(re-frame/subscribe [:communities/community-members
|
||||||
community-id])
|
community-id])
|
||||||
contacts-with-one-to-one (if (= chat-type constants/one-to-one-chat-type)
|
contacts-with-one-to-one (if (= chat-type constants/one-to-one-chat-type)
|
||||||
|
@ -1436,14 +1426,13 @@
|
||||||
members-left (into #{} (filter #(group-chat/member-removed? chat %) (keys users)))
|
members-left (into #{} (filter #(group-chat/member-removed? chat %) (keys users)))
|
||||||
filtered-contacts (select-keys contacts-with-one-to-one (if (nil? community-id)
|
filtered-contacts (select-keys contacts-with-one-to-one (if (nil? community-id)
|
||||||
(distinct (concat (seq contacts) (keys users) [chat-id]))
|
(distinct (concat (seq contacts) (keys users) [chat-id]))
|
||||||
(keys community-members)))]
|
(keys community-members)))
|
||||||
|
mentionable-commmunity-members (mentions/mentionable-commmunity-members
|
||||||
|
my-contacts public-key community-members)]
|
||||||
(apply dissoc
|
(apply dissoc
|
||||||
(-> users
|
(-> users
|
||||||
(merge filtered-contacts)
|
(merge filtered-contacts)
|
||||||
(assoc public-key (mentions/add-searchable-phrases
|
(merge mentionable-commmunity-members))
|
||||||
{:alias name
|
|
||||||
:name (or preferred-name name)
|
|
||||||
:public-key public-key})))
|
|
||||||
(conj (concat blocked members-left) public-key)))))
|
(conj (concat blocked members-left) public-key)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
|
|
Loading…
Reference in New Issue