Skip to content

Commit

Permalink
Merge pull request #90 from Adamant-im/develop
Browse files Browse the repository at this point in the history
v2.5.0
  • Loading branch information
adamant-al authored Jul 23, 2022
2 parents 67fce54 + 4b6147a commit a99eacf
Show file tree
Hide file tree
Showing 47 changed files with 1,338 additions and 232 deletions.
117 changes: 80 additions & 37 deletions Adamant.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
launchStyle = "1"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
Expand Down
100 changes: 51 additions & 49 deletions Adamant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

switch connection {
case .cellular, .wifi:
self?.dialogService.dissmisNoConnectionNotification()
DispatchQueue.onMainSync {
self?.dialogService.dissmisNoConnectionNotification()
}
repeater.resumeAll()

case .none:
self?.dialogService.showNoConnectionNotification()
DispatchQueue.onMainSync {
self?.dialogService.showNoConnectionNotification()
}
repeater.pauseAll()
}
}
Expand Down Expand Up @@ -341,45 +345,51 @@ extension AppDelegate: UNUserNotificationCenterDelegate {

//MARK: Open Chat From Notification
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let recipientAddress = userInfo[AdamantNotificationUserInfoKeys.pushRecipient] as? String
{
if application.applicationState != .background && application.applicationState != .inactive {
completionHandler(.noData)
return
}

if let tabbar = window?.rootViewController as? UITabBarController,
let chats = tabbar.viewControllers?.first as? UISplitViewController,
let chatList = chats.viewControllers.first as? UINavigationController,
let list = chatList.viewControllers.first as? ChatListViewController {

switch list.accountService.state {
case .loggedIn:
self.openDialog(chatList: chatList, tabbar: tabbar, list: list, recipientAddress: recipientAddress)
case .notLogged:
break
case .isLoggingIn:
break
case .updating:
break
}

// if not logged in
list.didLoadedMessages = { [weak self] in
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self?.openDialog(chatList: chatList, tabbar: tabbar, list: list, recipientAddress: recipientAddress)
}
}
}
completionHandler(.newData)
} else {
guard let transactionID = userInfo[AdamantNotificationUserInfoKeys.transactionId] as? String,
let transactionRaw = userInfo[AdamantNotificationUserInfoKeys.transaction] as? String,
let data = transactionRaw.data(using: .utf8),
let trs = try? JSONDecoder().decode(Transaction.self, from: data),
let tabbar = window?.rootViewController as? UITabBarController,
let chats = tabbar.viewControllers?.first as? UISplitViewController,
let chatList = chats.viewControllers.first as? UINavigationController,
let list = chatList.viewControllers.first as? ChatListViewController,
(application.applicationState != .active)
else {
completionHandler(.noData)
return
}

if case .loggedIn = list.accountService.state {
self.openDialog(chatList: chatList, tabbar: tabbar, list: list, transactionID: transactionID, senderAddress: trs.senderId)
}

// if not logged in
list.didLoadedMessages = { [weak self] in
var timeout = 2.0
if #available(iOS 13.0, *) { timeout = 0.5 }
DispatchQueue.main.asyncAfter(deadline: .now() + timeout) {
self?.dialogService.dismissProgress()
self?.openDialog(chatList: chatList, tabbar: tabbar, list: list, transactionID: transactionID, senderAddress: trs.senderId)
}
}

completionHandler(.newData)
}

