Skip to content

Commit

Permalink
wip 3
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed Jun 11, 2019
1 parent d203fab commit 9b894a9
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 154 deletions.
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://10.0.3.2:3449/figwheel-ws",
:ios "ws://192.168.56.1:3449/figwheel-ws",
(def figwheel-urls {:android "ws://localhost:3449/figwheel-ws",
:ios "ws://192.168.0.9:3449/figwheel-ws",
:desktop "ws://localhost:3449/figwheel-ws"}
)
1 change: 0 additions & 1 deletion src/status_im/chat/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[status-im.contact.db :as contact.db]
[status-im.group-chats.db :as group-chats.db]
[status-im.mailserver.constants :as mailserver.constants]
[status-im.transport.partitioned-topic :as topic]
[status-im.utils.gfycat.core :as gfycat]))

(defn group-chat-name
Expand Down
4 changes: 3 additions & 1 deletion src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
(log/error "can't remove a chat:" error))}]}
(navigation/navigate-to-cofx :home {}))
(fx/merge cofx
(mailserver/remove-gaps chat-id)
(mailserver/remove-gaps chat-id)
(mailserver/remove-range chat-id)
(deactivate-chat chat-id)
(clear-history chat-id)
Expand Down Expand Up @@ -238,6 +238,8 @@
(fx/merge cofx
{:db (-> (assoc db :current-chat-id chat-id)
(set-chat-ui-props {:validation-messages nil}))}
;; Group chat don't need this to load as all the loading of topics
;; happens on membership changes
(when-not (group-chat? cofx chat-id)
(contact-code/load-chat chat-id))
(when platform/desktop?
Expand Down
1 change: 0 additions & 1 deletion src/status_im/contact/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[status-im.mailserver.core :as mailserver]
[status-im.transport.message.contact :as message.contact]
[status-im.transport.message.protocol :as protocol]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.tribute-to-talk.db :as tribute-to-talk]
[status-im.tribute-to-talk.whitelist :as whitelist]
[status-im.ui.screens.navigation :as navigation]
Expand Down
33 changes: 16 additions & 17 deletions src/status_im/contact_code/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
[status-im.utils.handlers :as handlers]
[status-im.native-module.core :as status]
[status-im.contact.db :as contacts.db]
[status-im.mailserver.topics :as mailserver.topics]
[status-im.mailserver.topics :as mailserver.topics]
[status-im.mailserver.core :as mailserver]))


;; fx functions

(defn load-filter-fx [web3 filters]
Expand Down Expand Up @@ -118,15 +117,15 @@
members-joined
public?]}]
(cond
(not group-chat)
[{:ChatID chat-id
:OneToOne true
:Identity (subs chat-id 2)}]
public?
[{:ChatID chat-id
:OneToOne false}]
:else
(mapcat #(->filter-request {:chat-id %}) members-joined)))
(not group-chat)
[{:ChatID chat-id
:OneToOne true
:Identity (subs chat-id 2)}]
public?
[{:ChatID chat-id
:OneToOne false}]
:else
(mapcat #(->filter-request {:chat-id %}) members-joined)))

(defn- chats->filter-requests
"Convert a list of active chats to filter requests"
Expand Down Expand Up @@ -274,12 +273,12 @@
(contains? members chat-id)))
(vals (:chats db)))]
(when
(or public?
(and one-to-one?
(not (contact.db/active? db chat-id))
(not= my-public-key chat-id)
(not (get-in db [:chats chat-id :is-active]))
(empty? active-group-chats)))
(or public?
(and one-to-one?
(not (contact.db/active? db chat-id))
(not= my-public-key chat-id)
(not (get-in db [:chats chat-id :is-active]))
(empty? active-group-chats)))
(fx/merge
cofx
(remove-filter-fx (get-in db [:transport/filters chat-id]))))))
Expand Down
11 changes: 8 additions & 3 deletions src/status_im/data_store/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@
(re-frame/reg-fx
:data-store/base-tx
(fn [transactions]
(perform-transactions transactions @data-source/base-realm)))
(async/go (async/>! data-source/realm-queue
(partial perform-transactions
transactions
@data-source/base-realm)))))

(re-frame/reg-fx
:data-store/tx
(fn [transactions]
(perform-transactions transactions @data-source/account-realm)))

(async/go (async/>! data-source/realm-queue
(partial perform-transactions
transactions
@data-source/account-realm)))))
20 changes: 19 additions & 1 deletion src/status_im/data_store/realm/schemas/account/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,21 @@
contact-recovery/v1
mailserver-requests-gap/v1])

