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 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> { private func registerForVanillaPushToken() -> AnyPublisher<String, Error> {
AssertIsOnMainThread()
// Use the existing publisher if it exists // Use the existing publisher if it exists
if let vanillaTokenPublisher: AnyPublisher<Data, Error> = self.vanillaTokenPublisher { if let vanillaTokenPublisher: AnyPublisher<Data, Error> = self.vanillaTokenPublisher {
return vanillaTokenPublisher return vanillaTokenPublisher
@ -139,15 +136,17 @@ public enum PushRegistrationError: Error {
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
UIApplication.shared.registerForRemoteNotifications()
// No pending vanilla token yet; create a new publisher // No pending vanilla token yet; create a new publisher
let publisher: AnyPublisher<Data, Error> = Deferred { let publisher: AnyPublisher<Data, Error> = Deferred {
Future<Data, Error> { self.vanillaTokenResolver = $0 } Future<Data, Error> { self.vanillaTokenResolver = $0 }
} }
.shareReplay(1)
.eraseToAnyPublisher() .eraseToAnyPublisher()
self.vanillaTokenPublisher = publisher self.vanillaTokenPublisher = publisher
// Tell the device to register for remote notifications
DispatchQueue.main.sync { UIApplication.shared.registerForRemoteNotifications() }
return publisher return publisher
.timeout( .timeout(
.seconds(10), .seconds(10),

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

@ -16,7 +16,7 @@ extension MessageSender {
members: Set<String> members: Set<String>
) -> AnyPublisher<SessionThread, Error> { ) -> AnyPublisher<SessionThread, Error> {
Storage.shared Storage.shared
.writePublisher { db -> (String, SessionThread, [MessageSender.PreparedSendData]) in .writePublisher { db -> (String, SessionThread, [MessageSender.PreparedSendData], Set<String>) in
let userPublicKey: String = getUserHexEncodedPublicKey(db) let userPublicKey: String = getUserHexEncodedPublicKey(db)
var members: Set<String> = members var members: Set<String> = members
@ -111,21 +111,30 @@ extension MessageSender {
interactionId: nil 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 Publishers
.MergeMany( .MergeMany(
// Send a closed group update message to all members individually // Send a closed group update message to all members individually
memberSendData memberSendData
.map { MessageSender.sendImmediate(preparedSendData: $0) } .map { MessageSender.sendImmediate(preparedSendData: $0) }
.appending( .appending(
// Notify the PN server // Resubscribe to all legacy groups
PushNotificationAPI.performOperation( PushNotificationAPI.subscribeToLegacyGroups(
.subscribe, currentUserPublicKey: userPublicKey,
for: thread.id, legacyGroupIds: allActiveLegacyGroupIds
publicKey: userPublicKey
) )
) )
) )

@ -9,6 +9,7 @@ import SignalCoreKit
final class ShareNavController: UINavigationController, ShareViewDelegate { final class ShareNavController: UINavigationController, ShareViewDelegate {
public static var attachmentPrepPublisher: AnyPublisher<[SignalAttachment], Error>? public static var attachmentPrepPublisher: AnyPublisher<[SignalAttachment], Error>?
private let versionMigrationsComplete: Atomic<Bool> = Atomic(false)
// MARK: - Error // 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 /// 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 /// we call `checkIsAppReady` explicitly here assuming that either the `AppSetup` _hasn't_ complete or won't ever
/// get run /// get run
checkIsAppReady() checkIsAppReady(migrationsCompleted: versionMigrationsComplete.wrappedValue)
} }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@ -107,6 +108,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate {
} }
} }
versionMigrationsComplete.mutate { $0 = true }
checkIsAppReady(migrationsCompleted: true) checkIsAppReady(migrationsCompleted: true)
} }

Loading…
Cancel
Save