Merge branch 'dev' into fix-quoting-in-community-chats

pull/785/head
Ryan Zhao 2 years ago
commit e5a4aec0ee

@ -111,6 +111,7 @@ extension ContextMenuVC {
for cellViewModel: MessageViewModel, for cellViewModel: MessageViewModel,
recentEmojis: [EmojiWithSkinTones], recentEmojis: [EmojiWithSkinTones],
currentUserPublicKey: String, currentUserPublicKey: String,
currentUserBlindedPublicKey: String?,
currentUserIsOpenGroupModerator: Bool, currentUserIsOpenGroupModerator: Bool,
currentThreadIsMessageRequest: Bool, currentThreadIsMessageRequest: Bool,
delegate: ContextMenuActionDelegate? delegate: ContextMenuActionDelegate?
@ -165,6 +166,7 @@ extension ContextMenuVC {
cellViewModel.threadVariant != .openGroup || cellViewModel.threadVariant != .openGroup ||
currentUserIsOpenGroupModerator || currentUserIsOpenGroupModerator ||
cellViewModel.authorId == currentUserPublicKey || cellViewModel.authorId == currentUserPublicKey ||
cellViewModel.authorId == currentUserBlindedPublicKey ||
cellViewModel.state == .failed cellViewModel.state == .failed
) )
let canBan: Bool = ( let canBan: Bool = (

@ -778,6 +778,7 @@ extension ConversationVC:
for: cellViewModel, for: cellViewModel,
recentEmojis: (self.viewModel.threadData.recentReactionEmoji ?? []).compactMap { EmojiWithSkinTones(rawValue: $0) }, recentEmojis: (self.viewModel.threadData.recentReactionEmoji ?? []).compactMap { EmojiWithSkinTones(rawValue: $0) },
currentUserPublicKey: self.viewModel.threadData.currentUserPublicKey, currentUserPublicKey: self.viewModel.threadData.currentUserPublicKey,
currentUserBlindedPublicKey: self.viewModel.threadData.currentUserBlindedPublicKey,
currentUserIsOpenGroupModerator: OpenGroupManager.isUserModeratorOrAdmin( currentUserIsOpenGroupModerator: OpenGroupManager.isUserModeratorOrAdmin(
self.viewModel.threadData.currentUserPublicKey, self.viewModel.threadData.currentUserPublicKey,
for: self.viewModel.threadData.openGroupRoomToken, for: self.viewModel.threadData.openGroupRoomToken,

@ -119,6 +119,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
} }
) )
) )
.populatingCurrentUserBlindedKey()
/// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise /// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise
/// performance https://github.com/groue/GRDB.swift#valueobservation-performance /// performance https://github.com/groue/GRDB.swift#valueobservation-performance
@ -134,7 +135,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
private func setupObservableThreadData(for threadId: String) -> ValueObservation<ValueReducers.RemoveDuplicates<ValueReducers.Fetch<SessionThreadViewModel?>>> { private func setupObservableThreadData(for threadId: String) -> ValueObservation<ValueReducers.RemoveDuplicates<ValueReducers.Fetch<SessionThreadViewModel?>>> {
return ValueObservation return ValueObservation
.trackingConstantRegion { db -> SessionThreadViewModel? in .trackingConstantRegion { [weak self] db -> SessionThreadViewModel? in
let userPublicKey: String = getUserHexEncodedPublicKey(db) let userPublicKey: String = getUserHexEncodedPublicKey(db)
let recentReactionEmoji: [String] = try Emoji.getRecent(db, withDefaultEmoji: true) let recentReactionEmoji: [String] = try Emoji.getRecent(db, withDefaultEmoji: true)
let threadViewModel: SessionThreadViewModel? = try SessionThreadViewModel let threadViewModel: SessionThreadViewModel? = try SessionThreadViewModel
@ -143,6 +144,11 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
return threadViewModel return threadViewModel
.map { $0.with(recentReactionEmoji: recentReactionEmoji) } .map { $0.with(recentReactionEmoji: recentReactionEmoji) }
.map { viewModel -> SessionThreadViewModel in
viewModel.populatingCurrentUserBlindedKey(
currentUserBlindedPublicKeyForThisThread: self?.threadData.currentUserBlindedPublicKey
)
}
} }
.removeDuplicates() .removeDuplicates()
} }

