Replace remaining UI usage of `interaction.description`

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 897d4a925b
commit 9c81eb44a1

@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
@class TSMessage;
@class TSOutgoingMessage;
@class TSQuotedMessage;
@class YapDatabaseReadTransaction;
@protocol ConversationViewCellDelegate <NSObject>
@ -71,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
// The width of the collection view.
@property (nonatomic) int contentWidth;
- (void)loadForDisplay;
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (CGSize)cellSizeForViewWidth:(int)viewWidth contentWidth:(int)contentWidth;

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "ConversationViewCell.h"
@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
self.contentWidth = 0;
}
- (void)loadForDisplay
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSFail(@"%@ This method should be overridden.", self.logTag);
}

@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(self.viewItem);
OWSAssert([self.viewItem.interaction isKindOfClass:[OWSContactOffersInteraction class]]);

@ -150,7 +150,7 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Load
- (void)loadForDisplay
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(self.viewItem);
OWSAssert(self.viewItem.interaction);

@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(self.viewItem);
@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
self.imageView.image = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.imageView.tintColor = [self iconColorForInteraction:interaction];
self.titleLabel.textColor = [self textColor];
[self applyTitleForInteraction:interaction label:self.titleLabel];
[self applyTitleForInteraction:interaction label:self.titleLabel transaction:transaction];
[self setNeedsLayout];
}
@ -162,7 +162,9 @@ NS_ASSUME_NONNULL_BEGIN
return result;
}
- (void)applyTitleForInteraction:(TSInteraction *)interaction label:(UILabel *)label
- (void)applyTitleForInteraction:(TSInteraction *)interaction
label:(UILabel *)label
transaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(interaction);
OWSAssert(label);
@ -170,22 +172,24 @@ NS_ASSUME_NONNULL_BEGIN
// TODO: Should we move the copy generation into this view?
if ([interaction isKindOfClass:[TSErrorMessage class]]) {
label.text = interaction.description;
TSErrorMessage *errorMessage = (TSErrorMessage *)interaction;
label.text = [errorMessage previewTextWithTransaction:transaction];
} else if ([interaction isKindOfClass:[TSInfoMessage class]]) {
if ([interaction isKindOfClass:[OWSVerificationStateChangeMessage class]]) {
OWSVerificationStateChangeMessage *message = (OWSVerificationStateChangeMessage *)interaction;
BOOL isVerified = message.verificationState == OWSVerificationStateVerified;
TSInfoMessage *infoMessage = (TSInfoMessage *)interaction;
if ([infoMessage isKindOfClass:[OWSVerificationStateChangeMessage class]]) {
OWSVerificationStateChangeMessage *verificationMessage = (OWSVerificationStateChangeMessage *)infoMessage;
BOOL isVerified = verificationMessage.verificationState == OWSVerificationStateVerified;
NSString *displayName =
[[Environment current].contactsManager displayNameForPhoneIdentifier:message.recipientId];
[[Environment current].contactsManager displayNameForPhoneIdentifier:verificationMessage.recipientId];
NSString *titleFormat = (isVerified
? (message.isLocalChange
? (verificationMessage.isLocalChange
? NSLocalizedString(@"VERIFICATION_STATE_CHANGE_FORMAT_VERIFIED_LOCAL",
@"Format for info message indicating that the verification state was verified on "
@"this device. Embeds {{user's name or phone number}}.")
: NSLocalizedString(@"VERIFICATION_STATE_CHANGE_FORMAT_VERIFIED_OTHER_DEVICE",
@"Format for info message indicating that the verification state was verified on "
@"another device. Embeds {{user's name or phone number}}."))
: (message.isLocalChange
: (verificationMessage.isLocalChange
? NSLocalizedString(@"VERIFICATION_STATE_CHANGE_FORMAT_NOT_VERIFIED_LOCAL",
@"Format for info message indicating that the verification state was unverified on "
@"this device. Embeds {{user's name or phone number}}.")
@ -194,10 +198,11 @@ NS_ASSUME_NONNULL_BEGIN
@"another device. Embeds {{user's name or phone number}}.")));
label.text = [NSString stringWithFormat:titleFormat, displayName];
} else {
label.text = interaction.description;
label.text = [infoMessage previewTextWithTransaction:transaction];
}
} else if ([interaction isKindOfClass:[TSCall class]]) {
label.text = interaction.description;
TSCall *call = (TSCall *)interaction;
label.text = [call previewTextWithTransaction:transaction];
} else {
OWSFail(@"Unknown interaction type: %@", [interaction class]);
label.text = nil;
@ -266,7 +271,11 @@ NS_ASSUME_NONNULL_BEGIN
result.height += self.topVMargin;
result.height += self.bottomVMargin;
[self applyTitleForInteraction:interaction label:self.titleLabel];
// FIXME pass in transaction from the uiDBConnection.
[[TSYapDatabaseObject dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[self applyTitleForInteraction:interaction label:self.titleLabel transaction:transaction];
}];
CGFloat maxTitleWidth = (viewWidth - ([self hMargin] * 2.f + [self hSpacing] + [self iconSize]));
CGSize titleSize = [self.titleLabel sizeThatFits:CGSizeMake(maxTitleWidth, CGFLOAT_MAX)];

@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (void)loadForDisplay
- (void)loadForDisplayWithTransaction:(YapDatabaseReadTransaction *)transaction
{
OWSAssert(self.viewItem);
OWSAssert([self.viewItem.interaction isKindOfClass:[TSUnreadIndicatorInteraction class]]);

@ -4757,7 +4757,9 @@ typedef enum : NSUInteger {
}
cell.contentWidth = self.layout.contentWidth;
[cell loadForDisplay];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[cell loadForDisplayWithTransaction:transaction];
}];
return cell;
}

@ -3223,7 +3223,7 @@ NS_ASSUME_NONNULL_BEGIN
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:phoneNumber.toE164];
[self sendFakeMessages:messageCount thread:contactThread];
DDLogError(@"Create fake thread: %@, interactions: %zd",
DDLogError(@"Create fake thread: %@, interactions: %tu",
phoneNumber.toE164,
contactThread.numberOfInteractions);
}];
@ -3251,7 +3251,7 @@ NS_ASSUME_NONNULL_BEGIN
[self sendFakeMessages:batchSize thread:thread isTextOnly:isTextOnly transaction:transaction];
}];
remainder -= batchSize;
DDLogInfo(@"%@ sendFakeMessages %zd / %zd", self.logTag, counter - remainder, counter);
DDLogInfo(@"%@ sendFakeMessages %td / %tu", self.logTag, counter - remainder, counter);
}
});
}
@ -3263,7 +3263,7 @@ NS_ASSUME_NONNULL_BEGIN
isTextOnly:(BOOL)isTextOnly
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
DDLogInfo(@"%@ sendFakeMessages: %zd", self.logTag, counter);
DDLogInfo(@"%@ sendFakeMessages: %tu", self.logTag, counter);
for (NSUInteger i = 0; i < counter; i++) {
NSString *randomText = [self randomText];
@ -3411,7 +3411,7 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssert(thread);
DDLogInfo(@"%@ injectIncomingMessageInThread: %zd", self.logTag, counter);
DDLogInfo(@"%@ injectIncomingMessageInThread: %tu", self.logTag, counter);
NSString *randomText = [self randomText];
NSString *text = [[[@(counter) description] stringByAppendingString:@" "] stringByAppendingString:randomText];

@ -18,6 +18,7 @@
#import <SignalServiceKit/TSIncomingMessage.h>
#import <SignalServiceKit/TextSecureKitEnv.h>
#import <SignalServiceKit/Threading.h>
#import <YapDatabase/YapDatabaseTransaction.h>
@interface NotificationsManager ()
@ -200,51 +201,56 @@
#pragma mark - Signal Messages
- (void)notifyUserForErrorMessage:(TSErrorMessage *)message inThread:(TSThread *)thread {
- (void)notifyUserForErrorMessage:(TSErrorMessage *)message
thread:(TSThread *)thread
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssert(message);
OWSAssert(thread);
dispatch_async(dispatch_get_main_queue(), ^{
if (thread.isMuted) {
return;
}
BOOL shouldPlaySound = [self shouldPlaySoundForNotification];
NSString *messageDescription = message.description;
if (([UIApplication sharedApplication].applicationState != UIApplicationStateActive) && messageDescription) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.userInfo = @{ Signal_Thread_UserInfo_Key : thread.uniqueId };
if (shouldPlaySound) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
notification.soundName = [OWSSounds filenameForSound:sound];
}
NSString *alertBodyString = @"";
NSString *authorName = [thread name];
switch (self.notificationPreviewType) {
case NotificationNamePreview:
case NotificationNameNoPreview:
alertBodyString = [NSString stringWithFormat:@"%@: %@", authorName, messageDescription];
break;
case NotificationNoNameNoPreview:
alertBodyString = messageDescription;
break;
}
notification.alertBody = alertBodyString;
[[PushManager sharedManager] presentNotification:notification checkForCancel:NO];
} else {
if (shouldPlaySound && [Environment.preferences soundInForeground]) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
SystemSoundID soundId = [OWSSounds systemSoundIDForSound:sound quiet:YES];
// Vibrate, respect silent switch, respect "Alert" volume, not media volume.
AudioServicesPlayAlertSound(soundId);
}
}
});
NSString *messageText = [message previewTextWithTransaction:transaction];
[transaction
addCompletionQueue:nil
completionBlock:^() {
if (thread.isMuted) {
return;
}
BOOL shouldPlaySound = [self shouldPlaySoundForNotification];
if (([UIApplication sharedApplication].applicationState != UIApplicationStateActive) && messageText) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.userInfo = @{ Signal_Thread_UserInfo_Key : thread.uniqueId };
if (shouldPlaySound) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
notification.soundName = [OWSSounds filenameForSound:sound];
}
NSString *alertBodyString = @"";
NSString *authorName = [thread name];
switch (self.notificationPreviewType) {
case NotificationNamePreview:
case NotificationNameNoPreview:
alertBodyString = [NSString stringWithFormat:@"%@: %@", authorName, messageText];
break;
case NotificationNoNameNoPreview:
alertBodyString = messageText;
break;
}
notification.alertBody = alertBodyString;
[[PushManager sharedManager] presentNotification:notification checkForCancel:NO];
} else {
if (shouldPlaySound && [Environment.preferences soundInForeground]) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
SystemSoundID soundId = [OWSSounds systemSoundIDForSound:sound quiet:YES];
// Vibrate, respect silent switch, respect "Alert" volume, not media volume.
AudioServicesPlayAlertSound(soundId);
}
}
}];
}
- (void)notifyUserForIncomingMessage:(TSIncomingMessage *)message

