Skip to content

Commit

Permalink
Fetch messages from mailserver upon PN if db is unlocked. Part of #3451
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pombeiro committed Jan 31, 2019
1 parent 10739cd commit c267763
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
(handlers/register-handler-fx
:chat.ui/fetch-history-pressed
(fn [cofx [_ chat-id]]
(mailserver/fetch-history cofx chat-id)))
(mailserver/fetch-history cofx chat-id nil)))

(handlers/register-handler-fx
:chat.ui/remove-chat-pressed
Expand Down
5 changes: 3 additions & 2 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,14 @@
{:topic topic
:mailserver-topic mailserver-topic})]}))))
(fx/defn fetch-history
[{:keys [db] :as cofx} chat-id]
[{:keys [db] :as cofx} chat-id from-timestamp]
(log/debug "fetch-history" "chat-id:" chat-id "from-timestamp:" from-timestamp)
(let [topic (or (get-in db [:transport/chats chat-id :topic])
(transport.utils/get-topic constants/contact-discovery))
{:keys [chat-ids last-request] :as current-mailserver-topic}
(get-in db [:mailserver/topics topic] {:chat-ids #{}})]
(let [mailserver-topic (-> current-mailserver-topic
(assoc :last-request 1))]
(assoc :last-request (or from-timestamp 1)))]
(fx/merge cofx
{:db (assoc-in db [:mailserver/topics topic] mailserver-topic)
:data-store/tx [(data-store.mailservers/save-mailserver-topic-tx
Expand Down
7 changes: 6 additions & 1 deletion src/status_im/notifications/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[status-im.i18n :as i18n]
[status-im.accounts.db :as accounts.db]
[status-im.chat.models :as chat-model]
[status-im.mailserver.core :as mailserver]
[status-im.utils.platform :as platform]
[status-im.utils.fx :as fx]
[status-im.utils.utils :as utils]))
Expand All @@ -17,6 +18,7 @@
(def ^:private pn-message-id-hash-length 10)
(def ^:private pn-pubkey-hash-length 10)
(def ^:private pn-pubkey-length 132)
(def ^:private pull-recent-messages-window (* 15 60))

(when-not platform/desktop?

Expand Down Expand Up @@ -207,7 +209,7 @@
(vals (:chats db)))))

(fx/defn handle-on-message
[{:keys [db] :as cofx} decoded-payload {:keys [force]}]
[{:keys [db now] :as cofx} decoded-payload {:keys [force]}]
(let [view-id (:view-id db)
current-chat-id (:current-chat-id db)
app-state (:app-state db)
Expand All @@ -216,6 +218,9 @@
(log/debug "handle-on-message" "app-state:" app-state
"view-id:" view-id "current-chat-id:" current-chat-id
"from:" from "force:" force)
(when (and (= (.-length from) pn-pubkey-length)
(show-notification? cofx rehydrated-payload))
(mailserver/fetch-history cofx from (- now pull-recent-messages-window)))
(when (or force
(and
(not= app-state "active")
Expand Down

0 comments on commit c267763

Please sign in to comment.