trigger sync when colors updates

pull/1/head
Michael Kirk 6 years ago
parent d53f583e45
commit 61cb19ef6b

@ -417,6 +417,7 @@
4C20B2B720CA0034001BAC90 /* ThreadViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542DF51208B82E9007B4E76 /* ThreadViewModel.swift */; };
4C20B2B920CA10DE001BAC90 /* ConversationSearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */; };
4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */; };
4CC0B59C20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC0B59B20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift */; };
70377AAB1918450100CAF501 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70377AAA1918450100CAF501 /* MobileCoreServices.framework */; };
768A1A2B17FC9CD300E00ED8 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 768A1A2A17FC9CD300E00ED8 /* libz.dylib */; };
76C87F19181EFCE600C4ACAB /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; };
@ -1077,6 +1078,7 @@
4C13C9F520E57BA30089A98B /* ColorPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerViewController.swift; sourceTree = "<group>"; };
4C20B2B820CA10DE001BAC90 /* ConversationSearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationSearchViewController.swift; sourceTree = "<group>"; };
4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableTextField.swift; sourceTree = "<group>"; };
4CC0B59B20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationConfigurationSyncOperation.swift; sourceTree = "<group>"; };
69349DE607F5BA6036C9AC60 /* Pods-SignalShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SignalShareExtension/Pods-SignalShareExtension.debug.xcconfig"; sourceTree = "<group>"; };
70377AAA1918450100CAF501 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
748A5CAEDD7C919FC64C6807 /* Pods_SignalTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SignalTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -2016,6 +2018,7 @@
45CD81EE1DC030E7004C9430 /* SyncPushTokensJob.swift */,
452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */,
451686AA1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift */,
4CC0B59B20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift */,
);
path = Jobs;
sourceTree = "<group>";
@ -3198,6 +3201,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4CC0B59C20EC5F2E00CF6EE0 /* ConversationConfigurationSyncOperation.swift in Sources */,
3461293E1FD1D72B00532771 /* ExperienceUpgradeFinder.swift in Sources */,
34D1F0BD1F8D108C0066283D /* AttachmentUploadView.m in Sources */,
452EC6DF205E9E30000E787C /* MediaGalleryViewController.swift in Sources */,

@ -0,0 +1,118 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
class ConversationConfigurationSyncOperation: OWSOperation {
enum ColorSyncOperationError: Error {
case assertionError(description: String)
}
var dbConnection: YapDatabaseConnection {
return OWSPrimaryStorage.shared().dbReadConnection
}
var messageSender: MessageSender {
return Environment.current().messageSender
}
var contactsManager: OWSContactsManager {
return Environment.current().contactsManager
}
var profileManager: OWSProfileManager {
return OWSProfileManager.shared()
}
var identityManager: OWSIdentityManager {
return OWSIdentityManager.shared()
}
let thread: TSThread
@objc
init(thread: TSThread) {
self.thread = thread
super.init()
}
override func run() {
if let contactThread = thread as? TSContactThread {
sync(contactThread: contactThread)
} else if let groupThread = thread as? TSGroupThread {
sync(groupThread: groupThread)
} else {
self.reportAssertionError(description: "unknown thread type")
}
}
private func reportAssertionError(description: String) {
let error = ColorSyncOperationError.assertionError(description: description)
self.reportError(error)
}
func sync(contactThread: TSContactThread) {
guard let signalAccount: SignalAccount = self.contactsManager.signalAccount(forRecipientId: contactThread.contactIdentifier()) else {
reportAssertionError(description: "unable to find signalAccount")
return
}
let syncMessage: OWSSyncContactsMessage = OWSSyncContactsMessage(signalAccounts: [signalAccount],
identityManager: self.identityManager,
profileManager: self.profileManager)
var dataSource: DataSource? = nil
self.dbConnection.readWrite { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
}
guard let attachmentDataSource = dataSource else {
self.reportAssertionError(description: "unable to build attachment data source")
return
}
self.messageSender.enqueueTemporaryAttachment(attachmentDataSource,
contentType: OWSMimeTypeApplicationOctetStream,
in: syncMessage,
success: {
self.reportSuccess()
},
failure: { error in
self.reportError(error)
})
}
func sync(groupThread: TSGroupThread) {
// TODO sync only the affected group
// The current implementation works, but seems wasteful.
// Does desktop handle single group sync correctly?
// What does Android do?
let syncMessage: OWSSyncGroupsMessage = OWSSyncGroupsMessage()
var dataSource: DataSource? = nil
self.dbConnection.read { transaction in
let messageData: Data = syncMessage.buildPlainTextAttachmentData(with: transaction)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
}
guard let attachmentDataSource = dataSource else {
self.reportAssertionError(description: "unable to build attachment data source")
return
}
self.messageSender.enqueueTemporaryAttachment(attachmentDataSource,
contentType: OWSMimeTypeApplicationOctetStream,
in: syncMessage,
success: {
self.reportSuccess()
},
failure: { error in
self.reportError(error)
})
}
}

@ -1269,6 +1269,9 @@ const CGFloat kIconViewLength = 24;
[self.contactsManager.avatarCache removeAllImages];
[self updateTableContents];
[self.conversationSettingsViewDelegate conversationColorWasUpdated];
ConversationConfigurationSyncOperation *operation = [[ConversationConfigurationSyncOperation alloc] initWithThread:self.thread];
[self dismissViewControllerAnimated:YES completion:nil];
}];

Loading…
Cancel
Save