From b3ab6d06020d92e693788642ca1096b419d57a98 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 27 Sep 2017 16:38:41 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- Signal/src/Signal-Bridging-Header.h | 2 +- .../MessageMetadataViewController.swift | 8 ++--- Signal/src/util/DateUtil.h | 3 +- Signal/src/util/DateUtil.m | 36 ++++++++++++------- Signal/src/util/NSAttributedString+OWS.h | 6 ---- Signal/src/util/NSAttributedString+OWS.m | 16 --------- Signal/src/util/NSString+OWS.h | 2 ++ Signal/src/util/NSString+OWS.m | 13 +++++++ 8 files changed, 46 insertions(+), 40 deletions(-) diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 5acdf8c6a..268e700b4 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -10,7 +10,7 @@ #import "FLAnimatedImage.h" #import "FingerprintViewController.h" #import "HomeViewController.h" -#import "NSAttributedString+OWS.h" +#import "NSString+OWS.h" #import "NotificationsManager.h" #import "OWSAnyTouchGestureRecognizer.h" #import "OWSAudioAttachmentPlayer.h" diff --git a/Signal/src/ViewControllers/MessageMetadataViewController.swift b/Signal/src/ViewControllers/MessageMetadataViewController.swift index a53a7011b..48be602ca 100644 --- a/Signal/src/ViewControllers/MessageMetadataViewController.swift +++ b/Signal/src/ViewControllers/MessageMetadataViewController.swift @@ -121,12 +121,12 @@ class MessageMetadataViewController: OWSViewController { rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_SENT_DATE_TIME", comment: "Label for the 'sent date & time' field of the 'message metadata' view."), - value:DateUtil.formatPastTimestampRelative(toNow:message.timestamp))) + value:DateUtil.formatPastTimestampRelativeToNow(message.timestamp))) if let _ = message as? TSIncomingMessage { rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_RECEIVED_DATE_TIME", comment: "Label for the 'received date & time' field of the 'message metadata' view."), - value:DateUtil.formatPastTimestampRelative(toNow:message.timestampForSorting()))) + value:DateUtil.formatPastTimestampRelativeToNow(message.timestampForSorting()))) } // TODO: We could include the "disappearing messages" state here. @@ -279,7 +279,7 @@ class MessageMetadataViewController: OWSViewController { assert(message.messageState == .sentToService) return NSLocalizedString("MESSAGE_STATUS_READ", comment:"message footer for read messages").rtlSafeAppend(" ", referenceView:self.view) .rtlSafeAppend( - DateUtil.formatPastTimestampRelative(toNow:readTimestamp.uint64Value), referenceView:self.view) + DateUtil.formatPastTimestampRelativeToNow(readTimestamp.uint64Value), referenceView:self.view) } let recipientDeliveryMap = message.recipientDeliveryMap @@ -288,7 +288,7 @@ class MessageMetadataViewController: OWSViewController { return NSLocalizedString("MESSAGE_STATUS_DELIVERED", comment:"message status for message delivered to their recipient.").rtlSafeAppend(" ", referenceView:self.view) .rtlSafeAppend( - DateUtil.formatPastTimestampRelative(toNow:deliveryTimestamp.uint64Value), referenceView:self.view) + DateUtil.formatPastTimestampRelativeToNow(deliveryTimestamp.uint64Value), referenceView:self.view) } if message.wasDelivered { diff --git a/Signal/src/util/DateUtil.h b/Signal/src/util/DateUtil.h index 2deebe48d..d6b830412 100644 --- a/Signal/src/util/DateUtil.h +++ b/Signal/src/util/DateUtil.h @@ -10,6 +10,7 @@ + (BOOL)dateIsOlderThanOneWeek:(NSDate *)date; + (BOOL)dateIsToday:(NSDate *)date; -+ (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp; ++ (NSString *)formatPastTimestampRelativeToNow:(uint64_t)pastTimestamp + NS_SWIFT_NAME(formatPastTimestampRelativeToNow(_:)); @end diff --git a/Signal/src/util/DateUtil.m b/Signal/src/util/DateUtil.m index 588f9b0f9..802d417a5 100644 --- a/Signal/src/util/DateUtil.m +++ b/Signal/src/util/DateUtil.m @@ -10,25 +10,37 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE"; @implementation DateUtil + (NSDateFormatter *)dateFormatter { - NSDateFormatter *formatter = [NSDateFormatter new]; - [formatter setLocale:[NSLocale currentLocale]]; - [formatter setTimeStyle:NSDateFormatterNoStyle]; - [formatter setDateStyle:NSDateFormatterShortStyle]; + static NSDateFormatter *formatter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [NSDateFormatter new]; + [formatter setLocale:[NSLocale currentLocale]]; + [formatter setTimeStyle:NSDateFormatterNoStyle]; + [formatter setDateStyle:NSDateFormatterShortStyle]; + }); return formatter; } + (NSDateFormatter *)weekdayFormatter { - NSDateFormatter *formatter = [NSDateFormatter new]; - [formatter setLocale:[NSLocale currentLocale]]; - [formatter setDateFormat:DATE_FORMAT_WEEKDAY]; + static NSDateFormatter *formatter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [NSDateFormatter new]; + [formatter setLocale:[NSLocale currentLocale]]; + [formatter setDateFormat:DATE_FORMAT_WEEKDAY]; + }); return formatter; } + (NSDateFormatter *)timeFormatter { - NSDateFormatter *formatter = [NSDateFormatter new]; - [formatter setLocale:[NSLocale currentLocale]]; - [formatter setTimeStyle:NSDateFormatterShortStyle]; - [formatter setDateStyle:NSDateFormatterNoStyle]; + static NSDateFormatter *formatter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [NSDateFormatter new]; + [formatter setLocale:[NSLocale currentLocale]]; + [formatter setTimeStyle:NSDateFormatterShortStyle]; + [formatter setDateStyle:NSDateFormatterNoStyle]; + }); return formatter; } @@ -59,7 +71,7 @@ static NSString *const DATE_FORMAT_WEEKDAY = @"EEEE"; uint64_t nowTimestamp = [NSDate ows_millisecondTimeStamp]; if (pastTimestamp >= nowTimestamp) { - OWSCFail(@"%@ Unexpected timestamp", self.tag); + OWSFail(@"%@ Unexpected timestamp", self.tag); return NSLocalizedString(@"TIME_NOW", @"Indicates that the event happened now."); } diff --git a/Signal/src/util/NSAttributedString+OWS.h b/Signal/src/util/NSAttributedString+OWS.h index 883684d88..a1b32e17e 100644 --- a/Signal/src/util/NSAttributedString+OWS.h +++ b/Signal/src/util/NSAttributedString+OWS.h @@ -4,12 +4,6 @@ NS_ASSUME_NONNULL_BEGIN -@interface NSString (OWS) - -- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView; - -@end - @interface NSAttributedString (OWS) - (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string referenceView:(UIView *)referenceView; diff --git a/Signal/src/util/NSAttributedString+OWS.m b/Signal/src/util/NSAttributedString+OWS.m index 269b6c829..6ffea8956 100644 --- a/Signal/src/util/NSAttributedString+OWS.m +++ b/Signal/src/util/NSAttributedString+OWS.m @@ -7,22 +7,6 @@ NS_ASSUME_NONNULL_BEGIN -@implementation NSString (OWS) - -- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView -{ - OWSAssert(string); - OWSAssert(referenceView); - - if ([referenceView isRTL]) { - return [string stringByAppendingString:self]; - } else { - return [self stringByAppendingString:string]; - } -} - -@end - @implementation NSAttributedString (OWS) - (NSAttributedString *)rtlSafeAppend:(NSAttributedString *)string referenceView:(UIView *)referenceView diff --git a/Signal/src/util/NSString+OWS.h b/Signal/src/util/NSString+OWS.h index fd450f8ec..63fa578fc 100644 --- a/Signal/src/util/NSString+OWS.h +++ b/Signal/src/util/NSString+OWS.h @@ -6,4 +6,6 @@ - (NSString *)ows_stripped; +- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView; + @end diff --git a/Signal/src/util/NSString+OWS.m b/Signal/src/util/NSString+OWS.m index 71a092d4d..50ac43e63 100644 --- a/Signal/src/util/NSString+OWS.m +++ b/Signal/src/util/NSString+OWS.m @@ -3,6 +3,7 @@ // #import "NSString+OWS.h" +#import "UIView+OWS.h" @implementation NSString (OWS) @@ -11,4 +12,16 @@ return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; } +- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView +{ + OWSAssert(string); + OWSAssert(referenceView); + + if ([referenceView isRTL]) { + return [string stringByAppendingString:self]; + } else { + return [self stringByAppendingString:string]; + } +} + @end