func openDialog(chatList: UINavigationController, tabbar: UITabBarController, list: ChatListViewController, recipientAddress: String) {
func openDialog(chatList: UINavigationController, tabbar: UITabBarController, list: ChatListViewController, transactionID: String, senderAddress: String) {
if let chatVCNav = chatList.viewControllers.last as? UINavigationController,
let chatVC = chatVCNav.viewControllers.first as? ChatViewController,
chatVC.chatroom?.partner?.address == senderAddress {
chatVC.forceScrollToBottom = true
chatVC.scrollDown()
return
}

guard let chatroom = list.chatsController?.fetchedObjects?.first(where: { room in
return room.lastTransaction?.recipientAddress == recipientAddress
let transactionExist = room.transactions?.first(where: { message in
return (message as? ChatTransaction)?.senderAddress == senderAddress
})
return transactionExist != nil
}) else { return }

chatList.popToRootViewController(animated: false)
Expand All @@ -391,8 +401,8 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
var timeout = 0.25
if #available(iOS 13.0, *) { timeout = 0 }
DispatchQueue.main.asyncAfter(deadline: .now() + timeout) {
let chat = UINavigationController(rootViewController:vc)
split.showDetailViewController(chat, sender: self)
let chat = UINavigationController(rootViewController: vc)
split.showDetailViewController(chat, sender: list)
}
} else {
chatList.pushViewController(vc, animated: false)
Expand Down Expand Up @@ -480,7 +490,6 @@ extension AppDelegate {
} else {
unread = true
}

if let exchenge = AdamantContacts.adamantExchange.messages["chats.welcome_message"] {
chatProvider.fakeReceived(message: exchenge.message,
senderId: AdamantContacts.adamantExchange.address,
Expand Down Expand Up @@ -529,9 +538,9 @@ extension AppDelegate {
})
}

if let welcome = AdamantContacts.adamantBountyWallet.messages["chats.welcome_message"] {
if let welcome = AdamantContacts.adamantWelcomeWallet.messages["chats.welcome_message"] {
chatProvider.fakeReceived(message: welcome.message,
senderId: AdamantContacts.adamantBountyWallet.name,
senderId: AdamantContacts.adamantWelcomeWallet.name,
date: Date.adamantNullDate,
unread: unread,
silent: welcome.silentNotification,
Expand Down Expand Up @@ -577,15 +586,8 @@ extension AppDelegate {
let router = container.resolve(Router.self),
let list = chatList.viewControllers.first as? ChatListViewController {

switch list.accountService.state {
case .loggedIn:
if case .loggedIn = list.accountService.state {
self.openDialog(chatList: chatList, tabbar: tabbar, router: router, list: list, adamantAdr: adamantAdr)
case .notLogged:
break
case .isLoggingIn:
break
case .updating:
break
}

// if not logged in
Expand Down
3 changes: 3 additions & 0 deletions Adamant/Assets/l18n/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
/* System accounts: ADAMANT Tokens */
"Accounts.AdamantTokens" = "Willkommen in ADAMANT";

/* System accounts: ADAMANT Bounty */
"Accounts.AdamantBounty" = "ADAMANT Bounty Wallet";

/* System accounts: ADAMANT iOS Support */
"Accounts.iOSSupport" = "ADAMANT iOS Support";

Expand Down
3 changes: 3 additions & 0 deletions Adamant/Assets/l18n/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
/* System accounts: ADAMANT Tokens */
"Accounts.AdamantTokens" = "Welcome to ADAMANT";

/* System accounts: ADAMANT Bounty */
"Accounts.AdamantBounty" = "ADAMANT Bounty Wallet";

/* System accounts: ADAMANT iOS Support */
"Accounts.iOSSupport" = "ADAMANT iOS Support";

Expand Down
3 changes: 3 additions & 0 deletions Adamant/Assets/l18n/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
/* System accounts: ADAMANT Tokens */
"Accounts.AdamantTokens" = "Приветствие АДАМАНТа";

/* System accounts: ADAMANT Bounty */
"Accounts.AdamantBounty" = "ADAMANT Bounty Wallet";

/* System accounts: ADAMANT iOS Support */
"Accounts.iOSSupport" = "Техподдержка iOS ADAMANT";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17192" systemVersion="19G2021" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21F79" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="BaseAccount" representedClassName="BaseAccount" isAbstract="YES" syncable="YES">
<attribute name="address" attributeType="String"/>
<attribute name="avatar" optional="YES" attributeType="String"/>
Expand Down Expand Up @@ -62,7 +62,7 @@
</entity>
<elements>
<element name="BaseAccount" positionX="-27" positionY="171" width="128" height="120"/>
<element name="BaseTransaction" positionX="378" positionY="18" width="128" height="240"/>
<element name="BaseTransaction" positionX="378" positionY="18" width="128" height="224"/>
<element name="Chatroom" positionX="-74" positionY="26" width="128" height="180"/>
<element name="ChatTransaction" positionX="142" positionY="137" width="128" height="165"/>
<element name="CoreDataAccount" positionX="-236" positionY="174" width="128" height="75"/>
Expand Down
8 changes: 8 additions & 0 deletions Adamant/Debug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<array>
<string>applinks:msg.adamant.im</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)im.adamant.messenger-dev</string>
Expand Down
21 changes: 21 additions & 0 deletions Adamant/Helpers/MacOSDeterminer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// MacOSDeterminer.swift
// Adamant
//
// Created by Stanislav Jelezoglo on 08.07.2022.
// Copyright © 2022 Adamant. All rights reserved.
//

import Foundation

var isMacOS: Bool = {
#if targetEnvironment(macCatalyst)
return true
#else
if #available(iOS 14.0, *) {
return ProcessInfo.processInfo.isiOSAppOnMac
} else {
return false
}
#endif
}()
8 changes: 8 additions & 0 deletions Adamant/Release.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<array>
<string>applinks:msg.adamant.im</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
<true/>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)im.adamant.messenger</string>
Expand Down
5 changes: 5 additions & 0 deletions Adamant/ServiceProtocols/ApiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ protocol ApiService: AnyObject {
func getTransactions(forAccount: String, type: TransactionType, fromHeight: Int64?, offset: Int?, limit: Int?, completion: @escaping (ApiServiceResult<[Transaction]>) -> Void)


// MARK: - Chats Rooms

func getChatRooms(address: String, offset: Int?, completion: @escaping (ApiServiceResult<ChatRooms>) -> Void)
func getChatMessages(address: String, addressRecipient: String, offset: Int?, completion: @escaping (ApiServiceResult<ChatRooms>) -> Void)

// MARK: - Funds

func transferFunds(sender: String, recipient: String, amount: Decimal, keypair: Keypair, completion: @escaping (ApiServiceResult<UInt64>) -> Void)
Expand Down
25 changes: 18 additions & 7 deletions Adamant/ServiceProtocols/DataProviders/AccountsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ protocol AccountsProvider {
/// - Returns: Account, if found, created in main viewContext
func getAccount(byAddress address: String, completion: @escaping (AccountsProviderResult) -> Void)

/// Search for fetched account, if not found try to create or asks server for account.
///
/// - Returns: Account, if found, created in main viewContext
func getAccount(byAddress address: String, publicKey: String, completion: @escaping (AccountsProviderResult) -> Void)

/* That one bugged. Will be fixed later. Maybe. */
/// Search for fetched account, if not found, asks server for account.
///
Expand Down Expand Up @@ -83,9 +88,10 @@ enum AdamantContacts {
case adamantExchange
case betOnBitcoin
case donate
case adamantWelcomeWallet

static let systemAddresses: [String] = {
return [AdamantContacts.adamantExchange.name, AdamantContacts.betOnBitcoin.name, AdamantContacts.adamantIco.name, AdamantContacts.adamantBountyWallet.name, AdamantContacts.adamantNewBountyWallet.name, AdamantContacts.donate.name]
return [AdamantContacts.adamantExchange.name, AdamantContacts.betOnBitcoin.name, AdamantContacts.adamantIco.name, AdamantContacts.adamantBountyWallet.name, AdamantContacts.adamantNewBountyWallet.name, AdamantContacts.donate.name, AdamantContacts.adamantWelcomeWallet.name]
}()

static func messagesFor(address: String) -> [String:SystemMessage]? {
Expand All @@ -112,13 +118,14 @@ enum AdamantContacts {

var name: String {
switch self {
case .adamantBountyWallet, .adamantNewBountyWallet:
case .adamantWelcomeWallet:
return NSLocalizedString("Accounts.AdamantTokens", comment: "System accounts: ADAMANT Tokens")
case .adamantBountyWallet, .adamantNewBountyWallet:
return NSLocalizedString("Accounts.AdamantBounty", comment: "System accounts: ADAMANT Bounty")
case .adamantIco:
return "Adamant ICO"
case .iosSupport:
return NSLocalizedString("Accounts.iOSSupport", comment: "System accounts: ADAMANT iOS Support")

case .adamantExchange:
return NSLocalizedString("Accounts.AdamantExchange", comment: "System accounts: ADAMANT Exchange")
case .betOnBitcoin:
Expand Down Expand Up @@ -146,6 +153,7 @@ enum AdamantContacts {
case .adamantExchange: return AdamantResources.contacts.adamantExchange
case .betOnBitcoin: return AdamantResources.contacts.betOnBitcoin
case .donate: return AdamantResources.contacts.donateWallet
case .adamantWelcomeWallet: return AdamantResources.contacts.adamantWelcomeWallet
}
}

Expand All @@ -158,26 +166,27 @@ enum AdamantContacts {
case .iosSupport: return AdamantResources.contacts.iosSupportPK
case .adamantIco: return AdamantResources.contacts.adamantIcoPK
case .donate: return AdamantResources.contacts.donateWalletPK
case .adamantWelcomeWallet: return AdamantResources.contacts.adamantBountyWalletPK
}
}

var isReadonly: Bool {
switch self {
case .adamantBountyWallet, .adamantNewBountyWallet, .adamantIco: return true
case .adamantBountyWallet, .adamantNewBountyWallet, .adamantIco, .adamantWelcomeWallet: return true
case .iosSupport, .adamantExchange, .betOnBitcoin, .donate: return false
}
}

var isHidden: Bool {
switch self {
case .adamantBountyWallet, .adamantNewBountyWallet: return true
case .adamantIco, .iosSupport, .adamantExchange, .betOnBitcoin, .donate: return false
case .adamantIco, .iosSupport, .adamantExchange, .betOnBitcoin, .donate, .adamantWelcomeWallet: return false
}
}

var avatar: String {
switch self {
case .adamantExchange, .betOnBitcoin, .donate:
case .adamantExchange, .betOnBitcoin, .donate, .adamantBountyWallet, .adamantNewBountyWallet:
return ""
default:
return "avatar_bots"
Expand All @@ -189,7 +198,9 @@ enum AdamantContacts {
case .adamantBountyWallet, .adamantNewBountyWallet:
return ["chats.welcome_message": SystemMessage(message: AdamantMessage.markdownText(NSLocalizedString("Chats.WelcomeMessage", comment: "Known contacts: Adamant welcome message. Markdown supported.")),
silentNotification: true)]

case .adamantWelcomeWallet:
return ["chats.welcome_message": SystemMessage(message: AdamantMessage.markdownText(NSLocalizedString("Chats.WelcomeMessage", comment: "Known contacts: Adamant welcome message. Markdown supported.")),
silentNotification: true)]
case .adamantIco:
return [
"chats.preico_message": SystemMessage(message: AdamantMessage.text(NSLocalizedString("Chats.PreIcoMessage", comment: "Known contacts: Adamant pre ICO message")),
Expand Down
9 changes: 9 additions & 0 deletions Adamant/ServiceProtocols/DataProviders/ChatsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,18 @@ protocol ChatsProvider: DataProvider {
var chatPositon: [String: Double] { get set }
var blackList: [String] { get }

var roomsMaxCount: Int? { get }
var roomsLoadedCount: Int? { get }

var isChatLoaded: [String: Bool] { get }
var chatMaxMessages: [String: Int] { get }
var chatLoadedMessages: [String: Int] { get }

// MARK: - Getting chats and messages
func getChatroomsController() -> NSFetchedResultsController<Chatroom>
func getChatController(for chatroom: Chatroom) -> NSFetchedResultsController<ChatTransaction>
func getChatRooms(offset: Int?, completion: (() ->())?)
func getChatMessages(with addressRecipient: String, offset: Int?, completion: ((Int) ->())?)

/// Unread messages controller. Sections by chatroom.
func getUnreadMessagesController() -> NSFetchedResultsController<ChatTransaction>
Expand Down
Loading

0 comments on commit a99eacf

Please sign in to comment.