mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Purge dynamic interactions from database.
This commit is contained in:
parent
98137e9ddf
commit
bd40aacd53
4 changed files with 74 additions and 29 deletions
|
@ -241,6 +241,7 @@
|
|||
34BEDB1621C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.h in Headers */ = {isa = PBXBuildFile; fileRef = 34BEDB1421C80BC9007B0EAE /* OWSAnyTouchGestureRecognizer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
34BEDB1721C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 34BEDB1521C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.m */; };
|
||||
34BEDB1921C82AC5007B0EAE /* ImageEditorGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34BEDB1821C82AC5007B0EAE /* ImageEditorGestureRecognizer.swift */; };
|
||||
34BEDB0B21C2FA3D007B0EAE /* OWS114RemoveDynamicInteractions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34BEDB0A21C2FA3D007B0EAE /* OWS114RemoveDynamicInteractions.swift */; };
|
||||
34C3C78D20409F320000134C /* Opening.m4r in Resources */ = {isa = PBXBuildFile; fileRef = 34C3C78C20409F320000134C /* Opening.m4r */; };
|
||||
34C3C78F2040A4F70000134C /* sonarping.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 34C3C78E2040A4F70000134C /* sonarping.mp3 */; };
|
||||
34C3C7922040B0DD0000134C /* OWSAudioPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 34C3C7902040B0DC0000134C /* OWSAudioPlayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -917,6 +918,7 @@
|
|||
34BEDB1421C80BC9007B0EAE /* OWSAnyTouchGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSAnyTouchGestureRecognizer.h; sourceTree = "<group>"; };
|
||||
34BEDB1521C80BCA007B0EAE /* OWSAnyTouchGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSAnyTouchGestureRecognizer.m; sourceTree = "<group>"; };
|
||||
34BEDB1821C82AC5007B0EAE /* ImageEditorGestureRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageEditorGestureRecognizer.swift; sourceTree = "<group>"; };
|
||||
34BEDB0A21C2FA3D007B0EAE /* OWS114RemoveDynamicInteractions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWS114RemoveDynamicInteractions.swift; sourceTree = "<group>"; };
|
||||
34C3C78C20409F320000134C /* Opening.m4r */ = {isa = PBXFileReference; lastKnownFileType = file; path = Opening.m4r; sourceTree = "<group>"; };
|
||||
34C3C78E2040A4F70000134C /* sonarping.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; name = sonarping.mp3; path = Signal/AudioFiles/sonarping.mp3; sourceTree = SOURCE_ROOT; };
|
||||
34C3C7902040B0DC0000134C /* OWSAudioPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSAudioPlayer.h; sourceTree = "<group>"; };
|
||||
|
@ -1677,6 +1679,7 @@
|
|||
349EA07B2162AEA700F7B17F /* OWS111UDAttributesMigration.swift */,
|
||||
34B6A908218B8824007C4606 /* OWS112TypingIndicatorsMigration.swift */,
|
||||
4C7537882193779700DF5E37 /* OWS113MultiAttachmentMediaMessages.swift */,
|
||||
34BEDB0A21C2FA3D007B0EAE /* OWS114RemoveDynamicInteractions.swift */,
|
||||
346129931FD1E30000532771 /* OWSDatabaseMigration.h */,
|
||||
346129941FD1E30000532771 /* OWSDatabaseMigration.m */,
|
||||
346129E51FD5C0C600532771 /* OWSDatabaseMigrationRunner.h */,
|
||||
|
@ -3373,6 +3376,7 @@
|
|||
346129E31FD5C0BE00532771 /* VersionMigrations.m in Sources */,
|
||||
4C7537892193779700DF5E37 /* OWS113MultiAttachmentMediaMessages.swift in Sources */,
|
||||
34AC0A16211B39EA00997B47 /* OWSNavigationBar.swift in Sources */,
|
||||
34BEDB0B21C2FA3D007B0EAE /* OWS114RemoveDynamicInteractions.swift in Sources */,
|
||||
34AC0A1A211B39EA00997B47 /* CommonStrings.swift in Sources */,
|
||||
34AC0A19211B39EA00997B47 /* OWSAlerts.swift in Sources */,
|
||||
451F8A351FD710DE005CB9DA /* Searcher.swift in Sources */,
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SignalServiceKit
|
||||
|
||||
@objc
|
||||
public class OWS114RemoveDynamicInteractions: OWSDatabaseMigration {
|
||||
|
||||
// MARK: - Dependencies
|
||||
|
||||
// MARK: -
|
||||
|
||||
// Increment a similar constant for each migration.
|
||||
@objc
|
||||
class func migrationId() -> String {
|
||||
return "114"
|
||||
}
|
||||
|
||||
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
Logger.debug("")
|
||||
BenchAsync(title: "\(self.logTag)") { (benchCompletion) in
|
||||
self.doMigrationAsync(completion: {
|
||||
benchCompletion()
|
||||
completion()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func doMigrationAsync(completion : @escaping OWSDatabaseMigrationCompletion) {
|
||||
DispatchQueue.global().async {
|
||||
self.dbReadWriteConnection().readWrite { transaction in
|
||||
guard let dbView = TSDatabaseView.threadSpecialMessagesDatabaseView(transaction) as? YapDatabaseViewTransaction else {
|
||||
owsFailDebug("Couldn't load db view.")
|
||||
return
|
||||
}
|
||||
|
||||
var interactionsToDelete = [TSInteraction]()
|
||||
let groupIds = dbView.allGroups()
|
||||
for groupId in groupIds {
|
||||
dbView.enumerateKeysAndObjects(inGroup: groupId) { (_: String, _: String, object: Any, _: UInt, _: UnsafeMutablePointer<ObjCBool>) in
|
||||
guard let interaction = object as? TSInteraction else {
|
||||
owsFailDebug("Invalid database entity: \(type(of: object)).")
|
||||
return
|
||||
}
|
||||
guard interaction.isDynamicInteraction() else {
|
||||
return
|
||||
}
|
||||
interactionsToDelete.append(interaction)
|
||||
}
|
||||
}
|
||||
|
||||
for interaction in interactionsToDelete {
|
||||
Logger.debug("Cleaning up interaction: \(type(of: interaction)).")
|
||||
interaction.remove(with: transaction)
|
||||
}
|
||||
|
||||
self.save(with: transaction)
|
||||
}
|
||||
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[[OWS111UDAttributesMigration alloc] init],
|
||||
[[OWS112TypingIndicatorsMigration alloc] init],
|
||||
[[OWS113MultiAttachmentMediaMessages alloc] init],
|
||||
[[OWS114RemoveDynamicInteractions alloc] init],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -343,37 +343,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
ThreadDynamicInteractions *result = [ThreadDynamicInteractions new];
|
||||
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
// Find any "dynamic" interactions and safety number changes.
|
||||
//
|
||||
// We use different views for performance reasons.
|
||||
NSMutableArray<TSInvalidIdentityKeyErrorMessage *> *blockingSafetyNumberChanges = [NSMutableArray new];
|
||||
NSMutableArray<TSInteraction *> *nonBlockingSafetyNumberChanges = [NSMutableArray new];
|
||||
// We want to delete legacy and duplicate interactions.
|
||||
NSMutableArray<TSInteraction *> *interactionsToDelete = [NSMutableArray new];
|
||||
[[TSDatabaseView threadSpecialMessagesDatabaseView:transaction]
|
||||
enumerateKeysAndObjectsInGroup:thread.uniqueId
|
||||
usingBlock:^(
|
||||
NSString *collection, NSString *key, id object, NSUInteger index, BOOL *stop) {
|
||||
if ([object isKindOfClass:[OWSUnknownContactBlockOfferMessage class]]) {
|
||||
// Delete this legacy interactions, which has been superseded by
|
||||
// the OWSContactOffersInteraction.
|
||||
[interactionsToDelete addObject:object];
|
||||
} else if ([object isKindOfClass:[OWSAddToContactsOfferMessage class]]) {
|
||||
// Delete this legacy interactions, which has been superseded by
|
||||
// the OWSContactOffersInteraction.
|
||||
[interactionsToDelete addObject:object];
|
||||
} else if ([object isKindOfClass:[OWSAddToProfileWhitelistOfferMessage class]]) {
|
||||
// Delete this legacy interactions, which has been superseded by
|
||||
// the OWSContactOffersInteraction.
|
||||
[interactionsToDelete addObject:object];
|
||||
} else if ([object isKindOfClass:[TSUnreadIndicatorInteraction class]]) {
|
||||
// Remove obsolete unread indicator interactions.
|
||||
[interactionsToDelete addObject:object];
|
||||
} else if ([object isKindOfClass:[OWSContactOffersInteraction class]]) {
|
||||
// Remove obsolete contact offers.
|
||||
[interactionsToDelete addObject:object];
|
||||
} else if ([object isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) {
|
||||
if ([object isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) {
|
||||
[blockingSafetyNumberChanges addObject:object];
|
||||
} else if ([object isKindOfClass:[TSErrorMessage class]]) {
|
||||
TSErrorMessage *errorMessage = (TSErrorMessage *)object;
|
||||
|
@ -385,11 +365,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}];
|
||||
|
||||
for (TSInteraction *interaction in interactionsToDelete) {
|
||||
OWSLogDebug(@"Cleaning up interaction: %@", [interaction class]);
|
||||
[interaction removeWithTransaction:transaction];
|
||||
}
|
||||
|
||||
// Determine if there are "unread" messages in this conversation.
|
||||
// If we've been passed a firstUnseenInteractionTimestampParameter,
|
||||
// just use that value in order to preserve continuity of the
|
||||
|
@ -430,7 +405,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (void)ensureUnreadIndicator:(ThreadDynamicInteractions *)dynamicInteractions
|
||||
thread:(TSThread *)thread
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
transaction:(YapDatabaseReadTransaction *)transaction
|
||||
maxRangeSize:(int)maxRangeSize
|
||||
blockingSafetyNumberChanges:(NSArray<TSInvalidIdentityKeyErrorMessage *> *)blockingSafetyNumberChanges
|
||||
nonBlockingSafetyNumberChanges:(NSArray<TSInteraction *> *)nonBlockingSafetyNumberChanges
|
||||
|
@ -556,7 +531,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
+ (nullable NSNumber *)focusMessagePositionForThread:(TSThread *)thread
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
transaction:(YapDatabaseReadTransaction *)transaction
|
||||
focusMessageId:(NSString *)focusMessageId
|
||||
{
|
||||
OWSAssertDebug(thread);
|
||||
|
|
Loading…
Reference in a new issue