Group chat: stop watching of group's topic & handle new participant (fixes #265 #263)

Former-commit-id: 828010849b
This commit is contained in:
Roman Volosovskyi 2016-09-26 16:41:22 +03:00
parent 4543a80707
commit 3e95b85408
9 changed files with 61 additions and 44 deletions

View File

@ -3,9 +3,7 @@
[status-im.android.core :as core]
[figwheel.client :as figwheel :include-macros true]))
(enable-console-print!)
(set! js/console.disableYellowBox true)
(enable-console-print!)
(def cnt (r/atom 0))
(defn reloader [] @cnt [core/app-root])

View File

@ -373,6 +373,9 @@
(u/side-effect!
(fn [{:keys [web3 current-chat-id chats current-public-key]} _]
(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!
{:web3 web3
:group-id current-chat-id

View File

@ -9,7 +9,8 @@
[status-im.utils.types :refer [clj->json json->clj]]
[status-im.commands.utils :refer [generate-hiccup]]
[cljs.reader :as reader]
[clojure.string :as str]))
[clojure.string :as str]
[status-im.utils.hex :as i]))
(defn get-pending-messages! []
(->> (r/get-all :account :pending-message)
@ -19,9 +20,7 @@
(defn- get-id
[message-id to]
(let [to' (if (and to (str/starts-with? to "0x"))
(subs to 2)
to)
(let [to' (i/normalize-hex to)
to'' (when to' (subs to' 0 7))
id' (if to''
(str message-id "-" (subs to'' 0 7))

View File

@ -104,7 +104,7 @@
(defn stop-watching-group!
[{:keys [web3 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!
[{:keys [web3 group-id keypair callback identity]}]

View File

@ -18,30 +18,30 @@
updates-private-key]}
(get-in db [:accounts current-account-id])]
(let [groups (chats/active-group-chats)
w3 (protocol/init-whisper!
{:rpc-url "http://localhost:8545"
:identity public-key
:groups groups
:callback #(dispatch [:incoming-message %1 %2])
:ack-not-received-s-interval 125
:default-ttl 120
:send-online-s-interval 180
:ttl {}
:max-attempts-number 3
:delivery-loop-ms-interval 500
:profile-keypair {:public updates-public-key
:private updates-private-key}
:hashtags (u/get-hashtags status)
:pending-messages (pending-messages/get-pending-messages!)
:contacts (keep (fn [{:keys [whisper-identity
public-key
private-key]}]
(when (and public-key private-key)
{:identity whisper-identity
:keypair {:public public-key
:private private-key}}))
w3 (protocol/init-whisper!
{:rpc-url "http://localhost:8545"
:identity public-key
:groups groups
:callback #(dispatch [:incoming-message %1 %2])
:ack-not-received-s-interval 125
:default-ttl 120
:send-online-s-interval 180
:ttl {}
:max-attempts-number 3
:delivery-loop-ms-interval 500
:profile-keypair {:public updates-public-key
:private updates-private-key}
:hashtags (u/get-hashtags status)
:pending-messages (pending-messages/get-pending-messages!)
:contacts (keep (fn [{:keys [whisper-identity
public-key
private-key]}]
(when (and public-key private-key)
{:identity whisper-identity
:keypair {:public public-key
:private private-key}}))
(contacts/get-contacts))})]
(contacts/get-contacts))})]
(assoc db :web3 w3)))))
(register-handler :incoming-message
@ -56,6 +56,7 @@
(dispatch [:pending-message-remove message]))
:seen (dispatch [:message-seen 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])
:contact-request (dispatch [:contact-request-received message])
:discovery (dispatch [:discovery-response-received message])
@ -156,11 +157,12 @@
(register-handler :participant-invited-to-group
(u/side-effect!
(fn [{:keys [current-public-key]} [action from group-id identity message-id]]
(log/debug action message-id from group-id identity)
(fn [{:keys [current-public-key]}
[_ {:keys [from]
{:keys [group-id identity message-id]} :payload}]]
(participant-invited-to-group-message group-id current-public-key identity from message-id)
;; todo uncomment
#_(dispatch [:add-contact-to-group! group-id identity]))))
(when-not (= current-public-key identity)
(dispatch [:add-contact-to-group! group-id identity])))))
(register-handler :add-contact-to-group!
(u/side-effect!
@ -244,9 +246,9 @@
(when (#{:message :group-message} type)
(messages/update-message! {:message-id id
:delivery-status :pending}))))
(fn [db [_ {:keys [type id to groupd-id]}]]
(fn [db [_ {:keys [type id to group-id]}]]
(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])]
(if-not (= :seen current-status)
(assoc-in db [:message-status chat-id id] :pending)

View File

@ -3,7 +3,8 @@
[status-im.protocol.ack :as ack]
[status-im.protocol.web3.utils :as u]
[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]
(debug :parse-payload)
@ -34,7 +35,8 @@
(debug :message-received)
(let [{:keys [from payload to] :as message}
(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'}
(parse-payload payload)

View File

@ -89,7 +89,14 @@
(fn [messages]
(when messages
(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')
(assoc messages id message')
(dissoc messages id))))))

View File

@ -1,7 +1,8 @@
(ns status-im.transactions.subs
(:require-macros [reagent.ratom :refer [reaction]])
(: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
(fn [db]
@ -19,9 +20,7 @@
(fn [_ [_ address]]
(let [contacts (subscribe [:contacts-by-address])
address' (when address
(if (s/starts-with? address "0x")
(subs address 2)
address))]
(i/normalize-hex address))]
(reaction (@contacts address')))))
(register-sub :wrong-password?

View File

@ -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))