Move gaps to status-go
This commit moves gaps to status-go. Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
ef36ece15b
commit
e7fa010088
|
@ -443,7 +443,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String result = Statusgo.loginWithKeycard(whisperPrivateKey, encryptionPublicKey, configJSON);
|
String result = Statusgo.loginWithKeycard(whisperPrivateKey, encryptionPublicKey, configJSON);
|
||||||
|
|
||||||
callback.invoke(result);
|
callback.invoke(result);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -84,8 +84,7 @@
|
||||||
|
|
||||||
(fx/defn messages-loaded
|
(fx/defn messages-loaded
|
||||||
"Loads more messages for current chat"
|
"Loads more messages for current chat"
|
||||||
{:events [::messages-loaded]
|
{:events [::messages-loaded]}
|
||||||
:interceptors [(re-frame/inject-cofx :data-store/all-gaps)]}
|
|
||||||
[{{:keys [current-chat-id] :as db} :db :as cofx}
|
[{{:keys [current-chat-id] :as db} :db :as cofx}
|
||||||
chat-id
|
chat-id
|
||||||
{:keys [cursor messages]}]
|
{:keys [cursor messages]}]
|
||||||
|
@ -113,11 +112,10 @@
|
||||||
(assoc-in [:chats current-chat-id :cursor] cursor)
|
(assoc-in [:chats current-chat-id :cursor] cursor)
|
||||||
(assoc-in [:chats current-chat-id :all-loaded?]
|
(assoc-in [:chats current-chat-id :all-loaded?]
|
||||||
(empty? cursor)))}
|
(empty? cursor)))}
|
||||||
(mailserver/load-gaps current-chat-id)
|
|
||||||
(group-chat-messages current-chat-id new-messages)
|
(group-chat-messages current-chat-id new-messages)
|
||||||
(chat-model/mark-messages-seen current-chat-id)))))
|
(chat-model/mark-messages-seen current-chat-id)))))
|
||||||
|
|
||||||
(defn load-more-messages
|
(fx/defn load-more-messages
|
||||||
[{:keys [db]}]
|
[{:keys [db]}]
|
||||||
(when-let [current-chat-id (:current-chat-id db)]
|
(when-let [current-chat-id (:current-chat-id db)]
|
||||||
(when-not (get-in db [:chats current-chat-id :all-loaded?])
|
(when-not (get-in db [:chats current-chat-id :all-loaded?])
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
(:require [cljs.tools.reader.edn :as edn]
|
(:require [cljs.tools.reader.edn :as edn]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.utils.fx :as fx]
|
||||||
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
[status-im.data-store.realm.core :as core]))
|
[status-im.data-store.realm.core :as core]))
|
||||||
|
|
||||||
(re-frame/reg-cofx
|
(re-frame/reg-cofx
|
||||||
|
@ -14,6 +16,39 @@
|
||||||
(core/get-all :mailserver)
|
(core/get-all :mailserver)
|
||||||
(core/all-clj :mailserver))))))
|
(core/all-clj :mailserver))))))
|
||||||
|
|
||||||
|
(defn mailserver-request-gaps->rpc [{:keys [chat-id] :as gap}]
|
||||||
|
(-> gap
|
||||||
|
(assoc :chatId chat-id)
|
||||||
|
(dissoc :chat-id)))
|
||||||
|
|
||||||
|
(fx/defn load-gaps [cofx chat-id success-fn]
|
||||||
|
{::json-rpc/call [{:method "mailservers_getMailserverRequestGaps"
|
||||||
|
:params [chat-id]
|
||||||
|
:on-success #(let [indexed-gaps (reduce (fn [acc {:keys [id] :as g}]
|
||||||
|
(assoc acc id g))
|
||||||
|
{}
|
||||||
|
%)]
|
||||||
|
(success-fn chat-id indexed-gaps))
|
||||||
|
:on-failure #(log/error "failed to fetch gaps" %)}]})
|
||||||
|
|
||||||
|
(fx/defn save-gaps [cofx gaps]
|
||||||
|
{::json-rpc/call [{:method "mailservers_addMailserverRequestGaps"
|
||||||
|
:params [(map mailserver-request-gaps->rpc gaps)]
|
||||||
|
:on-success #(log/info "saved gaps successfully")
|
||||||
|
:on-failure #(log/error "failed to save gap" %)}]})
|
||||||
|
|
||||||
|
(fx/defn delete-gaps [cofx ids]
|
||||||
|
{::json-rpc/call [{:method "mailservers_deleteMailserverRequestGaps"
|
||||||
|
:params [ids]
|
||||||
|
:on-success #(log/info "deleted gaps successfully")
|
||||||
|
:on-failure #(log/error "failed to delete gap" %)}]})
|
||||||
|
|
||||||
|
(fx/defn delete-gaps-by-chat-id [cofx chat-id]
|
||||||
|
{::json-rpc/call [{:method "mailservers_deleteMailserverRequestGapsByChatID"
|
||||||
|
:params [chat-id]
|
||||||
|
:on-success #(log/info "deleted gaps successfully")
|
||||||
|
:on-failure #(log/error "failed to delete gap" %)}]})
|
||||||
|
|
||||||
(defn save-tx
|
(defn save-tx
|
||||||
"Returns tx function for saving a mailserver"
|
"Returns tx function for saving a mailserver"
|
||||||
[{:keys [id] :as mailserver}]
|
[{:keys [id] :as mailserver}]
|
||||||
|
@ -84,41 +119,6 @@
|
||||||
(core/get-all :chat-requests-range)
|
(core/get-all :chat-requests-range)
|
||||||
(core/all-clj :chat-requests-range))))))
|
(core/all-clj :chat-requests-range))))))
|
||||||
|
|
||||||
(re-frame/reg-cofx
|
|
||||||
:data-store/all-gaps
|
|
||||||
(fn [cofx _]
|
|
||||||
(assoc cofx
|
|
||||||
:data-store/all-gaps
|
|
||||||
(fn [chat-id]
|
|
||||||
(reduce (fn [acc {:keys [id] :as gap}]
|
|
||||||
(assoc acc id gap))
|
|
||||||
{}
|
|
||||||
(-> @core/account-realm
|
|
||||||
(core/get-by-field :mailserver-requests-gap :chat-id chat-id)
|
|
||||||
(core/all-clj :mailserver-requests-gap)))))))
|
|
||||||
|
|
||||||
(defn save-mailserver-requests-gap
|
|
||||||
[gap]
|
|
||||||
(fn [realm]
|
|
||||||
(log/debug "saving gap" gap)
|
|
||||||
(core/create realm :mailserver-requests-gap gap true)))
|
|
||||||
|
|
||||||
(defn delete-mailserver-requests-gaps
|
|
||||||
[ids]
|
|
||||||
(fn [realm]
|
|
||||||
(log/debug "deleting gaps" ids)
|
|
||||||
(doseq [id ids]
|
|
||||||
(core/delete
|
|
||||||
realm
|
|
||||||
(core/get-by-field realm :mailserver-requests-gap :id id)))))
|
|
||||||
|
|
||||||
(defn delete-all-gaps-by-chat
|
|
||||||
[chat-id]
|
|
||||||
(fn [realm]
|
|
||||||
(log/debug "deleting all gaps for chat" chat-id)
|
|
||||||
(core/delete realm
|
|
||||||
(core/get-by-field realm :mailserver-requests-gap :chat-id chat-id))))
|
|
||||||
|
|
||||||
(defn delete-range
|
(defn delete-range
|
||||||
[chat-id]
|
[chat-id]
|
||||||
(fn [realm]
|
(fn [realm]
|
||||||
|
|
|
@ -63,6 +63,10 @@
|
||||||
"browsers_getBrowsers" {}
|
"browsers_getBrowsers" {}
|
||||||
"browsers_addBrowser" {}
|
"browsers_addBrowser" {}
|
||||||
"browsers_deleteBrowser" {}
|
"browsers_deleteBrowser" {}
|
||||||
|
"mailservers_getMailserverRequestGaps" {}
|
||||||
|
"mailservers_addMailserverRequestGaps" {}
|
||||||
|
"mailservers_deleteMailserverRequestGaps" {}
|
||||||
|
"mailservers_deleteMailserverRequestGapsByChatID" {}
|
||||||
"permissions_addDappPermissions" {}
|
"permissions_addDappPermissions" {}
|
||||||
"permissions_getDappPermissions" {}
|
"permissions_getDappPermissions" {}
|
||||||
"permissions_deleteDappPermissions" {}
|
"permissions_deleteDappPermissions" {}
|
||||||
|
|
|
@ -547,7 +547,10 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:chat.ui/load-more-messages
|
:chat.ui/load-more-messages
|
||||||
(fn [cofx _]
|
(fn [cofx _]
|
||||||
(chat.loading/load-more-messages cofx)))
|
(let [chat-id (get-in cofx [:db :current-chat-id])]
|
||||||
|
(fx/merge cofx
|
||||||
|
(chat.loading/load-more-messages)
|
||||||
|
(mailserver/load-gaps-fx chat-id)))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:chat.ui/start-chat
|
:chat.ui/start-chat
|
||||||
|
|
|
@ -492,9 +492,10 @@
|
||||||
(connect-to-mailserver))))
|
(connect-to-mailserver))))
|
||||||
|
|
||||||
(fx/defn remove-gaps
|
(fx/defn remove-gaps
|
||||||
[{:keys [db]} chat-id]
|
[{:keys [db] :as cofx} chat-id]
|
||||||
{:db (update db :mailserver/gaps dissoc chat-id)
|
(fx/merge cofx
|
||||||
:data-store/tx [(data-store.mailservers/delete-all-gaps-by-chat chat-id)]})
|
{:db (update db :mailserver/gaps dissoc chat-id)}
|
||||||
|
(data-store.mailservers/delete-gaps-by-chat-id chat-id)))
|
||||||
|
|
||||||
(fx/defn remove-range
|
(fx/defn remove-range
|
||||||
[{:keys [db]} chat-id]
|
[{:keys [db]} chat-id]
|
||||||
|
@ -654,7 +655,7 @@
|
||||||
chat-ids))
|
chat-ids))
|
||||||
|
|
||||||
(fx/defn update-gaps
|
(fx/defn update-gaps
|
||||||
[{:keys [db]}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [{:keys [topics] :as request} (get db :mailserver/current-request)
|
(let [{:keys [topics] :as request} (get db :mailserver/current-request)
|
||||||
chat-ids (into #{}
|
chat-ids (into #{}
|
||||||
(comp
|
(comp
|
||||||
|
@ -668,6 +669,7 @@
|
||||||
|
|
||||||
ranges (:mailserver/ranges db)
|
ranges (:mailserver/ranges db)
|
||||||
prepared-new-gaps (prepare-new-gaps new-gaps ranges request chat-ids)]
|
prepared-new-gaps (prepare-new-gaps new-gaps ranges request chat-ids)]
|
||||||
|
(fx/merge cofx
|
||||||
{:db
|
{:db
|
||||||
(reduce (fn [db chat-id]
|
(reduce (fn [db chat-id]
|
||||||
(let [chats-deleted-gaps (get deleted-gaps chat-id)
|
(let [chats-deleted-gaps (get deleted-gaps chat-id)
|
||||||
|
@ -678,16 +680,11 @@
|
||||||
(-> (apply dissoc chat-gaps chats-deleted-gaps)
|
(-> (apply dissoc chat-gaps chats-deleted-gaps)
|
||||||
(merge chats-updated-gaps))))))
|
(merge chats-updated-gaps))))))
|
||||||
db
|
db
|
||||||
chat-ids)
|
chat-ids)}
|
||||||
|
(data-store.mailservers/delete-gaps (mapcat val deleted-gaps))
|
||||||
:data-store/tx
|
(data-store.mailservers/save-gaps
|
||||||
(conj
|
|
||||||
(map
|
|
||||||
data-store.mailservers/save-mailserver-requests-gap
|
|
||||||
(concat (mapcat vals (vals updated-gaps))
|
(concat (mapcat vals (vals updated-gaps))
|
||||||
(mapcat vals (vals prepared-new-gaps))))
|
(mapcat vals (vals prepared-new-gaps)))))))
|
||||||
(data-store.mailservers/delete-mailserver-requests-gaps
|
|
||||||
(mapcat val deleted-gaps)))}))
|
|
||||||
|
|
||||||
(fx/defn update-chats-and-gaps
|
(fx/defn update-chats-and-gaps
|
||||||
[cofx cursor]
|
[cofx cursor]
|
||||||
|
@ -1068,20 +1065,25 @@
|
||||||
{::data-store.mailservers/all-chat-requests-ranges
|
{::data-store.mailservers/all-chat-requests-ranges
|
||||||
#(re-frame/dispatch [::ranges-loaded %])})
|
#(re-frame/dispatch [::ranges-loaded %])})
|
||||||
|
|
||||||
(fx/defn load-gaps
|
(fx/defn load-gaps-fx [{:keys [db] :as cofx} chat-id]
|
||||||
[{:keys [db now :data-store/all-gaps]} chat-id]
|
|
||||||
(when-not (get-in db [:chats chat-id :gaps-loaded?])
|
(when-not (get-in db [:chats chat-id :gaps-loaded?])
|
||||||
|
(let [success-fn #(re-frame/dispatch [::gaps-loaded %1 %2])]
|
||||||
|
(data-store.mailservers/load-gaps cofx chat-id success-fn))))
|
||||||
|
|
||||||
|
(fx/defn load-gaps
|
||||||
|
{:events [::gaps-loaded]}
|
||||||
|
[{:keys [db now] :as cofx} chat-id gaps]
|
||||||
(let [now-s (quot now 1000)
|
(let [now-s (quot now 1000)
|
||||||
gaps (all-gaps chat-id)
|
|
||||||
outdated-gaps (into [] (comp (filter #(< (:to %)
|
outdated-gaps (into [] (comp (filter #(< (:to %)
|
||||||
(- now-s constants/max-gaps-range)))
|
(- now-s constants/max-gaps-range)))
|
||||||
(map :id))
|
(map :id))
|
||||||
(vals gaps))
|
(vals gaps))
|
||||||
gaps (apply dissoc gaps outdated-gaps)]
|
gaps (apply dissoc gaps outdated-gaps)]
|
||||||
|
(fx/merge
|
||||||
|
cofx
|
||||||
{:db
|
{:db
|
||||||
(-> db
|
(-> db
|
||||||
(assoc-in [:chats chat-id :gaps-loaded?] true)
|
(assoc-in [:chats chat-id :gaps-loaded?] true)
|
||||||
(assoc-in [:mailserver/gaps chat-id] gaps))
|
(assoc-in [:mailserver/gaps chat-id] gaps))}
|
||||||
:data-store/tx
|
|
||||||
[(data-store.mailservers/delete-mailserver-requests-gaps
|
(data-store.mailservers/delete-gaps outdated-gaps))))
|
||||||
outdated-gaps)]})))
|
|
||||||
|
|
|
@ -119,6 +119,7 @@
|
||||||
(assoc :WalletConfig {:Enabled true}
|
(assoc :WalletConfig {:Enabled true}
|
||||||
:BrowsersConfig {:Enabled true}
|
:BrowsersConfig {:Enabled true}
|
||||||
:PermissionsConfig {:Enabled true}
|
:PermissionsConfig {:Enabled true}
|
||||||
|
:MailserversConfig {:Enabled true}
|
||||||
:WhisperConfig {:Enabled true
|
:WhisperConfig {:Enabled true
|
||||||
:LightClient true
|
:LightClient true
|
||||||
:MinimumPoW 0.001
|
:MinimumPoW 0.001
|
||||||
|
|
|
@ -1596,11 +1596,11 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:mailserver/connected?
|
:mailserver/connected?
|
||||||
:<- [:mailserver/state]
|
:<- [:mailserver/state]
|
||||||
:<- [:network-status]
|
:<- [:disconnected?]
|
||||||
(fn [[mail-state network-status]]
|
(fn [[mail-state disconnected?]]
|
||||||
(let [connected? (= :connected mail-state)
|
(let [mailserver-connected? (= :connected mail-state)]
|
||||||
online? (= :online network-status)]
|
(and mailserver-connected?
|
||||||
(and connected? online?))))
|
(not disconnected?)))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:mailserver/preferred-id
|
:mailserver/preferred-id
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "develop",
|
"version": "develop",
|
||||||
"commit-sha1": "42199e682fdf90a82e59451a58b9ae07749a8e12",
|
"commit-sha1": "b27779aa4e202a13a387897332dea377bf9b6552",
|
||||||
"src-sha256": "11ykhcx057l6s0zg5cansv5x8728k0j86ygsj12m8ax86xjkdzyc"
|
"src-sha256": "0yab9pjsg9583b7x89ywbbyxxw4fy03dyw260ybjb9g26z166064"
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
(testing "it adds the relevant transactions for realm"
|
(testing "it adds the relevant transactions for realm"
|
||||||
(let [actual (chat/remove-chat cofx chat-id)]
|
(let [actual (chat/remove-chat cofx chat-id)]
|
||||||
(is (:data-store/tx actual))
|
(is (:data-store/tx actual))
|
||||||
(is (= 2 (count (:data-store/tx actual))))))))
|
(is (= 1 (count (:data-store/tx actual))))))))
|
||||||
|
|
||||||
(deftest multi-user-chat?
|
(deftest multi-user-chat?
|
||||||
(let [chat-id "1"]
|
(let [chat-id "1"]
|
||||||
|
|
Loading…
Reference in New Issue