(def v47 [chat/v15
chat-requests-range/v1
transport/v10
contact/v8
message/v11
mailserver/v11
mailserver-topic/v2
membership-update/v1
installation/v3
browser/v8
dapp-permissions/v9
contact-device-info/v1
contact-recovery/v1
mailserver-requests-gap/v1])

;; put schemas ordered by version
(def schemas [{:schema v1
:schemaVersion 1
Expand Down Expand Up @@ -698,4 +713,7 @@
:migration (constantly nil)}
{:schema v46
:schemaVersion 46
:migration migrations/v46}])
:migration migrations/v46}
{:schema v47
:schemaVersion 47
:migration (constantly nil)}])
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@
(def v9 (update v8 :properties
dissoc
:ack :seen :pending-ack :pending-send))
(def v10 (update v9 :properties dissoc :sym-key-id :sym-key))

(def v10 (update v9 :properties dissoc :topic :sym-key-id :sym-key))
13 changes: 3 additions & 10 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -827,13 +827,11 @@

(handlers/register-handler-fx
:chat.ui/start-chat
[(re-frame/inject-cofx :web3/get-web3)]
(fn [cofx [_ contact-id opts]]
(chat/start-chat cofx contact-id opts)))

(handlers/register-handler-fx
:chat.ui/start-public-chat
[(re-frame/inject-cofx :web3/get-web3)]
(fn [cofx [_ topic opts]]
(fx/merge
cofx
Expand All @@ -842,7 +840,6 @@

(handlers/register-handler-fx
:chat.ui/remove-chat
[(re-frame/inject-cofx :web3/get-web3)]
(fn [cofx [_ chat-id]]
(chat/remove-chat cofx chat-id)))

Expand Down Expand Up @@ -1715,8 +1712,7 @@

(handlers/register-handler-fx
:contact.ui/add-to-contact-pressed
[(re-frame/inject-cofx :random-id-generator)
(re-frame/inject-cofx :web3/get-web3)]
[(re-frame/inject-cofx :random-id-generator)]
(fn [cofx [_ public-key]]
(contact/add-contact cofx public-key)))

Expand All @@ -1727,21 +1723,18 @@

(handlers/register-handler-fx
:contact.ui/block-contact-confirmed
[(re-frame/inject-cofx :data-store/get-user-messages)
(re-frame/inject-cofx :web3/get-web3)]
[(re-frame/inject-cofx :data-store/get-user-messages)]
(fn [cofx [_ public-key]]
(contact.block/block-contact cofx public-key)))

(handlers/register-handler-fx
:contact.ui/unblock-contact-pressed
[(re-frame/inject-cofx :web3/get-web3)]
(fn [cofx [_ public-key]]
(contact.block/unblock-contact cofx public-key)))

(handlers/register-handler-fx
:contact/qr-code-scanned
[(re-frame/inject-cofx :random-id-generator)
(re-frame/inject-cofx :web3/get-web3)]
[(re-frame/inject-cofx :random-id-generator)]
(fn [{:keys [db] :as cofx} [_ _ contact-identity]]
(let [current-account (:account/account db)
fx {:db (assoc db :contacts/new-identity contact-identity)}
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/group_chats/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
[status-im.native-module.core :as native-module]
[status-im.transport.message.group-chat :as message.group-chat]
[status-im.transport.message.protocol :as protocol]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.utils.clocks :as utils.clocks]
[status-im.utils.fx :as fx]
[status-im.mailserver.core :as mailserver]
Expand Down Expand Up @@ -458,7 +457,6 @@
(contact-code/load-members members)
(mailserver/process-next-messages-request)))))


(fx/defn handle-membership-update
"Upsert chat and receive message if valid"
;; Care needs to be taken here as chat-id is not coming from a whisper filter
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/mailserver/constants.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ^{:doc "Mailserver events and API"}
status-im.mailserver.constants)
status-im.mailserver.constants)

(def one-day (* 24 3600))
(def seven-days (* 7 one-day))
Expand Down
28 changes: 2 additions & 26 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
[status-im.utils.handlers :as handlers]
[status-im.accounts.update.core :as accounts.update]
[status-im.ui.screens.navigation :as navigation]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils]
[status-im.utils.random :as rand]))

Expand Down Expand Up @@ -498,31 +497,6 @@
(reset-request-to)
(connect-to-mailserver))))