@ -11,6 +11,7 @@ public enum SyncPushTokensJob: JobExecutor {
public static let maxFailureCount: Int = -1 public static let maxFailureCount: Int = -1
public static let requiresThreadId: Bool = false public static let requiresThreadId: Bool = false
public static let requiresInteractionId: Bool = false public static let requiresInteractionId: Bool = false
private static let maxFrequency: TimeInterval = (12 * 60 * 60)
public static func run( public static func run(
_ job: Job, _ job: Job,
@ -34,45 +35,44 @@ public enum SyncPushTokensJob: JobExecutor {
return return
} }
// Push tokens don't normally change while the app is launched, so checking once during launch is // Push tokens don't normally change while the app is launched, so you would assume checking once
// usually sufficient, but e.g. on iOS11, users who have disabled "Allow Notifications" and disabled // during launch is sufficient, but e.g. on iOS11, users who have disabled "Allow Notifications"
// "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not // and disabled "Background App Refresh" will not be able to obtain an APN token. Enabling those
// restart the app, so we check every activation for users who haven't yet registered. // settings does not restart the app, so we check every activation for users who haven't yet
guard job.behaviour != .recurringOnActive || !UIApplication.shared.isRegisteredForRemoteNotifications else { // registered.
//
// It's also possible for a device to successfully register for push notifications but fail to
// register with Session
//
// Due to the above we want to re-register at least once every ~12 hours to ensure users will
// continue to receive push notifications
//
// In addition to this if we are custom running the job (eg. by toggling the push notification
// setting) then we should run regardless of the other settings so users have a mechanism to force
// the registration to run
let lastPushNotificationSync: Date = UserDefaults.standard[.lastPushNotificationSync]
.defaulting(to: Date.distantPast)
guard
job.behaviour == .runOnce ||
!UIApplication.shared.isRegisteredForRemoteNotifications ||
Date().timeIntervalSince(lastPushNotificationSync) >= SyncPushTokensJob.maxFrequency
else {
deferred(job) // Don't need to do anything if push notifications are already registered deferred(job) // Don't need to do anything if push notifications are already registered
return return
} }
Logger.info("Retrying remote notification registration since user hasn't registered yet.") Logger.info("Re-registering for remote notifications.")
// Determine if we want to upload only if stale (Note: This should default to true, and be true if
// 'details' isn't provided)
let uploadOnlyIfStale: Bool = ((try? JSONDecoder().decode(Details.self, from: job.details ?? Data()))?.uploadOnlyIfStale ?? true)
// Get the app version info (used to determine if we want to update the push tokens)
let lastAppVersion: String? = AppVersion.sharedInstance().lastAppVersion
let currentAppVersion: String? = AppVersion.sharedInstance().currentAppVersion
// Perform device registration
PushRegistrationManager.shared.requestPushTokens() PushRegistrationManager.shared.requestPushTokens()
.then(on: queue) { (pushToken: String, voipToken: String) -> Promise<Void> in .then(on: queue) { (pushToken: String, voipToken: String) -> Promise<Void> in
let lastPushToken: String? = Storage.shared[.lastRecordedPushToken]
let lastVoipToken: String? = Storage.shared[.lastRecordedVoipToken]
let shouldUploadTokens: Bool = (
!uploadOnlyIfStale || (
lastPushToken != pushToken ||
lastVoipToken != voipToken
) ||
lastAppVersion != currentAppVersion
)
guard shouldUploadTokens else { return Promise.value(()) }
let (promise, seal) = Promise<Void>.pending() let (promise, seal) = Promise<Void>.pending()
SyncPushTokensJob.registerForPushNotifications( SyncPushTokensJob.registerForPushNotifications(
pushToken: pushToken, pushToken: pushToken,
voipToken: voipToken, voipToken: voipToken,
isForcedUpdate: shouldUploadTokens, isForcedUpdate: true,
success: { seal.fulfill(()) }, success: { seal.fulfill(()) },
failure: seal.reject failure: seal.reject
) )
@ -94,6 +94,7 @@ public enum SyncPushTokensJob: JobExecutor {
public static func run(uploadOnlyIfStale: Bool) { public static func run(uploadOnlyIfStale: Bool) {
guard let job: Job = Job( guard let job: Job = Job(
variant: .syncPushTokens, variant: .syncPushTokens,
behaviour: .runOnce,
details: SyncPushTokensJob.Details( details: SyncPushTokensJob.Details(
uploadOnlyIfStale: uploadOnlyIfStale uploadOnlyIfStale: uploadOnlyIfStale
) )

@ -44,6 +44,7 @@ public enum SNUserDefaults {
case lastOpenGroupImageUpdate case lastOpenGroupImageUpdate
case lastOpen case lastOpen
case lastGarbageCollection case lastGarbageCollection
case lastPushNotificationSync
} }
public enum Double: Swift.String { public enum Double: Swift.String {

Loading…
Cancel
Save