fix notification preview type nested transaction crash

This commit is contained in:
ryanzhao 2021-09-30 14:24:04 +10:00
parent bd73f14915
commit b7c6eafa87
4 changed files with 18 additions and 5 deletions

View File

@ -181,6 +181,7 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
let senderName = Storage.shared.getContact(with: incomingMessage.authorId, using: transaction)?.displayName(for: context) ?? incomingMessage.authorId
let notificationTitle: String?
let previewType = preferences.notificationPreviewType(with: transaction)
switch previewType {
case .noNameNoPreview:
notificationTitle = nil

View File

@ -25,8 +25,8 @@ extension Storage {
@objc(setContact:usingTransaction:)
public func setContact(_ contact: Contact, using transaction: Any) {
let oldContact = getContact(with: contact.sessionID)
let transaction = transaction as! YapDatabaseReadWriteTransaction
let oldContact = getContact(with: contact.sessionID, using: transaction)
if contact.sessionID == getUserHexEncodedPublicKey() {
contact.isTrusted = true // Always trust ourselves
}

View File

@ -3,6 +3,10 @@
//
#import <Foundation/Foundation.h>
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SessionMessagingKit/YapDatabaseConnection+OWS.h>
#import <SessionMessagingKit/YapDatabaseTransaction+OWS.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
NS_ASSUME_NONNULL_BEGIN
@ -47,6 +51,7 @@ extern NSString *const OWSPreferencesCallLoggingDidChangeNotification;
- (void)setScreenSecurity:(BOOL)flag;
- (NotificationType)notificationPreviewType;
- (NotificationType)notificationPreviewTypeWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (void)setNotificationPreviewType:(NotificationType)type;
- (NSString *)nameForNotificationPreviewType:(NotificationType)notificationType;

View File

@ -3,10 +3,6 @@
//
#import "OWSPreferences.h"
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SessionMessagingKit/YapDatabaseConnection+OWS.h>
#import <SessionMessagingKit/YapDatabaseTransaction+OWS.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
NS_ASSUME_NONNULL_BEGIN
@ -384,6 +380,17 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste
}
}
- (NotificationType)notificationPreviewTypeWithTransaction:(YapDatabaseReadTransaction *)transaction
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyNotificationPreviewType transaction:transaction];
if (preference) {
return [preference unsignedIntegerValue];
} else {
return NotificationNamePreview;
}
}
- (NSString *)nameForNotificationPreviewType:(NotificationType)notificationType
{
switch (notificationType) {