(fx/defn remove-chat-from-mailserver-topic
"if the chat is the only chat of the mailserver topic delete the mailserver topic
and process-next-messages-requests again to remove pending request for that topic
otherwise remove the chat-id of the chat from the mailserver topic and save"
[{: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)
:data-store/tx [(data-store.mailservers/delete-mailserver-topic-tx topic)]}
(process-next-messages-request))
{:db (assoc-in db [:mailserver/topics topic] mailserver-topic)
:data-store/tx [(data-store.mailservers/save-mailserver-topic-tx
{:topic topic
:mailserver-topic mailserver-topic})]})))

(fx/defn remove-gaps
[{:keys [db]} chat-id]
{:db (update db :mailserver/gaps dissoc chat-id)
Expand Down Expand Up @@ -852,6 +826,8 @@
:confirm-button-text (i18n/label :t/mailserver-request-retry)}}))

(fx/defn fetch-history
"Retrive a list of topics given a chat id, set them to the specified time interval
and start a mailserver request"
[{:keys [db] :as cofx} chat-id {:keys [from to]}]
(let [topics (mailserver.topics/topics-for-chat
db
Expand Down
19 changes: 6 additions & 13 deletions src/status_im/mailserver/topics.cljs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
(ns ^{:doc "Mailserver events and API"}
status-im.mailserver.topics
status-im.mailserver.topics
(:require
[clojure.string :as string]
[taoensso.timbre :as log]
[status-im.data-store.mailservers :as data-store.mailservers]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.mailserver.constants :as constants]
[status-im.utils.fx :as fx]))


(defn calculate-last-request [{:keys [fetch? discovery?] :or {fetch? true}}
{:keys [new-account?
previous-last-request
Expand All @@ -28,7 +26,6 @@
:else
(- now-s constants/max-request-range)))


(fx/defn store [{:keys [db]} {:keys [topic
filter-ids
chat-ids] :as mailserver-topic}]
Expand Down Expand Up @@ -84,7 +81,6 @@
(store topic)
(when persist? (persist topic))))


(fx/defn upsert
"if the topic didn't exist
create the topic
Expand Down Expand Up @@ -117,11 +113,11 @@
(fx/defn delete [{:keys [db] :as cofx} {:keys [chat-id filter-id]}]
(println (vals (:mailserver/topics db)))
(when-let [matching-topics (filter (fn [{:keys [filter-ids] :as topic}]
(if (not filter-ids)
(do (log/warn "topic not initialized, removing" topic)
true)
(filter-ids filter-id)))
(vals (:mailserver/topics db)))]
(if (not filter-ids)
(do (log/warn "topic not initialized, removing" topic)
true)
(filter-ids filter-id)))
(vals (:mailserver/topics db)))]
(println "UPDATING" matching-topics)
(update-many cofx (map #(update % :filter-ids disj filter-id) matching-topics))))

Expand All @@ -130,8 +126,6 @@
[cofx filters]
(apply fx/merge cofx (map delete filters)))



(defn extract-topics
"return all the topics for this chat, including discovery topics if specified"
[topics chat-id include-discovery?]
Expand Down Expand Up @@ -169,7 +163,6 @@
{:modified [] :removed []}
topics))


(fx/defn upsert-group-chat
"Based on the members it will upsert a mailserver topic for any discovery topic
and any personal topic that is in members. It will also remove the chat-id from any existing topic if not with a member"
Expand Down
1 change: 0 additions & 1 deletion src/status_im/transport/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[status-im.native-module.core :as status]
[status-im.mailserver.core :as mailserver]
[status-im.transport.message.core :as message]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.contact-code.core :as contact-code]
[status-im.utils.publisher :as publisher]
[status-im.utils.fx :as fx]
Expand Down
5 changes: 3 additions & 2 deletions src/status_im/transport/message/protocol.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
[status-im.accounts.db :as accounts.db]
[status-im.ethereum.core :as ethereum]
[status-im.transport.db :as transport.db]
[status-im.transport.partitioned-topic :as transport.topic]
[status-im.data-store.transport :as transport-store]
[status-im.transport.utils :as transport.utils]
[status-im.tribute-to-talk.whitelist :as whitelist]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]))

(defn discovery-topic-hash [] (transport.utils/get-topic constants/contact-discovery))

(defprotocol StatusMessage
"Protocol for the messages that are sent through the transport layer"
(send [this chat-id cofx] "Method producing all effects necessary for sending the message record")
Expand Down Expand Up @@ -74,7 +75,7 @@
chat-id
success-event
payload)
(let [topic-hash (transport.topic/discovery-topic-hash)]
(let [topic-hash (discovery-topic-hash)]
{:shh/post [{:web3 web3
:success-event success-event
:message (merge {:sig (accounts.db/current-public-key cofx)
Expand Down
Loading

0 comments on commit 9b894a9

Please sign in to comment.