mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'dev' of https://github.com/loki-project/session-ios into PN-with-preview
This commit is contained in:
commit
471870d8a5
12 changed files with 57 additions and 60 deletions
|
@ -4952,6 +4952,7 @@
|
|||
LLVM_LTO = NO;
|
||||
MARKETING_VERSION = 1.0.8;
|
||||
OTHER_LDFLAGS = "$(inherited)";
|
||||
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger";
|
||||
PRODUCT_NAME = Session;
|
||||
PROVISIONING_PROFILE = "";
|
||||
|
|
|
@ -59,7 +59,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
|||
|
||||
static NSTimeInterval launchStartedAt;
|
||||
|
||||
// Debug settings
|
||||
static BOOL isInternalTestVersion = NO;
|
||||
static BOOL isUsingFullAPNs = YES;
|
||||
|
||||
@interface AppDelegate () <UNUserNotificationCenterDelegate>
|
||||
|
||||
|
@ -587,9 +589,11 @@ static BOOL isInternalTestVersion = NO;
|
|||
}
|
||||
|
||||
OWSLogInfo(@"Registered for push notifications with token: %@.", deviceToken);
|
||||
//TODO: For normal push notification test
|
||||
[LKPushNotificationManager.shared registerWithToken:deviceToken pubkey:self.tsAccountManager.localNumber];
|
||||
// [LKPushNotificationManager.shared registerWithToken:deviceToken];
|
||||
if (isUsingFullAPNs) {
|
||||
[LKPushNotificationManager registerWithToken:deviceToken hexEncodedPublicKey:self.tsAccountManager.localNumber];
|
||||
} else {
|
||||
[LKPushNotificationManager registerWithToken:deviceToken];
|
||||
}
|
||||
// [self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
|
||||
}
|
||||
|
||||
|
@ -1555,7 +1559,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
{
|
||||
OWSLogInfo(@"");
|
||||
if (notification.request.content.userInfo[@"remote"]) {
|
||||
OWSLogInfo(@"[Loki] Ignore remote notifications when app is foreground.");
|
||||
OWSLogInfo(@"[Loki] Ignoring remote notifications while the app is in the foreground.");
|
||||
return;
|
||||
}
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^() {
|
||||
|
|
|
@ -1,75 +1,71 @@
|
|||
import UIKit
|
||||
|
||||
// Ideally this should be in SignalServiceKit, but somehow linking fails when it is.
|
||||
|
||||
@objc(LKPushNotificationManager)
|
||||
final class LokiPushNotificationManager : NSObject {
|
||||
|
||||
@objc static let shared = LokiPushNotificationManager()
|
||||
// MARK: Settings
|
||||
#if DEBUG
|
||||
private static let url = URL(string: "https://dev.apns.getsession.org/register")!
|
||||
#else
|
||||
private static let url = URL(string: "https://live.apns.getsession.org/register")!
|
||||
#endif
|
||||
private static let tokenExpirationInterval: TimeInterval = 2 * 24 * 60 * 60
|
||||
|
||||
private override init() { super.init() }
|
||||
// MARK: Initialization
|
||||
private override init() { }
|
||||
|
||||
// MARK: Registration
|
||||
@objc(registerWithToken:)
|
||||
func register(with token: Data) {
|
||||
let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
static func register(with token: Data) {
|
||||
let hexEncodedToken = token.toHexString()
|
||||
let userDefaults = UserDefaults.standard
|
||||
let oldToken = userDefaults[.deviceToken]
|
||||
let lastUploadTime = userDefaults[.lastDeviceTokenUpload]
|
||||
let applyNormalNotification = userDefaults[.applyNormalNotification]
|
||||
let isUsingFullAPNs = userDefaults[.isUsingFullAPNs]
|
||||
let now = Date().timeIntervalSince1970
|
||||
if hexEncodedToken == oldToken && now - lastUploadTime < 2 * 24 * 60 * 60 {
|
||||
print("[Loki] Device token hasn't changed; no need to upload.")
|
||||
return
|
||||
guard hexEncodedToken != oldToken || now - lastUploadTime < tokenExpirationInterval else {
|
||||
return print("[Loki] Device token hasn't changed; no need to re-upload.")
|
||||
}
|
||||
if applyNormalNotification {
|
||||
print("[Loki] Using normal notification; no need to upload.")
|
||||
return
|
||||
guard !isUsingFullAPNs else {
|
||||
return print("[Loki] Using full APNs; no need to upload device token.")
|
||||
}
|
||||
// Send token to Loki server
|
||||
let parameters = [ "token" : hexEncodedToken ]
|
||||
#if DEBUG
|
||||
let url = URL(string: "https://dev.apns.getsession.org/register")!
|
||||
#else
|
||||
let url = URL(string: "https://live.apns.getsession.org/register")!
|
||||
#endif
|
||||
let request = TSRequest(url: url, method: "POST", parameters: parameters)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ]
|
||||
TSNetworkManager.shared().makeRequest(request, success: { _, response in
|
||||
guard let json = response as? JSON else { return }
|
||||
guard let json = response as? JSON else {
|
||||
return print("[Loki] Couldn't register device token.")
|
||||
}
|
||||
guard json["code"] as? Int != 0 else {
|
||||
return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").")
|
||||
return print("[Loki] Couldn't register device token due to error: \(json["message"] as? String ?? "nil").")
|
||||
}
|
||||
userDefaults[.deviceToken] = hexEncodedToken
|
||||
userDefaults[.lastDeviceTokenUpload] = now
|
||||
userDefaults[.applyNormalNotification] = false
|
||||
userDefaults[.isUsingFullAPNs] = false
|
||||
}, failure: { _, error in
|
||||
print("[Loki] Couldn't register device token.")
|
||||
})
|
||||
}
|
||||
|
||||
@objc(registerWithToken: pubkey:)
|
||||
func register(with token: Data, pubkey: String) {
|
||||
let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
@objc(registerWithToken:hexEncodedPublicKey:)
|
||||
static func register(with token: Data, hexEncodedPublicKey: String) {
|
||||
let hexEncodedToken = token.toHexString()
|
||||
let userDefaults = UserDefaults.standard
|
||||
let now = Date().timeIntervalSince1970
|
||||
// Send token to Loki server
|
||||
let parameters = [ "token" : hexEncodedToken,
|
||||
"pubKey": pubkey]
|
||||
#if DEBUG
|
||||
let url = URL(string: "https://dev.apns.getsession.org/register")!
|
||||
#else
|
||||
let url = URL(string: "https://live.apns.getsession.org/register")!
|
||||
#endif
|
||||
let parameters = [ "token" : hexEncodedToken, "pubKey" : hexEncodedPublicKey]
|
||||
let request = TSRequest(url: url, method: "POST", parameters: parameters)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ]
|
||||
TSNetworkManager.shared().makeRequest(request, success: { _, response in
|
||||
guard let json = response as? JSON else { return }
|
||||
guard let json = response as? JSON else {
|
||||
return print("[Loki] Couldn't register device token.")
|
||||
}
|
||||
guard json["code"] as? Int != 0 else {
|
||||
return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").")
|
||||
return print("[Loki] Couldn't register device token due to error: \(json["message"] as? String ?? "nil").")
|
||||
}
|
||||
userDefaults[.deviceToken] = hexEncodedToken
|
||||
userDefaults[.lastDeviceTokenUpload] = now
|
||||
userDefaults[.applyNormalNotification] = true
|
||||
userDefaults[.isUsingFullAPNs] = true
|
||||
}, failure: { _, error in
|
||||
print("[Loki] Couldn't register device token.")
|
||||
})
|
||||
|
|
|
@ -642,8 +642,7 @@ class NotificationActionHandler {
|
|||
|
||||
func showThread(userInfo: [AnyHashable: Any]) throws -> Promise<Void> {
|
||||
guard let threadId = userInfo[AppNotificationUserInfoKey.threadId] as? String else {
|
||||
return showHomePage()
|
||||
// throw NotificationError.failDebug("threadId was unexpectedly nil")
|
||||
return showHomeVC()
|
||||
}
|
||||
|
||||
// If this happens when the the app is not, visible we skip the animation so the thread
|
||||
|
@ -654,7 +653,7 @@ class NotificationActionHandler {
|
|||
return Promise.value(())
|
||||
}
|
||||
|
||||
func showHomePage() -> Promise<Void> {
|
||||
func showHomeVC() -> Promise<Void> {
|
||||
signalApp.showHomeView()
|
||||
return Promise.value(())
|
||||
}
|
||||
|
|
|
@ -352,8 +352,7 @@ public class SystemContactsFetcher: NSObject {
|
|||
|
||||
guard let contacts = fetchedContacts else {
|
||||
owsFailDebug("contacts was unexpectedly not set.")
|
||||
completion(nil)
|
||||
return
|
||||
return completion(nil)
|
||||
}
|
||||
|
||||
Logger.info("fetched \(contacts.count) contacts.")
|
||||
|
|
|
@ -48,7 +48,7 @@ public extension LokiAPI {
|
|||
]
|
||||
]
|
||||
])
|
||||
print("[Loki] Invoking get_n_service_nodes on \(target).")
|
||||
print("[Loki] Invoking get_service_nodes on \(target).")
|
||||
return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map(on: DispatchQueue.global()) { intermediate in
|
||||
let rawResponse = intermediate.responseObject
|
||||
guard let json = rawResponse as? JSON, let intermediate = json["result"] as? JSON, let rawTargets = intermediate["service_node_states"] as? [JSON] else { throw LokiAPIError.randomSnodePoolUpdatingFailed }
|
||||
|
|
|
@ -2,10 +2,12 @@ import PromiseKit
|
|||
|
||||
@objc(LKAPI)
|
||||
public final class LokiAPI : NSObject {
|
||||
private static let stateQueue = DispatchQueue(label: "stateQueue")
|
||||
|
||||
/// Only ever modified from the message processing queue (`OWSBatchMessageProcessor.processingQueue`).
|
||||
private static var syncMessageTimestamps: [String:Set<UInt64>] = [:]
|
||||
|
||||
public static var _lastDeviceLinkUpdate: [String:Date] = [:]
|
||||
private static var _lastDeviceLinkUpdate: [String:Date] = [:]
|
||||
/// A mapping from hex encoded public key to date updated.
|
||||
public static var lastDeviceLinkUpdate: [String:Date] {
|
||||
get { stateQueue.sync { _lastDeviceLinkUpdate } }
|
||||
|
@ -19,8 +21,6 @@ public final class LokiAPI : NSObject {
|
|||
set { stateQueue.sync { _userHexEncodedPublicKeyCache = newValue } }
|
||||
}
|
||||
|
||||
private static let stateQueue = DispatchQueue(label: "stateQueue")
|
||||
|
||||
/// All service node related errors must be handled on this queue to avoid race conditions maintaining e.g. failure counts.
|
||||
public static let errorHandlingQueue = DispatchQueue(label: "errorHandlingQueue")
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
}
|
||||
|
||||
#pragma mark Settings
|
||||
- (uint)ttl { return 2 * kMinuteInMs; }
|
||||
- (uint)ttl { return 4 * kMinuteInMs; }
|
||||
- (BOOL)shouldSyncTranscript { return NO; }
|
||||
- (BOOL)shouldBeSaved { return NO; }
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ public enum LKUserDefaults {
|
|||
case hasViewedSeed
|
||||
/// Whether the device was unlinked as a slave device (used to notify the user on the landing screen).
|
||||
case wasUnlinked
|
||||
case applyNormalNotification
|
||||
case isUsingFullAPNs
|
||||
}
|
||||
|
||||
public enum Date : Swift.String {
|
||||
|
|
|
@ -61,11 +61,6 @@ public class TypingIndicatorMessage: TSOutgoingMessage {
|
|||
return true
|
||||
}
|
||||
|
||||
@objc
|
||||
public override var ttl: UInt32 {
|
||||
return UInt32(10 * kMinuteInMs)
|
||||
}
|
||||
|
||||
private func protoAction(forAction action: TypingIndicatorAction) -> SSKProtoTypingMessage.SSKProtoTypingMessageAction {
|
||||
switch action {
|
||||
case .started:
|
||||
|
@ -105,6 +100,9 @@ public class TypingIndicatorMessage: TSOutgoingMessage {
|
|||
return false
|
||||
}
|
||||
|
||||
@objc
|
||||
public override var ttl: UInt32 { return UInt32(2 * kMinuteInMs) }
|
||||
|
||||
@objc
|
||||
public override var debugDescription: String {
|
||||
return "typingIndicatorMessage"
|
||||
|
|
Loading…
Reference in a new issue