Skip to content

Commit

Permalink
ios pn
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer authored and cammellos committed Sep 9, 2020
1 parent 72daf93 commit 163b21d
Show file tree
Hide file tree
Showing 33 changed files with 531 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEV_BUILD=1
ERC20_CONTRACT_WARNINGS=0
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=0
FLEET=eth.prod
FLEET=eth.test
GROUP_CHATS_ENABLED=1
LOG_LEVEL=info
MAILSERVER_CONFIRMATIONS_ENABLED=1
Expand All @@ -24,3 +24,4 @@ QR_READ_TEST_MENU=1
ENABLE_ROOT_ALERT=1
ENABLE_REFERRAL_INVITE=1
ENABLE_QUO_PREVIEW=1
APN_TOPIC=im.status.ethereum.pr
1 change: 1 addition & 0 deletions .env.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ KEYCARD_TEST_MENU=1
QR_READ_TEST_MENU=1
ENABLE_ROOT_ALERT=0
ENABLE_REFERRAL_INVITE=1
APN_TOPIC=im.status.ethereum.pr
3 changes: 2 additions & 1 deletion .env.jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DEFAULT_NETWORK=mainnet_rpc
ERC20_CONTRACT_WARNINGS=0
ETHEREUM_DEV_CLUSTER=1
EXTENSIONS=0
FLEET=eth.prod
FLEET=eth.test
GROUP_CHATS_ENABLED=1
LOG_LEVEL=info
MAILSERVER_CONFIRMATIONS_ENABLED=1
Expand All @@ -22,3 +22,4 @@ KEYCARD_TEST_MENU=0
ENABLE_ROOT_ALERT=1
ENABLE_REFERRAL_INVITE=1
DISABLE_WALLET_ON_MOBILE_NETWORK=1
APN_TOPIC=im.status.ethereum.pr
14 changes: 10 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ PODS:
- React
- RNCMaskedView (0.1.9):
- React
- RNCPushNotificationIOS (1.4.1):
- React
- RNDeviceInfo (5.6.1):
- React
- RNFS (2.16.6):
Expand Down Expand Up @@ -363,7 +365,7 @@ PODS:
- SQLCipher/standard (3.4.2):
- SQLCipher/common
- SSZipArchive (2.2.3)
- TOCropViewController (2.5.3)
- TOCropViewController (2.5.4)
- TouchID (4.4.1):
- React
- Yoga (1.14.0)
Expand Down Expand Up @@ -435,6 +437,7 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- "RNCPushNotificationIOS (from `../node_modules/@react-native-community/push-notification-ios`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
Expand Down Expand Up @@ -554,6 +557,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-community/clipboard"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNCPushNotificationIOS:
:path: "../node_modules/@react-native-community/push-notification-ios"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNFS:
Expand Down Expand Up @@ -596,7 +601,7 @@ SPEC CHECKSUMS:
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
FlipperKit: afd4259ef9eadeeb2d30250b37d95cb3b6b97a69
Folly: 30e7936e1c45c08d884aa59369ed951a8e68cf51
glog: 682164e7ac67e41afd8f7b6a37a96d04caf61cc0
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
Permission-Camera: afad27bf90337684d4a86f3825112d648c8c4d3b
Permission-Microphone: 0ffabc3fe1c75cfb260525ee3f529383c9f4368c
Expand Down Expand Up @@ -635,6 +640,7 @@ SPEC CHECKSUMS:
RNCAsyncStorage: d059c3ee71738c39834a627476322a5a8cd5bf36
RNCClipboard: 8148e21ac347c51fd6cd4b683389094c216bb543
RNCMaskedView: 71fc32d971f03b7f03d6ab6b86b730c4ee64f5b6
RNCPushNotificationIOS: c145c6253ea016e5efeff604f2720736b4a596f7
RNDeviceInfo: b6e650fbd234732c759544218657d549b4339038
RNFS: 2bd9eb49dc82fa9676382f0585b992c424cd59df
RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38
Expand All @@ -648,11 +654,11 @@ SPEC CHECKSUMS:
RNSVG: 8ba35cbeb385a52fd960fd28db9d7d18b4c2974f
SQLCipher: f9fcf29b2e59ced7defc2a2bdd0ebe79b40d4990
SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9
TOCropViewController: 20a14b6a7a098308bf369e7c8d700dc983a974e6
TOCropViewController: 2a1ae1242600b1f2d996fd91a5268b2309a33b5c
TouchID: ba4c656d849cceabc2e4eef722dea5e55959ecf4
Yoga: 3ebccbdd559724312790e7742142d062476b698e
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 5faa578ff5cb7a30abc18b9d620df288750a72fe

COCOAPODS: 1.9.1
COCOAPODS: 1.9.3
3 changes: 2 additions & 1 deletion ios/StatusIm/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

Expand Down
35 changes: 35 additions & 0 deletions ios/StatusIm/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>

#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
Expand Down Expand Up @@ -88,6 +91,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.window makeKeyAndVisible];
[RNSplashScreen show];

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;

return YES;
}

Expand Down Expand Up @@ -137,4 +143,33 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
}
}

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// IOS 10+ Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
completionHandler();
}
// IOS 4-10 Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}

@end
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@react-native-community/hooks": "^2.5.1",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/netinfo": "^4.4.0",
"@react-native-community/push-notification-ios": "^1.4.1",
"@react-native-community/slider": "^3.0.0",
"@react-navigation/bottom-tabs": "^5.7.0",
"@react-navigation/native": "^5.7.0",
Expand Down
Binary file added resources/images/icons/tiny_muted@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icons/tiny_muted@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/mocks/js_dependencies.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
#js {:localNotification identity
:requestPermission identity})

(def push-notification-ios #js {})
;; Update i18n_resources.cljs
(defn mock [module]
(case module
Expand Down Expand Up @@ -219,6 +220,7 @@
"react-native-haptic-feedback" react-native-haptic-feedback
"react-native-device-info" react-native-device-info
"react-native-push-notification" react-native-push-notification
"@react-native-community/push-notification-ios" push-notification-ios
"./fleets.js" default-fleets
"./chats.js" default-chats
"../translations/ar.json" (js/JSON.parse (slurp "./translations/ar.json"))
Expand Down
40 changes: 33 additions & 7 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.chat.models
(:require [re-frame.core :as re-frame]
[taoensso.timbre :as log]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.transport.filters.core :as transport.filters]
[status-im.contact.core :as contact.core]
Expand Down Expand Up @@ -136,15 +137,15 @@

(fx/defn upsert-chat
"Upsert chat when not deleted"
[{:keys [db] :as cofx} {:keys [chat-id] :as chat-props}]
[{:keys [db] :as cofx} {:keys [chat-id] :as chat-props} on-success]
(fx/merge cofx
(ensure-chat chat-props)
#(chats-store/save-chat % (get-in % [:db :chats chat-id]))))
#(chats-store/save-chat % (get-in % [:db :chats chat-id]) on-success)))

(fx/defn handle-save-chat
{:events [::save-chat]}
[{:keys [db] :as cofx} chat-id]
(chats-store/save-chat cofx (get-in db [:chats chat-id])))
[{:keys [db] :as cofx} chat-id on-success]
(chats-store/save-chat cofx (get-in db [:chats chat-id]) on-success))

(fx/defn handle-mark-all-read-successful
{:events [::mark-all-read-successful]}
Expand Down Expand Up @@ -172,7 +173,8 @@
:public? true
:might-have-join-time-messages? true
:unviewed-messages-count 0
:loaded-unviewed-messages-ids #{}}))
:loaded-unviewed-messages-ids #{}}
nil))

(fx/defn clear-history
"Clears history of the particular chat"
Expand All @@ -192,7 +194,7 @@
:unviewed-messages-count 0
:deleted-at-clock-value last-message-clock-value}))}
(messages-store/delete-messages-by-chat-id chat-id)
#(chats-store/save-chat % (get-in % [:db :chats chat-id])))))
#(chats-store/save-chat % (get-in % [:db :chats chat-id]) nil))))

(fx/defn deactivate-chat
"Deactivate chat in db, no side effects"
Expand Down Expand Up @@ -253,7 +255,8 @@
(when (not= (multiaccounts.model/current-public-key cofx) chat-id)
(fx/merge cofx
(upsert-chat {:chat-id chat-id
:is-active true})
:is-active true}
nil)
(transport.filters/load-chat chat-id)
(navigate-to-chat chat-id))))

Expand Down Expand Up @@ -293,6 +296,29 @@
{:db (assoc db :contacts/identity identity)}
(navigation/navigate-to-cofx :profile nil)))))

(fx/defn mute-chat-failed
{:events [::mute-chat-failed]}
[{:keys [db] :as cofx} chat-id muted? error]
(log/error "mute chat failed" chat-id error)
{:db (assoc-in db [:chats chat-id :muted] (not muted?))})

(fx/defn mute-chat
{:events [::mute-chat-toggled]}
[{:keys [db] :as cofx} chat-id muted?]
(let [method (if muted? "muteChat" "unmuteChat")
chat (get-in db [:chats chat-id])]
;; chat does not exist, create and then mute
(if-not chat
(upsert-chat cofx
{:is-active true
:chat-id chat-id}
#(re-frame/dispatch [::mute-chat-toggled chat-id muted?]))
{:db (assoc-in db [:chats chat-id :muted] muted?)
::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) method)
:params [chat-id]
:on-error #(re-frame/dispatch [::mute-chat-failed chat-id muted? %])
:on-success #(log/info method "successful" chat-id)}]})))

(fx/defn show-profile
{:events [:chat.ui/show-profile]}
[cofx identity]
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/chat/models_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
cofx {:now "now"
:db {:contacts/contacts {chat-id
{:name contact-name}}}}
response (chat/upsert-chat cofx chat-props)
response (chat/upsert-chat cofx chat-props nil)
actual-chat (get-in response [:db :chats chat-id])]
(testing "it adds the chat to the chats collection"
(is actual-chat))
Expand All @@ -36,7 +36,7 @@
:extra-prop "some"}
cofx {:db {:chats {chat-id {:is-active true
:name "old-name"}}}}
response (chat/upsert-chat cofx chat-props)
response (chat/upsert-chat cofx chat-props nil)
actual-chat (get-in response [:db :chats chat-id])]
(testing "it adds the chat to the chats collection"
(is actual-chat))
Expand Down
6 changes: 4 additions & 2 deletions src/status_im/data_store/chats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@
(update :last-message #(when % (messages/<-rpc %)))
(dissoc :chatType :members)))

(fx/defn save-chat [cofx {:keys [chat-id] :as chat}]
(fx/defn save-chat [cofx {:keys [chat-id] :as chat} on-success]
{::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "saveChat")
:params [(->rpc chat)]
:on-success #(log/debug "saved chat" chat-id "successfuly")
:on-success #(do
(log/debug "saved chat" chat-id "successfuly")
(when on-success (on-success)))
:on-failure #(log/error "failed to save chat" chat-id %)}]})

(fx/defn fetch-chats-rpc [cofx {:keys [on-success]}]
Expand Down
40 changes: 36 additions & 4 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"shhext_updateMessageOutgoingStatus" {}
"shhext_chatMessages" {}
"shhext_saveChat" {}
"shhext_muteChat" {}
"shhext_unmuteChat" {}
"shhext_contacts" {}
"shhext_prepareContent" {}
"shhext_blockContact" {}
Expand All @@ -93,6 +95,18 @@
"shhext_sendGroupChatInvitationRequest" {}
"shhext_sendGroupChatInvitationRejection" {}
"shhext_getGroupChatInvitations" {}
"shhext_registerForPushNotifications" {}
"shhext_unregisterFromPushNotifications" {}
"shhext_enablePushNotificationsFromContactsOnly" {}
"shhext_disablePushNotificationsFromContactsOnly" {}
"shhext_startPushNotificationsServer" {}
"shhext_stopPushNotificationsServer" {}
"shhext_disableSendingNotifications" {}
"shhext_enableSendingNotifications" {}
"shhext_addPushNotificationsServer" {}
"shhext_getPushNotificationsServers" {}
"shhext_enablePushNotificationsBlockMentions" {}
"shhext_disablePushNotificationsBlockMentions" {}
"wakuext_post" {}
"wakuext_startMessenger" {}
"wakuext_sendPairInstallation" {}
Expand Down Expand Up @@ -130,6 +144,8 @@
"wakuext_updateMessageOutgoingStatus" {}
"wakuext_chatMessages" {}
"wakuext_saveChat" {}
"wakuext_muteChat" {}
"wakuext_unmuteChat" {}
"wakuext_contacts" {}
"wakuext_prepareContent" {}
"wakuext_blockContact" {}
Expand All @@ -152,6 +168,18 @@
"wakuext_sendGroupChatInvitationRequest" {}
"wakuext_sendGroupChatInvitationRejection" {}
"wakuext_getGroupChatInvitations" {}
"wakuext_registerForPushNotifications" {}
"wakuext_unregisterFromPushNotifications" {}
"wakuext_enablePushNotificationsFromContactsOnly" {}
"wakuext_disablePushNotificationsFromContactsOnly" {}
"wakuext_startPushNotificationsServer" {}
"wakuext_stopPushNotificationsServer" {}
"wakuext_disableSendingNotifications" {}
"wakuext_enableSendingNotifications" {}
"wakuext_addPushNotificationsServer" {}
"wakuext_getPushNotificationsServers" {}
"wakuext_enablePushNotificationsBlockMentions" {}
"wakuext_disablePushNotificationsBlockMentions" {}
"status_chats" {}
"wallet_getTransfers" {}
"wallet_getTokensBalances" {}
Expand Down Expand Up @@ -210,16 +238,20 @@
(str "shhext_" method)))

(defn call
[{:keys [method params on-success] :as arg}]
[{:keys [method params on-success on-error] :as arg}]
(if-let [method-options (json-rpc-api method)]
(let [params (or params [])
{:keys [id on-result subscription?]
:or {on-result identity
id 1}} method-options
on-error (or (on-error-retry call arg)
#(log/warn :json-rpc/error method :error % :params params))]
on-error (or
on-error
(on-error-retry call arg)
#(log/warn :json-rpc/error method :error % :params params))]
(if (nil? method)
(log/error :json-rpc/method-not-found method)
(do
(log/error :json-rpc/method-not-found method)
(on-error :json-rpc/method-not-found))
(status/call-private-rpc
(types/clj->json {:jsonrpc "2.0"
:id id
Expand Down
Loading

0 comments on commit 163b21d

Please sign in to comment.