From 96b5c92281b8cb97e5847f537eb641e3ac9f4350 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 5 Jul 2016 18:49:31 +0300 Subject: [PATCH] fix double generation of message's id --- .gitignore | 1 + src/cljs/status_im/protocol/api.cljs | 114 +++++++++++++------------- src/cljs/status_im/protocol/web3.cljs | 8 +- 3 files changed, 63 insertions(+), 60 deletions(-) diff --git a/.gitignore b/.gitignore index 5fd8fde..d23decf 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pom.xml.asc .hgignore .hg/ .idea +*.iml diff --git a/src/cljs/status_im/protocol/api.cljs b/src/cljs/status_im/protocol/api.cljs index fe7f18f..1e890ce 100644 --- a/src/cljs/status_im/protocol/api.cljs +++ b/src/cljs/status_im/protocol/api.cljs @@ -2,49 +2,49 @@ (:require [cljs.core.async :refer [ (set identities) - (conj my-identity))] + identities (-> (set identities) + (conj my-identity))] (save-keypair store group-topic keypair) (save-identities store group-topic identities) (save-group-admin store group-topic my-identity) @@ -137,14 +139,14 @@ (defn group-add-participant "Only call if you are the group-admin" [group-id new-peer-identity] - (let [store (storage) + (let [store (storage) my-identity (my-identity)] (if-not (group-admin? store group-id my-identity) (log/error "Called group-add-participant but not group admin, group-id:" group-id "my-identity:" my-identity) (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 group-name identities keypair)] @@ -158,14 +160,14 @@ (defn group-remove-participant "Only call if you are the group-admin" [group-id identity-to-remove] - (let [store (storage) + (let [store (storage) my-identity (my-identity)] (if-not (group-admin? store group-id my-identity) (log/error "Called group-remove-participant but not group admin, group-id:" group-id "my-identity:" my-identity) (let [connection (connection) identities (-> (get-identities store group-id) (disj identity-to-remove)) - keypair (new-keypair)] + keypair (new-keypair)] (save-identities store group-id identities) (save-keypair store group-id keypair) (doseq [ident identities :when (not (= ident my-identity))] @@ -177,7 +179,7 @@ (post-msg connection msg)))))) (defn leave-group-chat [group-id] - (let [store (storage) + (let [store (storage) my-identity (my-identity)] (send-group-msg {:group-id group-id :type :left-group @@ -195,13 +197,13 @@ (defn broadcast-discover-status [name status hashtags] (log/debug "Broadcasting status: " name status hashtags) (let [topics (get-hashtag-topics hashtags)] - (stop-broadcasting-discover) - (listen (connection) handle-incoming-whisper-msg {:topics topics}) - (save-name name) - (save-topics topics) - (save-hashtags hashtags) - (save-status status) - (broadcast-status))) + (stop-broadcasting-discover) + (listen (connection) handle-incoming-whisper-msg {:topics topics}) + (save-name name) + (save-topics topics) + (save-hashtags hashtags) + (save-status status) + (broadcast-status))) (defn search-discover [hashtags] (let [{:keys [msg-id msg]} (discovery-search-message hashtags)] diff --git a/src/cljs/status_im/protocol/web3.cljs b/src/cljs/status_im/protocol/web3.cljs index 05f4aff..88a77e0 100644 --- a/src/cljs/status_im/protocol/web3.cljs +++ b/src/cljs/status_im/protocol/web3.cljs @@ -95,15 +95,15 @@ (defn make-msg "Returns [msg-id msg], `msg` is formed for Web3.shh.post()" - [{:keys [from to ttl topics payload encrypt? public-key clear-info] + [{:keys [from to ttl topics payload encrypt? public-key clear-info msg-id] :or {ttl status-msg-ttl topics []}}] - (let [msg-id (random/id)] - {:msg-id msg-id + (let [msg-id' (or msg-id (random/id))] + {:msg-id msg-id' :msg (cond-> {:ttl ttl :topics (->> (conj topics status-app-topic) (mapv from-utf8)) - :payload (cond->> (merge payload {:msg-id msg-id}) + :payload (cond->> (merge payload {:msg-id msg-id'}) true (str) encrypt? (encrypt-payload public-key clear-info) true (from-utf8))}