@ -7,11 +7,11 @@ import SignalServiceKit
@objc
public class NoopNotificationsManager: NSObject, NotificationsProtocol {
public func notifyUser(for incomingMessage: TSIncomingMessage!, in thread: TSThread!, contactsManager: ContactsManagerProtocol!, transaction: YapDatabaseReadTransaction!) {
public func notifyUser(for incomingMessage: TSIncomingMessage, in thread: TSThread, contactsManager: ContactsManagerProtocol, transaction: YapDatabaseReadTransaction) {
owsFail("\(self.logTag) in \(#function).")
}
public func notifyUser(for error: TSErrorMessage!, in thread: TSThread!) {
public func notifyUser(for error: TSErrorMessage, thread: TSThread, transaction: YapDatabaseReadWriteTransaction) {
Logger.warn("\(self.logTag) in \(#function), skipping notification for: \(error.description)")
}
}

@ -545,7 +545,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
[message saveWithTransaction:transaction];
}
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:errorMessage inThread:contactThread];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:errorMessage
thread:contactThread
transaction:transaction];
}
- (void)enqueueSyncMessageForVerificationStateForRecipientId:(NSString *)recipientId

@ -269,8 +269,10 @@ NS_ASSUME_NONNULL_BEGIN
exception.name,
exception.reason);
__block TSErrorMessage *errorMessage;
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSErrorMessage *errorMessage;
if ([exception.name isEqualToString:NoSessionException]) {
OWSProdErrorWEnvelope([OWSAnalyticsEvents messageManagerErrorNoSession], envelope);
errorMessage = [TSErrorMessage missingSessionWithEnvelope:envelope withTransaction:transaction];
@ -298,18 +300,21 @@ NS_ASSUME_NONNULL_BEGIN
}
OWSAssert(errorMessage);
[errorMessage saveWithTransaction:transaction];
if (errorMessage != nil) {
[errorMessage saveWithTransaction:transaction];
[self notifyUserForErrorMessage:errorMessage envelope:envelope transaction:transaction];
}
}];
if (errorMessage != nil) {
[self notifyForErrorMessage:errorMessage withEnvelope:envelope];
}
}
- (void)notifyForErrorMessage:(TSErrorMessage *)errorMessage withEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
- (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage
envelope:(OWSSignalServiceProtosEnvelope *)envelope
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:errorMessage inThread:contactThread];
TSThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:errorMessage
thread:contactThread
transaction:transaction];
}
@end

