Skip to content

Commit

Permalink
fix(mention)_: async call for mention suggestion (#21171)
Browse files Browse the repository at this point in the history
* fix(mention)_: ensure async call work as expected

status-im/status-go@81cfce7...b2c2e40

* chore_: remove call-time and rename

* chore_: update status go version
  • Loading branch information
qfrank authored Sep 19, 2024
1 parent f606dc0 commit 2e61f94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
31 changes: 20 additions & 11 deletions src/legacy/status_im/chat/models/mentions.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns legacy.status-im.chat.models.mentions
(:require
[clojure.set :as set]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
(:require [clojure.set :as set]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))

(defn- transfer-input-segments
[segments]
Expand Down Expand Up @@ -59,18 +58,20 @@

(defn- transfer-mention-result
[result]
(let [{:keys [input-segments mentionable-users state chat-id new-text]}
(let [{:keys [input-segments mentionable-users state chat-id new-text call-id]}
(set/rename-keys result
{:InputSegments :input-segments
:MentionSuggestions :mentionable-users
:MentionState :state
:ChatID :chat-id
:NewText :new-text})]
:NewText :new-text
:CallID :call-id})]
{:chat-id chat-id
:input-segments (transfer-input-segments input-segments)
:mentionable-users (rename-mentionable-users mentionable-users)
:state (rename-state state)
:new-text new-text}))
:new-text new-text
:call-id call-id}))

(rf/defn on-error
{:events [:mention/on-error]}
Expand Down Expand Up @@ -104,10 +105,12 @@
{:events [:mention/on-change-text]}
[{:keys [db]} text]
(let [chat-id (:current-chat-id db)
params [chat-id text]
call-id (inc (get-in db [:chat/inputs chat-id :current-mentions-call-id] 0))
params [chat-id text call-id]
method "wakuext_chatMentionOnChangeText"]
(log/debug "[mentions] on-change-text" {:params params})
{:json-rpc/call [{:method method
{:db (assoc-in db [:chat/inputs chat-id :current-mentions-call-id] call-id)
:json-rpc/call [{:method method
:params params
:on-success #(rf/dispatch [:mention/on-change-text-success %])
:on-error #(rf/dispatch [:mention/on-error
Expand All @@ -118,8 +121,14 @@
{:events [:mention/on-change-text-success]}
[{:keys [db]} result]
(log/debug "[mentions] on-change-text-success" {:result result})
(let [{:keys [chat-id mentionable-users]} (transfer-mention-result result)]
{:db (assoc-in db [:chats/mention-suggestions chat-id] mentionable-users)}))
(let [{:keys [state chat-id mentionable-users
input-segments call-id]} (transfer-mention-result result)
current-mentions-call-id (get-in db [:chat/inputs chat-id :current-mentions-call-id])]
(when (= call-id current-mentions-call-id)
{:db (-> db
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments)
(assoc-in [:chats/mention-suggestions chat-id] mentionable-users)
(assoc-in [:chats/mentions chat-id :mentions] state))})))

(rf/defn on-select-mention-success
{:events [:mention/on-select-mention-success]}
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "f859b58c3896523b2fb9a09b3e5c1cedb04f959b",
"commit-sha1": "f859b58c3896523b2fb9a09b3e5c1cedb04f959b",
"src-sha256": "009nd47aajng5k7wrcqv5zvvzniaswqi706fpkbbjhqziympi1s1"
"version": "6e5a32c02215f36509b21645a32361fca85b10f7",
"commit-sha1": "6e5a32c02215f36509b21645a32361fca85b10f7",
"src-sha256": "0wp0a7xp7vw64kkiyrpkswb37dfabj1al4a4nrb71iyfrcyrzscl"
}

0 comments on commit 2e61f94

Please sign in to comment.