Make database utility play nice with legacy Signal code

pull/220/head
nielsandriesse 5 years ago
parent 2e9dc8123d
commit 6b19b2180b

@ -84,6 +84,8 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
profileNameEncrypted:(nullable NSData *)profileNameEncrypted profileNameEncrypted:(nullable NSData *)profileNameEncrypted
avatarUrlPath:(nullable NSString *)avatarUrlPath; avatarUrlPath:(nullable NSString *)avatarUrlPath;
- (void)ensureProfileCachedForContactWithID:(NSString *)contactID with:(YapDatabaseReadWriteTransaction *)transaction;
#pragma mark - User Interface #pragma mark - User Interface
- (void)presentAddThreadToProfileWhitelist:(TSThread *)thread - (void)presentAddThreadToProfileWhitelist:(TSThread *)thread

@ -178,6 +178,8 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
- (OWSUserProfile *)localUserProfile - (OWSUserProfile *)localUserProfile
{ {
if (_localUserProfile) { return _localUserProfile; }
__block OWSUserProfile *userProfile; __block OWSUserProfile *userProfile;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
userProfile = [self getLocalUserProfileWithTransaction:transaction]; userProfile = [self getLocalUserProfileWithTransaction:transaction];
@ -1277,6 +1279,12 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
[userProfile updateWithProfileName:displayName avatarUrlPath:userProfile.avatarUrlPath avatarFileName:userProfile.avatarFileName transaction:transaction completion:nil]; [userProfile updateWithProfileName:displayName avatarUrlPath:userProfile.avatarUrlPath avatarFileName:userProfile.avatarFileName transaction:transaction completion:nil];
} }
- (void)ensureProfileCachedForContactWithID:(NSString *)contactID with:(YapDatabaseReadWriteTransaction *)transaction
{
OWSUserProfile *userProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:contactID transaction:transaction];
[userProfile saveWithTransaction:transaction];
}
- (BOOL)isNullableDataEqual:(NSData *_Nullable)left toData:(NSData *_Nullable)right - (BOOL)isNullableDataEqual:(NSData *_Nullable)left toData:(NSData *_Nullable)right
{ {
if (left == nil && right == nil) { if (left == nil && right == nil) {

@ -55,9 +55,19 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
dbConnection:(YapDatabaseConnection *)dbConnection dbConnection:(YapDatabaseConnection *)dbConnection
{ {
__block OWSUserProfile *userProfile; __block OWSUserProfile *userProfile;
[dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
userProfile = [OWSUserProfile fetchObjectWithUniqueID:recipientId transaction:transaction];
}];
if (userProfile != nil) {
return userProfile;
}
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
userProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId transaction:transaction]; userProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId transaction:transaction];
} error:nil]; } error:nil];
return userProfile; return userProfile;
} }

@ -168,7 +168,8 @@ public final class MultiDeviceProtocol : NSObject {
let (promise, seal) = Promise<OWSMessageSend>.pending() let (promise, seal) = Promise<OWSMessageSend>.pending()
var recipientUDAccess: OWSUDAccess? var recipientUDAccess: OWSUDAccess?
if let senderCertificate = senderCertificate { if let senderCertificate = senderCertificate {
recipientUDAccess = udManager.udAccess(forRecipientId: hexEncodedPublicKey, requireSyncAccess: true) // Starts a new write transaction internally SSKEnvironment.shared.profileManager.ensureProfileCachedForContact(withID: hexEncodedPublicKey, with: transaction) // Prevent the line below from starting a write transaction
recipientUDAccess = udManager.udAccess(forRecipientId: hexEncodedPublicKey, requireSyncAccess: true)
} }
let messageSend = OWSMessageSend(message: message, thread: thread, recipient: recipient, senderCertificate: senderCertificate, let messageSend = OWSMessageSend(message: message, thread: thread, recipient: recipient, senderCertificate: senderCertificate,
udAccess: recipientUDAccess, localNumber: getUserHexEncodedPublicKey(), success: { udAccess: recipientUDAccess, localNumber: getUserHexEncodedPublicKey(), success: {

@ -117,7 +117,8 @@ public final class SessionManagementProtocol : NSObject {
let (promise, seal) = Promise<OWSMessageSend>.pending() let (promise, seal) = Promise<OWSMessageSend>.pending()
var recipientUDAccess: OWSUDAccess? var recipientUDAccess: OWSUDAccess?
if let senderCertificate = senderCertificate { if let senderCertificate = senderCertificate {
recipientUDAccess = udManager.udAccess(forRecipientId: hexEncodedPublicKey, requireSyncAccess: true) // Starts a new write transaction internally SSKEnvironment.shared.profileManager.ensureProfileCachedForContact(withID: hexEncodedPublicKey, with: transaction) // Prevent the line below from starting a write transaction
recipientUDAccess = udManager.udAccess(forRecipientId: hexEncodedPublicKey, requireSyncAccess: true)
} }
let messageSend = OWSMessageSend(message: message, thread: thread, recipient: recipient, senderCertificate: senderCertificate, let messageSend = OWSMessageSend(message: message, thread: thread, recipient: recipient, senderCertificate: senderCertificate,
udAccess: recipientUDAccess, localNumber: getUserHexEncodedPublicKey(), success: { udAccess: recipientUDAccess, localNumber: getUserHexEncodedPublicKey(), success: {

@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateServiceWithProfileName:(nullable NSString *)localProfileName avatarURL:(nullable NSString *)avatarURL; - (void)updateServiceWithProfileName:(nullable NSString *)localProfileName avatarURL:(nullable NSString *)avatarURL;
- (void)ensureLocalProfileCached; - (void)ensureLocalProfileCached;
- (void)ensureProfileCachedForContactWithID:(NSString *)contactID with:(YapDatabaseReadWriteTransaction *)transaction;
@end @end

Loading…
Cancel
Save