Merge pull request #270 from status-im/bug/group-leaving-bugs
Group chat: stop watching of group's topic & handle new participant
Former-commit-id: caad695d90
This commit is contained in:
commit
150b84fe8f
|
@ -3,9 +3,7 @@
|
||||||
[status-im.android.core :as core]
|
[status-im.android.core :as core]
|
||||||
[figwheel.client :as figwheel :include-macros true]))
|
[figwheel.client :as figwheel :include-macros true]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
(set! js/console.disableYellowBox true)
|
|
||||||
|
|
||||||
(def cnt (r/atom 0))
|
(def cnt (r/atom 0))
|
||||||
(defn reloader [] @cnt [core/app-root])
|
(defn reloader [] @cnt [core/app-root])
|
||||||
|
|
|
@ -373,6 +373,9 @@
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [web3 current-chat-id chats current-public-key]} _]
|
(fn [{:keys [web3 current-chat-id chats current-public-key]} _]
|
||||||
(let [{:keys [public-key private-key]} (chats current-chat-id)]
|
(let [{:keys [public-key private-key]} (chats current-chat-id)]
|
||||||
|
(protocol/stop-watching-group!
|
||||||
|
{:web3 web3
|
||||||
|
:group-id current-chat-id})
|
||||||
(protocol/leave-group-chat!
|
(protocol/leave-group-chat!
|
||||||
{:web3 web3
|
{:web3 web3
|
||||||
:group-id current-chat-id
|
:group-id current-chat-id
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
[status-im.utils.types :refer [clj->json json->clj]]
|
[status-im.utils.types :refer [clj->json json->clj]]
|
||||||
[status-im.commands.utils :refer [generate-hiccup]]
|
[status-im.commands.utils :refer [generate-hiccup]]
|
||||||
[cljs.reader :as reader]
|
[cljs.reader :as reader]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[status-im.utils.hex :as i]))
|
||||||
|
|
||||||
(defn get-pending-messages! []
|
(defn get-pending-messages! []
|
||||||
(->> (r/get-all :account :pending-message)
|
(->> (r/get-all :account :pending-message)
|
||||||
|
@ -19,9 +20,7 @@
|
||||||
|
|
||||||
(defn- get-id
|
(defn- get-id
|
||||||
[message-id to]
|
[message-id to]
|
||||||
(let [to' (if (and to (str/starts-with? to "0x"))
|
(let [to' (i/normalize-hex to)
|
||||||
(subs to 2)
|
|
||||||
to)
|
|
||||||
to'' (when to' (subs to' 0 7))
|
to'' (when to' (subs to' 0 7))
|
||||||
id' (if to''
|
id' (if to''
|
||||||
(str message-id "-" (subs to'' 0 7))
|
(str message-id "-" (subs to'' 0 7))
|
||||||
|
|
|
@ -104,7 +104,7 @@
|
||||||
(defn stop-watching-group!
|
(defn stop-watching-group!
|
||||||
[{:keys [web3 group-id]}]
|
[{:keys [web3 group-id]}]
|
||||||
{:pre [(valid? :message/chat-id group-id)]}
|
{:pre [(valid? :message/chat-id group-id)]}
|
||||||
(f/remove-filter! web3 [group-id]))
|
(f/remove-filter! web3 {:topics [group-id]}))
|
||||||
|
|
||||||
(defn start-watching-group!
|
(defn start-watching-group!
|
||||||
[{:keys [web3 group-id keypair callback identity]}]
|
[{:keys [web3 group-id keypair callback identity]}]
|
||||||
|
|
|
@ -18,30 +18,30 @@
|
||||||
updates-private-key]}
|
updates-private-key]}
|
||||||
(get-in db [:accounts current-account-id])]
|
(get-in db [:accounts current-account-id])]
|
||||||
(let [groups (chats/active-group-chats)
|
(let [groups (chats/active-group-chats)
|
||||||
w3 (protocol/init-whisper!
|
w3 (protocol/init-whisper!
|
||||||
{:rpc-url "http://localhost:8545"
|
{:rpc-url "http://localhost:8545"
|
||||||
:identity public-key
|
:identity public-key
|
||||||
:groups groups
|
:groups groups
|
||||||
:callback #(dispatch [:incoming-message %1 %2])
|
:callback #(dispatch [:incoming-message %1 %2])
|
||||||
:ack-not-received-s-interval 125
|
:ack-not-received-s-interval 125
|
||||||
:default-ttl 120
|
:default-ttl 120
|
||||||
:send-online-s-interval 180
|
:send-online-s-interval 180
|
||||||
:ttl {}
|
:ttl {}
|
||||||
:max-attempts-number 3
|
:max-attempts-number 3
|
||||||
:delivery-loop-ms-interval 500
|
:delivery-loop-ms-interval 500
|
||||||
:profile-keypair {:public updates-public-key
|
:profile-keypair {:public updates-public-key
|
||||||
:private updates-private-key}
|
:private updates-private-key}
|
||||||
:hashtags (u/get-hashtags status)
|
:hashtags (u/get-hashtags status)
|
||||||
:pending-messages (pending-messages/get-pending-messages!)
|
:pending-messages (pending-messages/get-pending-messages!)
|
||||||
:contacts (keep (fn [{:keys [whisper-identity
|
:contacts (keep (fn [{:keys [whisper-identity
|
||||||
public-key
|
public-key
|
||||||
private-key]}]
|
private-key]}]
|
||||||
(when (and public-key private-key)
|
(when (and public-key private-key)
|
||||||
{:identity whisper-identity
|
{:identity whisper-identity
|
||||||
:keypair {:public public-key
|
:keypair {:public public-key
|
||||||
:private private-key}}))
|
:private private-key}}))
|
||||||
|
|
||||||
(contacts/get-contacts))})]
|
(contacts/get-contacts))})]
|
||||||
(assoc db :web3 w3)))))
|
(assoc db :web3 w3)))))
|
||||||
|
|
||||||
(register-handler :incoming-message
|
(register-handler :incoming-message
|
||||||
|
@ -56,6 +56,7 @@
|
||||||
(dispatch [:pending-message-remove message]))
|
(dispatch [:pending-message-remove message]))
|
||||||
:seen (dispatch [:message-seen message])
|
:seen (dispatch [:message-seen message])
|
||||||
:group-invitation (dispatch [:group-chat-invite-received message])
|
:group-invitation (dispatch [:group-chat-invite-received message])
|
||||||
|
:add-group-identity (dispatch [:participant-invited-to-group message])
|
||||||
:leave-group (dispatch [:participant-left-group message])
|
:leave-group (dispatch [:participant-left-group message])
|
||||||
:contact-request (dispatch [:contact-request-received message])
|
:contact-request (dispatch [:contact-request-received message])
|
||||||
:discovery (dispatch [:discovery-response-received message])
|
:discovery (dispatch [:discovery-response-received message])
|
||||||
|
@ -156,11 +157,12 @@
|
||||||
|
|
||||||
(register-handler :participant-invited-to-group
|
(register-handler :participant-invited-to-group
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-public-key]} [action from group-id identity message-id]]
|
(fn [{:keys [current-public-key]}
|
||||||
(log/debug action message-id from group-id identity)
|
[_ {:keys [from]
|
||||||
|
{:keys [group-id identity message-id]} :payload}]]
|
||||||
(participant-invited-to-group-message group-id current-public-key identity from message-id)
|
(participant-invited-to-group-message group-id current-public-key identity from message-id)
|
||||||
;; todo uncomment
|
(when-not (= current-public-key identity)
|
||||||
#_(dispatch [:add-contact-to-group! group-id identity]))))
|
(dispatch [:add-contact-to-group! group-id identity])))))
|
||||||
|
|
||||||
(register-handler :add-contact-to-group!
|
(register-handler :add-contact-to-group!
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
@ -244,9 +246,9 @@
|
||||||
(when (#{:message :group-message} type)
|
(when (#{:message :group-message} type)
|
||||||
(messages/update-message! {:message-id id
|
(messages/update-message! {:message-id id
|
||||||
:delivery-status :pending}))))
|
:delivery-status :pending}))))
|
||||||
(fn [db [_ {:keys [type id to groupd-id]}]]
|
(fn [db [_ {:keys [type id to group-id]}]]
|
||||||
(if (#{:message :group-message} type)
|
(if (#{:message :group-message} type)
|
||||||
(let [chat-id (or groupd-id to)
|
(let [chat-id (or group-id to)
|
||||||
current-status (get-in db [:message-status chat-id id])]
|
current-status (get-in db [:message-status chat-id id])]
|
||||||
(if-not (= :seen current-status)
|
(if-not (= :seen current-status)
|
||||||
(assoc-in db [:message-status chat-id id] :pending)
|
(assoc-in db [:message-status chat-id id] :pending)
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
[status-im.protocol.ack :as ack]
|
[status-im.protocol.ack :as ack]
|
||||||
[status-im.protocol.web3.utils :as u]
|
[status-im.protocol.web3.utils :as u]
|
||||||
[status-im.protocol.encryption :as e]
|
[status-im.protocol.encryption :as e]
|
||||||
[taoensso.timbre :refer-macros [debug] :as log]))
|
[taoensso.timbre :refer-macros [debug] :as log]
|
||||||
|
[status-im.utils.hex :as i]))
|
||||||
|
|
||||||
(defn- parse-payload [payload]
|
(defn- parse-payload [payload]
|
||||||
(debug :parse-payload)
|
(debug :parse-payload)
|
||||||
|
@ -34,7 +35,8 @@
|
||||||
(debug :message-received)
|
(debug :message-received)
|
||||||
(let [{:keys [from payload to] :as message}
|
(let [{:keys [from payload to] :as message}
|
||||||
(js->clj js-message :keywordize-keys true)]
|
(js->clj js-message :keywordize-keys true)]
|
||||||
(when-not (= identity from)
|
(when-not (= (i/normalize-hex identity)
|
||||||
|
(i/normalize-hex from))
|
||||||
(let [{:keys [type ack?] :as payload'}
|
(let [{:keys [type ack?] :as payload'}
|
||||||
(parse-payload payload)
|
(parse-payload payload)
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,14 @@
|
||||||
(fn [messages]
|
(fn [messages]
|
||||||
(when messages
|
(when messages
|
||||||
(let [message (messages id)
|
(let [message (messages id)
|
||||||
message' (dissoc message to)]
|
;; Message that is send without specified "from" option
|
||||||
|
;; is stored in pending "messages" map as
|
||||||
|
;; {message-id {nil message}}.
|
||||||
|
;; When we receive the first ack for such message it is
|
||||||
|
;; removed from pending messages adding of the nil key
|
||||||
|
;; to the next dissoc form
|
||||||
|
;; todo rewrite handling of ack message in more clear way
|
||||||
|
message' (dissoc message to nil)]
|
||||||
(if (seq message')
|
(if (seq message')
|
||||||
(assoc messages id message')
|
(assoc messages id message')
|
||||||
(dissoc messages id))))))
|
(dissoc messages id))))))
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
(ns status-im.transactions.subs
|
(ns status-im.transactions.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub subscribe]]
|
(:require [re-frame.core :refer [register-sub subscribe]]
|
||||||
[clojure.string :as s]))
|
[clojure.string :as s]
|
||||||
|
[status-im.utils.hex :as i]))
|
||||||
|
|
||||||
(register-sub :transactions
|
(register-sub :transactions
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
@ -19,9 +20,7 @@
|
||||||
(fn [_ [_ address]]
|
(fn [_ [_ address]]
|
||||||
(let [contacts (subscribe [:contacts-by-address])
|
(let [contacts (subscribe [:contacts-by-address])
|
||||||
address' (when address
|
address' (when address
|
||||||
(if (s/starts-with? address "0x")
|
(i/normalize-hex address))]
|
||||||
(subs address 2)
|
|
||||||
address))]
|
|
||||||
(reaction (@contacts address')))))
|
(reaction (@contacts address')))))
|
||||||
|
|
||||||
(register-sub :wrong-password?
|
(register-sub :wrong-password?
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
(ns status-im.utils.hex
|
||||||
|
(:require [clojure.string :as s]))
|
||||||
|
|
||||||
|
(defn normalize-hex [hex]
|
||||||
|
(if (and hex (s/starts-with? hex "0x"))
|
||||||
|
(subs hex 2)
|
||||||
|
hex))
|
Loading…
Reference in New Issue