diff --git a/src/status_im/chat/models/mentions.cljs b/src/status_im/chat/models/mentions.cljs index dc8a6ca112..fcaec1797f 100644 --- a/src/status_im/chat/models/mentions.cljs +++ b/src/status_im/chat/models/mentions.cljs @@ -195,6 +195,10 @@ :name name})) {} group-contacts)) + (= chat-type constants/one-to-one-chat-type) + (assoc users + current-chat-id + (contact.db/public-key->contact contacts current-chat-id)) :else users) {:keys [name preferred-name public-key]} diff --git a/src/status_im/contact/db.cljs b/src/status_im/contact/db.cljs index ec664bd539..3e496d0324 100644 --- a/src/status_im/contact/db.cljs +++ b/src/status_im/contact/db.cljs @@ -18,8 +18,8 @@ (defn public-key->contact [contacts public-key] (when public-key - (get contacts public-key - (public-key->new-contact public-key)))) + (or (get contacts public-key) + (public-key->new-contact public-key)))) (defn- contact-by-address [[addr contact] address] (when (ethereum/address= addr address) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 718b892b62..e826d9854e 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -121,7 +121,6 @@ (reg-root-key-sub :camera-roll-photos :camera-roll-photos) (reg-root-key-sub :group-chat/invitations :group-chat/invitations) (reg-root-key-sub :chats/mention-suggestions :chats/mention-suggestions) -(reg-root-key-sub :chats/cursor :chats/cursor) (reg-root-key-sub :chat/inputs-with-mentions :chat/inputs-with-mentions) (reg-root-key-sub :inactive-chat-id :inactive-chat-id) ;;browser @@ -1065,15 +1064,20 @@ :<- [:chats/mentionable-contacts] :<- [:contacts/blocked-set] :<- [:multiaccount] - (fn [[{:keys [users]} contacts blocked {:keys [name preferred-name public-key]}]] - (apply dissoc - (-> users - (merge contacts) - (assoc public-key (mentions/add-searchable-phrases - {:alias name - :name (or preferred-name name) - :public-key public-key}))) - blocked))) + (fn [[{:keys [chat-id users chat-type]} contacts blocked {:keys [name preferred-name public-key]}]] + (let [contacts-with-one-to-one (if (= chat-type constants/one-to-one-chat-type) + (assoc contacts chat-id (get contacts chat-id (-> chat-id + contact.db/public-key->new-contact + contact.db/enrich-contact))) + contacts)] + (apply dissoc + (-> users + (merge contacts-with-one-to-one) + (assoc public-key (mentions/add-searchable-phrases + {:alias name + :name (or preferred-name name) + :public-key public-key}))) + blocked)))) (re-frame/reg-sub :chat/mention-suggestions @@ -1082,13 +1086,6 @@ (fn [[chat-id mentions]] (take 15 (get mentions chat-id)))) -(re-frame/reg-sub - :chat/cursor - :<- [:chats/current-chat-id] - :<- [:chats/cursor] - (fn [[chat-id cursor]] - (get cursor chat-id))) - (re-frame/reg-sub :chat/input-with-mentions :<- [:chats/current-chat-id] diff --git a/src/status_im/ui/screens/chat/components/input.cljs b/src/status_im/ui/screens/chat/components/input.cljs index 761967ba9e..33f34fcd2a 100644 --- a/src/status_im/ui/screens/chat/components/input.cljs +++ b/src/status_im/ui/screens/chat/components/input.cljs @@ -79,15 +79,7 @@ :accessibility-label :send-message-button :color (styles/send-icon-color)}]]]) -(defn selection [cursor] - ;; NOTE(rasom): In case if mention is added on pressing suggestion and - ;; it is placed inside some text we have to specify `:selection` on - ;; Android to ensure that cursor is added after the mention, not after - ;; the last char in input. On iOS it works that way without this code - (when (and cursor platform/android?) - (clj->js {:start cursor :end cursor}))) - -(defn on-selection-change [cursor timeout-id last-text-change mentionable-users args] +(defn on-selection-change [timeout-id last-text-change mentionable-users args] (let [selection (.-selection ^js (.-nativeEvent ^js args)) start (.-start selection) end (.-end selection)] @@ -113,11 +105,7 @@ (re-frame/dispatch [::mentions/on-selection-change {:start start :end end} - mentionable-users])) - ;; NOTE(rasom): we have to reset `cursor` value when user starts using - ;; text-input because otherwise cursor will stay in the same position - (when (and cursor platform/android?) - (re-frame/dispatch [::mentions/clear-cursor])))) + mentionable-users])))) (defn on-change [on-text-change last-text-change timeout-id mentionable-users args] (let [text (.-text ^js (.-nativeEvent ^js args))] @@ -155,8 +143,7 @@ (defn text-input [{:keys [cooldown-enabled? input-with-mentions on-text-change set-active-panel text-input-ref]}] - (let [cursor @(re-frame/subscribe [:chat/cursor]) - mentionable-users @(re-frame/subscribe [:chats/mentionable-users]) + (let [mentionable-users @(re-frame/subscribe [:chats/mentionable-users]) timeout-id (atom nil) last-text-change (atom nil)] [rn/view {:style (styles/text-input-wrapper)} @@ -178,25 +165,18 @@ (i18n/label :t/type-a-message)) :underline-color-android :transparent :auto-capitalize :sentences - :selection (selection cursor) - :on-selection-change (partial on-selection-change - cursor timeout-id last-text-change mentionable-users) + :on-selection-change (partial on-selection-change timeout-id last-text-change mentionable-users) :on-change (partial on-change on-text-change last-text-change timeout-id mentionable-users) :on-text-input (partial on-text-input mentionable-users)} - ;; NOTE(rasom): reduce was used instead of for here because although - ;; each text component was given a unique id it still would mess with - ;; colors on Android. In case if entire component is built without lists - ;; inside it works just fine on both platforms. - (reduce - (fn [acc [type text]] - (conj - acc - [rn/text (when (= type :mention) - {:style {:color "#0DA4C9"}}) - text])) - [:<>] - input-with-mentions)]])) + (for [[idx [type text]] (map-indexed + (fn [idx item] + [idx item]) + input-with-mentions)] + ^{:key (str idx "_" type "_" text)} + [rn/text (when (= type :mention) + {:style {:color "#0DA4C9"}}) + text])]])) (defn mention-item [[public-key {:keys [alias name nickname] :as user}] _ _ text-input-ref]