Skip to content

Commit 0c48d09

Browse files
committed
Add back group chats messages
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
1 parent 2346c0d commit 0c48d09

39 files changed

Lines changed: 415 additions & 262 deletions

File tree

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ CACHED_WEBVIEWS_ENABLED=1
1717
EXTENSIONS=1
1818
HARDWALLET_ENABLED=0
1919
PFS_ENCRYPTION_ENABLED=0
20+
GROUP_CHATS_ENABLED=0

.env.e2e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ POW_TIME=1
99
DEFAULT_NETWORK=testnet_rpc
1010
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
1111
DEBUG_WEBVIEW=1
12-
GROUP_CHATS_ENABLED=1
12+
GROUP_CHATS_ENABLED=0
1313
EXTENSIONS=0
1414
PFS_ENCRYPTION_ENABLED=0

desktop_files/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop_files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"string_decoder": "0.10.31",
8585
"text-encoding": "^0.6.4",
8686
"url": "0.10.3",
87-
"web3": "github:status-im/web3.js#feature/shhext"
87+
"web3": "git+https://github.com/status-im/web3.js.git#feature/chat-api"
8888
},
8989
"devDependencies": {
9090
"patch-package": "^5.1.1"

mobile_files/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile_files/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@
6767
"string_decoder": "0.10.31",
6868
"text-encoding": "^0.6.4",
6969
"url": "0.10.3",
70-
"web3": "https://github.com/status-im/web3.js.git#feature/shhext"
70+
"web3": "git+https://github.com/status-im/web3.js.git#feature/chat-api"
7171
}
7272
}

src/status_im/chat/events.cljs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
[status-im.data-store.user-statuses :as user-statuses-store]
1111
[status-im.i18n :as i18n]
1212
[status-im.transport.message.core :as transport.message]
13-
[status-im.transport.message.v1.group-chat :as group-chat]
13+
[status-im.transport.message.v1.core :as protocol]
1414
[status-im.transport.message.v1.public-chat :as public-chat]
1515
[status-im.ui.screens.navigation :as navigation]
1616
[status-im.utils.fx :as fx]
17+
[status-im.group-chats.core :as group-chats]
1718
[status-im.utils.handlers :as handlers]
1819
[status-im.utils.utils :as utils]))
1920

@@ -128,22 +129,22 @@
128129
(cons username)
129130
(string/join ", ")))
130131

132+
(fx/defn send-group-update [cofx group-update chat-id]
133+
(transport.message/send group-update chat-id cofx))
134+
131135
(handlers/register-handler-fx
132136
:create-new-group-chat-and-open
133137
[(re-frame/inject-cofx :random-id)]
134138
(fn [{:keys [db random-id] :as cofx} [_ group-name]]
135-
(let [selected-contacts (:group/selected-contacts db)
136-
chat-name (if-not (string/blank? group-name)
137-
group-name
138-
(group-name-from-contacts selected-contacts
139-
(:contacts/contacts db)
140-
(:username db)))]
139+
(let [my-public-key (:current-public-key db)
140+
selected-contacts (conj (:group/selected-contacts db)
141+
my-public-key)
142+
group-update (protocol/GroupMembershipUpdate. random-id group-name my-public-key selected-contacts nil nil nil)]
141143
(fx/merge cofx
142144
{:db (assoc db :group/selected-contacts #{})}
143-
(models/add-group-chat random-id chat-name (:current-public-key db) selected-contacts)
144-
(navigation/navigate-to-cofx :home nil)
145145
(models/navigate-to-chat random-id {})
146-
#(transport.message/send (group-chat/GroupAdminUpdate. chat-name selected-contacts) random-id %)))))
146+
(group-chats/handle-membership-update group-update my-public-key)
147+
(send-group-update group-update random-id)))))
147148

148149
(fx/defn show-profile [{:keys [db]} identity]
149150
(navigation/navigate-to-cofx {:db (assoc db :contacts/identity identity)} :profile nil))

src/status_im/chat/models.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[status-im.data-store.user-statuses :as user-statuses-store]
55
[status-im.transport.message.core :as transport.message]
66
[status-im.transport.message.v1.protocol :as protocol]
7-
[status-im.transport.message.v1.group-chat :as transport.group-chat]
7+
[status-im.transport.message.v1.core :as transport]
88
[status-im.transport.utils :as transport.utils]
99
[status-im.ui.components.styles :as styles]
1010
[status-im.ui.screens.navigation :as navigation]
@@ -106,7 +106,7 @@
106106
[{:keys [db] :as cofx} chat-id]
107107
;; if this is private group chat, we have to broadcast leave and unsubscribe after that
108108
(if (group-chat? cofx chat-id)
109-
(transport.message/send (transport.group-chat/GroupLeave.) chat-id cofx)
109+
(transport.message/send (transport/GroupLeave.) chat-id cofx)
110110
(transport.utils/unsubscribe-from-chat cofx chat-id)))
111111

112112
(fx/defn deactivate-chat
@@ -133,7 +133,7 @@
133133

134134
(fx/defn send-messages-seen
135135
[{:keys [db] :as cofx} chat-id message-ids]
136-
(when (not (get-in db [:chats chat-id :public?]))
136+
(when (not (get-in db [:chats chat-id :group-chat]))
137137
(transport.message/send (protocol/map->MessagesSeen {:message-ids message-ids}) chat-id cofx)))
138138

139139
;; TODO (janherich) - ressurect `constants/system` messages for group chats in the future

src/status_im/chat/models/group_chat.cljs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[status-im.ui.screens.group.core :as group]
77
[status-im.chat.models :as models.chat]
88
[status-im.transport.message.core :as message]
9-
[status-im.transport.message.v1.group-chat :as transport.group-chat]
109
[status-im.chat.models.message :as models.message]
1110
[status-im.utils.fx :as fx]))
1211

@@ -30,7 +29,14 @@
3029
(seq removed-participants)
3130
(str admin-name " " (i18n/label :t/removed) " " (apply str (interpose ", " removed-participants-names))))))
3231

