Skip to content

Commit 5a69b41

Browse files
Pedro Pombeirorasom
Pedro Pombeiro
authored andcommitted
Update PNs to use data-only messaging, and only encode/decode data values. Fixes #6772
Fix navigation to chat when PN is tapped while signed off. Fixes #3488 Anonymize PN pubkeys. Part of #6772
1 parent 4af2073 commit 5a69b41

File tree

26 files changed

+464
-217
lines changed

26 files changed

+464
-217
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ conan*.txt
156156
conanbuildinfo.*
157157
conan.cmake
158158
/yarn-error.log
159+
/default.realm/

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ android-ports: ##@other Add proxies to Android Device/Simulator
211211
adb reverse tcp:4567 tcp:4567
212212
adb forward tcp:5561 tcp:5561
213213

214+
android-logcat:
215+
adb logcat | grep -e StatusModule -e ReactNativeJS -e StatusNativeLogs
214216

215217
startdev-%:
216218
$(eval SYSTEM := $(word 2, $(subst -, , $@)))

STATUS_GO_VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
181221-204011-e80de6
1+
0.19.0-beta.1

android/app/proguard-rules.pro

+4
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@
6868
-dontwarn java.nio.file.*
6969
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
7070
-dontwarn okio.**
71+
72+
# Firebase
73+
-keep class io.invertase.firebase.** { *; }
74+
-dontwarn io.invertase.firebase.**

ci/Jenkinsfile.ios

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pipeline {
1313
timestamps()
1414
disableConcurrentBuilds()
1515
/* Prevent Jenkins jobs from running forever */
16-
timeout(time: 35, unit: 'MINUTES')
16+
timeout(time: 45, unit: 'MINUTES')
1717
/* Limit builds retained */
1818
buildDiscarder(logRotator(
1919
numToKeepStr: '10',

doc/codebase-structure-and-guidelines.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Each business logic module is managed in a module directory.
66

77
*There is no rigid structure on how to organize code inside modules outside of core and db namespaces*
88

9-
```
9+
```txt
1010
- events.cljs
1111
- subs.cljs
1212
- notifications
@@ -37,13 +37,13 @@ Core namespace must only contain functions that can be called outside of the mod
3737

3838
- fx producing functions called by events and other modules
3939

40-
```clojure
41-
(def get-current-account
42-
module.db/get-current-account)
40+
```clojure
41+
(def get-current-account
42+
module.db/get-current-account)
4343

44-
(defn set-current-account [{db :db :as cofx}]
45-
{:db (module.db/set-current-account db)})
46-
```
44+
(defn set-current-account [{db :db :as cofx}]
45+
{:db (module.db/set-current-account db)})
46+
```
4747

4848
## db.cljs
4949

@@ -61,13 +61,14 @@ These guidelines make db.cljs namespaces the place to go when making changes to
6161
- events must always be declared with `register-handler-fx`, no `register-handler-db`
6262
- events must never use the `trim-v` interceptor
6363
- events must only contain a function call defined in a module
64-
```clojure
65-
(handlers/register-handler-fx
66-
:notifications/handle-push-notification
67-
(fn [cofx [_ event]]
68-
(notifications/handle-push-notification event cofx)))
69-
```
64+
```clojure
65+
(handlers/register-handler-fx
66+
:notifications/handle-push-notification-open
67+
(fn [cofx [_ event]]
68+
(notifications/handle-push-notification-open event cofx)))
69+
```
7070
- events must use synthetic namespaces:
71-
- `:module.ui/` for user triggered events
72-
- `:module.callback/` for callback events, which are events bringing back the result of an fx to the event loop, the name of the event should end with `-success` or `-error` most of the time. Other possibilities can be `-granted`, `-denied` for instance.
73-
- `:module/` for internal events, examples are time based events marked `-timed-out`, external changes marked `-changed` or reception of external events marked `-received`.
71+
72+
- `:module.ui/` for user triggered events
73+
- `:module.callback/` for callback events, which are events bringing back the result of an fx to the event loop, the name of the event should end with `-success` or `-error` most of the time. Other possibilities can be `-granted`, `-denied` for instance.
74+
- `:module/` for internal events, examples are time based events marked `-timed-out`, external changes marked `-changed` or reception of external events marked `-received`.

modules/react-native-desktop-notification/desktop/desktopnotification.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ QList<ModuleMethod *> DesktopNotification::methodsToExport() {
105105

106106
QVariantMap DesktopNotification::constantsToExport() { return QVariantMap(); }
107107

108-
void DesktopNotification::sendNotification(QString title, QString body, bool prioritary) {
108+
void DesktopNotification::displayNotification(QString title, QString body, bool prioritary) {
109109
Q_D(DesktopNotification);
110-
qCDebug(NOTIFICATION) << "::sendNotification";
110+
qCDebug(NOTIFICATION) << "::displayNotification";
111111

112112
if (m_appHasFocus) {
113-
qCDebug(NOTIFICATION) << "Not sending notification since an application window is active";
113+
qCDebug(NOTIFICATION) << "Not displaying notification since an application window is active";
114114
return;
115115
}
116116

modules/react-native-desktop-notification/desktop/desktopnotification.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DesktopNotification : public QObject, public ModuleInterface {
3535
QList<ModuleMethod*> methodsToExport() override;
3636
QVariantMap constantsToExport() override;
3737

38-
Q_INVOKABLE void sendNotification(QString title, QString body, bool prioritary);
38+
Q_INVOKABLE void displayNotification(QString title, QString body, bool prioritary);
3939
Q_INVOKABLE void setDockBadgeLabel(const QString label);
4040
private:
4141
QScopedPointer<DesktopNotificationPrivate> d_ptr;

modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String getName() {
8181
}
8282

8383
@Override
84-
public void onHostResume() { // Actvity `onResume`
84+
public void onHostResume() { // Activity `onResume`
8585
module = this;
8686
Activity currentActivity = getCurrentActivity();
8787
if (currentActivity == null) {
@@ -459,7 +459,7 @@ public void run() {
459459
}
460460

461461
@ReactMethod
462-
public void notifyUsers(final String message, final String payloadJSON, final String tokensJSON, final Callback callback) {
462+
public void notifyUsers(final String dataPayloadJSON, final String tokensJSON, final Callback callback) {
463463
Log.d(TAG, "notifyUsers");
464464
if (!checkAvailability()) {
465465
callback.invoke(false);
@@ -469,7 +469,7 @@ public void notifyUsers(final String message, final String payloadJSON, final St
469469
Runnable r = new Runnable() {
470470
@Override
471471
public void run() {
472-
String res = Statusgo.NotifyUsers(message, payloadJSON, tokensJSON);
472+
String res = Statusgo.NotifyUsers(dataPayloadJSON, tokensJSON);
473473

474474
callback.invoke(res);
475475
}

modules/react-native-status/desktop/rctstatus.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ void RCTStatus::createAccount(QString password, double callbackId) {
136136
}
137137

138138

139-
void RCTStatus::notifyUsers(QString token, QString payloadJSON, QString tokensJSON, double callbackId) {
139+
void RCTStatus::notifyUsers(QString dataPayloadJSON, QString tokensJSON, double callbackId) {
140140
Q_D(RCTStatus);
141141
qCDebug(RCTSTATUS) << "::notifyUsers call - callbackId:" << callbackId;
142-
QtConcurrent::run([&](QString token, QString payloadJSON, QString tokensJSON, double callbackId) {
143-
const char* result = NotifyUsers(token.toUtf8().data(), payloadJSON.toUtf8().data(), tokensJSON.toUtf8().data());
142+
QtConcurrent::run([&](QString dataPayloadJSON, QString tokensJSON, double callbackId) {
143+
const char* result = NotifyUsers(dataPayloadJSON.toUtf8().data(), tokensJSON.toUtf8().data());
144144
logStatusGoResult("::notifyUsers Notify", result);
145145
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
146-
}, token, payloadJSON, tokensJSON, callbackId);
146+
}, dataPayloadJSON, tokensJSON, callbackId);
147147
}
148148

149149

modules/react-native-status/desktop/rctstatus.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RCTStatus : public QObject, public ModuleInterface {
3838
Q_INVOKABLE void startNode(QString configString);
3939
Q_INVOKABLE void stopNode();
4040
Q_INVOKABLE void createAccount(QString password, double callbackId);
41-
Q_INVOKABLE void notifyUsers(QString token, QString payloadJSON, QString tokensJSON, double callbackId);
41+
Q_INVOKABLE void notifyUsers(QString dataPayloadJSON, QString tokensJSON, double callbackId);
4242
Q_INVOKABLE void sendLogs(QString dbJSON);
4343
Q_INVOKABLE void addPeer(QString enode, double callbackId);
4444
Q_INVOKABLE void recoverAccount(QString passphrase, QString password, double callbackId);

modules/react-native-status/ios/RCTStatus/RCTStatus.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,10 @@ -(void)setBridge:(RCTBridge *)newBridge
185185
////////////////////////////////////////////////////////////////////
186186
#pragma mark - NotifyUsers method
187187
//////////////////////////////////////////////////////////////////// notifyUsers
188-
RCT_EXPORT_METHOD(notifyUsers:(NSString *)message
189-
payloadJSON:(NSString *)payloadJSON
188+
RCT_EXPORT_METHOD(notifyUsers:(NSString *)dataPayloadJSON
190189
tokensJSON:(NSString *)tokensJSON
191190
callback:(RCTResponseSenderBlock)callback) {
192-
char * result = NotifyUsers((char *) [message UTF8String], (char *) [payloadJSON UTF8String], (char *) [tokensJSON UTF8String]);
191+
char * result = NotifyUsers((char *) [dataPayloadJSON UTF8String], (char *) [tokensJSON UTF8String]);
193192
callback(@[[NSString stringWithUTF8String: result]]);
194193
#if DEBUG
195194
NSLog(@"NotifyUsers() method called");

src/status_im/android/core.cljs

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
(.addEventListener react/app-state "change" app-state-change-handler))
4141
:component-did-mount
4242
(fn [this]
43-
(dispatch [:set-initial-props (reagent/props this)])
44-
;; TODO(oskarth): Background click_action handler
45-
(notifications/init))
43+
(dispatch [:set-initial-props (reagent/props this)]))
4644
:component-will-unmount
4745
(fn []
4846
(.stop react/http-bridge)

src/status_im/chat/models/message.cljs

+18-27
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
(get-in db [:account/account :desktop-notifications?])
122122
(< (time/seconds-ago (time/to-date timestamp)) constants/one-earth-day))
123123
(let [{:keys [title body prioritary?]} (build-desktop-notification cofx message)]
124-
(.sendNotification react/desktop-notification title body prioritary?)))
124+
(.displayNotification react/desktop-notification title body prioritary?)))
125125
(fx/merge cofx
126126
{:db (cond->
127127
(-> db
@@ -159,19 +159,6 @@
159159
message
160160
(assoc message :clock-value (utils.clocks/send last-clock-value))))
161161

162-
(fx/defn display-notification
163-
[cofx chat-id]
164-
(when config/in-app-notifications-enabled?
165-
(let [view-id (get-in cofx [:db :view-id])
166-
from (accounts.db/current-public-key cofx)
167-
current-chat-id (get-in cofx [:db :current-chat-id])]
168-
(when-not (and (= :chat view-id)
169-
(= current-chat-id chat-id))
170-
{:notifications/display-notification {:title (i18n/label :notifications-new-message-title)
171-
:body (i18n/label :notifications-new-message-body)
172-
:to chat-id
173-
:from from}}))))
174-
175162
(defn check-response-to
176163
[{{:keys [response-to response-to-v2]} :content :as message}
177164
old-id->message]
@@ -210,7 +197,6 @@
210197
current-chat? :seen
211198
:else :received))
212199
(commands-receiving/receive message)
213-
(display-notification chat-id)
214200
(send-message-seen chat-id message-id (and (not group-chat)
215201
current-chat?
216202
(not (= constants/system from))
@@ -391,14 +377,14 @@
391377
(add-own-status chat-id message-id :sending)
392378
(send chat-id message-id wrapped-record))))
393379

394-
(fx/defn send-push-notification [cofx fcm-token status]
380+
(fx/defn send-push-notification [cofx message-id fcm-token status]
381+
(log/debug "#6772 - send-push-notification" message-id fcm-token)
395382
(when (and fcm-token (= status :sent))
396-
{:send-notification {:message (js/JSON.stringify #js {:from (accounts.db/current-public-key cofx)
397-
:to (get-in cofx [:db :current-chat-id])})
398-
:payload {:title (i18n/label :notifications-new-message-title)
399-
:body (i18n/label :notifications-new-message-body)
400-
:sound notifications/sound-name}
401-
:tokens [fcm-token]}}))
383+
(let [payload {:from (accounts.db/current-public-key cofx)
384+
:to (get-in cofx [:db :current-chat-id])
385+
:id message-id}]
386+
{:send-notification {:data-payload (notifications/encode-notification-payload payload)
387+
:tokens [fcm-token]}})))
402388

403389
(fx/defn update-message-status [{:keys [db]} chat-id message-id status]
404390
(let [from (get-in db [:chats chat-id :messages message-id :from])
@@ -484,8 +470,13 @@
484470

485471
(re-frame/reg-fx
486472
:send-notification
487-
(fn [{:keys [message payload tokens]}]
488-
(let [payload-json (types/clj->json payload)
489-
tokens-json (types/clj->json tokens)]
490-
(log/debug "send-notification message: " message " payload-json: " payload-json " tokens-json: " tokens-json)
491-
(status/notify-users {:message message :payload payload-json :tokens tokens-json} #(log/debug "send-notification cb result: " %)))))
473+
(fn [{:keys [data-payload tokens]}]
474+
"Sends a notification to another device. data-payload is a Clojure map of strings to strings"
475+
(let [data-payload-json (types/clj->json data-payload)
476+
tokens-json (types/clj->json tokens)]
477+
(log/debug "send-notification data-payload-json:" data-payload-json "tokens-json:" tokens-json)
478+
;; NOTE: react-native-firebase doesn't have a good implementation of sendMessage
479+
;; (supporting e.g. priority or content_available properties),
480+
;; therefore we must use an implementation in status-go.
481+
(status/notify-users {:data-payload data-payload-json :tokens tokens-json}
482+
#(log/debug "send-notification cb result: " %)))))

src/status_im/core.cljs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
(ns status-im.core
22
(:require [re-frame.core :as re-frame]
33
[status-im.utils.error-handler :as error-handler]
4+
[status-im.utils.platform :as platform]
45
[status-im.ui.components.react :as react]
6+
[status-im.notifications.background :as background-messaging]
57
[reagent.core :as reagent]
68
status-im.transport.impl.receive
79
status-im.transport.impl.send
@@ -18,4 +20,6 @@
1820
(log/set-level! config/log-level)
1921
(error-handler/register-exception-handler!)
2022
(re-frame/dispatch [:init/app-started])
21-
(.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)))
23+
(.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root))
24+
(when platform/android?
25+
(.registerHeadlessTask react/app-registry "RNFirebaseBackgroundMessage" background-messaging/message-handler-fn)))

src/status_im/events.cljs

+8-3
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,9 @@
830830
;; notifications module
831831

832832
(handlers/register-handler-fx
833-
:notifications/notification-event-received
834-
(fn [cofx [_ event]]
835-
(notifications/handle-push-notification cofx event)))
833+
:notifications/notification-open-event-received
834+
(fn [cofx [_ decoded-payload ctx]]
835+
(notifications/handle-push-notification-open cofx decoded-payload ctx)))
836836

837837
(handlers/register-handler-fx
838838
:notifications.callback/get-fcm-token-success
@@ -849,6 +849,11 @@
849849
(fn [cofx _]
850850
(accounts/show-mainnet-is-default-alert cofx)))
851851

852+
(handlers/register-handler-fx
853+
:notifications.callback/on-message
854+
(fn [cofx [_ decoded-payload opts]]
855+
(notifications/handle-on-message cofx decoded-payload opts)))
856+
852857
;; hardwallet module
853858

854859
(handlers/register-handler-fx

src/status_im/hardwallet/card.cljs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-support-success %])))))
2020

2121
(defn check-nfc-enabled []
22-
(when platform/android?
22+
(when (and platform/android?
23+
config/hardwallet-enabled?)
2324
(.. keycard
2425
nfcIsEnabled
2526
(then #(re-frame/dispatch [:hardwallet.callback/check-nfc-enabled-success %])))))

0 commit comments

Comments
 (0)