Skip to content

Commit

Permalink
Merge pull request #81 from Adamant-im/develop
Browse files Browse the repository at this point in the history
Socket support & Open specific chat from Push notification & Fix nodes crash
  • Loading branch information
StanislavDevIOS authored May 16, 2022
2 parents 8f5bdd1 + 589d76c commit 67fce54
Show file tree
Hide file tree
Showing 34 changed files with 484 additions and 306 deletions.
56 changes: 40 additions & 16 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
3A64FAA827BA67BF007D5588 /* AdamantSecret.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A64FAA527BA67BF007D5588 /* AdamantSecret.swift */; };
3A64FAA927BA67BF007D5588 /* AdamantSecret.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A64FAA527BA67BF007D5588 /* AdamantSecret.swift */; };
3A8875EF27BBF38D00436195 /* Parchment in Frameworks */ = {isa = PBXBuildFile; productRef = 3A8875EE27BBF38D00436195 /* Parchment */; };
3AA2D5F7280EADE3000ED971 /* SocketService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA2D5F6280EADE3000ED971 /* SocketService.swift */; };
3AA2D5FA280EAF5D000ED971 /* AdamantSocketService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA2D5F9280EAF5D000ED971 /* AdamantSocketService.swift */; };
3C06931576393125C61FB8F6 /* Pods_Adamant.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33975C0D891698AA7E74EBCC /* Pods_Adamant.framework */; };
553B1284281C6EE100FFF24C /* GCDUtilites.swift in Sources */ = {isa = PBXBuildFile; fileRef = 553B1283281C6EE100FFF24C /* GCDUtilites.swift */; };
6403F5DB2272389800D58779 /* (null) in Sources */ = {isa = PBXBuildFile; };
6403F5DE22723C6800D58779 /* DashMainnet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6403F5DD22723C6800D58779 /* DashMainnet.swift */; };
6403F5E022723F6400D58779 /* DashWalletRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6403F5DF22723F6400D58779 /* DashWalletRouter.swift */; };
Expand Down Expand Up @@ -607,7 +610,10 @@
33975C0D891698AA7E74EBCC /* Pods_Adamant.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Adamant.framework; sourceTree = BUILT_PRODUCTS_DIR; };
36AB8CE9537B3B873972548B /* Pods_AdmCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AdmCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3A64FAA527BA67BF007D5588 /* AdamantSecret.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdamantSecret.swift; sourceTree = "<group>"; };
3AA2D5F6280EADE3000ED971 /* SocketService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocketService.swift; sourceTree = "<group>"; };
3AA2D5F9280EAF5D000ED971 /* AdamantSocketService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantSocketService.swift; sourceTree = "<group>"; };
4A4D67BD3DC89C07D1351248 /* Pods-AdmCore.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AdmCore.release.xcconfig"; path = "Target Support Files/Pods-AdmCore/Pods-AdmCore.release.xcconfig"; sourceTree = "<group>"; };
553B1283281C6EE100FFF24C /* GCDUtilites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GCDUtilites.swift; sourceTree = "<group>"; };
6403F5DD22723C6800D58779 /* DashMainnet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashMainnet.swift; sourceTree = "<group>"; };
6403F5DF22723F6400D58779 /* DashWalletRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashWalletRouter.swift; sourceTree = "<group>"; };
6403F5E122723F7500D58779 /* DashWallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashWallet.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1101,6 +1107,14 @@
path = Pods;
sourceTree = "<group>";
};
3AA2D5F8280EAF49000ED971 /* SocketService */ = {
isa = PBXGroup;
children = (
3AA2D5F9280EAF5D000ED971 /* AdamantSocketService.swift */,
);
path = SocketService;
sourceTree = "<group>";
};
6403F5DC22723C2800D58779 /* Dash */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1262,6 +1276,7 @@
E913C9071FFFA943001A83F7 /* AdamantCore.swift */,
6455E9F021075D3600B2E94C /* AddressBookService.swift */,
E91947AB20001A9A001362F8 /* ApiService.swift */,
3AA2D5F6280EADE3000ED971 /* SocketService.swift */,
648BCA6C213D384F00875EB5 /* AvatarService.swift */,
E9A174B22057EC47003667CD /* BackgroundFetchService.swift */,
E9E7CDBD2003AEFB00DFC4DB /* CellFactory.swift */,
Expand All @@ -1281,6 +1296,7 @@
E913C9061FFFA92E001A83F7 /* Services */ = {
isa = PBXGroup;
children = (
3AA2D5F8280EAF49000ED971 /* SocketService */,
E9CAE8D02018AA5000345E76 /* ApiService */,
E9B3D39F201FA2090019EB36 /* DataProviders */,
E9E7CD922002740500DFC4DB /* AdamantAccountService.swift */,
Expand Down Expand Up @@ -1759,6 +1775,7 @@
E927171D20C04613002BB9A6 /* UIColor+hex.swift */,
E9D1BE19211DA25300E86B72 /* UIView+constraints.swift */,
E935C84C22AC06E500A8CA2F /* RichMessageTools.swift */,
553B1283281C6EE100FFF24C /* GCDUtilites.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2311,6 +2328,8 @@
"${BUILT_PRODUCTS_DIR}/MessageKit/MessageKit.framework",
"${BUILT_PRODUCTS_DIR}/MyLittlePinpad/MyLittlePinpad.framework",
"${BUILT_PRODUCTS_DIR}/PMAlertController/PMAlertController.framework",
"${BUILT_PRODUCTS_DIR}/Socket.IO-Client-Swift/SocketIO.framework",
"${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
Expand All @@ -2320,6 +2339,8 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MessageKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MyLittlePinpad.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PMAlertController.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SocketIO.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Starscream.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -2432,6 +2453,7 @@
6449BA69235CA0930033B936 /* ERC20TransferViewController.swift in Sources */,
E9E7CD8B20026B0600DFC4DB /* AccountService.swift in Sources */,
640EFAA42558613A00E9724B /* EthProvider.swift in Sources */,
553B1284281C6EE100FFF24C /* GCDUtilites.swift in Sources */,
648CE3AC229AD2190070A2CC /* DashTransferViewController.swift in Sources */,
640EFA9C2558613200E9724B /* AdamantProvider.swift in Sources */,
64F085D920E2D7600006DE68 /* AdmTransactionsViewController.swift in Sources */,
Expand Down Expand Up @@ -2516,6 +2538,7 @@
644793C32166314A00FC4CF5 /* OnboardPage.swift in Sources */,
64E1C831222E9617006C4DA7 /* DogeWalletService.swift in Sources */,
E91947B22000246A001362F8 /* AdamantError.swift in Sources */,
3AA2D5F7280EADE3000ED971 /* SocketService.swift in Sources */,
E95F85802008C8D70070534A /* ChatsRoutes.swift in Sources */,
6416B1A721B024B6006089AC /* LskWalletService+Send.swift in Sources */,
E9942B87203D9E5100C163AF /* EurekaQRRow.swift in Sources */,
Expand Down Expand Up @@ -2617,6 +2640,7 @@
E9502740202E257E002C1098 /* RepeaterService.swift in Sources */,
E93D7AC02052CF63005D19DC /* AdamantNotificationService.swift in Sources */,
645938942378395E00A2BE7C /* EulaViewController.swift in Sources */,
3AA2D5FA280EAF5D000ED971 /* AdamantSocketService.swift in Sources */,
649D6BEC21BD5A53009E727B /* UISuffixTextField.swift in Sources */,
E93B0D762028B28E00126346 /* AdamantChatsProvider.swift in Sources */,
E993302021354B1800CD5200 /* AdmWalletRoutes.swift in Sources */,
Expand Down Expand Up @@ -2877,7 +2901,7 @@
CODE_SIGN_ENTITLEMENTS = MessageNotificationContentExtension/Debug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -2886,7 +2910,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.MessageNotificationContentExtension";
Expand All @@ -2906,7 +2930,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -2915,7 +2939,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.MessageNotificationContentExtension";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -3053,7 +3077,7 @@
CODE_SIGN_ENTITLEMENTS = Adamant/Debug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
DISPLAY_NAME = ADM.Dev;
EXCLUDED_SOURCE_FILE_NAMES = "";
Expand All @@ -3063,7 +3087,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "e4233bbf-3705-44fe-95b0-e77475672c60";
Expand All @@ -3082,7 +3106,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
DISPLAY_NAME = Adamant;
EXCLUDED_SOURCE_FILE_NAMES = Debug.xcassets;
Expand All @@ -3092,7 +3116,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "bedd1b75-2f23-4a85-a0b2-14c424fcff42";
Expand All @@ -3110,7 +3134,7 @@
CODE_SIGN_ENTITLEMENTS = TransferNotificationContentExtension/Debug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -3119,7 +3143,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.TransferNotificationContentExtension";
Expand All @@ -3139,7 +3163,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -3148,7 +3172,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.TransferNotificationContentExtension";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -3168,7 +3192,7 @@
CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/Debug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -3177,7 +3201,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.NotificationServiceExtension";
Expand All @@ -3197,7 +3221,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 173;
CURRENT_PROJECT_VERSION = 180;
DEVELOPMENT_TEAM = J2L77FMN46;
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand All @@ -3206,7 +3230,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.4.0;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.NotificationServiceExtension";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
72 changes: 66 additions & 6 deletions Adamant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// Register repeater services
if let chatsProvider = container.resolve(ChatsProvider.self) {
repeater.registerForegroundCall(label: "chatsProvider", interval: 3, queue: .global(qos: .utility), callback: chatsProvider.update)
repeater.registerForegroundCall(label: "chatsProvider", interval: 10, queue: .global(qos: .utility), callback: chatsProvider.update)

} else {
dialogService.showError(withMessage: "Failed to register ChatsProvider autoupdate. Please, report a bug", error: nil)
}
Expand Down Expand Up @@ -264,7 +265,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

// MARK: - Remote notifications
extension AppDelegate {
extension AppDelegate: UNUserNotificationCenterDelegate {
private struct RegistrationPayload: Codable {
let token: String

Expand All @@ -283,7 +284,6 @@ extension AppDelegate {
}

let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

// 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")
Expand Down Expand Up @@ -338,6 +338,66 @@ extension AppDelegate {
service.showError(withMessage: String.localizedStringWithFormat(String.adamantLocalized.notifications.registerRemotesError, error.localizedDescription), error: error)
}
}

//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 {
completionHandler(.noData)
}
}

func openDialog(chatList: UINavigationController, tabbar: UITabBarController, list: ChatListViewController, recipientAddress: String) {
guard let chatroom = list.chatsController?.fetchedObjects?.first(where: { room in
return room.lastTransaction?.recipientAddress == recipientAddress
}) else { return }

chatList.popToRootViewController(animated: false)
chatList.dismiss(animated: false, completion: nil)
tabbar.selectedIndex = 0

let vc = list.chatViewController(for: chatroom, forceScrollToBottom: true)
if let split = list.splitViewController {
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)
}
} else {
chatList.pushViewController(vc, animated: false)
}
}
}


