Skip to content

Commit 9436465

Browse files
Processing tap for push notification
1 parent 6132964 commit 9436465

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

Adamant.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,7 @@
28972897
CODE_SIGN_ENTITLEMENTS = MessageNotificationContentExtension/Debug.entitlements;
28982898
CODE_SIGN_IDENTITY = "iPhone Developer";
28992899
CODE_SIGN_STYLE = Manual;
2900-
CURRENT_PROJECT_VERSION = 176;
2900+
CURRENT_PROJECT_VERSION = 180;
29012901
DEVELOPMENT_TEAM = J2L77FMN46;
29022902
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
29032903
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -2906,7 +2906,7 @@
29062906
"@executable_path/Frameworks",
29072907
"@executable_path/../../Frameworks",
29082908
);
2909-
MARKETING_VERSION = 2.3.3;
2909+
MARKETING_VERSION = 2.4.0;
29102910
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
29112911
MTL_FAST_MATH = YES;
29122912
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.MessageNotificationContentExtension";
@@ -2926,7 +2926,7 @@
29262926
CODE_SIGN_IDENTITY = "Apple Development";
29272927
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
29282928
CODE_SIGN_STYLE = Manual;
2929-
CURRENT_PROJECT_VERSION = 176;
2929+
CURRENT_PROJECT_VERSION = 180;
29302930
DEVELOPMENT_TEAM = J2L77FMN46;
29312931
INFOPLIST_FILE = MessageNotificationContentExtension/Info.plist;
29322932
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -2935,7 +2935,7 @@
29352935
"@executable_path/Frameworks",
29362936
"@executable_path/../../Frameworks",
29372937
);
2938-
MARKETING_VERSION = 2.3.3;
2938+
MARKETING_VERSION = 2.4.0;
29392939
MTL_FAST_MATH = YES;
29402940
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.MessageNotificationContentExtension";
29412941
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -3073,7 +3073,7 @@
30733073
CODE_SIGN_ENTITLEMENTS = Adamant/Debug.entitlements;
30743074
CODE_SIGN_IDENTITY = "iPhone Developer";
30753075
CODE_SIGN_STYLE = Manual;
3076-
CURRENT_PROJECT_VERSION = 176;
3076+
CURRENT_PROJECT_VERSION = 180;
30773077
DEVELOPMENT_TEAM = J2L77FMN46;
30783078
DISPLAY_NAME = ADM.Dev;
30793079
EXCLUDED_SOURCE_FILE_NAMES = "";
@@ -3083,7 +3083,7 @@
30833083
"$(inherited)",
30843084
"@executable_path/Frameworks",
30853085
);
3086-
MARKETING_VERSION = 2.3.3;
3086+
MARKETING_VERSION = 2.4.0;
30873087
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev";
30883088
PRODUCT_NAME = "$(TARGET_NAME)";
30893089
PROVISIONING_PROFILE = "e4233bbf-3705-44fe-95b0-e77475672c60";
@@ -3102,7 +3102,7 @@
31023102
CODE_SIGN_IDENTITY = "Apple Development";
31033103
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
31043104
CODE_SIGN_STYLE = Manual;
3105-
CURRENT_PROJECT_VERSION = 176;
3105+
CURRENT_PROJECT_VERSION = 180;
31063106
DEVELOPMENT_TEAM = J2L77FMN46;
31073107
DISPLAY_NAME = Adamant;
31083108
EXCLUDED_SOURCE_FILE_NAMES = Debug.xcassets;
@@ -3112,7 +3112,7 @@
31123112
"$(inherited)",
31133113
"@executable_path/Frameworks",
31143114
);
3115-
MARKETING_VERSION = 2.3.3;
3115+
MARKETING_VERSION = 2.4.0;
31163116
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger";
31173117
PRODUCT_NAME = "$(TARGET_NAME)";
31183118
PROVISIONING_PROFILE = "bedd1b75-2f23-4a85-a0b2-14c424fcff42";
@@ -3130,7 +3130,7 @@
31303130
CODE_SIGN_ENTITLEMENTS = TransferNotificationContentExtension/Debug.entitlements;
31313131
CODE_SIGN_IDENTITY = "iPhone Developer";
31323132
CODE_SIGN_STYLE = Manual;
3133-
CURRENT_PROJECT_VERSION = 176;
3133+
CURRENT_PROJECT_VERSION = 180;
31343134
DEVELOPMENT_TEAM = J2L77FMN46;
31353135
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
31363136
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3139,7 +3139,7 @@
31393139
"@executable_path/Frameworks",
31403140
"@executable_path/../../Frameworks",
31413141
);
3142-
MARKETING_VERSION = 2.3.3;
3142+
MARKETING_VERSION = 2.4.0;
31433143
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
31443144
MTL_FAST_MATH = YES;
31453145
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.TransferNotificationContentExtension";
@@ -3159,7 +3159,7 @@
31593159
CODE_SIGN_IDENTITY = "Apple Development";
31603160
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
31613161
CODE_SIGN_STYLE = Manual;
3162-
CURRENT_PROJECT_VERSION = 176;
3162+
CURRENT_PROJECT_VERSION = 180;
31633163
DEVELOPMENT_TEAM = J2L77FMN46;
31643164
INFOPLIST_FILE = TransferNotificationContentExtension/Info.plist;
31653165
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3168,7 +3168,7 @@
31683168
"@executable_path/Frameworks",
31693169
"@executable_path/../../Frameworks",
31703170
);
3171-
MARKETING_VERSION = 2.3.3;
3171+
MARKETING_VERSION = 2.4.0;
31723172
MTL_FAST_MATH = YES;
31733173
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.TransferNotificationContentExtension";
31743174
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -3188,7 +3188,7 @@
31883188
CODE_SIGN_ENTITLEMENTS = NotificationServiceExtension/Debug.entitlements;
31893189
CODE_SIGN_IDENTITY = "iPhone Developer";
31903190
CODE_SIGN_STYLE = Manual;
3191-
CURRENT_PROJECT_VERSION = 176;
3191+
CURRENT_PROJECT_VERSION = 180;
31923192
DEVELOPMENT_TEAM = J2L77FMN46;
31933193
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
31943194
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3197,7 +3197,7 @@
31973197
"@executable_path/Frameworks",
31983198
"@executable_path/../../Frameworks",
31993199
);
3200-
MARKETING_VERSION = 2.3.3;
3200+
MARKETING_VERSION = 2.4.0;
32013201
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
32023202
MTL_FAST_MATH = YES;
32033203
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger-dev.NotificationServiceExtension";
@@ -3217,7 +3217,7 @@
32173217
CODE_SIGN_IDENTITY = "Apple Development";
32183218
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
32193219
CODE_SIGN_STYLE = Manual;
3220-
CURRENT_PROJECT_VERSION = 176;
3220+
CURRENT_PROJECT_VERSION = 180;
32213221
DEVELOPMENT_TEAM = J2L77FMN46;
32223222
INFOPLIST_FILE = NotificationServiceExtension/Info.plist;
32233223
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
@@ -3226,7 +3226,7 @@
32263226
"@executable_path/Frameworks",
32273227
"@executable_path/../../Frameworks",
32283228
);
3229-
MARKETING_VERSION = 2.3.3;
3229+
MARKETING_VERSION = 2.4.0;
32303230
MTL_FAST_MATH = YES;
32313231
PRODUCT_BUNDLE_IDENTIFIER = "im.adamant.adamant-messenger.NotificationServiceExtension";
32323232
PRODUCT_NAME = "$(TARGET_NAME)";

Adamant/AppDelegate.swift

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,19 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
343343
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
344344
if let recipientAddress = userInfo[AdamantNotificationUserInfoKeys.pushRecipient] as? String
345345
{
346+
if application.applicationState != .background && application.applicationState != .inactive {
347+
completionHandler(.noData)
348+
return
349+
}
350+
346351
if let tabbar = window?.rootViewController as? UITabBarController,
347352
let chats = tabbar.viewControllers?.first as? UISplitViewController,
348353
let chatList = chats.viewControllers.first as? UINavigationController,
349354
let list = chatList.viewControllers.first as? ChatListViewController {
350-
351-
guard let room = list.chatsController?.fetchedObjects?.first(where: { room in
352-
return room.lastTransaction?.recipientAddress == recipientAddress
353-
}) else { return }
354355

355356
switch list.accountService.state {
356357
case .loggedIn:
357-
self.openDialog(chatList: chatList, tabbar: tabbar, list: list, chatroom: room)
358+
self.openDialog(chatList: chatList, tabbar: tabbar, list: list, recipientAddress: recipientAddress)
358359
case .notLogged:
359360
break
360361
case .isLoggingIn:
@@ -366,7 +367,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
366367
// if not logged in
367368
list.didLoadedMessages = { [weak self] in
368369
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
369-
self?.openDialog(chatList: chatList, tabbar: tabbar, list: list, chatroom: room)
370+
self?.openDialog(chatList: chatList, tabbar: tabbar, list: list, recipientAddress: recipientAddress)
370371
}
371372
}
372373
}
@@ -376,18 +377,25 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
376377
}
377378
}
378379

