integrate mailserver-ranges api

This commit is contained in:
yenda 2019-09-05 19:33:36 +02:00
parent 277f9ffda5
commit 172038b70d
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
8 changed files with 38 additions and 41 deletions

View File

@ -197,10 +197,8 @@
#(re-frame/dispatch [::verify-success % realm-error]))))
(fx/defn handle-change-multiaccount-success
{:events [::multiaccount-change-success]
:interceptors [(re-frame/inject-cofx :data-store/all-chat-requests-ranges)]}
[{:data-store/keys [mailserver-ranges] :as cofx}]
(protocol/initialize-protocol cofx {:mailserver-ranges mailserver-ranges}))
{:events [::multiaccount-change-success]}
[cofx])
(defn change-multiaccount!
[address password create-database-if-not-exist?]

View File

@ -42,27 +42,3 @@
:params [chat-id]
:on-success #(log/info "deleted gaps successfully")
:on-failure #(log/error "failed to delete gap" %)}]})
(defn save-chat-requests-range
[chat-requests-range]
(fn [realm]
(log/debug "saving ranges" chat-requests-range)
(core/create realm :chat-requests-range chat-requests-range true)))
(re-frame/reg-cofx
:data-store/all-chat-requests-ranges
(fn [cofx _]
(assoc cofx :data-store/mailserver-ranges
(reduce (fn [acc {:keys [chat-id] :as range}]
(assoc acc chat-id range))
{}
(-> @core/account-realm
(core/get-all :chat-requests-range)
(core/all-clj :chat-requests-range))))))
(defn delete-range
[chat-id]
(fn [realm]
(log/debug "deleting range" chat-id)
(core/delete realm
(core/get-by-field realm :chat-requests-range :chat-id chat-id))))

View File

@ -81,7 +81,10 @@
"mailservers_deleteMailserver" {}
"mailservers_addMailserverTopic" {}
"mailservers_getMailserverTopics" {}
"mailservers_deleteMailserverTopic" {}})
"mailservers_deleteMailserverTopic" {}
"mailservers_addChatRequestRange" {}
"mailservers_getChatRequestRanges" {}
"mailservers_deleteChatRequestRange" {}})
(defn call
[{:keys [method params on-success on-error] :as p}]

View File

@ -491,7 +491,11 @@
(fx/defn remove-range
[{:keys [db]} chat-id]
{:db (update db :mailserver/ranges dissoc chat-id)
:data-store/tx [(data-store.mailservers/delete-range chat-id)]})
::json-rpc/call
[{:method "mailservers_deleteChatRequestRange"
:params [chat-id]
:on-success #(log/debug "deleted chat request range successfully")
:on-failure #(log/error "failed to delete chat request range" %)}]})
(defn update-mailserver-topic
[{:keys [last-request] :as config}
@ -609,10 +613,15 @@
(< from lowest-request-from))
(assoc :lowest-request-from from))])))
chat-ids)]
(fx/merge
cofx
(fx/merge cofx
{:db (update db :mailserver/ranges merge updated-ranges)
:data-store/tx (map data-store.mailservers/save-chat-requests-range
::json-rpc/call
(mapv (fn [chat-requests-range]
{:method "mailservers_addChatRequestRange"
:params [chat-requests-range]
:on-success #()
:on-failure
#(log/error "failed to save chat request range" %)})
(vals updated-ranges))})))
(defn prepare-new-gaps [new-gaps ranges {:keys [from to] :as req} chat-ids]

View File

@ -164,6 +164,8 @@
::json-rpc/call
[{:method "mailservers_getMailserverTopics"
:on-success #(re-frame/dispatch [::protocol/initialize-protocol {:mailserver-topics (or % {})}])}
{:method "mailservers_getChatRequestRanges"
:on-success #(re-frame/dispatch [::protocol/initialize-protocol {:mailserver-ranges (or % {})}])}
{:method "browsers_getBrowsers"
:on-success #(re-frame/dispatch [::initialize-browsers %])}
{:method "permissions_getDappPermissions"

View File

@ -59,6 +59,15 @@
{}
mailserver-topics)))
(defn add-mailserver-ranges
[db mailserver-ranges]
(assoc db
:mailserver/ranges
(reduce (fn [acc {:keys [chat-id] :as range}]
(assoc acc chat-id range))
{}
mailserver-ranges)))
(fx/defn initialize-protocol
{:events [::initialize-protocol]}
[{:keys [db] :as cofx}
@ -77,7 +86,7 @@
(fx/merge cofx
{:db (cond-> db
mailserver-ranges
(assoc :mailserver/ranges mailserver-ranges)
(add-mailserver-ranges mailserver-ranges)
mailserver-topics
(add-mailserver-topics mailserver-topics)
mailservers

View File

@ -3,6 +3,6 @@
"owner": "status-im",
"repo": "status-go",
"version": "develop",
"commit-sha1": "9df64efe2c3d88596ab5cfe358741ed8f9be86b7",
"src-sha256": "0yc76v2kcamxjv7g7b9x4ywmbzch4azzb4sj49rhcdkg0wz8qi5j"
"commit-sha1": "76d184b4c9e666383ba54303b3c4a438ac4519de",
"src-sha256": "141glfhal3chlykz5m3jbmzrv10rprly9yk4xf1ss4a3hd8hj90c"
}

View File

@ -113,10 +113,10 @@
(testing "it sets the chat as inactive"
(let [actual (chat/remove-chat cofx chat-id)]
(is (= false (get-in actual [:db :chats chat-id :is-active])))))
(testing "it adds the relevant transactions for realm"
(testing "it makes the relevant json-rpc calls"
(let [actual (chat/remove-chat cofx chat-id)]
(is (:data-store/tx actual))
(is (= 1 (count (:data-store/tx actual))))))))
(is (::json-rpc/call actual))
(is (= 5 (count (::json-rpc/call actual))))))))
(deftest multi-user-chat?
(let [chat-id "1"]