Expand Down Expand Up @@ -529,9 +589,9 @@ extension AppDelegate {
}

// if not logged in
list.didLoadedMessages = {
list.didLoadedMessages = { [weak self] in
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.openDialog(chatList: chatList, tabbar: tabbar, router: router, list: list, adamantAdr: adamantAdr)
self?.openDialog(chatList: chatList, tabbar: tabbar, router: router, list: list, adamantAdr: adamantAdr)
}
}
}
Expand All @@ -541,7 +601,7 @@ extension AppDelegate {
return true
}

func openDialog(chatList: UINavigationController, tabbar: UITabBarController, router: Router, list: ChatListViewController, adamantAdr: AdamantAddress){
func openDialog(chatList: UINavigationController, tabbar: UITabBarController, router: Router, list: ChatListViewController, adamantAdr: AdamantAddress) {
chatList.popToRootViewController(animated: false)
chatList.dismiss(animated: false, completion: nil)
tabbar.selectedIndex = 0
Expand Down
7 changes: 3 additions & 4 deletions Adamant/CoreData/Chatroom+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ public class Chatroom: NSManagedObject {
static let entityName = "Chatroom"

func markAsReaded() {
if hasUnreadMessages {
hasUnreadMessages = false
}

hasUnreadMessages = false

if let trs = transactions as? Set<ChatTransaction> {
trs.filter { $0.isUnread }.forEach { $0.isUnread = false }
}
lastTransaction?.isUnread = false
}

func getFirstUnread() -> ChatTransaction? {
Expand Down
2 changes: 2 additions & 0 deletions Adamant/ServiceProtocols/NodesSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ protocol NodesSource {
func getNewNode() -> Node
func getValidNode(completion: @escaping ((Node?) -> Void))

func getSocketNewNode() -> Node

func saveNodes()
func reloadNodes()

Expand Down
Loading

0 comments on commit 67fce54

Please sign in to comment.