Fixed the build issues and a bug where a new legacy group wasn't subscribile

pull/856/head
Morgan Pretty 11 months ago
parent 1b0fda56ad
commit 66b94778e0

@ -128,10 +128,7 @@ public enum PushRegistrationError: Error {
return true
}
// FIXME: Might be nice to try to avoid having this required to run on the main thread (follow a similar approach to the 'SyncPushTokensJob' & `Atomic<T>`?)
private func registerForVanillaPushToken() -> AnyPublisher<String, Error> {
AssertIsOnMainThread()
// Use the existing publisher if it exists
if let vanillaTokenPublisher: AnyPublisher<Data, Error> = self.vanillaTokenPublisher {
return vanillaTokenPublisher
@ -139,15 +136,17 @@ public enum PushRegistrationError: Error {
.eraseToAnyPublisher()
}
UIApplication.shared.registerForRemoteNotifications()
// No pending vanilla token yet; create a new publisher
let publisher: AnyPublisher<Data, Error> = Deferred {
Future<Data, Error> { self.vanillaTokenResolver = $0 }
}
.shareReplay(1)
.eraseToAnyPublisher()
self.vanillaTokenPublisher = publisher
// Tell the device to register for remote notifications
DispatchQueue.main.sync { UIApplication.shared.registerForRemoteNotifications() }
return publisher
.timeout(
.seconds(10),

@ -58,7 +58,7 @@ public enum SyncPushTokensJob: JobExecutor {
guard isUsingFullAPNs else {
Just(Storage.shared[.lastRecordedPushToken])
.setFailureType(to: Error.self)
.flatMap { lastRecordedPushToken in
.flatMap { lastRecordedPushToken -> AnyPublisher<String, Error> in
if let existingToken: String = lastRecordedPushToken {
SNLog("[SyncPushTokensJob] Unregister using last recorded push token: \(redact(existingToken))")
return Just(existingToken)
@ -71,7 +71,7 @@ public enum SyncPushTokensJob: JobExecutor {
.map { token, _ in token }
.eraseToAnyPublisher()
}
.flatMap { pushToken in PushNotificationAPI.unregister(Data(hex: pushToken)) }
.flatMap { pushToken in PushNotificationAPI.unsubscribe(token: Data(hex: pushToken)) }
.map {
// Tell the device to unregister for remote notifications (essentially try to invalidate
// the token if needed
@ -102,9 +102,8 @@ public enum SyncPushTokensJob: JobExecutor {
PushRegistrationManager.shared.requestPushTokens()
.flatMap { (pushToken: String, voipToken: String) -> AnyPublisher<Void, Error> in
PushNotificationAPI
.register(
with: Data(hex: pushToken),
publicKey: getUserHexEncodedPublicKey(),
.subscribe(
token: Data(hex: pushToken),
isForcedUpdate: true
)
.retry(3)

@ -16,7 +16,7 @@ extension MessageSender {
members: Set<String>
) -> AnyPublisher<SessionThread, Error> {
Storage.shared
.writePublisher { db -> (String, SessionThread, [MessageSender.PreparedSendData]) in
.writePublisher { db -> (String, SessionThread, [MessageSender.PreparedSendData], Set<String>) in
let userPublicKey: String = getUserHexEncodedPublicKey(db)
var members: Set<String> = members
@ -111,21 +111,30 @@ extension MessageSender {
interactionId: nil
)
}
let allActiveLegacyGroupIds: Set<String> = try ClosedGroup
.select(.threadId)
.filter(!ClosedGroup.Columns.threadId.like("\(SessionId.Prefix.group.rawValue)%"))
.joining(
required: ClosedGroup.members
.filter(GroupMember.Columns.profileId == userPublicKey)
)
.asRequest(of: String.self)
.fetchSet(db)
.inserting(groupPublicKey) // Insert the new key just to be sure
return (userPublicKey, thread, memberSendData)
return (userPublicKey, thread, memberSendData, allActiveLegacyGroupIds)
}
.flatMap { userPublicKey, thread, memberSendData in
.flatMap { userPublicKey, thread, memberSendData, allActiveLegacyGroupIds in
Publishers
.MergeMany(
// Send a closed group update message to all members individually
memberSendData
.map { MessageSender.sendImmediate(preparedSendData: $0) }
.appending(
// Notify the PN server
PushNotificationAPI.performOperation(
.subscribe,
for: thread.id,
publicKey: userPublicKey
// Resubscribe to all legacy groups
PushNotificationAPI.subscribeToLegacyGroups(
currentUserPublicKey: userPublicKey,
legacyGroupIds: allActiveLegacyGroupIds
)
)
)

@ -9,6 +9,7 @@ import SignalCoreKit
final class ShareNavController: UINavigationController, ShareViewDelegate {
public static var attachmentPrepPublisher: AnyPublisher<[SignalAttachment], Error>?
private let versionMigrationsComplete: Atomic<Bool> = Atomic(false)
// MARK: - Error
@ -84,7 +85,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate {
/// results in the `AppSetup` not actually running (and the UI not actually being loaded correctly) - in order to avoid this
/// we call `checkIsAppReady` explicitly here assuming that either the `AppSetup` _hasn't_ complete or won't ever
/// get run
checkIsAppReady()
checkIsAppReady(migrationsCompleted: versionMigrationsComplete.wrappedValue)
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@ -107,6 +108,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate {
}
}
versionMigrationsComplete.mutate { $0 = true }
checkIsAppReady(migrationsCompleted: true)
}

Loading…
Cancel
Save