sync profile updating to slave device

pull/203/head
ryanzhao 5 years ago
parent 12cb5b1a75
commit 1f5c5aadd9

@ -238,7 +238,8 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
// Ensure that the success and failure blocks are called on the main thread.
void (^failureBlock)(NSError *) = ^(NSError *error) {
OWSLogError(@"Updating service with profile failed.");
/*
// We use a "self-only" contact sync to indicate to desktop
// that we've changed our profile and that it should do a
// profile fetch for "self".
@ -248,6 +249,10 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
if (requiresSync) {
[[self.syncManager syncLocalContact] retainUntilComplete];
}
*/
if (requiresSync) {
[LKSyncMessagesProtocol syncProfileUpdate];
}
dispatch_async(dispatch_get_main_queue(), ^{
failureBlockParameter(error);
@ -255,13 +260,18 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
};
void (^successBlock)(void) = ^{
OWSLogInfo(@"Successfully updated service with profile.");
/*
// We use a "self-only" contact sync to indicate to desktop
// that we've changed our profile and that it should do a
// profile fetch for "self".
if (requiresSync) {
[[self.syncManager syncLocalContact] retainUntilComplete];
}
*/
if (requiresSync) {
[LKSyncMessagesProtocol syncProfileUpdate];
}
dispatch_async(dispatch_get_main_queue(), ^{
successBlockParameter();

@ -23,6 +23,22 @@ public final class SyncMessagesProtocol : NSObject {
// FIXME: We added this check to avoid a crash, but we should really figure out why that crash was happening in the first place
return !UserDefaults.standard[.hasLaunchedOnce]
}
@objc(syncProfileUpdate)
public static func syncProfileUpdate() {
storage.dbReadWriteConnection.readWrite{ transaction in
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: userHexEncodedPublicKey, in: transaction)
for hexEncodedPublicKey in linkedDevices {
guard hexEncodedPublicKey != userHexEncodedPublicKey else { continue }
let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction)
let syncMessage = OWSOutgoingSyncMessage.init(in: thread, messageBody: "", attachmentId: nil)
syncMessage.save(with: transaction)
let messageSenderJobQueue = SSKEnvironment.shared.messageSenderJobQueue
messageSenderJobQueue.add(message: syncMessage, transaction: transaction)
}
}
}
@objc(syncContactWithHexEncodedPublicKey:in:)
public static func syncContact(_ hexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> AnyPromise {
@ -166,9 +182,10 @@ public final class SyncMessagesProtocol : NSObject {
let parser = ContactParser(data: data)
let hexEncodedPublicKeys = parser.parseHexEncodedPublicKeys()
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
let linkedDevices = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: userHexEncodedPublicKey, in: transaction)
// Try to establish sessions
for hexEncodedPublicKey in hexEncodedPublicKeys {
guard hexEncodedPublicKey != userHexEncodedPublicKey else { continue } // Skip self
guard !linkedDevices.contains(hexEncodedPublicKey) else { continue } // Skip self and linked devices
// We don't update the friend request status; that's done in OWSMessageSender.sendMessage(_:)
let friendRequestStatus = storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction)
switch friendRequestStatus {

Loading…
Cancel
Save