379-
func openDialog(chatList: UINavigationController, tabbar: UITabBarController, list: ChatListViewController, chatroom: Chatroom) {
380+
func openDialog(chatList: UINavigationController, tabbar: UITabBarController, list: ChatListViewController, recipientAddress: String) {
381+
guard let chatroom = list.chatsController?.fetchedObjects?.first(where: { room in
382+
return room.lastTransaction?.recipientAddress == recipientAddress
383+
}) else { return }
384+
380385
chatList.popToRootViewController(animated: false)
381386
chatList.dismiss(animated: false, completion: nil)
382387
tabbar.selectedIndex = 0
383388

384-
let vc = list.chatViewController(for: chatroom)
385-
389+
let vc = list.chatViewController(for: chatroom, forceScrollToBottom: true)
386390
if let split = list.splitViewController {
387-
let chat = UINavigationController(rootViewController:vc)
388-
split.showDetailViewController(chat, sender: self)
391+
var timeout = 0.25
392+
if #available(iOS 13.0, *) { timeout = 0 }
393+
DispatchQueue.main.asyncAfter(deadline: .now() + timeout) {
394+
let chat = UINavigationController(rootViewController:vc)
395+
split.showDetailViewController(chat, sender: self)
396+
}
389397
} else {
390-
chatList.pushViewController(vc, animated: true)
398+
chatList.pushViewController(vc, animated: false)
391399
}
392400
}
393401
}

Adamant/Stories/Chats/ChatListViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ChatListViewController: UIViewController {
219219

220220

221221
// MARK: Helpers
222-
func chatViewController(for chatroom: Chatroom, with message: MessageTransaction? = nil) -> ChatViewController {
222+
func chatViewController(for chatroom: Chatroom, with message: MessageTransaction? = nil, forceScrollToBottom: Bool = false) -> ChatViewController {
223223
guard let vc = router.get(scene: AdamantScene.Chats.chat) as? ChatViewController else {
224224
fatalError("Can't get ChatViewController")
225225
}
@@ -232,6 +232,8 @@ class ChatListViewController: UIViewController {
232232
vc.messageToShow = message
233233
}
234234

235+
vc.forceScrollToBottom = forceScrollToBottom
236+
235237
vc.hidesBottomBarWhenPushed = true
236238
vc.chatroom = chatroom
237239
vc.delegate = self

Adamant/Stories/Chats/ChatViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ChatViewController: MessagesViewController {
6868
var account: AdamantAccount?
6969
var chatroom: Chatroom?
7070
var messageToShow: MessageTransaction?
71+
var forceScrollToBottom: Bool?
7172
var dateFormatter: DateFormatter {
7273
let formatter = DateFormatter()
7374
formatter.dateStyle = .short
@@ -505,6 +506,10 @@ class ChatViewController: MessagesViewController {
505506

506507
scrollToBottomBtn.isHidden = chatPositionOffset < chatPositionDelata
507508
scrollToBottomBtnOffetConstraint?.constant = -20 - self.messageInputBar.bounds.height
509+
510+
if forceScrollToBottom ?? false {
511+
scrollDown()
512+
}
508513
}
509514

510515
override func viewDidDisappear(_ animated: Bool) {

0 commit comments

Comments
 (0)