Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-09-27 16:38:41 -04:00
parent 3a39a1ba51
commit b3ab6d0602
8 changed files with 46 additions and 40 deletions

View file

@ -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"

View file

@ -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 {

View file

@ -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

View file

@ -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.");
}

View file

@ -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;

View file

@ -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

View file

@ -6,4 +6,6 @@
- (NSString *)ows_stripped;
- (NSString *)rtlSafeAppend:(NSString *)string referenceView:(UIView *)referenceView;
@end

View file

@ -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