[fix] recover lost contact requests and following messages
- Fetch discovery topic from offline inboxing - Send ContactRequestResponse on discovery channel with new-key message for recovery of invited contacts Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
df901e8748
commit
b7ab49d305
|
@ -3,13 +3,14 @@
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.transport.utils :as web3.utils]
|
[status-im.transport.utils :as transport.utils]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[day8.re-frame.async-flow-fx]))
|
[day8.re-frame.async-flow-fx]
|
||||||
|
[status-im.constants :as constants]))
|
||||||
|
|
||||||
(defn- parse-json
|
(defn- parse-json
|
||||||
;; NOTE(dmitryn) Expects JSON response like:
|
;; NOTE(dmitryn) Expects JSON response like:
|
||||||
|
@ -48,13 +49,13 @@
|
||||||
{:first-dispatch [:inbox/get-sym-key]
|
{:first-dispatch [:inbox/get-sym-key]
|
||||||
:rules [{:when :seen-both?
|
:rules [{:when :seen-both?
|
||||||
:events [:inbox/get-sym-key-success :inbox/connection-success]
|
:events [:inbox/get-sym-key-success :inbox/connection-success]
|
||||||
:dispatch [:inbox/request-messages]}]})
|
:dispatch [:inbox/request-messages {:discover? true}]}]})
|
||||||
|
|
||||||
(defn recover-offline-inbox-flow []
|
(defn recover-offline-inbox-flow []
|
||||||
{:first-dispatch [:inbox/fetch-peers]
|
{:first-dispatch [:inbox/fetch-peers]
|
||||||
:rules [{:when :seen?
|
:rules [{:when :seen?
|
||||||
:events :inbox/connection-success
|
:events :inbox/connection-success
|
||||||
:dispatch [:inbox/request-messages]}]})
|
:dispatch [:inbox/request-messages {:discover? true}]}]})
|
||||||
|
|
||||||
(defn initialize-offline-inbox
|
(defn initialize-offline-inbox
|
||||||
"Initialises offline inbox if inboxing enabled in config"
|
"Initialises offline inbox if inboxing enabled in config"
|
||||||
|
@ -96,11 +97,11 @@
|
||||||
|
|
||||||
(defn registered-peer? [peers enode]
|
(defn registered-peer? [peers enode]
|
||||||
(let [peer-ids (into #{} (map :id) peers)
|
(let [peer-ids (into #{} (map :id) peers)
|
||||||
enode-id (web3.utils/extract-enode-id enode)]
|
enode-id (transport.utils/extract-enode-id enode)]
|
||||||
(contains? peer-ids enode-id)))
|
(contains? peer-ids enode-id)))
|
||||||
|
|
||||||
(defn mark-trusted-peer [web3 enode success-fn error-fn]
|
(defn mark-trusted-peer [web3 enode success-fn error-fn]
|
||||||
(.markTrustedPeer (web3.utils/shh web3)
|
(.markTrustedPeer (transport.utils/shh web3)
|
||||||
enode
|
enode
|
||||||
(fn [err resp]
|
(fn [err resp]
|
||||||
(if-not err
|
(if-not err
|
||||||
|
@ -116,7 +117,7 @@
|
||||||
(doseq [topic topics]
|
(doseq [topic topics]
|
||||||
(let [opts (assoc opts :topic topic)]
|
(let [opts (assoc opts :topic topic)]
|
||||||
(log/info "offline inbox: request-messages args" (pr-str opts))
|
(log/info "offline inbox: request-messages args" (pr-str opts))
|
||||||
(.requestMessages (web3.utils/shh web3)
|
(.requestMessages (transport.utils/shh web3)
|
||||||
(clj->js opts)
|
(clj->js opts)
|
||||||
(fn [err resp]
|
(fn [err resp]
|
||||||
(if-not err
|
(if-not err
|
||||||
|
@ -215,18 +216,20 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:inbox/request-messages
|
:inbox/request-messages
|
||||||
(fn [{:keys [db now]} [_ {:keys [from topics]}]]
|
(fn [{:keys [db now]} [_ {:keys [from topics discover?]}]]
|
||||||
(let [web3 (:web3 db)
|
(let [web3 (:web3 db)
|
||||||
wnode (get-current-wnode-address db)
|
wnode (get-current-wnode-address db)
|
||||||
topics (or topics
|
topics (or topics
|
||||||
(map #(:topic %) (vals (:transport/chats db))))
|
(map #(:topic %) (vals (:transport/chats db))))
|
||||||
from (or from (:inbox/last-request db) nil)
|
from (or from (:inbox/last-request db) nil)
|
||||||
sym-key-id (:inbox/sym-key-id db)]
|
sym-key-id (:inbox/sym-key-id db)]
|
||||||
{::request-messages {:wnode wnode
|
{::request-messages {:wnode wnode
|
||||||
:topics topics
|
:topics (if discover?
|
||||||
;;TODO (yenda) fix from, right now mailserver is dropping us
|
(conj topics (transport.utils/get-topic constants/contact-discovery))
|
||||||
;;when we send a requestMessage with a from field
|
topics)
|
||||||
;;:from from
|
;;TODO (yenda) fix from, right now mailserver is dropping us
|
||||||
|
;;when we send a requestMessage with a from field
|
||||||
|
;;:from from
|
||||||
:sym-key-id sym-key-id
|
:sym-key-id sym-key-id
|
||||||
:web3 web3}
|
:web3 web3}
|
||||||
:db (assoc db :inbox/last-request (quot now 1000))})))
|
:db (assoc db :inbox/last-request (quot now 1000))})))
|
||||||
|
|
|
@ -45,10 +45,12 @@
|
||||||
(protocol/init-chat chat-id topic)
|
(protocol/init-chat chat-id topic)
|
||||||
#_(protocol/requires-ack message-id chat-id))))
|
#_(protocol/requires-ack message-id chat-id))))
|
||||||
(receive [this chat-id signature {:keys [db] :as cofx}]
|
(receive [this chat-id signature {:keys [db] :as cofx}]
|
||||||
(let [message-id (transport.utils/message-id this)]
|
(let [message-id (transport.utils/message-id this)
|
||||||
|
topic (transport.utils/get-topic chat-id)]
|
||||||
(when (protocol/is-new? message-id)
|
(when (protocol/is-new? message-id)
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
#_(protocol/ack message-id chat-id)
|
#_(protocol/ack message-id chat-id)
|
||||||
|
{:dispatch [:inbox/request-messages {:topics [topic]}]}
|
||||||
(contacts/receive-contact-request signature
|
(contacts/receive-contact-request signature
|
||||||
this))))))
|
this))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue