Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed Jun 10, 2019
1 parent 0e7f73f commit 011a431
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 413 deletions.
2 changes: 1 addition & 1 deletion STATUS_GO_SHA256
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead

0049i6znvl45hc651bqyzwgmzlv0fp40maggfjsrv13q5avd0g6d
0kxiw130lf4yf9kk0zcs60k58ycd88khwqy1wqvlskj0yqsbmy8k
2 changes: 1 addition & 1 deletion STATUS_GO_VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## DO NOT EDIT THIS FILE BY HAND. USE `scripts/update-status-go.sh <tag>` instead

v0.25.0-beta.1
v0.26.0-alpha.38
4 changes: 2 additions & 2 deletions env/dev/env/config.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns env.config)

(def figwheel-urls {:android "ws://localhost:3449/figwheel-ws",
:ios "ws://192.168.0.9:3449/figwheel-ws",
(def figwheel-urls {:android "ws://10.0.3.2:3449/figwheel-ws",
:ios "ws://192.168.56.1:3449/figwheel-ws",
:desktop "ws://localhost:3449/figwheel-ws"}
)
2 changes: 1 addition & 1 deletion mobile_files/package.json.orig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"string_decoder": "0.10.31",
"text-encoding": "^0.6.4",
"url": "0.10.3",
"web3": "git+https://github.com/status-im/web3.js.git#0.20.2-status",
"web3": "git+https://github.com/status-im/web3.js.git#0.20.3-status.alpha.3",
"web3-utils": "1.0.0-beta.36"
}
}
4 changes: 2 additions & 2 deletions mobile_files/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7081,9 +7081,9 @@ web3-utils@1.0.0-beta.36:
underscore "1.8.3"
utf8 "2.1.1"

"web3@git+https://github.com/status-im/web3.js.git#0.20.2-status":
"web3@git+https://github.com/status-im/web3.js.git#0.20.3-status.alpha.3":
version "0.20.1"
resolved "git+https://github.com/status-im/web3.js.git#958dbabff2c77615e23f5de678a6fae0b0d70147"
resolved "git+https://github.com/status-im/web3.js.git#29677754c8b87c55c828df2694e35b0b760dca5f"
dependencies:
bignumber.js "git+https://github.com/status-im/bignumber.js.git#v4.0.2-status"
crypto-js "^3.1.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,4 +1133,64 @@ Map<String, Object> getConstants() {
public void isDeviceRooted(final Callback callback) {
callback.invoke(rootedDevice);
}

@ReactMethod
public void loadFilters(final String chats, final Callback callback) {
Log.d(TAG, "loadFilters");
if (!checkAvailability()) {
callback.invoke(false);
return;
}

Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.loadFilters(chats);

callback.invoke(res);
}
};

StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void loadFilter(final String chat, final Callback callback) {
Log.d(TAG, "loadFilter");
if (!checkAvailability()) {
callback.invoke(false);
return;
}

Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.loadFilter(chat);

callback.invoke(res);
}
};

StatusThreadPoolExecutor.getInstance().execute(r);
}

@ReactMethod
public void removeFilter(final String chat, final Callback callback) {
Log.d(TAG, "removeFilter");
if (!checkAvailability()) {
callback.invoke(false);
return;
}

Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.removeFilter(chat);

callback.invoke(res);
}
};

StatusThreadPoolExecutor.getInstance().execute(r);
}
}
10 changes: 2 additions & 8 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,16 @@
(log/error "can't remove a chat:" error))}]}
(navigation/navigate-to-cofx :home {}))
(fx/merge cofx
;; TODO: There's a race condition here, as the removal of the filter (async)
;; is done at the same time as the removal of the chat, so a message
;; might come between and restore the chat. Multiple way to handle this
;; (remove chat only after the filter has been removed, probably the safest,
;; flag the chat to ignore new messages, change receive method for public/group chats)
;; For now to keep the code simplier and avoid significant changes, best to leave as it is.
#(when (public-chat? % chat-id)
(transport.chat/unsubscribe-from-chat % chat-id))
#(when (group-chat? % chat-id)
(mailserver/remove-chat-from-mailserver-topic % chat-id))
(mailserver/remove-gaps chat-id)
(mailserver/remove-range chat-id)
(deactivate-chat chat-id)
(clear-history chat-id)
#(when (one-to-one-chat? % chat-id)
(contact-code/stop-listening % chat-id))
#(when (public-chat? % chat-id)
(transport.chat/unsubscribe-from-chat % chat-id))
(navigation/navigate-to-cofx :home {}))))

(defn- unread-messages-number [chats]
Expand Down
18 changes: 0 additions & 18 deletions src/status_im/contact/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,6 @@
{:db (assoc-in db [:contacts/new-identity] "")}
(upsert-contact contact)))))

(fx/defn add-contacts-filter [{:keys [db]} public-key action]
(when (not= (get-in db [:account/account :public-key]) public-key)
(let [current-public-key (get-in db [:account/account :public-key])]
{:db
(cond-> db
config/partitioned-topic-enabled?
(assoc :filters/after-adding-discovery-filter
{:action action
:public-key public-key}))

:shh/add-discovery-filters
{:web3 (:web3 db)
:private-key-id current-public-key
:topics [{:topic (transport.topic/partitioned-topic-hash public-key)
:chat-id public-key
:minPow 1
:callback (constantly nil)}]}})))

(defn handle-contact-update
[public-key
timestamp
Expand Down
48 changes: 4 additions & 44 deletions src/status_im/contact_code/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
(str pk "-contact-code"))

(fx/defn listen [cofx chat-id]
(transport.public-chat/join-public-chat
(transport.public-chat/join-one-to-one-chat
cofx
(topic chat-id)))
chat-id))

(fx/defn listen-to-chat
"For a one-to-one chat, listen to the pk of the user, for a group chat
Expand Down Expand Up @@ -47,52 +47,12 @@
(and is-active
(contains? members-joined my-public-key)
(contains? members their-public-key)))
(vals (:chats db)))
their-topic (topic their-public-key)]
(vals (:chats db)))]
(when (and (not (contact.db/active? db their-public-key))
(not= my-public-key their-public-key)
(not (get-in db [:chats their-public-key :is-active]))
(empty? active-group-chats))
(fx/merge
cofx
(mailserver/remove-gaps their-topic)
(mailserver/remove-range their-topic)
(transport.chat/unsubscribe-from-chat their-topic)))))
(transport.chat/unsubscribe-from-chat their-public-key)))))

;; Publish contact code every 12hrs
(def publish-contact-code-interval (* 12 60 60 1000))

(fx/defn init [cofx]
(log/debug "initializing contact-code")
(let [current-public-key (accounts.db/current-public-key cofx)]
(listen cofx current-public-key)))

(defn publish! [{:keys [web3 now] :as cofx}]
(let [current-public-key (accounts.db/current-public-key cofx)
chat-id (topic current-public-key)
peers-count (:peers-count @re-frame.db/app-db)
last-published (get-in
@re-frame.db/app-db
[:account/account :last-published-contact-code])]
(when (and (pos? peers-count)
(< publish-contact-code-interval
(- now last-published)))

(let [message {:chat chat-id
:sig current-public-key
:payload ""}]
(shh/send-public-message!
web3
message
[:contact-code.callback/contact-code-published]
:contact-code.callback/contact-code-publishing-failed)))))

(fx/defn published [{:keys [now db] :as cofx}]
(let [new-account (assoc (:account/account db)
:last-published-contact-code
now)]
{:db (assoc db :account/account new-account)
:data-store/base-tx [(data-store.accounts/save-account-tx new-account)]}))

(fx/defn publishing-failed [cofx]
(log/warn "failed to publish contact-code"))
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@
(def v9 (update v8 :properties
dissoc
:ack :seen :pending-ack :pending-send))
(def v10 (update v9 :properties dissoc :sym-key-id :sym-key))
19 changes: 2 additions & 17 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
[status-im.chat.models.input :as chat.input]
[status-im.chat.models.loading :as chat.loading]
[status-im.chat.models.message :as chat.message]
[status-im.contact-code.core :as contact-code]
[status-im.contact-recovery.core :as contact-recovery]
[status-im.contact.block :as contact.block]
[status-im.contact.core :as contact]
Expand Down Expand Up @@ -1712,9 +1711,7 @@
:contact.ui/add-to-contact-pressed
[(re-frame/inject-cofx :random-id-generator)]
(fn [cofx [_ public-key]]
(if config/partitioned-topic-enabled?
(contact/add-contacts-filter cofx public-key :add-contact)
(contact/add-contact cofx public-key))))
(contact/add-contact cofx public-key)))

(handlers/register-handler-fx
:contact.ui/block-contact-pressed
Expand Down Expand Up @@ -1745,9 +1742,7 @@
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}}
(fx/merge cofx
fx
(if config/partitioned-topic-enabled?
(contact/add-contacts-filter contact-identity :open-chat)
(chat/start-chat contact-identity {:navigation-reset? true})))))))
(chat/start-chat contact-identity {:navigation-reset? true}))))))

(handlers/register-handler-fx
:contact/filters-added
Expand Down Expand Up @@ -1800,16 +1795,6 @@
(fn [cofx [_ initial-props]]
{:db (assoc (:db cofx) :initial-props initial-props)}))

(handlers/register-handler-fx
:contact-code.callback/contact-code-published
(fn [cofx arg]
(contact-code/published cofx)))

(handlers/register-handler-fx
:contact-code.callback/contact-code-publishing-failed
(fn [cofx _]
(contact-code/publishing-failed cofx)))

(handlers/register-handler-fx
:pairing.ui/enable-installation-pressed
(fn [cofx [_ installation-id]]
Expand Down
7 changes: 5 additions & 2 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
;; as soon as the mailserver becomes available


(def one-day (* 24 3600))
(def one-hour 3600)
(def one-day (* 24 one-hour))
(def seven-days (* 7 one-day))
(def max-gaps-range (* 30 one-day))
(def max-request-range one-day)
Expand Down Expand Up @@ -406,7 +407,6 @@
[{:keys [db now] :as cofx}]
(when (and
(mobile-network-utils/syncing-allowed? cofx)
(transport.db/all-filters-added? cofx)
(not (:mailserver/current-request db)))
(when-let [mailserver (get-mailserver-when-ready cofx)]
(let [request-to (or (:mailserver/request-to db)
Expand Down Expand Up @@ -517,11 +517,14 @@
[{:keys [db] :as cofx} chat-id]
(let [{:keys [public?] :as chat} (get-in db [:chats chat-id])
topic (if (and chat (not public?))
;; TODO: look for all the topics for this chat and remove them
(transport.topic/discovery-topic-hash)
(get-in db [:transport/chats chat-id :topic]))
{:keys [chat-ids] :as mailserver-topic} (update (get-in db [:mailserver/topics topic])
:chat-ids
disj chat-id)]

(log/info "mailserver: removing topic: " topic " chat-id: " chat-id " chat-ids: " chat-ids)
(if (empty? chat-ids)
(fx/merge cofx
{:db (update db :mailserver/topics dissoc topic)
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/native_module/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@

(def enable-installation native-module/enable-installation)

(def load-filters native-module/load-filters)

(def load-filter native-module/load-filter)

(def remove-filter native-module/remove-filter)

(def disable-installation native-module/disable-installation)

(def update-mailservers native-module/update-mailservers)
Expand Down
24 changes: 24 additions & 0 deletions src/status_im/native_module/impl/module.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@
(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-filter [chat callback]
(let [params {:jsonrpc "2.0"
:id 2
:method "shhext_removeFilter"
:params [chat]}
payload (.stringify js/JSON (clj->js params))]
(call-private-rpc payload callback)))

(defn is24Hour []
(when (status)
(.-is24Hour (status))))
Expand Down
8 changes: 8 additions & 0 deletions src/status_im/signals/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[status-im.node.core :as node]
[status-im.pairing.core :as pairing]
[status-im.transport.message.core :as transport.message]
[status-im.transport.filters :as transport.filters]
[status-im.utils.fx :as fx]
[status-im.utils.security :as security]
[status-im.utils.types :as types]
Expand Down Expand Up @@ -77,4 +78,11 @@
"subscriptions.data" (ethereum.subscriptions/handle-signal cofx event)
"subscriptions.error" (ethereum.subscriptions/handle-error cofx event)
"status.chats.did-change" (chat.loading/load-chats-from-rpc cofx)
"whisper.filter.added" {:shh/add-raw-filters
{:web3 (get-in cofx [:db :web3])
:filters (map #(hash-map :sym-key-id (:symKeyId %)
:chat-id (str "0x" (:identity %))
:topic (:topic %)
:filter-id (:filterId %))
(:filters event))}}
(log/debug "Event " type " not handled"))))
Loading

0 comments on commit 011a431

Please sign in to comment.