Merge pull request #47 from status-im/protocol-integration-bugfixes
Protocol integration bugfixes
This commit is contained in:
commit
e4c6f6d531
|
@ -9,22 +9,7 @@
|
|||
(def content-type-command "command")
|
||||
(def content-type-command-request "command-request")
|
||||
(def content-type-status "status")
|
||||
(def group-chat-colors [{:background "#AB7967", :text "#FFFFFF"}
|
||||
{:background "#B48EAD", :text "#FFFFFF"}
|
||||
{:background "#8FA1B3", :text "#FFFFFF"}
|
||||
{:background "#96B5B4", :text "#FFFFFF"}
|
||||
{:background "#A3BE8C", :text "#FFFFFF"}
|
||||
{:background "#EBCB8B", :text "#FFFFFF"}
|
||||
{:background "#D08770", :text "#FFFFFF"}
|
||||
{:background "#BF616A", :text "#FFFFFF"}
|
||||
{:background "#EFF1F5", :text "#000000"}
|
||||
{:background "#DFE1E8", :text "#000000"}
|
||||
{:background "#C0C5CE", :text "#000000"}
|
||||
{:background "#A7ADBA", :text "#000000"}
|
||||
{:background "#65737E", :text "#FFFFFF"}
|
||||
{:background "#4F5B66", :text "#FFFFFF"}
|
||||
{:background "#343D46", :text "#FFFFFF"}
|
||||
{:background "#2B303B", :text "#FFFFFF"}])
|
||||
|
||||
|
||||
(comment
|
||||
|
||||
|
|
|
@ -29,10 +29,12 @@
|
|||
check-suggestion]]
|
||||
[syng-im.handlers.sign-up :as sign-up-service]
|
||||
|
||||
[syng-im.models.chats :refer [create-chat
|
||||
[syng-im.models.chats :refer [chat-exists?
|
||||
create-chat
|
||||
chat-add-participants
|
||||
chat-remove-participants
|
||||
set-chat-active]]
|
||||
set-chat-active
|
||||
re-join-group-chat]]
|
||||
[syng-im.models.chat :refer [signal-chat-updated
|
||||
set-current-chat-id
|
||||
current-chat-id
|
||||
|
@ -148,13 +150,15 @@
|
|||
(defn joined-chat-msg [chat-id from msg-id]
|
||||
(let [contact-name (:name (contacts/contact-by-identity from))]
|
||||
(save-message chat-id {:from "system"
|
||||
:msg-id msg-id
|
||||
:msg-id (str msg-id "_" from)
|
||||
:content (str (or contact-name from) " received chat invitation")
|
||||
:content-type text-content-type})))
|
||||
|
||||
(defn participant-invited-to-group-msg [chat-id identity from msg-id]
|
||||
(let [inviter-name (:name (contacts/contact-by-identity from))
|
||||
invitee-name (:name (contacts/contact-by-identity identity))]
|
||||
invitee-name (if (= identity (api/my-identity))
|
||||
"You"
|
||||
(:name (contacts/contact-by-identity identity)))]
|
||||
(save-message chat-id {:from "system"
|
||||
:msg-id msg-id
|
||||
:content (str (or inviter-name from) " invited " (or invitee-name identity))
|
||||
|
@ -218,8 +222,10 @@
|
|||
(register-handler :participant-left-group
|
||||
(fn [db [action from group-id msg-id]]
|
||||
(log/debug action msg-id from group-id)
|
||||
(participant-left-group-msg group-id from msg-id)
|
||||
(signal-chat-updated db group-id)))
|
||||
(if (= (api/my-identity) from)
|
||||
db
|
||||
(do (participant-left-group-msg group-id from msg-id)
|
||||
(signal-chat-updated db group-id)))))
|
||||
|
||||
(register-handler :participant-invited-to-group
|
||||
(fn [db [action from group-id identity msg-id]]
|
||||
|
@ -498,8 +504,10 @@
|
|||
(register-handler :group-chat-invite-received
|
||||
(fn [db [action from group-id identities group-name]]
|
||||
(log/debug action from group-id identities)
|
||||
(create-chat db group-id identities true group-name)))
|
||||
(if (chat-exists? group-id)
|
||||
(re-join-group-chat db group-id identities group-name)
|
||||
(create-chat db group-id identities true group-name))))
|
||||
|
||||
(comment
|
||||
|
||||
(dispatch [:set-signed-up true])
|
||||
)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
(ns syng-im.models.chats
|
||||
(:require [syng-im.persistence.realm :as r]
|
||||
(:require [clojure.set :refer [difference]]
|
||||
[syng-im.persistence.realm :as r]
|
||||
[syng-im.utils.random :refer [timestamp]]
|
||||
[clojure.string :refer [join blank?]]
|
||||
[syng-im.db :as db]
|
||||
[syng-im.utils.logging :as log]
|
||||
[syng-im.constants :refer [group-chat-colors]]
|
||||
[syng-im.persistence.realm-queries :refer [include-query]]))
|
||||
[syng-im.persistence.realm-queries :refer [include-query]]
|
||||
[syng-im.models.chat :refer [signal-chat-updated]]))
|
||||
|
||||
(defn signal-chats-updated [db]
|
||||
(update-in db db/updated-chats-signal-path (fn [current]
|
||||
|
@ -31,21 +32,22 @@
|
|||
(or (chat-name-from-contacts identities)
|
||||
chat-id))
|
||||
|
||||
(defn chat-exists? [chat-id]
|
||||
(r/exists? :chats :chat-id chat-id))
|
||||
|
||||
(defn create-chat
|
||||
([db chat-id identities group-chat?]
|
||||
(create-chat db chat-id identities group-chat? nil))
|
||||
([db chat-id identities group-chat? chat-name]
|
||||
(if (r/exists? :chats :chat-id chat-id)
|
||||
(if (chat-exists? chat-id)
|
||||
db
|
||||
(let [chat-name (or chat-name
|
||||
(get-chat-name chat-id identities))
|
||||
_ (log/debug "creating chat" chat-name)]
|
||||
(r/write
|
||||
(fn []
|
||||
(let [contacts (mapv (fn [ident {:keys [background text]}]
|
||||
{:identity ident
|
||||
:background-color background
|
||||
:text-color text}) identities group-chat-colors)]
|
||||
(let [contacts (mapv (fn [ident]
|
||||
{:identity ident}) identities)]
|
||||
(r/create :chats {:chat-id chat-id
|
||||
:is-active true
|
||||
:name chat-name
|
||||
|
@ -54,6 +56,30 @@
|
|||
:contacts contacts}))))
|
||||
(signal-chats-updated db)))))
|
||||
|
||||
(defn chat-contacts [chat-id]
|
||||
(-> (r/get-by-field :chats :chat-id chat-id)
|
||||
(r/single)
|
||||
(aget "contacts")))
|
||||
|
||||
(defn re-join-group-chat [db group-id identities group-name]
|
||||
(r/write
|
||||
(fn []
|
||||
(let [new-identities (set identities)
|
||||
only-old-contacts (->> (chat-contacts group-id)
|
||||
(r/cljs-list)
|
||||
(remove (fn [{:keys [identity]}]
|
||||
(new-identities identity))))
|
||||
contacts (->> new-identities
|
||||
(mapv (fn [ident]
|
||||
{:identity ident}))
|
||||
(concat only-old-contacts))]
|
||||
(r/create :chats {:chat-id group-id
|
||||
:is-active true
|
||||
:name group-name
|
||||
:contacts contacts} true))))
|
||||
(-> (signal-chats-updated db)
|
||||
(signal-chat-updated group-id)))
|
||||
|
||||
(defn chats-list []
|
||||
(r/sorted (r/get-all :chats) :timestamp :desc))
|
||||
|
||||
|
@ -65,20 +91,12 @@
|
|||
(defn chat-add-participants [chat-id identities]
|
||||
(r/write
|
||||
(fn []
|
||||
(let [contacts (-> (r/get-by-field :chats :chat-id chat-id)
|
||||
(r/single)
|
||||
(aget "contacts"))
|
||||
colors-in-use (set (.map contacts (fn [object index collection]
|
||||
{:text-color (aget object "text-color")
|
||||
:background-color (aget object "background-color")})))
|
||||
colors (filter (fn [color]
|
||||
(not (contains? colors-in-use color))) group-chat-colors)
|
||||
new-contacts (mapv (fn [ident {:keys [background text]}]
|
||||
{:identity ident
|
||||
:background-color background
|
||||
:text-color text}) identities colors)]
|
||||
(doseq [contact new-contacts]
|
||||
(.push contacts (clj->js contact)))))))
|
||||
(let [contacts (chat-contacts chat-id)]
|
||||
(doseq [contact-identity identities]
|
||||
(if-let [contact-exists (.find contacts (fn [object index collection]
|
||||
(= contact-identity (aget object "identity"))))]
|
||||
(aset contact-exists "is-in-chat" true)
|
||||
(.push contacts (clj->js {:identity contact-identity}))))))))
|
||||
|
||||
(defn chat-remove-participants [chat-id identities]
|
||||
(r/write
|
||||
|
@ -87,7 +105,8 @@
|
|||
chat (r/single (r/get-by-field :chats :chat-id chat-id))]
|
||||
(-> (aget chat "contacts")
|
||||
(r/filtered query)
|
||||
(r/delete))))))
|
||||
(.forEach (fn [object index collection]
|
||||
(aset object "is-in-chat" false))))))))
|
||||
|
||||
(defn active-group-chats []
|
||||
(let [results (r/filtered (r/get-all :chats)
|
||||
|
@ -102,7 +121,7 @@
|
|||
(r/single)
|
||||
(aset "is-active" active?)))))
|
||||
|
||||
#_(comment
|
||||
(comment
|
||||
(active-group-chats)
|
||||
|
||||
|
||||
|
@ -119,10 +138,9 @@
|
|||
|
||||
|
||||
(-> (aget (aget (chats-list) 0) "contacts")
|
||||
(js->clj :keywordize-keys true)
|
||||
)
|
||||
(r/cljs-list))
|
||||
|
||||
(r/delete (chats-list))
|
||||
(r/write (fn [] (r/delete (chats-list))))
|
||||
|
||||
(swap! re-frame.db/app-db signal-chats-updated)
|
||||
|
||||
|
@ -136,4 +154,8 @@
|
|||
(swap! re-frame.db/app-db (fn [db]
|
||||
(create-chat db "A group chat")))
|
||||
|
||||
|
||||
(-> (chats-list)
|
||||
(.find (fn [object index collection]
|
||||
(= "console1" (aget object "chat-id")))))
|
||||
)
|
||||
|
|
|
@ -111,13 +111,13 @@
|
|||
(comment
|
||||
|
||||
(r/write #(create-contact {:phone-number "0543072333"
|
||||
:whisper-identity "0x041e1a37a0317a66f8d826e6779d808a9f39b88c2f896c5d3c08c4ded259719be256e4e6d6f49dab2324993ec822b588f2c0591b7a723cb0be659f2eccf48b5fed"
|
||||
:name "Mr. Bean"
|
||||
:whisper-identity "0x04e43e861a6dd99ad9eee7bd58af89dcaa430188ebec8698de7b7bad54573324fff4ac5cb9bb277af317efd7abfc917b91bf48cc41e40bf70062fd79400016a1f9"
|
||||
:name "Splinter"
|
||||
:photo-path ""}))
|
||||
|
||||
(r/write #(create-contact {:phone-number "0544828649"
|
||||
:whisper-identity "0x04dcbf434bbf6925f251b7f43337f66a5a3f943e8983284045af703551cab39684d8c838e73f0234169f26fe126d7ef1ea3b8c1013e7dad1d4c5a82c7a651647fd"
|
||||
:name "Mr. Batman"
|
||||
:whisper-identity "0x0487954e7fa746d8cf787403c2c491aadad540b9bb1f0f7b8184792e91c33b6a394079295f5777ec6d4af9ad5ba24794b3ff1ec8be9ff6a708c85a163733192665"
|
||||
:name "Exodius"
|
||||
:photo-path ""}))
|
||||
|
||||
(r/write #(create-contact {:phone-number "0522222222"
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
:optional true}}}
|
||||
{:name :chat-contact
|
||||
:properties {:identity "string"
|
||||
:text-color "string"
|
||||
:background-color "string"}}
|
||||
:is-in-chat {:type "bool"
|
||||
:default true}}}
|
||||
{:name :chats
|
||||
:primaryKey :chat-id
|
||||
:properties {:chat-id "string"
|
||||
|
@ -106,6 +106,10 @@
|
|||
(some-> (aget result 0)
|
||||
(js->clj :keywordize-keys true)))
|
||||
|
||||
(defn cljs-list [results]
|
||||
(-> (js->clj results :keywordize-keys true)
|
||||
(vals)))
|
||||
|
||||
(defn list-to-array [record list-field]
|
||||
(update-in record [list-field] (comp vec vals)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue