mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'fix-profile-picture-updating' of github.com:RyanRory/loki-messenger-ios into database-3
This commit is contained in:
commit
6686122461
3 changed files with 41 additions and 12 deletions
|
@ -239,7 +239,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".
|
||||
|
@ -249,6 +250,10 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
if (requiresSync) {
|
||||
[[self.syncManager syncLocalContact] retainUntilComplete];
|
||||
}
|
||||
*/
|
||||
if (requiresSync) {
|
||||
[LKSyncMessagesProtocol syncProfileUpdate];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
failureBlockParameter(error);
|
||||
|
@ -256,13 +261,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 {
|
||||
|
|
|
@ -1125,21 +1125,23 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
|
|||
}
|
||||
|
||||
- (SSKProtoContentBuilder *)prepareCustomContentBuilder:(SignalRecipient *)recipient {
|
||||
return SSKProtoContent.builder;
|
||||
SSKProtoDataMessage *_Nullable dataMessage = [self buildDataMessage:recipient.recipientId];
|
||||
if (!dataMessage) {
|
||||
OWSFailDebug(@"could not build protobuf");
|
||||
return nil;
|
||||
}
|
||||
|
||||
SSKProtoContentBuilder *contentBuilder = SSKProtoContent.builder;
|
||||
[contentBuilder setDataMessage:dataMessage];
|
||||
|
||||
return contentBuilder;
|
||||
}
|
||||
|
||||
- (nullable NSData *)buildPlainTextData:(SignalRecipient *)recipient
|
||||
{
|
||||
NSError *error;
|
||||
SSKProtoDataMessage *_Nullable dataMessage = [self buildDataMessage:recipient.recipientId];
|
||||
if (error || !dataMessage) {
|
||||
OWSFailDebug(@"could not build protobuf: %@", error);
|
||||
return nil;
|
||||
}
|
||||
|
||||
SSKProtoContentBuilder *contentBuilder = [self prepareCustomContentBuilder:recipient];
|
||||
NSError *error;
|
||||
|
||||
[contentBuilder setDataMessage:dataMessage];
|
||||
NSData *_Nullable contentData = [contentBuilder buildSerializedDataAndReturnError:&error];
|
||||
if (error || !contentData) {
|
||||
OWSFailDebug(@"could not serialize protobuf: %@", error);
|
||||
|
|
Loading…
Reference in a new issue