Persist unseen messages

This commit is contained in:
janherich 2018-06-05 10:30:26 +02:00
parent 5cd643b98e
commit cd5542f648
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
3 changed files with 12 additions and 9 deletions

View File

@ -70,13 +70,16 @@
(when-not (get-in db [:chats current-chat-id :all-loaded?])
(let [loaded-count (count (get-in db [:chats current-chat-id :messages]))
new-messages (get-stored-messages current-chat-id loaded-count)
indexed-messages (index-messages new-messages)]
indexed-messages (index-messages new-messages)
new-message-ids (keys indexed-messages)]
(handlers-macro/merge-fx
cofx
{:db (-> db
(update-in [:chats current-chat-id :messages] merge indexed-messages)
(update-in [:chats current-chat-id :not-loaded-message-ids]
#(apply disj % (keys indexed-messages)))
#(apply disj % new-message-ids))
(update-in [:chats current-chat-id :unviewed-messages]
#(apply disj % new-message-ids))
(assoc-in [:chats current-chat-id :all-loaded?]
(> constants/default-number-of-messages (count new-messages))))}
(models.message/group-messages current-chat-id new-messages))))))

View File

@ -73,7 +73,7 @@
(core/get-by-fields
:user-status
:and {:whisper-identity (:current-public-key db)
:status :received})
:status "received"})
(core/all-clj :user-status)))))))
(defn- prepare-content [content]

View File

@ -235,14 +235,14 @@
[results schema-name]
(realm-list->clj-coll results [] #(realm-obj->clj (object/get results %) schema-name)))
(defn- field-type [realm schema-name field]
(defn- field-type [schema-name field]
(let [field-def (get-in entity->schemas [schema-name :properties field])]
(or (:type field-def) field-def)))
(defmulti to-query (fn [_ _ operator _ _] operator))
(defmulti to-query (fn [_ operator _ _] operator))
(defmethod to-query :eq [schema schema-name _ field value]
(let [field-type (field-type schema schema-name field)
(defmethod to-query :eq [schema-name _ field value]
(let [field-type (field-type schema-name field)
escaped-value (when value (gstr/escapeString (str value)))
query (str (name field) "=" (if (= "string" (name field-type))
(str "\"" escaped-value "\"")
@ -252,7 +252,7 @@
(defn get-by-field
"Selects objects from realm identified by schema-name based on value of field"
[realm schema-name field value]
(let [q (to-query realm schema-name :eq field value)]
(let [q (to-query schema-name :eq field value)]
(.filtered (.objects realm (name schema-name)) q)))
(defn- and-query [queries]
@ -266,7 +266,7 @@
combined by `:and`/`:or` operator"
[realm schema-name op fields]
(let [queries (map (fn [[k v]]
(to-query realm schema-name :eq k v))
(to-query schema-name :eq k v))
fields)]
(.filtered (.objects realm (name schema-name))
(case op