From 2e61f94d84edcb2a14763d1119779971091029e3 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 19 Sep 2024 13:24:48 +0800 Subject: [PATCH] fix(mention)_: async call for mention suggestion (#21171) * fix(mention)_: ensure async call work as expected https://github.com/status-im/status-go/compare/81cfce70...b2c2e407 * chore_: remove call-time and rename * chore_: update status go version --- .../status_im/chat/models/mentions.cljs | 31 ++++++++++++------- status-go-version.json | 6 ++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/legacy/status_im/chat/models/mentions.cljs b/src/legacy/status_im/chat/models/mentions.cljs index f637190fbf0..2a8db93264a 100644 --- a/src/legacy/status_im/chat/models/mentions.cljs +++ b/src/legacy/status_im/chat/models/mentions.cljs @@ -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] @@ -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]} @@ -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 @@ -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]} diff --git a/status-go-version.json b/status-go-version.json index bdf66482876..6d747486bb3 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "f859b58c3896523b2fb9a09b3e5c1cedb04f959b", - "commit-sha1": "f859b58c3896523b2fb9a09b3e5c1cedb04f959b", - "src-sha256": "009nd47aajng5k7wrcqv5zvvzniaswqi706fpkbbjhqziympi1s1" + "version": "6e5a32c02215f36509b21645a32361fca85b10f7", + "commit-sha1": "6e5a32c02215f36509b21645a32361fca85b10f7", + "src-sha256": "0wp0a7xp7vw64kkiyrpkswb37dfabj1al4a4nrb71iyfrcyrzscl" }