remove message cache

message cache was initialized when logging-in so it was basically useless
it was causing a bug when switching account and getting a contact request
from the same user in 2 accounts without killing the app because the cache
was not reset and the subsequent contact requests were ignored

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Eric Dvorsak 2018-05-13 16:51:58 +02:00 committed by Julien Eluard
parent 0d2849d955
commit baa471a929
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
4 changed files with 18 additions and 58 deletions

View File

@ -3,7 +3,6 @@
[re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.native-module.core :as status]
[status-im.transport.message-cache :as message-cache]
[status-im.utils.datetime :as datetime]
[status-im.utils.ethereum.core :as utils]
[status-im.utils.handlers :as handlers]

View File

@ -30,8 +30,7 @@
(defrecord ContactRequest [name profile-image address fcm-token]
message/StatusMessage
(send [this chat-id {:keys [db random-id] :as cofx}]
(let [message-id (transport.utils/message-id this)
topic (transport.utils/get-topic random-id)
(let [topic (transport.utils/get-topic random-id)
on-success (fn [sym-key sym-key-id]
(re-frame/dispatch [:contact/send-new-sym-key
{:sym-key-id sym-key-id
@ -42,46 +41,34 @@
(handlers-macro/merge-fx cofx
{:shh/get-new-sym-key {:web3 (:web3 db)
:on-success on-success}}
(protocol/init-chat chat-id topic)
#_(protocol/requires-ack message-id chat-id))))
(protocol/init-chat chat-id topic))))
(receive [this chat-id signature {:keys [db] :as cofx}]
(let [message-id (transport.utils/message-id this)
topic (transport.utils/get-topic chat-id)]
(when (protocol/is-new? message-id)
(handlers-macro/merge-fx cofx
#_(protocol/ack message-id chat-id)
{:dispatch [:inbox/request-messages {:topics [topic]}]}
(contacts/receive-contact-request signature
this))))))
(let [topic (transport.utils/get-topic chat-id)]
(handlers-macro/merge-fx cofx
{:dispatch [:inbox/request-messages {:topics [topic]}]}
(contacts/receive-contact-request signature
this)))))
(defrecord ContactRequestConfirmed [name profile-image address fcm-token]
message/StatusMessage
(send [this chat-id cofx]
(let [message-id (transport.utils/message-id this)]
(handlers-macro/merge-fx cofx
#_(protocol/requires-ack message-id chat-id)
(protocol/send {:chat-id chat-id
:payload this}))))
(handlers-macro/merge-fx cofx
(protocol/send {:chat-id chat-id
:payload this})))
(receive [this chat-id signature cofx]
(let [message-id (transport.utils/message-id this)]
(when (protocol/is-new? message-id)
(handlers-macro/merge-fx cofx
#_(protocol/ack message-id chat-id)
(contacts/receive-contact-request-confirmation signature
this))))))
(handlers-macro/merge-fx cofx
(contacts/receive-contact-request-confirmation signature
this))))
(defrecord ContactUpdate [name profile-image]
message/StatusMessage
(send [this _ {:keys [db] :as cofx}]
(let [message-id (transport.utils/message-id this)
public-keys (remove nil? (map :public-key (vals (:contacts/contacts db))))]
(let [public-keys (remove nil? (map :public-key (vals (:contacts/contacts db))))]
(handlers-macro/merge-fx cofx
(protocol/multi-send-by-pubkey {:public-keys public-keys
:payload this}))))
(receive [this chat-id signature cofx]
(let [message-id (transport.utils/message-id this)]
(when (protocol/is-new? message-id)
(handlers-macro/merge-fx cofx
(contacts/receive-contact-update chat-id
signature
this))))))
(handlers-macro/merge-fx cofx
(contacts/receive-contact-update chat-id
signature
this))))

View File

@ -3,7 +3,6 @@
(:require [status-im.utils.config :as config]
[status-im.constants :as constants]
[status-im.chat.core :as chat]
[status-im.transport.message-cache :as message-cache]
[status-im.transport.db :as transport.db]
[status-im.transport.message.core :as message]
[status-im.transport.utils :as transport.utils]))
@ -22,12 +21,6 @@
([chat-id topic {:keys [db] :as cofx}]
{:db (assoc-in db [:transport/chats chat-id] (transport.db/create-chat topic))}))
(defn is-new?
"Determines if given message-id already exists in in-memory message cache"
[message-id]
(when-not (message-cache/exists? message-id)
(message-cache/add! message-id)))
#_(defn requires-ack [message-id chat-id {:keys [db] :as cofx}]
{:db (update-in db [:transport/chats chat-id :pending-ack] conj message-id)})

View File

@ -1,19 +0,0 @@
(ns ^{:doc "Message caching API for message deduplication"}
status-im.transport.message-cache
(:refer-clojure :exclude [exists?]))
(defonce messages-set (atom #{}))
(defn init!
[messages]
(reset! messages-set (set (map :message-id messages))))
(defn add!
[message-id]
(when message-id
(swap! messages-set conj message-id)))
(defn exists?
[message-id]
(when message-id
(@messages-set message-id)))