send group name to new participants, catch exception from ecjs

This commit is contained in:
michaelr 2016-04-29 02:03:05 +03:00
parent fe45178ce0
commit dd9e1d98f4
4 changed files with 27 additions and 8 deletions

View File

@ -14,8 +14,10 @@
get-identities
save-identities
save-group-admin
save-group-name
group-admin?
remove-group-data]]
remove-group-data
group-name]]
[syng-im.protocol.delivery :refer [start-delivery-loop]]
[syng-im.protocol.web3 :refer [listen
make-msg
@ -103,7 +105,7 @@
(defn start-group-chat
([identities]
(start-group-chat identities nil))
(start-group-chat identities nil))
([identities group-name]
(let [group-topic (random/id)
keypair (new-keypair)
@ -115,6 +117,7 @@
(save-keypair store group-topic keypair)
(save-identities store group-topic identities)
(save-group-admin store group-topic my-identity)
(save-group-name store group-topic group-name)
(listen connection handle-incoming-whisper-msg {:topics [group-topic]})
(doseq [ident identities :when (not (= ident my-identity))]
(let [{:keys [msg-id msg]} (init-group-chat-msg ident group-topic identities keypair group-name)]
@ -132,9 +135,10 @@
(let [connection (connection)
identities (-> (get-identities store group-id)
(conj new-peer-identity))
keypair (get-keypair store group-id)]
keypair (get-keypair store group-id)
group-name (group-name store group-id)]
(save-identities store group-id identities)
(let [{:keys [msg-id msg]} (group-add-participant-msg new-peer-identity group-id identities keypair)]
(let [{:keys [msg-id msg]} (group-add-participant-msg new-peer-identity group-id group-name identities keypair)]
(add-pending-message msg-id msg {:internal? true})
(post-msg connection msg))
(send-group-msg {:group-id group-id

View File

@ -34,11 +34,12 @@
:identities identities
:keypair keypair}}))
(defn group-add-participant-msg [to group-id identities keypair]
(defn group-add-participant-msg [to group-id group-name identities keypair]
(make-msg {:from (state/my-identity)
:to to
:payload {:type :init-group-chat
:group-topic group-id
:group-name group-name
:identities identities
:keypair keypair}}))

View File

@ -75,9 +75,12 @@
(defn decrypt-group-msg [group-topic encrypted-payload]
(let [store (storage)]
(when-let [{private-key :private} (get-keypair store group-topic)]
(-> (decrypt private-key encrypted-payload)
(read-string)
(assoc :group-topic group-topic)))))
(try
(-> (decrypt private-key encrypted-payload)
(read-string)
(assoc :group-topic group-topic))
(catch :default e
(log/warn "Failed to decrypt group message for group" group-topic e))))))
(defn handle-group-user-msg [web3 from {:keys [msg-id group-topic] :as payload}]
(send-ack web3 from msg-id)

View File

@ -11,6 +11,13 @@
(defn topic-admin-ident-key [topic]
(str "group-chat.topic-admin-ident." topic))
(defn topic-group-name-key [topic]
(str "group-chat.topic-group-name." topic))
(defn save-group-name [storage topic group-name]
(let [key (topic-group-name-key topic)]
(s/put storage key group-name)))
(defn save-keypair [storage topic keypair]
(let [key (topic-keypair-key topic)]
(s/put storage key keypair)))
@ -51,6 +58,10 @@
(let [key (topic-keypair-key topic)]
(s/get storage key)))
(defn group-name [storage topic]
(let [key (topic-group-name-key topic)]
(s/get storage key)))
(defn remove-group-data [storage topic]
(let [keypair-key (topic-keypair-key topic)
identities-key (topic-identities-key topic)]