|
41 | 41 |
|
42 | 42 | (rf/defn select-mention
|
43 | 43 | {:events [:chat.ui/select-mention]}
|
44 |
| - [{:keys [db] :as cofx} text-input-ref {:keys [primary-name searched-text match] :as user}] |
45 |
| - (let [chat-id (:current-chat-id db) |
46 |
| - new-text (mentions/new-input-text-with-mention cofx user) |
47 |
| - at-sign-idx (get-in db [:chats/mentions chat-id :mentions :at-sign-idx]) |
48 |
| - cursor (+ at-sign-idx (count primary-name) 2)] |
49 |
| - (rf/merge |
50 |
| - cofx |
51 |
| - {:db (-> db |
52 |
| - (assoc-in [:chats/cursor chat-id] cursor) |
53 |
| - (assoc-in [:chats/mention-suggestions chat-id] nil)) |
54 |
| - :set-text-input-value [chat-id new-text text-input-ref]} |
55 |
| - (set-chat-input-text new-text chat-id) |
56 |
| - ;; NOTE(rasom): Some keyboards do not react on selection property passed to |
57 |
| - ;; text input (specifically Samsung keyboard with predictive text set on). |
58 |
| - ;; In this case, if the user continues typing after the programmatic change, |
59 |
| - ;; the new text is added to the last known cursor position before |
60 |
| - ;; programmatic change. By calling `reset-text-input-cursor` we force the |
61 |
| - ;; keyboard's cursor position to be changed before the next input. |
62 |
| - (mentions/reset-text-input-cursor text-input-ref cursor) |
63 |
| - ;; NOTE(roman): on-text-input event is not dispatched when we change input |
64 |
| - ;; programmatically, so we have to call `on-text-input` manually |
65 |
| - (mentions/on-text-input |
66 |
| - (let [match-len (count match) |
67 |
| - start (inc at-sign-idx) |
68 |
| - end (+ start match-len)] |
69 |
| - {:new-text match |
70 |
| - :previous-text searched-text |
71 |
| - :start start |
72 |
| - :end end})) |
73 |
| - (mentions/recheck-at-idxs {primary-name user})))) |
| 44 | + [{:keys [db] :as cofx} text-input-ref {:keys [primary-name searched-text match public-key] :as user}] |
| 45 | + (let [chat-id (:current-chat-id db) |
| 46 | + text (get-in db [:chat/inputs chat-id :input-text]) |
| 47 | + method "wakuext_chatMentionNewInputTextWithMention" |
| 48 | + params [chat-id text primary-name]] |
| 49 | + {:json-rpc/call [{:method method |
| 50 | + :params params |
| 51 | + :on-success #(rf/dispatch [:mention/on-new-input-text-with-mentions-success % |
| 52 | + primary-name text-input-ref match searched-text |
| 53 | + public-key]) |
| 54 | + :on-error #(rf/dispatch [:mention/on-error |
| 55 | + {:method method |
| 56 | + :params params} %])}]})) |
74 | 57 |
|
75 | 58 | (rf/defn disable-chat-cooldown
|
76 | 59 | "Turns off chat cooldown (protection against message spamming)"
|
|
182 | 165 | (rf/merge cofx
|
183 | 166 | {:set-text-input-value [current-chat-id ""]}
|
184 | 167 | (clean-input current-chat-id)
|
185 |
| - (mentions/clear-mentions) |
186 |
| - (mentions/clear-cursor)))) |
| 168 | + (mentions/clear-mentions)))) |
187 | 169 |
|
188 | 170 | (rf/defn send-messages
|
189 | 171 | [{:keys [db] :as cofx} input-text current-chat-id]
|
|
251 | 233 | [{{:keys [current-chat-id] :as db} :db :as cofx}]
|
252 | 234 | (let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id])
|
253 | 235 | editing-message (:editing-message metadata)
|
254 |
| - input-text-with-mentions (mentions/check-mentions cofx input-text)] |
255 |
| - (rf/merge cofx |
256 |
| - (if editing-message |
257 |
| - (send-edited-message input-text-with-mentions editing-message) |
258 |
| - (send-messages input-text-with-mentions current-chat-id)) |
259 |
| - (mentions/clear-mentions) |
260 |
| - (mentions/clear-cursor)))) |
| 236 | + method "wakuext_chatMentionCheckMentions" |
| 237 | + params [current-chat-id input-text]] |
| 238 | + {:json-rpc/call [{:method method |
| 239 | + :params params |
| 240 | + :on-error #(rf/dispatch [:mention/on-error {:method method :params params} %]) |
| 241 | + :on-success #(rf/dispatch [:mention/on-check-mentions-success |
| 242 | + current-chat-id |
| 243 | + editing-message |
| 244 | + input-text |
| 245 | + %])}]})) |
| 246 | + |
| 247 | +(rf/defn on-check-mentions-success |
| 248 | + {:events [:mention/on-check-mentions-success]} |
| 249 | + [{:keys [db] :as cofx} current-chat-id editing-message input-text new-text] |
| 250 | + (log/debug "[mentions] on-check-mentions-success" |
| 251 | + {:chat-id current-chat-id |
| 252 | + :editing-message editing-message |
| 253 | + :input-text input-text |
| 254 | + :new-text new-text}) |
| 255 | + (rf/merge cofx |
| 256 | + (if editing-message |
| 257 | + (send-edited-message new-text editing-message) |
| 258 | + (send-messages new-text current-chat-id)))) |
261 | 259 |
|
262 | 260 | (rf/defn send-contact-request
|
263 | 261 | {:events [:contacts/send-contact-request]}
|
|
271 | 269 | :on-error #(log/warn "failed to send a contact request" %)
|
272 | 270 | :on-success #(re-frame/dispatch [:transport/message-sent %])}]}
|
273 | 271 | (mentions/clear-mentions)
|
274 |
| - (mentions/clear-cursor) |
275 | 272 | (clean-input (:current-chat-id db))))
|
276 | 273 |
|
277 | 274 | (rf/defn cancel-contact-request
|
|
282 | 279 | (rf/merge cofx
|
283 | 280 | {:db (assoc-in db [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)}
|
284 | 281 | (mentions/clear-mentions)
|
285 |
| - (mentions/clear-cursor) |
286 | 282 | (clean-input (:current-chat-id db)))))
|
287 | 283 |
|
288 | 284 | (rf/defn chat-send-sticker
|
|
0 commit comments