Move installations to status-go
This commit moves the management of installations to status-go, and migrates the data from realm. Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
e1bcaebd2c
commit
138ade3b8d
|
@ -1,3 +1,3 @@
|
|||
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
|
||||
|
||||
1bhwwmypb64kf180kp634jwfppd3h6yda3qyh2icj3lz7y10pgvp
|
||||
0hrjppsayih655a7cz3cdl3yp5ff98cxxcrmzwlzsfaqj82jk7jp
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead
|
||||
|
||||
v0.27.0-beta.1
|
||||
v0.28.0-beta.0
|
||||
|
|
|
@ -99,7 +99,6 @@ var TopLevel = {
|
|||
"DesktopNotification" : function () {},
|
||||
"DeviceEventEmitter" : function () {},
|
||||
"Dimensions" : function () {},
|
||||
"disableInstallation" : function () {},
|
||||
"dispatch" : function () {},
|
||||
"displayNotification" : function () {},
|
||||
"dividedBy" : function () {},
|
||||
|
@ -108,7 +107,6 @@ var TopLevel = {
|
|||
"dy" : function () {},
|
||||
"ease" : function () {},
|
||||
"Easing" : function () {},
|
||||
"enableInstallation" : function () {},
|
||||
"enableVibration" : function () {},
|
||||
"encode" : function () {},
|
||||
"encodeURIComponent" : function () {},
|
||||
|
|
|
@ -1015,45 +1015,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
|||
StatusThreadPoolExecutor.getInstance().execute(r);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void enableInstallation(final String installationId, final Callback callback) {
|
||||
Log.d(TAG, "enableInstallation");
|
||||
if (!checkAvailability()) {
|
||||
callback.invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String result = Statusgo.enableInstallation(installationId);
|
||||
|
||||
callback.invoke(result);
|
||||
}
|
||||
};
|
||||
|
||||
StatusThreadPoolExecutor.getInstance().execute(r);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void disableInstallation(final String installationId, final Callback callback) {
|
||||
Log.d(TAG, "disableInstallation");
|
||||
if (!checkAvailability()) {
|
||||
callback.invoke(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String result = Statusgo.disableInstallation(installationId);
|
||||
|
||||
callback.invoke(result);
|
||||
}
|
||||
};
|
||||
|
||||
StatusThreadPoolExecutor.getInstance().execute(r);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void updateMailservers(final String enodes, final Callback callback) {
|
||||
|
|
|
@ -330,22 +330,6 @@ void RCTStatus::extractGroupMembershipSignatures(QString signatures, double call
|
|||
}, signatures, callbackId);
|
||||
}
|
||||
|
||||
void RCTStatus::enableInstallation(QString installationId, double callbackId) {
|
||||
Q_D(RCTStatus);
|
||||
QtConcurrent::run([&](QString installationId, double callbackId) {
|
||||
const char* result = EnableInstallation(installationId.toUtf8().data());
|
||||
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
|
||||
}, installationId, callbackId);
|
||||
}
|
||||
|
||||
void RCTStatus::disableInstallation(QString installationId, double callbackId) {
|
||||
Q_D(RCTStatus);
|
||||
QtConcurrent::run([&](QString installationId, double callbackId) {
|
||||
const char* result = DisableInstallation(installationId.toUtf8().data());
|
||||
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
|
||||
}, installationId, callbackId);
|
||||
}
|
||||
|
||||
void RCTStatus::setAdjustResize() {
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ public:
|
|||
Q_INVOKABLE void signMessage(QString rpcParams, double callbackId);
|
||||
Q_INVOKABLE void signGroupMembership(QString content, double callbackId);
|
||||
Q_INVOKABLE void extractGroupMembershipSignatures(QString signatures, double callbackId);
|
||||
Q_INVOKABLE void enableInstallation(QString installationId, double callbackId);
|
||||
Q_INVOKABLE void disableInstallation(QString installationId, double callbackId);
|
||||
Q_INVOKABLE void updateMailservers(QString enodes, double callbackId);
|
||||
Q_INVOKABLE void getNodesFromContract(QString url, QString address, double callbackId);
|
||||
Q_INVOKABLE void chaosModeUpdate(bool on, double callbackId);
|
||||
|
|
|
@ -425,30 +425,6 @@ RCT_EXPORT_METHOD(extractGroupMembershipSignatures:(NSString *)content
|
|||
callback(@[result]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - EnableInstallation
|
||||
//////////////////////////////////////////////////////////////////// enableInstallation
|
||||
RCT_EXPORT_METHOD(enableInstallation:(NSString *)content
|
||||
callback:(RCTResponseSenderBlock)callback) {
|
||||
#if DEBUG
|
||||
NSLog(@"EnableInstallation() method called");
|
||||
#endif
|
||||
NSString *result = StatusgoEnableInstallation(content);
|
||||
callback(@[result]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - DisableInstallation
|
||||
//////////////////////////////////////////////////////////////////// disableInstallation
|
||||
RCT_EXPORT_METHOD(disableInstallation:(NSString *)content
|
||||
callback:(RCTResponseSenderBlock)callback) {
|
||||
#if DEBUG
|
||||
NSLog(@"DisableInstallation() method called");
|
||||
#endif
|
||||
NSString *result = StatusgoDisableInstallation(content);
|
||||
callback(@[result]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#pragma mark - only android methods
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -140,6 +140,7 @@
|
|||
{:events [:accounts.login.callback/login-success]
|
||||
:interceptors [(re-frame/inject-cofx :web3/get-web3)
|
||||
(re-frame/inject-cofx :data-store/get-all-mailservers)
|
||||
(re-frame/inject-cofx :data-store/get-all-installations)
|
||||
(re-frame/inject-cofx :data-store/transport)
|
||||
(re-frame/inject-cofx :data-store/mailserver-topics)]}
|
||||
[{:keys [db web3] :as cofx} login-result]
|
||||
|
|
|
@ -27,3 +27,11 @@
|
|||
[installation-id]
|
||||
(save {:installation-id installation-id
|
||||
:enabled? false}))
|
||||
|
||||
(defn delete
|
||||
"Returns tx function for deleting an installation"
|
||||
[id]
|
||||
(fn [realm]
|
||||
(core/delete realm
|
||||
(core/get-by-field realm :installation :installation-id (name id)))))
|
||||
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
"eth_newFilter" {:subscription? true}
|
||||
"eth_syncing" {}
|
||||
"net_version" {}
|
||||
"shhext_enableInstallation" {}
|
||||
"shhext_disableInstallation" {}
|
||||
"shhext_getOurInstallations" {}
|
||||
"shhext_setInstallationMetadata" {}
|
||||
"shhext_loadFilters" {}
|
||||
"shhext_loadFilter" {}
|
||||
"shhext_removeFilters" {}
|
||||
"status_joinPublicChat" {}
|
||||
"status_chats" {}
|
||||
"status_startOneOnOneChat" {}
|
||||
|
|
|
@ -1645,6 +1645,16 @@
|
|||
(fn [cofx _]
|
||||
(pairing/send-installation-messages cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:pairing.callback/get-our-installations-success
|
||||
(fn [cofx [_ installations]]
|
||||
(pairing/load-installations cofx installations)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:pairing.callback/set-installation-metadata-success
|
||||
(fn [cofx [_ installation-id metadata]]
|
||||
(pairing/update-installation cofx installation-id metadata)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:set-initial-props
|
||||
(fn [cofx [_ initial-props]]
|
||||
|
@ -1969,4 +1979,4 @@
|
|||
(commands.sending/send public-key
|
||||
request-command
|
||||
{:asset (name symbol)
|
||||
:amount (str (money/internal->formatted amount symbol decimals))})))))
|
||||
:amount (str (money/internal->formatted amount symbol decimals))})))))
|
||||
|
|
|
@ -237,7 +237,6 @@
|
|||
{:notifications/get-fcm-token nil}
|
||||
(initialize-account-db address)
|
||||
(contact/load-contacts)
|
||||
(pairing/load-installations)
|
||||
#(when (dev-mode? %)
|
||||
(models.dev-server/start))
|
||||
(browser/initialize-browsers)
|
||||
|
|
|
@ -101,16 +101,6 @@
|
|||
|
||||
(def sign-group-membership native-module/sign-group-membership)
|
||||
|
||||
(def enable-installation native-module/enable-installation)
|
||||
|
||||
(def load-filters native-module/load-filters)
|
||||
|
||||
(def load-filter native-module/load-filter)
|
||||
|
||||
(def remove-filters native-module/remove-filters)
|
||||
|
||||
(def disable-installation native-module/disable-installation)
|
||||
|
||||
(def update-mailservers native-module/update-mailservers)
|
||||
|
||||
(def rooted-device? native-module/rooted-device?)
|
||||
|
|
|
@ -144,38 +144,6 @@
|
|||
(when (status)
|
||||
(.signGroupMembership (status) content callback)))
|
||||
|
||||
(defn enable-installation [installation-id callback]
|
||||
(when (status)
|
||||
(.enableInstallation (status) installation-id callback)))
|
||||
|
||||
(defn disable-installation [installation-id callback]
|
||||
(when (status)
|
||||
(.disableInstallation (status) installation-id callback)))
|
||||
|
||||
(defn load-filters [chats callback]
|
||||
(let [params {:jsonrpc "2.0"
|
||||
:id 2
|
||||
:method "shhext_loadFilters"
|
||||
:params [chats]}
|
||||
payload (.stringify js/JSON (clj->js params))]
|
||||
(call-private-rpc payload callback)))
|
||||
|
||||
(defn load-filter [chat callback]
|
||||
(let [params {:jsonrpc "2.0"
|
||||
:id 2
|
||||
:method "shhext_loadFilter"
|
||||
:params [chat]}
|
||||
payload (.stringify js/JSON (clj->js params))]
|
||||
(call-private-rpc payload callback)))
|
||||
|
||||
(defn remove-filters [chats callback]
|
||||
(let [params {:jsonrpc "2.0"
|
||||
:id 2
|
||||
:method "shhext_removeFilters"
|
||||
:params [chats]}
|
||||
payload (.stringify js/JSON (clj->js params))]
|
||||
(call-private-rpc payload callback)))
|
||||
|
||||
(defn is24Hour []
|
||||
(when (status)
|
||||
(.-is24Hour (status))))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[clojure.string :as string]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.contact.device-info :as device-info]
|
||||
[status-im.contact.db :as contact.db]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
|
@ -12,7 +13,6 @@
|
|||
[status-im.accounts.model :as accounts.model]
|
||||
[status-im.transport.message.protocol :as protocol]
|
||||
[status-im.data-store.installations :as data-store.installations]
|
||||
[status-im.native-module.core :as native-module]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.contact.core :as contact]
|
||||
[status-im.transport.filters.core :as transport.filters]
|
||||
|
@ -20,17 +20,57 @@
|
|||
[status-im.data-store.accounts :as data-store.accounts]
|
||||
[status-im.transport.message.pairing :as transport.pairing]))
|
||||
|
||||
(defn enable-installation-rpc [installation-id on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_enableInstallation"
|
||||
:params [installation-id]
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
(defn disable-installation-rpc [installation-id on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_disableInstallation"
|
||||
:params [installation-id]
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
(defn set-installation-metadata-rpc [installation-id metadata on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_setInstallationMetadata"
|
||||
:params [installation-id metadata]
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
(defn get-our-installations-rpc [on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_getOurInstallations"
|
||||
:params []
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
(def contact-batch-n 4)
|
||||
|
||||
(defn- parse-response [response-js]
|
||||
(-> response-js
|
||||
js/JSON.parse
|
||||
(js->clj :keywordize-keys true)))
|
||||
(defn compare-installation
|
||||
"Sort installations, first by our installation-id, then on whether is
|
||||
enabled, and last on timestamp value"
|
||||
[our-installation-id a b]
|
||||
(cond
|
||||
(= our-installation-id (:installation-id a))
|
||||
-1
|
||||
(= our-installation-id (:installation-id b))
|
||||
1
|
||||
:else
|
||||
(let [enabled-compare (compare (:enabled? b)
|
||||
(:enabled? a))]
|
||||
(if (not= 0 enabled-compare)
|
||||
enabled-compare
|
||||
(compare (:timestamp b)
|
||||
(:timestamp a))))))
|
||||
|
||||
(defn sort-installations
|
||||
[our-installation-id installations]
|
||||
(sort (partial compare-installation our-installation-id) installations))
|
||||
|
||||
(defn pair-installation [cofx]
|
||||
(let [fcm-token (get-in cofx [:db :notifications :fcm-token])
|
||||
installation-name (get-in cofx [:db :account/account :installation-name])
|
||||
installation-id (get-in cofx [:db :account/account :installation-id])
|
||||
installation-name (get-in cofx [:db :pairing/installations installation-id :name])
|
||||
device-type utils.platform/os]
|
||||
(protocol/send (transport.pairing/PairInstallation. installation-id device-type installation-name fcm-token) nil cofx)))
|
||||
|
||||
|
@ -91,28 +131,48 @@
|
|||
:on-cancel #(re-frame/dispatch [:pairing.ui/prompt-dismissed])
|
||||
:on-accept #(re-frame/dispatch [:pairing.ui/prompt-accepted])}}))
|
||||
|
||||
(fx/defn upsert-installation [{:keys [db] :as cofx} {:keys [installation-id] :as new-installation}]
|
||||
(let [success-event [:message/messages-persisted [(or (:dedup-id cofx) (:js-obj cofx))]]
|
||||
old-installation (get-in db [:pairing/installations installation-id])
|
||||
updated-installation (merge old-installation new-installation)]
|
||||
{:db (assoc-in db
|
||||
[:pairing/installations installation-id]
|
||||
updated-installation)
|
||||
:data-store/tx [{:transaction (data-store.installations/save updated-installation)
|
||||
:success-event success-event}]}))
|
||||
(fx/defn set-name
|
||||
"Set the name of the device"
|
||||
[{:keys [db] :as cofx} installation-name]
|
||||
(let [fcm-token (get-in cofx [:db :notifications :fcm-token])
|
||||
our-installation-id (get-in db [:account/account :installation-id])]
|
||||
{:pairing/set-installation-metadata [[our-installation-id {:name installation-name
|
||||
:deviceType utils.platform/os
|
||||
:fcmToken fcm-token}]]}))
|
||||
|
||||
(fx/defn migrate-installations
|
||||
"Take the realm installations and move them to status-go, also move installation-name
|
||||
to status-go, clean up after so it is run only once"
|
||||
[{:keys [db] :as cofx} installations]
|
||||
(let [installation-name (get-in db [:account/account :installation-name])]
|
||||
(fx/merge cofx
|
||||
{:pairing/set-installation-metadata
|
||||
(map (fn [{:keys [installation-id name device-type fcm-token]}]
|
||||
[installation-id {:name name
|
||||
:deviceType device-type
|
||||
:fcmToken fcm-token}])
|
||||
installations)}
|
||||
#(when-not (string/blank? installation-name)
|
||||
(set-name % installation-name))
|
||||
#(when-not (string/blank? installation-name)
|
||||
(let [new-account (dissoc (:account/account (:db %)) :installation-name)]
|
||||
{:db (assoc (:db %) :account/account new-account)
|
||||
:data-store/base-tx [(data-store.accounts/save-account-tx new-account)]})))))
|
||||
|
||||
(fx/defn init [cofx old-installations]
|
||||
(fx/merge cofx
|
||||
{:pairing/get-our-installations []}
|
||||
(migrate-installations old-installations)))
|
||||
|
||||
(defn handle-bundles-added [{:keys [db] :as cofx} bundle]
|
||||
(let [installation-id (:installationID bundle)
|
||||
new-installation {:installation-id installation-id
|
||||
:has-bundle? true}]
|
||||
(let [installation-id (:installationID bundle)]
|
||||
(when
|
||||
(and (= (:identity bundle)
|
||||
(accounts.model/current-public-key cofx))
|
||||
(not= (get-in db [:account/account :installation-id]) installation-id)
|
||||
(not (get-in db [:pairing/installations installation-id])))
|
||||
(not= (get-in db [:account/account :installation-id]) installation-id))
|
||||
(fx/merge cofx
|
||||
(upsert-installation new-installation)
|
||||
#(when-not (or (get-in % [:db :pairing/prompt-user-pop-up])
|
||||
(init [])
|
||||
#(when-not (or (:pairing/prompt-user-pop-up db)
|
||||
(= :installations (:view-id db)))
|
||||
(prompt-user-on-new-installation %))))))
|
||||
|
||||
|
@ -159,41 +219,54 @@
|
|||
(fx/defn enable [{:keys [db]} installation-id]
|
||||
{:db (assoc-in db
|
||||
[:pairing/installations installation-id :enabled?]
|
||||
true)
|
||||
:data-store/tx [(data-store.installations/enable installation-id)]})
|
||||
true)})
|
||||
|
||||
(fx/defn disable [{:keys [db]} installation-id]
|
||||
{:db (assoc-in db
|
||||
[:pairing/installations installation-id :enabled?]
|
||||
false)
|
||||
:data-store/tx [(data-store.installations/disable installation-id)]})
|
||||
false)})
|
||||
|
||||
(defn handle-enable-installation-response
|
||||
(defn handle-enable-installation-response-success
|
||||
"Callback to dispatch on enable signature response"
|
||||
[installation-id response-js]
|
||||
(let [{:keys [error]} (parse-response response-js)]
|
||||
(if error
|
||||
(re-frame/dispatch [:pairing.callback/enable-installation-failed error])
|
||||
(re-frame/dispatch [:pairing.callback/enable-installation-success installation-id]))))
|
||||
[installation-id]
|
||||
(re-frame/dispatch [:pairing.callback/enable-installation-success installation-id]))
|
||||
|
||||
(defn handle-disable-installation-response
|
||||
(defn handle-disable-installation-response-success
|
||||
"Callback to dispatch on disable signature response"
|
||||
[installation-id response-js]
|
||||
(let [{:keys [error]} (parse-response response-js)]
|
||||
(if error
|
||||
(re-frame/dispatch [:pairing.callback/disable-installation-failed error])
|
||||
(re-frame/dispatch [:pairing.callback/disable-installation-success installation-id]))))
|
||||
[installation-id]
|
||||
(re-frame/dispatch [:pairing.callback/disable-installation-success installation-id]))
|
||||
|
||||
(defn handle-set-installation-metadata-response-success
|
||||
"Callback to dispatch on set-installation-metadata response"
|
||||
[installation-id metadata]
|
||||
(re-frame/dispatch [:pairing.callback/set-installation-metadata-success installation-id metadata]))
|
||||
|
||||
(defn handle-get-our-installations-response-success
|
||||
"Callback to dispatch on get-our-installation response"
|
||||
[result]
|
||||
(re-frame/dispatch [:pairing.callback/get-our-installations-success result]))
|
||||
|
||||
(defn enable-installation! [installation-id]
|
||||
(native-module/enable-installation installation-id
|
||||
(partial handle-enable-installation-response installation-id)))
|
||||
(enable-installation-rpc installation-id
|
||||
(partial handle-enable-installation-response-success installation-id)
|
||||
nil))
|
||||
|
||||
(defn disable-installation! [installation-id]
|
||||
(native-module/disable-installation installation-id
|
||||
(partial handle-disable-installation-response installation-id)))
|
||||
(disable-installation-rpc installation-id
|
||||
(partial handle-disable-installation-response-success installation-id)
|
||||
nil))
|
||||
|
||||
(defn set-installation-metadata! [installation-id metadata]
|
||||
(set-installation-metadata-rpc installation-id
|
||||
metadata
|
||||
(partial handle-set-installation-metadata-response-success installation-id metadata)
|
||||
nil))
|
||||
|
||||
(defn get-our-installations []
|
||||
(get-our-installations-rpc handle-get-our-installations-response-success nil))
|
||||
|
||||
(defn enable-fx [cofx installation-id]
|
||||
(if (< (count (filter :enabled? (get-in cofx [:db :pairing/installations]))) config/max-installations)
|
||||
(if (< (count (filter :enabled? (vals (get-in cofx [:db :pairing/installations])))) (inc config/max-installations))
|
||||
{:pairing/enable-installation installation-id}
|
||||
{:utils/show-popup {:title (i18n/label :t/pairing-maximum-number-reached-title)
|
||||
|
||||
|
@ -210,6 +283,16 @@
|
|||
:pairing/disable-installation
|
||||
disable-installation!)
|
||||
|
||||
(re-frame/reg-fx
|
||||
:pairing/set-installation-metadata
|
||||
(fn [pairs]
|
||||
(doseq [[installation-id metadata] pairs]
|
||||
(set-installation-metadata! installation-id metadata))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:pairing/get-our-installations
|
||||
get-our-installations)
|
||||
|
||||
(fx/defn send-sync-installation [cofx payload]
|
||||
(let [{:keys [web3]} (:db cofx)
|
||||
current-public-key (accounts.model/current-public-key cofx)]
|
||||
|
@ -301,23 +384,31 @@
|
|||
device-type]} timestamp sender]
|
||||
(if (and (= sender (accounts.model/current-public-key cofx))
|
||||
(not= (get-in db [:account/account :installation-id]) installation-id))
|
||||
(let [installation {:installation-id installation-id
|
||||
:name name
|
||||
:fcm-token fcm-token
|
||||
:device-type device-type
|
||||
:last-paired timestamp}]
|
||||
(upsert-installation cofx installation))
|
||||
{:pairing/set-installation-metadata [[installation-id {:name name
|
||||
:deviceType device-type
|
||||
:fcmToken fcm-token}]]}
|
||||
(confirm-message-processed cofx (or (:dedup-id cofx)
|
||||
(:js-obj cofx)))))
|
||||
|
||||
(fx/defn set-name [{:keys [db] :as cofx} installation-name]
|
||||
(let [new-account (assoc (get-in cofx [:db :account/account]) :installation-name installation-name)]
|
||||
{:db (assoc db :account/account new-account)
|
||||
:data-store/base-tx [(data-store.accounts/save-account-tx new-account)]}))
|
||||
(fx/defn update-installation [{:keys [db]} installation-id metadata]
|
||||
{:db (update-in db [:pairing/installations installation-id]
|
||||
assoc
|
||||
:name (:name metadata)
|
||||
:device-type (:deviceType metadata)
|
||||
:fcmToken (:fcmToken metadata))
|
||||
;; we count it as migrated, and delete it from realm
|
||||
:data-store/tx [(data-store.installations/delete installation-id)]})
|
||||
|
||||
(fx/defn load-installations [{:keys [db all-installations]}]
|
||||
(fx/defn load-installations [{:keys [db]} installations]
|
||||
{:db (assoc db :pairing/installations (reduce
|
||||
(fn [acc {:keys [installation-id] :as i}]
|
||||
(assoc acc installation-id i))
|
||||
(fn [acc {:keys [metadata id enabled] :as i}]
|
||||
(assoc acc id
|
||||
{:installation-id id
|
||||
:name (:name metadata)
|
||||
:timestamp (:timestamp metadata)
|
||||
:device-type (:deviceType metadata)
|
||||
:fcm-token (:fcmToken metadata)
|
||||
:enabled? enabled}))
|
||||
{}
|
||||
all-installations))})
|
||||
installations))})
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
[re-frame.core :as re-frame]
|
||||
[status-im.accounts.model :as accounts.model]
|
||||
[status-im.accounts.db :as accounts.db]
|
||||
[status-im.pairing.core :as pairing]
|
||||
[status-im.browser.core :as browser]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.chat.commands.input :as commands.input]
|
||||
|
@ -921,13 +922,15 @@
|
|||
|
||||
;;PAIRING ==============================================================================================================
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
:pairing/installations
|
||||
:<- [:get-pairing-installations]
|
||||
(fn [installations]
|
||||
:<- [:pairing/installation-id]
|
||||
(fn [[installations installation-id]]
|
||||
(->> installations
|
||||
vals
|
||||
(sort-by (comp unchecked-negate :last-paired)))))
|
||||
(pairing/sort-installations installation-id))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:pairing/installation-id
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
[status-im.mailserver.core :as mailserver]
|
||||
[status-im.transport.message.core :as message]
|
||||
[status-im.transport.filters.core :as transport.filters]
|
||||
[status-im.pairing.core :as pairing]
|
||||
[status-im.utils.publisher :as publisher]
|
||||
[status-im.utils.fx :as fx]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
|
@ -38,10 +39,11 @@
|
|||
- adding fixed shh discovery filter
|
||||
- restoring existing symetric keys along with their unique filters
|
||||
- (optionally) initializing mailserver"
|
||||
[{:keys [db web3] :as cofx}]
|
||||
[{:keys [db web3 all-installations] :as cofx}]
|
||||
(fx/merge cofx
|
||||
(fetch-node-info-fx)
|
||||
(transport.filters/load-filters)
|
||||
(pairing/init all-installations)
|
||||
(publisher/start-fx)
|
||||
(mailserver/connect-to-mailserver)
|
||||
(message/resend-contact-messages [])))
|
||||
|
|
|
@ -7,12 +7,24 @@
|
|||
[status-im.utils.fx :as fx]
|
||||
[status-im.transport.utils :as utils]
|
||||
[status-im.data-store.accounts :as data-store.accounts]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.accounts.model :as accounts.model]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.mailserver.topics :as mailserver.topics]
|
||||
[status-im.mailserver.core :as mailserver]))
|
||||
|
||||
(defn load-filters-rpc [chats on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_loadFilters"
|
||||
:params [chats]
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
(defn remove-filters-rpc [chats on-success on-failure]
|
||||
(json-rpc/call {:method "shhext_removeFilters"
|
||||
:params [chats]
|
||||
:on-success on-success
|
||||
:on-failure on-failure}))
|
||||
|
||||
;; fx functions
|
||||
|
||||
(defn load-filter-fx [web3 filters]
|
||||
|
@ -360,10 +372,10 @@
|
|||
(fn [filters]
|
||||
(log/debug "removing filters" filters)
|
||||
(stop-watching! (map :filter filters))
|
||||
(status/remove-filters
|
||||
(remove-filters-rpc
|
||||
(map ->remove-filter-request filters)
|
||||
(handlers/response-handler #(filters-removed! filters)
|
||||
#(log/error "remove-filters: failed error" %)))))
|
||||
#(filters-removed! filters)
|
||||
#(log/error "remove-filters: failed error" %))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:filters/stop-filters
|
||||
|
@ -377,8 +389,8 @@
|
|||
(when (seq ops)
|
||||
(let [web3 (first (peek ops))
|
||||
filters (mapcat peek ops)]
|
||||
(status/load-filters
|
||||
(load-filters-rpc
|
||||
filters
|
||||
(handlers/response-handler #(add-filters! web3
|
||||
(map responses->filters %))
|
||||
#(log/error "load-filters: failed error" %)))))))
|
||||
#(add-filters! web3
|
||||
(map responses->filters %))
|
||||
#(log/error "load-filters: failed error" %))))))
|
||||
|
|
|
@ -76,19 +76,17 @@
|
|||
[react/text {:style styles/qr-code-copy-text}
|
||||
(i18n/label :copy-qr)]]]]]))
|
||||
|
||||
(defn installations-section [your-installation-id
|
||||
your-installation-name
|
||||
installations]
|
||||
(defn installations-section [installations]
|
||||
[react/view
|
||||
(if (string/blank? your-installation-name)
|
||||
(if (string/blank? (-> installations first :name))
|
||||
[pairing.views/edit-installation-name]
|
||||
[react/view
|
||||
[pairing.views/pair-this-device]
|
||||
[pairing.views/info-section]
|
||||
[pairing.views/sync-devices]
|
||||
[react/view {:style pairing.styles/installation-list}
|
||||
[pairing.views/your-device your-installation-id your-installation-name]
|
||||
(for [installation installations]
|
||||
[pairing.views/your-device (first installations)]
|
||||
(for [installation (rest installations)]
|
||||
^{:key (:installation-id installation)}
|
||||
[react/view {:style {:margin-bottom 10}}
|
||||
(pairing.views/render-row installation)])]])])
|
||||
|
@ -222,14 +220,9 @@
|
|||
:on-value-change #(re-frame/dispatch [:accounts.ui/toggle-device-to-device (not pfs?)])}]]])))
|
||||
|
||||
(views/defview installations []
|
||||
(views/letsubs [installations [:pairing/installations]
|
||||
installation-id [:pairing/installation-id]
|
||||
installation-name [:pairing/installation-name]]
|
||||
(views/letsubs [installations [:pairing/installations]]
|
||||
[react/scroll-view
|
||||
(installations-section
|
||||
installation-id
|
||||
installation-name
|
||||
installations)]))
|
||||
(installations-section installations)]))
|
||||
|
||||
(views/defview backup-recovery-phrase []
|
||||
[profile.recovery/backup-seed])
|
||||
|
|
|
@ -96,17 +96,19 @@
|
|||
(i18n/label :t/syncing-devices)
|
||||
(i18n/label :t/sync-all-devices))]]]]])
|
||||
|
||||
(defn your-device [installation-id installation-name]
|
||||
(defn your-device [{:keys [installation-id name device-type]}]
|
||||
[react/view {:style styles/installation-item}
|
||||
[react/view {:style (styles/pairing-button true)}
|
||||
[icons/icon (if utils.platform/desktop?
|
||||
:main-icons/desktop
|
||||
:main-icons/mobile)
|
||||
[icons/icon (if (= "desktop"
|
||||
device-type)
|
||||
:main-icons/desktop
|
||||
:main-icons/mobile)
|
||||
|
||||
(icon-style (styles/pairing-button-icon true))]]
|
||||
[react/view {:style styles/pairing-actions-text}
|
||||
[react/view
|
||||
[react/text (str
|
||||
installation-name
|
||||
name
|
||||
" ("
|
||||
(i18n/label :t/you)
|
||||
", "
|
||||
|
@ -128,13 +130,13 @@
|
|||
(icon-style (styles/pairing-button-icon enabled?))]]
|
||||
[react/view {:style styles/pairing-actions-text}
|
||||
[react/view
|
||||
[react/text (if (string/blank? name)
|
||||
(str
|
||||
[react/text (str
|
||||
(if (string/blank? name)
|
||||
(i18n/label :t/pairing-no-info)
|
||||
" ("
|
||||
(subs installation-id 0 5)
|
||||
")")
|
||||
name)]]]
|
||||
name)
|
||||
" ("
|
||||
(subs installation-id 0 5)
|
||||
")")]]]
|
||||
[react/view
|
||||
(if utils.platform/ios?
|
||||
;; On IOS switches seems to be broken, they take up value of dev-mode? (so if dev mode is on they all show to be on).
|
||||
|
@ -145,11 +147,11 @@
|
|||
:value enabled?
|
||||
:on-value-change (partial toggle-enabled! installation-id enabled?)}])]]])
|
||||
|
||||
(defn render-rows [installation-id installation-name installations]
|
||||
(defn render-rows [installations]
|
||||
[react/scroll-view {:style styles/wrapper}
|
||||
[your-device installation-id installation-name]
|
||||
(when (seq installations)
|
||||
[list/flat-list {:data installations
|
||||
[your-device (first installations)]
|
||||
(when (seq (rest installations))
|
||||
[list/flat-list {:data (rest installations)
|
||||
:default-separator? false
|
||||
:key-fn :installation-id
|
||||
:render-fn render-row}])])
|
||||
|
@ -182,26 +184,24 @@
|
|||
[react/touchable-highlight {:on-press #(.openURL (react/linking) "https://status.im/tutorials/pairing.html")}
|
||||
[react/text {:style styles/info-section-text} (i18n/label :t/learn-more)]]])
|
||||
|
||||
(defn installations-list [installation-id installation-name installations]
|
||||
(defn installations-list [installations]
|
||||
[react/view {:style styles/installation-list}
|
||||
[react/view {:style styles/paired-devices-title}
|
||||
[react/text (i18n/label :t/paired-devices)]]
|
||||
(render-rows installation-id installation-name installations)])
|
||||
(render-rows installations)])
|
||||
|
||||
(views/defview installations []
|
||||
(views/letsubs [installation-id [:pairing/installation-id]
|
||||
installation-name [:pairing/installation-name]
|
||||
installations [:pairing/installations]]
|
||||
(views/letsubs [installations [:pairing/installations]]
|
||||
[react/view {:flex 1}
|
||||
[status-bar/status-bar]
|
||||
[toolbar/toolbar {}
|
||||
toolbar/default-nav-back
|
||||
[toolbar/content-title (i18n/label :t/devices)]]
|
||||
[react/scroll-view {:style {:background-color :white}}
|
||||
(if (string/blank? installation-name)
|
||||
(if (and false (string/blank? (-> installations first :name)))
|
||||
[edit-installation-name]
|
||||
[react/view
|
||||
[pair-this-device]
|
||||
[info-section]
|
||||
[installations-list installation-id installation-name installations]])]
|
||||
[installations-list installations]])]
|
||||
(when (seq installations) [footer syncing])]))
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
(def ^:private mergable-keys
|
||||
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
||||
:shh/post :filters/load-filters
|
||||
:pairing/set-installation-metadata
|
||||
:shh/send-direct-message :shh/remove-filter
|
||||
:shh/generate-sym-key-from-password :transport/confirm-messages-processed
|
||||
:group-chats/extract-membership-signature :utils/dispatch-later :json-rpc/call})
|
||||
|
|
|
@ -229,17 +229,12 @@
|
|||
(testing "not coming from us"
|
||||
(is (not (:db (pairing/handle-pair-installation cofx pair-message 1 "not-us")))))
|
||||
(testing "coming from us"
|
||||
(is (= {"1" {:has-bundle? true
|
||||
:installation-id "1"
|
||||
:fcm-token "fcm-token"
|
||||
:name "name"
|
||||
:last-paired 1
|
||||
:device-type "ios"}
|
||||
"2" {:has-bundle? false
|
||||
:installation-id "2"}}
|
||||
(get-in
|
||||
(pairing/handle-pair-installation cofx pair-message 1 "us")
|
||||
[:db :pairing/installations]))))))
|
||||
(is (= [["1"
|
||||
{:name "name"
|
||||
:fcmToken "fcm-token"
|
||||
:deviceType "ios"}]]
|
||||
(:pairing/set-installation-metadata
|
||||
(pairing/handle-pair-installation cofx pair-message 1 "us")))))))
|
||||
|
||||
(deftest sync-installation-messages-test
|
||||
(testing "it creates a sync installation message"
|
||||
|
@ -306,10 +301,7 @@
|
|||
expected {"installation-1" installation-1
|
||||
"installation-2" {:has-bundle? true
|
||||
:installation-id "installation-2"}}]
|
||||
(is (= expected (get-in (pairing/handle-bundles-added cofx new-installation) [:db :pairing/installations])))))
|
||||
(testing "already existing installation"
|
||||
(let [old-installation {:identity "us" :installationID "installation-1"}]
|
||||
(is (not (pairing/handle-bundles-added cofx old-installation)))))
|
||||
(is (:pairing/get-our-installations (pairing/handle-bundles-added cofx new-installation)))))
|
||||
(testing "not from us"
|
||||
(let [new-installation {:identity "not-us" :installationID "does-not-matter"}]
|
||||
(is (not (pairing/handle-bundles-added cofx new-installation)))))))
|
||||
|
@ -321,3 +313,23 @@
|
|||
(testing "has paired devices"
|
||||
(is (pairing/has-paired-installations? {:db {:pairing/installations {"1" {}
|
||||
"2" {:enabled? true}}}}))))
|
||||
|
||||
(deftest sort-installations
|
||||
(let [id "0"
|
||||
expected [{:installation-id id
|
||||
:timestamp (rand-int 200)
|
||||
:enabled? false}
|
||||
{:installation-id "1"
|
||||
:timestamp 3
|
||||
:enabled? true}
|
||||
{:installation-id "2"
|
||||
:timestamp 2
|
||||
:enabled? true}
|
||||
{:installation-id "3"
|
||||
:timestamp 10
|
||||
:enabled? false}
|
||||
{:installation-id "4"
|
||||
:timestamp 9
|
||||
:enabled? false}]]
|
||||
(is (= expected (pairing/sort-installations id (shuffle expected))))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue