-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
623 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ extension String.adamantLocalized { | |
static let chats = NSLocalizedString("Tabs.Chats", comment: "Main tab bar: Chats page") | ||
static let settings = NSLocalizedString("Tabs.Settings", comment: "Main tab bar: Settings page") | ||
} | ||
|
||
struct application { | ||
static let deviceTokenSendFailed = NSLocalizedString("Application.deviceTokenErrorFormat", comment: "Application: Failed to send deviceToken to ANS error format. %@ for error description") | ||
} | ||
} | ||
|
||
extension StoreKey { | ||
|
@@ -38,11 +42,16 @@ struct AdamantResources { | |
static let nodes: [Node] = [ | ||
Node(scheme: .https, host: "endless.adamant.im", port: nil), | ||
Node(scheme: .https, host: "clown.adamant.im", port: nil), | ||
Node(scheme: .https, host: "lake.adamant.im", port: nil) | ||
Node(scheme: .https, host: "lake.adamant.im", port: nil), | ||
Node(scheme: .http, host: "80.211.177.181", port: nil) | ||
] | ||
|
||
static let iosAppSupportEmail = "[email protected]" | ||
|
||
// ANS Contact | ||
static let ansAddress = "U10629337621822775991" | ||
static let ansPublicKey = "188b24bd116a556ac8ba905bbbdaa16e237dfb14269f5a4f9a26be77537d977c" | ||
|
||
private init() {} | ||
} | ||
|
||
|
@@ -208,6 +217,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | |
|
||
// MARK: - Remote notifications | ||
extension AppDelegate { | ||
private struct RegistrationPayload: Codable { | ||
let token: String | ||
|
||
#if DEBUG | ||
let provider: String = "apns-sandbox" | ||
#else | ||
let provider: String = "apns" | ||
#endif | ||
} | ||
|
||
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | ||
guard let address = accountService.account?.address, let keypair = accountService.keypair else { | ||
print("Trying to register with no user logged") | ||
|
@@ -217,7 +236,7 @@ extension AppDelegate { | |
|
||
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() | ||
|
||
// Checking, if device token had not changed | ||
// MARK: 1. Checking, if device token had not changed | ||
guard let securedStore = container.resolve(SecuredStore.self) else { | ||
fatalError("can't get secured store to get device token hash") | ||
} | ||
|
@@ -230,19 +249,48 @@ extension AppDelegate { | |
securedStore.set(tokenHash, for: StoreKey.application.deviceTokenHash) | ||
} | ||
|
||
// Storing new token in blockchain | ||
// MARK: 2. Preparing message | ||
guard let adamantCore = container.resolve(AdamantCore.self) else { | ||
fatalError("Can't get AdamantCore to register device token") | ||
} | ||
|
||
let payload: String | ||
do { | ||
let data = try JSONEncoder().encode(RegistrationPayload(token: token)) | ||
payload = String(data: data, encoding: String.Encoding.utf8)! | ||
} catch { | ||
dialogService.showError(withMessage: "Failed to prepare ANS signal payload", error: error) | ||
return | ||
} | ||
|
||
guard let encodedPayload = adamantCore.encodeMessage(payload, recipientPublicKey: AdamantResources.ansPublicKey, privateKey: keypair.privateKey) else { | ||
dialogService.showError(withMessage: "Failed to encode ANS signal. Payload: \(payload)", error: nil) | ||
return | ||
} | ||
|
||
// MARK: 3. Send signal to ANS | ||
guard let apiService = container.resolve(ApiService.self) else { | ||
fatalError("can't get api service to register device token") | ||
} | ||
|
||
apiService.store(key: "deviceToken", value: token, type: StateType.keyValue, sender: address, keypair: keypair) { [weak self] result in | ||
apiService.sendMessage(senderId: address, recipientId: AdamantResources.ansAddress, keypair: keypair, message: encodedPayload.message, type: ChatType.signal, nonce: encodedPayload.nonce) { [unowned self] result in | ||
switch result { | ||
case .success: | ||
return | ||
|
||
case .failure(let error): | ||
print("Failed to store device token: \(error)") | ||
self?.notificationService?.setNotificationsMode(.disabled, completion: nil) | ||
self.notificationService?.setNotificationsMode(.disabled, completion: nil) | ||
|
||
switch error { | ||
case .networkError, .notLogged: | ||
self.dialogService.showWarning(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, error.localized)) | ||
|
||
case .accountNotFound, .serverError: | ||
self.dialogService.showError(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, error.localized), error: error) | ||
|
||
case .internalError(let message, _): | ||
self.dialogService.showError(withMessage: String.localizedStringWithFormat(String.adamantLocalized.application.deviceTokenSendFailed, message), error: error) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+672 Bytes
(140%)
Adamant/Assets/Assets.xcassets/avatar_bots.imageset/avatar_bots.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 modified
BIN
+671 Bytes
(110%)
Adamant/Assets/Assets.xcassets/avatar_bots.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+434 Bytes
(100%)
Adamant/Assets/Assets.xcassets/avatar_bots.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.