Merge pull request #87 from RyanRory/push-notification-fix

Fix Push Notifications
pull/89/head
gmbnt 5 years ago committed by GitHub
commit d967724348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -580,7 +580,7 @@ static NSTimeInterval launchStartedAt;
OWSLogInfo(@"Registered for push notifications with token: %@.", deviceToken);
[LKPushNotificationManager.shared registerWithToken:deviceToken];
[self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
// [self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

@ -230,6 +230,8 @@ public class MessageFetcherJob: NSObject {
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withServerGuid: serverGuid)
} else if let source = envelope.source, source.count > 0, envelope.timestamp > 0 {
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: source, timestamp: envelope.timestamp)
} else if envelope.type == .unidentifiedSender, envelope.timestamp > 0 {
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source!, timestamp: envelope.timestamp)
} else {
owsFailDebug("Cannot ACK message which has neither source, nor server GUID and timestamp.")
return

@ -12,7 +12,11 @@ final class LokiPushNotificationManager : NSObject {
@objc(registerWithToken:)
func register(with token: Data) {
let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined()
print("Registering device token: (\(hexEncodedToken))")
let oldToken = UserDefaults.standard.string(forKey: "deviceToken")
if (hexEncodedToken == oldToken) {
Logger.info("Token is not changed, no need to upload")
return
}
// Send token to Loki server
let parameters = [ "token" : hexEncodedToken ]
let url = URL(string: "https://live.apns.getsession.org/register")!
@ -23,6 +27,7 @@ final class LokiPushNotificationManager : NSObject {
guard json["code"] as? Int != 0 else {
return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").")
}
UserDefaults.standard.set(hexEncodedToken, forKey: "deviceToken")
}, failure: { _, error in
print("[Loki] Couldn't register device token.")
})

@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp
{
OWSAssertDebug(source.length > 0);
// OWSAssertDebug(source.length > 0);
OWSAssertDebug(timestamp > 0);
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];

Loading…
Cancel
Save