33-
(defn handle-group-admin-update [{:keys [chat-name participants]} chat-id signature {:keys [now db random-id] :as cofx}]
32+
(defn handle-group-chat-create [{:keys [chat-name participants chat-id]} signature {:keys [now db random-id] :as cofx}]
33+
(models.chat/add-group-chat chat-id
34+
chat-name
35+
signature
36+
participants
37+
cofx))
38+
39+
(defn handle-group-admin-update [{:keys [chat-name participants chat-id]} chat-id signature {:keys [now db random-id] :as cofx}]
3440
(let [me (:current-public-key db)]
3541
;; we have to check if we already have a chat, or it's a new one
3642
(if-let [{:keys [group-admin contacts] :as chat} (get-in db [:chats chat-id])]
@@ -70,9 +76,9 @@
7076
(when (and
7177
(not= signature me)
7278
(get-in db [:chats chat-id])) ;; chat is present
79+
7380
(fx/merge cofx
7481
(models.message/receive
7582
(models.message/system-message chat-id random-id now
7683
(str participant-leaving-name " " (i18n/label :t/left))))
77-
(group/participants-removed chat-id #{signature})
78-
(transport.group-chat/send-new-group-key nil chat-id)))))
84+
(group/participants-removed chat-id #{signature})))))

src/status_im/chat/models/message.cljs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[status-im.utils.config :as config]
77
[status-im.utils.ethereum.core :as ethereum]
88
[status-im.utils.datetime :as time]
9+
[status-im.group-chats.core :as group-chats]
910
[status-im.chat.models :as chat-model]
1011
[status-im.chat.models.loading :as chat-loading]
1112
[status-im.chat.models.input :as input]
@@ -124,15 +125,15 @@
124125
batch?
125126
{:keys [from message-id chat-id content content-type clock-value js-obj] :as raw-message}]
126127
(let [{:keys [web3 current-chat-id view-id]} db
127-
current-chat? (and (or (= :chat view-id) (= :chat-modal view-id)) (= current-chat-id chat-id))
128-
{:keys [public?] :as chat} (get-in db [:chats chat-id])
129-
message (-> raw-message
130-
(commands-receiving/enhance-receive-parameters cofx)
131-
(ensure-clock-value chat)
132-
;; TODO (cammellos): Refactor so it's not computed twice
133-
(add-outgoing-status cofx)
134-
;; TODO (janherich): Remove after couple of releases
135-
update-legacy-type)]
128+
current-chat? (and (or (= :chat view-id) (= :chat-modal view-id)) (= current-chat-id chat-id))
129+
{:keys [group-chat] :as chat} (get-in db [:chats chat-id])
130+
message (-> raw-message
131+
(commands-receiving/enhance-receive-parameters cofx)
132+
(ensure-clock-value chat)
133+
;; TODO (cammellos): Refactor so it's not computed twice
134+
(add-outgoing-status cofx)
135+
;; TODO (janherich): Remove after couple of releases
136+
update-legacy-type)]
136137
(fx/merge cofx
137138
{:confirm-messages-processed [{:web3 web3
138139
:js-obj js-obj}]}
@@ -145,7 +146,7 @@
145146
:else :received))
146147
(commands-receiving/receive message)
147148
(display-notification chat-id)
148-
(send-message-seen chat-id message-id (and (not public?)
149+
(send-message-seen chat-id message-id (and (not group-chat)
149150
current-chat?
150151
(not (= constants/system from))
151152
(not (:outgoing message)))))))
@@ -208,7 +209,11 @@
208209
(if (= network-status :offline)
209210
{:dispatch-later [{:ms 10000
210211
:dispatch [:update-message-status chat-id message-id current-public-key :not-sent]}]}
211-
(transport/send send-record chat-id cofx)))
212+
(let [wrapped-record (if (= (:message-type send-record) :group-user-message)
213+
(group-chats/wrap-group-message cofx chat-id send-record)
214+
send-record)]
215+
216+
(transport/send wrapped-record chat-id cofx))))
212217

213218
(defn add-message-type [message {:keys [chat-id group-chat public?]}]
214219
(cond-> message

0 commit comments

Comments
 (0)