@ -20,7 +20,7 @@ typedef enum {
RPRecentCallTypeIncomingDeclined
} RPRecentCallType;
@interface TSCall : TSInteraction <OWSReadTracking>
@interface TSCall : TSInteraction <OWSReadTracking, OWSPreviewText>
@property (nonatomic, readonly) RPRecentCallType callType;

@ -69,11 +69,7 @@ NSUInteger TSCallCurrentSchemaVersion = 1;
- (NSString *)previewTextWithTransaction:(YapDatabaseReadTransaction *)transaction
{
return [self previewText];
}
- (NSString *)previewText
{
// We don't actually use the `transaction` but other sibling classes do.
switch (_callType) {
case RPRecentCallTypeIncoming:
return NSLocalizedString(@"INCOMING_CALL", @"");
@ -93,12 +89,6 @@ NSUInteger TSCallCurrentSchemaVersion = 1;
}
}
- (NSString *)description
{
OWSFail(@"%@ in %s verify this isnt exposed in the UI", self.logTag, __PRETTY_FUNCTION__);
return [self previewText];
}
#pragma mark - OWSReadTracking
- (uint64_t)expireStartedAt

@ -1,11 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@class TSErrorMessage;
@class TSIncomingMessage;
@class TSThread;
@class YapDatabaseReadTransaction;
@protocol ContactsManagerProtocol;
@protocol NotificationsProtocol <NSObject>
@ -15,6 +18,10 @@
contactsManager:(id<ContactsManagerProtocol>)contactsManager
transaction:(YapDatabaseReadTransaction *)transaction;
- (void)notifyUserForErrorMessage:(TSErrorMessage *)error inThread:(TSThread *)thread;
- (void)notifyUserForErrorMessage:(TSErrorMessage *)error
thread:(TSThread *)thread
transaction:(YapDatabaseReadWriteTransaction *)transaction;
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save