From a4bc752e772adc2b0c1d865b629e538085d6ac30 Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Thu, 4 Jan 2018 11:50:14 +0100 Subject: [PATCH] [ISSUE #2287] Push Notifications: Use status-go NotifyUsers Signed-off-by: Andrey Shovkoplyas --- .../java/im/status/ethereum/module/StatusModule.java | 6 +++--- .../react-native-status/ios/RCTStatus/RCTStatus.m | 12 +++++++----- src/status_im/chat/events/send_message.cljs | 8 +++++--- src/status_im/chat/models/message.cljs | 4 +++- src/status_im/native_module/core.cljs | 4 ++-- src/status_im/native_module/impl/module.cljs | 8 ++++---- .../native_module/impl/non_status_go_module.cljs | 2 +- src/status_im/native_module/module.cljs | 2 +- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index 746c79f0ce..f99d8c5d8e 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -404,8 +404,8 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL } @ReactMethod - public void notify(final String token, final Callback callback) { - Log.d(TAG, "notify"); + public void notifyUsers(final String message, final String payloadJSON, final String tokensJSON, final Callback callback) { + Log.d(TAG, "notifyUsers"); if (!checkAvailability()) { callback.invoke(false); return; @@ -414,7 +414,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL Thread thread = new Thread() { @Override public void run() { - String res = Statusgo.Notify(token); + String res = Statusgo.NotifyUsers(message, payloadJSON, tokensJSON); callback.invoke(res); } diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index 8f42782237..2ded38d32f 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -276,14 +276,16 @@ RCT_EXPORT_METHOD(createAccount:(NSString *)password } //////////////////////////////////////////////////////////////////// -#pragma mark - Notify method -//////////////////////////////////////////////////////////////////// notify -RCT_EXPORT_METHOD(notify:(NSString *)token +#pragma mark - NotifyUsers method +//////////////////////////////////////////////////////////////////// notifyUsers +RCT_EXPORT_METHOD(notifyUsers:(NSString *)message + payloadJSON:(NSString *)payloadJSON + tokensJSON:(NSString *)tokensJSON callback:(RCTResponseSenderBlock)callback) { - char * result = Notify((char *) [token UTF8String]); + char * result = NotifyUsers((char *) [message UTF8String], (char *) [payloadJSON UTF8String], (char *) [tokensJSON UTF8String]); callback(@[[NSString stringWithUTF8String: result]]); #if DEBUG - NSLog(@"Notify() method called"); + NSLog(@"NotifyUsers() method called"); #endif } diff --git a/src/status_im/chat/events/send_message.cljs b/src/status_im/chat/events/send_message.cljs index 210e7a97a2..e0613a6a97 100644 --- a/src/status_im/chat/events/send_message.cljs +++ b/src/status_im/chat/events/send_message.cljs @@ -10,9 +10,11 @@ (re-frame/reg-fx :send-notification - (fn [fcm-token] - (log/debug "send-notification fcm-token: " fcm-token) - (status/notify fcm-token #(log/debug "send-notification cb result: " %)))) + (fn [{:keys [message payload tokens]}] + (let [payload-json (types/clj->json payload) + tokens-json (types/clj->json tokens)] + (log/debug "send-notification message: " message " payload-json: " payload-json " tokens-json: " tokens-json) + (status/notify-users {:message message :payload payload-json :tokens tokens-json} #(log/debug "send-notification cb result: " %))))) (re-frame/reg-fx :send-group-message diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 5e0189f2eb..777df1bf92 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -186,7 +186,9 @@ :else (merge {:send-message (assoc-in options [:message :to] chat-id)} - (when-not command) {:send-notification fcm-token})))))) + (when fcm-token {:send-notification {:message "message" + :payload {:title "Status" :body "You have a new message"} + :tokens [fcm-token]}}))))))) (defn- prepare-message [params chat] (let [{:keys [chat-id identity message-text]} params diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index f96e3ec4a0..22a8098254 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -84,8 +84,8 @@ (defn should-move-to-internal-storage? [callback] (module-interface/-should-move-to-internal-storage? rns-module callback)) -(defn notify [token callback] - (module-interface/-notify rns-module token callback)) +(defn notify-users [{:keys [message payload tokens] :as m} callback] + (module-interface/-notify-users rns-module m callback)) (defn add-peer [enode callback] (module-interface/-add-peer rns-module enode callback)) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 171e16ab20..b773c86271 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -103,9 +103,9 @@ true) false)))))) -(defn notify [token on-result] +(defn notify-users [{:keys [message payload tokens] :as m} on-result] (when status - (call-module #(.notify status token on-result)))) + (call-module #(.notifyUsers status message payload tokens on-result)))) (defn add-peer [enode on-result] (when status @@ -259,8 +259,8 @@ (call-function! params)) (-call-web3 [this payload callback] (call-web3 payload callback)) - (-notify [this token callback] - (notify token callback)) + (-notify-users [this {:keys [message payload tokens] :as m} callback] + (notify-users m callback)) (-add-peer [this enode callback] (add-peer enode callback)) diff --git a/src/status_im/native_module/impl/non_status_go_module.cljs b/src/status_im/native_module/impl/non_status_go_module.cljs index 858c7a1db1..d4e283ffcd 100644 --- a/src/status_im/native_module/impl/non_status_go_module.cljs +++ b/src/status_im/native_module/impl/non_status_go_module.cljs @@ -58,6 +58,6 @@ (impl/module-initialized!)) (-should-move-to-internal-storage? [this callback] (impl/should-move-to-internal-storage? callback)) - (-notify [this token callback]) + (-notify-users [this {:keys [message payload tokens] :as m} callback]) (-add-peer [this enode callback]) (-close-application [this])) diff --git a/src/status_im/native_module/module.cljs b/src/status_im/native_module/module.cljs index 0cb4de9ebf..a121fab123 100644 --- a/src/status_im/native_module/module.cljs +++ b/src/status_im/native_module/module.cljs @@ -18,7 +18,7 @@ (-call-web3 [this payload callback]) (-module-initialized! [this]) (-should-move-to-internal-storage? [this callback]) - (-notify [this token callback]) + (-notify-users [this {:keys [message payload tokens] :as m} callback]) (-add-peer [this enode callback]) (-close-application [this]))