adjust code to work with 'Contact' - >:contact, fix bug
Former-commit-id: c6a589bd4b
This commit is contained in:
parent
12533d9330
commit
0af746b06b
|
@ -61,8 +61,9 @@
|
||||||
(set-initialized true))))
|
(set-initialized true))))
|
||||||
|
|
||||||
(register-handler :received-msg
|
(register-handler :received-msg
|
||||||
(fn [db [_ {chat-id :from
|
(fn [db [action {chat-id :from
|
||||||
msg-id :msg-id :as msg}]]
|
msg-id :msg-id :as msg}]]
|
||||||
|
(log/debug action "msg" msg)
|
||||||
(save-message chat-id msg)
|
(save-message chat-id msg)
|
||||||
(-> db
|
(-> db
|
||||||
(create-chat chat-id [chat-id])
|
(create-chat chat-id [chat-id])
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
(defn signal-chat-updated [db chat-id]
|
(defn signal-chat-updated [db chat-id]
|
||||||
(update-in db (db/updated-chat-signal-path chat-id) (fn [current]
|
(update-in db (db/updated-chat-signal-path chat-id) (fn [current]
|
||||||
(if current
|
(if current
|
||||||
(inc current)
|
(inc current)
|
||||||
0))))
|
0))))
|
||||||
|
|
||||||
(defn chat-updated? [db chat-id]
|
(defn chat-updated? [db chat-id]
|
||||||
(->> (db/updated-chat-signal-path chat-id)
|
(->> (db/updated-chat-signal-path chat-id)
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
(:require [syng-im.persistence.realm :as r]
|
(:require [syng-im.persistence.realm :as r]
|
||||||
[syng-im.utils.random :refer [timestamp]]
|
[syng-im.utils.random :refer [timestamp]]
|
||||||
[clojure.string :refer [join blank?]]
|
[clojure.string :refer [join blank?]]
|
||||||
[syng-im.db :as db]))
|
[syng-im.db :as db]
|
||||||
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
(defn signal-chats-updated [db]
|
(defn signal-chats-updated [db]
|
||||||
(update-in db db/updated-chats-signal-path (fn [current]
|
(update-in db db/updated-chats-signal-path (fn [current]
|
||||||
|
@ -32,9 +33,11 @@
|
||||||
([db chat-id identities]
|
([db chat-id identities]
|
||||||
(create-chat db chat-id identities nil))
|
(create-chat db chat-id identities nil))
|
||||||
([db chat-id identities chat-name]
|
([db chat-id identities chat-name]
|
||||||
(when-not (r/exists? :chats :chat-id chat-id)
|
(if (r/exists? :chats :chat-id chat-id)
|
||||||
|
db
|
||||||
(let [chat-name (or chat-name
|
(let [chat-name (or chat-name
|
||||||
(get-chat-name chat-id identities))]
|
(get-chat-name chat-id identities))
|
||||||
|
_ (log/debug "creating chat" chat-name)]
|
||||||
(r/write
|
(r/write
|
||||||
(fn []
|
(fn []
|
||||||
(let [group-chat? (> (count identities) 1)
|
(let [group-chat? (> (count identities) 1)
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
:whisper-identity "abc"
|
:whisper-identity "abc"
|
||||||
:name "fake"
|
:name "fake"
|
||||||
:photo-path ""}]
|
:photo-path ""}]
|
||||||
(realm/get-list "Contact")))
|
(realm/get-list :contacts)))
|
||||||
|
|
||||||
(defn load-syng-contacts [db]
|
(defn load-syng-contacts [db]
|
||||||
(let [contacts (map (fn [contact]
|
(let [contacts (map (fn [contact]
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
(assoc db :contacts contacts)))
|
(assoc db :contacts contacts)))
|
||||||
|
|
||||||
(defn- create-contact [{:keys [phone-number whisper-identity name photo-path]}]
|
(defn- create-contact [{:keys [phone-number whisper-identity name photo-path]}]
|
||||||
(realm/create "Contact"
|
(realm/create :contacts
|
||||||
{:phone-number phone-number
|
{:phone-number phone-number
|
||||||
:whisper-identity whisper-identity
|
:whisper-identity whisper-identity
|
||||||
:name (or name "")
|
:name (or name "")
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
(.-length objs))
|
(.-length objs))
|
||||||
|
|
||||||
(defn get-list [schema-name]
|
(defn get-list [schema-name]
|
||||||
(vals (js->clj (.objects realm schema-name) :keywordize-keys true)))
|
(vals (js->clj (.objects realm (to-string schema-name)) :keywordize-keys true)))
|
||||||
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
Loading…
Reference in New Issue