2015-08-21 18:00:39 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-08-21 18:00:39 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "EventFormatter.h"
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2018-11-30 15:36:34 +00:00
|
|
|
#import "Riot-Swift.h"
|
2015-11-26 17:04:03 +00:00
|
|
|
|
2017-08-30 15:37:14 +00:00
|
|
|
#import "WidgetManager.h"
|
|
|
|
|
2018-06-08 15:21:52 +00:00
|
|
|
#import "MXDecryptionResult.h"
|
2018-06-29 05:35:31 +00:00
|
|
|
#import "DecryptionFailureTracker.h"
|
2018-06-08 15:21:52 +00:00
|
|
|
|
|
|
|
#pragma mark - Constants definitions
|
|
|
|
|
2019-06-12 14:05:34 +00:00
|
|
|
NSString *const EventFormatterOnReRequestKeysLinkAction = @"EventFormatterOnReRequestKeysLinkAction";
|
|
|
|
NSString *const EventFormatterLinkActionSeparator = @"/";
|
|
|
|
NSString *const EventFormatterEditedEventLinkAction = @"EventFormatterEditedEventLinkAction";
|
2018-06-08 15:21:52 +00:00
|
|
|
|
2019-05-23 16:26:38 +00:00
|
|
|
static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
2019-05-22 14:39:11 +00:00
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
@interface EventFormatter ()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
The calendar used to retrieve the today date.
|
|
|
|
*/
|
|
|
|
NSCalendar *calendar;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation EventFormatter
|
|
|
|
|
2019-05-22 14:39:11 +00:00
|
|
|
- (void)initDateTimeFormatters
|
|
|
|
{
|
|
|
|
[super initDateTimeFormatters];
|
|
|
|
|
2019-05-23 16:26:38 +00:00
|
|
|
timeFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
|
2019-05-22 14:39:11 +00:00
|
|
|
[timeFormatter setDateFormat:kEventFormatterTimeFormat];
|
|
|
|
}
|
|
|
|
|
2017-08-30 15:37:14 +00:00
|
|
|
- (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState:(MXRoomState *)roomState error:(MXKEventFormatterError *)error
|
|
|
|
{
|
2018-05-07 08:12:02 +00:00
|
|
|
// Build strings for widget events
|
2017-08-30 15:37:14 +00:00
|
|
|
if (event.eventType == MXEventTypeCustom
|
2018-05-07 08:12:02 +00:00
|
|
|
&& ([event.type isEqualToString:kWidgetMatrixEventTypeString]
|
|
|
|
|| [event.type isEqualToString:kWidgetModularEventTypeString]))
|
2017-08-30 15:37:14 +00:00
|
|
|
{
|
|
|
|
NSString *displayText;
|
|
|
|
|
2017-09-27 15:04:40 +00:00
|
|
|
Widget *widget = [[Widget alloc] initWithWidgetEvent:event inMatrixSession:mxSession];
|
|
|
|
if (widget)
|
2017-08-30 15:37:14 +00:00
|
|
|
{
|
2017-09-27 15:04:40 +00:00
|
|
|
// Prepare the display name of the sender
|
|
|
|
NSString *senderDisplayName = roomState ? [self senderDisplayNameForEvent:event withRoomState:roomState] : event.sender;
|
|
|
|
|
|
|
|
if (widget.isActive)
|
|
|
|
{
|
|
|
|
if ([widget.type isEqualToString:kWidgetTypeJitsi])
|
|
|
|
{
|
|
|
|
// This is an alive jitsi widget
|
|
|
|
displayText = [NSString stringWithFormat:NSLocalizedStringFromTable(@"event_formatter_jitsi_widget_added", @"Vector", nil), senderDisplayName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
displayText = [NSString stringWithFormat:NSLocalizedStringFromTable(@"event_formatter_widget_added", @"Vector", nil),
|
|
|
|
widget.name ? widget.name : widget.type,
|
|
|
|
senderDisplayName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-08-30 15:37:14 +00:00
|
|
|
{
|
2017-09-27 15:04:40 +00:00
|
|
|
// This is a closed widget
|
|
|
|
// Check if it corresponds to a jitsi widget by looking at other state events for
|
|
|
|
// this jitsi widget (widget id = event.stateKey).
|
2018-05-07 08:12:02 +00:00
|
|
|
// Get all widgets state events in the room
|
|
|
|
NSMutableArray<MXEvent*> *widgetStateEvents = [NSMutableArray arrayWithArray:[roomState stateEventsWithType:kWidgetMatrixEventTypeString]];
|
|
|
|
[widgetStateEvents addObjectsFromArray:[roomState stateEventsWithType:kWidgetModularEventTypeString]];
|
|
|
|
|
|
|
|
for (MXEvent *widgetStateEvent in widgetStateEvents)
|
2017-08-30 15:37:14 +00:00
|
|
|
{
|
2017-09-27 15:04:40 +00:00
|
|
|
if ([widgetStateEvent.stateKey isEqualToString:widget.widgetId])
|
|
|
|
{
|
|
|
|
Widget *activeWidget = [[Widget alloc] initWithWidgetEvent:widgetStateEvent inMatrixSession:mxSession];
|
|
|
|
if (activeWidget.isActive)
|
|
|
|
{
|
|
|
|
if ([activeWidget.type isEqualToString:kWidgetTypeJitsi])
|
|
|
|
{
|
|
|
|
// This was a jitsi widget
|
|
|
|
displayText = [NSString stringWithFormat:NSLocalizedStringFromTable(@"event_formatter_jitsi_widget_removed", @"Vector", nil), senderDisplayName];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
displayText = [NSString stringWithFormat:NSLocalizedStringFromTable(@"event_formatter_widget_removed", @"Vector", nil),
|
|
|
|
activeWidget.name ? activeWidget.name : activeWidget.type,
|
|
|
|
senderDisplayName];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-30 15:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayText)
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
*error = MXKEventFormatterErrorNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the attributed string with the right font and color for the events
|
|
|
|
return [self renderString:displayText forEvent:event];
|
|
|
|
}
|
|
|
|
}
|
2018-07-27 16:45:23 +00:00
|
|
|
|
2018-08-07 09:23:03 +00:00
|
|
|
if (event.eventType == MXEventTypeRoomCreate)
|
2018-07-27 16:45:23 +00:00
|
|
|
{
|
2018-08-07 09:23:03 +00:00
|
|
|
MXRoomCreateContent *createContent = [MXRoomCreateContent modelFromJSON:event.content];
|
|
|
|
|
|
|
|
NSString *roomPredecessorId = createContent.roomPredecessorInfo.roomId;
|
|
|
|
|
|
|
|
if (roomPredecessorId)
|
|
|
|
{
|
|
|
|
return [self roomCreatePredecessorAttributedStringWithPredecessorRoomId:roomPredecessorId];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
2018-07-27 16:45:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 18:58:16 +00:00
|
|
|
// Make event types MXEventTypeKeyVerificationCancel and MXEventTypeKeyVerificationDone visible in timeline.
|
|
|
|
// TODO: Find another way to keep them visible and avoid instantiate empty NSMutableAttributedString.
|
|
|
|
if (event.eventType == MXEventTypeKeyVerificationCancel || event.eventType == MXEventTypeKeyVerificationDone)
|
|
|
|
{
|
|
|
|
return [NSMutableAttributedString new];
|
|
|
|
}
|
|
|
|
|
2018-06-08 15:21:52 +00:00
|
|
|
NSAttributedString *attributedString = [super attributedStringFromEvent:event withRoomState:roomState error:error];
|
|
|
|
|
|
|
|
if (event.sentState == MXEventSentStateSent
|
2018-06-29 05:35:31 +00:00
|
|
|
&& [event.decryptionError.domain isEqualToString:MXDecryptingErrorDomain])
|
2018-06-08 15:21:52 +00:00
|
|
|
{
|
2018-06-29 05:35:31 +00:00
|
|
|
// Track e2e failures
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[[DecryptionFailureTracker sharedInstance] reportUnableToDecryptErrorForEvent:event withRoomState:roomState myUser:mxSession.myUser.userId];
|
|
|
|
});
|
|
|
|
|
|
|
|
if (event.decryptionError.code == MXDecryptingErrorUnknownInboundSessionIdCode)
|
|
|
|
{
|
|
|
|
// Append to the displayed error an attibuted string with a tappable link
|
|
|
|
// so that the user can try to fix the UTD
|
|
|
|
NSMutableAttributedString *attributedStringWithRerequestMessage = [attributedString mutableCopy];
|
|
|
|
[attributedStringWithRerequestMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
|
|
|
|
|
2019-06-12 14:05:34 +00:00
|
|
|
NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterOnReRequestKeysLinkAction,
|
|
|
|
EventFormatterLinkActionSeparator,
|
2018-06-29 05:35:31 +00:00
|
|
|
event.eventId];
|
|
|
|
|
|
|
|
[attributedStringWithRerequestMessage appendAttributedString:
|
|
|
|
[[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"event_formatter_rerequest_keys_part1_link", @"Vector", nil)
|
|
|
|
attributes:@{
|
|
|
|
NSLinkAttributeName: linkActionString,
|
|
|
|
NSForegroundColorAttributeName: self.sendingTextColor,
|
|
|
|
NSFontAttributeName: self.encryptedMessagesTextFont
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[attributedStringWithRerequestMessage appendAttributedString:
|
|
|
|
[[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"event_formatter_rerequest_keys_part2", @"Vector", nil)
|
|
|
|
attributes:@{
|
|
|
|
NSForegroundColorAttributeName: self.sendingTextColor,
|
|
|
|
NSFontAttributeName: self.encryptedMessagesTextFont
|
|
|
|
}]];
|
|
|
|
|
|
|
|
attributedString = attributedStringWithRerequestMessage;
|
|
|
|
}
|
2018-06-08 15:21:52 +00:00
|
|
|
}
|
2019-07-01 10:42:42 +00:00
|
|
|
else if (self.showEditionMention && event.contentHasBeenEdited)
|
2019-06-12 14:05:34 +00:00
|
|
|
{
|
|
|
|
NSMutableAttributedString *attributedStringWithEditMention = [attributedString mutableCopy];
|
|
|
|
|
|
|
|
NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterEditedEventLinkAction,
|
|
|
|
EventFormatterLinkActionSeparator,
|
|
|
|
event.eventId];
|
|
|
|
|
|
|
|
[attributedStringWithEditMention appendAttributedString:
|
|
|
|
[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", NSLocalizedStringFromTable(@"event_formatter_message_edited_mention", @"Vector", nil)]
|
|
|
|
attributes:@{
|
|
|
|
NSLinkAttributeName: linkActionString,
|
|
|
|
// NOTE: Color is curretly overidden by UIText.tintColor as we use `NSLinkAttributeName`.
|
|
|
|
// If we use UITextView.linkTextAttributes to set link color we will also have the issue that color will be the same for all kind of links.
|
|
|
|
NSForegroundColorAttributeName: self.editionMentionTextColor,
|
|
|
|
NSFontAttributeName: self.editionMentionTextFont
|
|
|
|
}]];
|
|
|
|
|
|
|
|
attributedString = attributedStringWithEditMention;
|
|
|
|
}
|
2018-06-08 15:21:52 +00:00
|
|
|
|
|
|
|
return attributedString;
|
2017-08-30 15:37:14 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 13:26:30 +00:00
|
|
|
- (NSAttributedString*)attributedStringFromEvents:(NSArray<MXEvent*>*)events withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error
|
|
|
|
{
|
|
|
|
NSString *displayText;
|
|
|
|
|
|
|
|
if (events.count)
|
|
|
|
{
|
|
|
|
if (events[0].eventType == MXEventTypeRoomMember)
|
|
|
|
{
|
2017-07-17 08:30:46 +00:00
|
|
|
// This is a series for cells tagged with RoomBubbleCellDataTagMembership
|
2017-07-07 13:26:30 +00:00
|
|
|
// TODO: Build a complete summary like Riot-web
|
2017-07-07 15:58:39 +00:00
|
|
|
displayText = [NSString stringWithFormat:NSLocalizedStringFromTable(@"event_formatter_member_updates", @"Vector", nil), events.count];
|
2017-07-07 13:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (displayText)
|
|
|
|
{
|
|
|
|
// Build the attributed string with the right font and color for the events
|
|
|
|
return [self renderString:displayText forEvent:events[0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super attributedStringFromEvents:events withRoomState:roomState error:error];
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
- (instancetype)initWithMatrixSession:(MXSession *)matrixSession
|
|
|
|
{
|
|
|
|
self = [super initWithMatrixSession:matrixSession];
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
2015-11-26 17:04:03 +00:00
|
|
|
|
2017-08-16 07:40:47 +00:00
|
|
|
// Use the secondary bg color to set the background color in the default CSS.
|
2019-01-11 10:45:27 +00:00
|
|
|
NSUInteger bgColor = [MXKTools rgbValueWithColor:ThemeService.shared.theme.headerBackgroundColor];
|
2017-08-14 13:43:50 +00:00
|
|
|
self.defaultCSS = [NSString stringWithFormat:@" \
|
|
|
|
pre,code { \
|
2017-08-16 07:40:47 +00:00
|
|
|
background-color: #%06lX; \
|
2017-08-14 13:43:50 +00:00
|
|
|
display: inline; \
|
|
|
|
font-family: monospace; \
|
|
|
|
white-space: pre; \
|
|
|
|
-coretext-fontname: Menlo-Regular; \
|
|
|
|
font-size: small; \
|
2017-08-30 15:37:14 +00:00
|
|
|
}", (unsigned long)bgColor];
|
2017-08-14 13:43:50 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.defaultTextColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
self.subTitleTextColor = ThemeService.shared.theme.textSecondaryColor;
|
|
|
|
self.prefixTextColor = ThemeService.shared.theme.textSecondaryColor;
|
2019-02-12 18:06:22 +00:00
|
|
|
self.bingTextColor = ThemeService.shared.theme.noticeColor;
|
2019-01-11 10:45:27 +00:00
|
|
|
self.encryptingTextColor = ThemeService.shared.theme.tintColor;
|
|
|
|
self.sendingTextColor = ThemeService.shared.theme.textSecondaryColor;
|
2019-01-18 12:40:09 +00:00
|
|
|
self.errorTextColor = ThemeService.shared.theme.warningColor;
|
2019-07-01 10:42:42 +00:00
|
|
|
self.showEditionMention = YES;
|
2019-06-12 14:05:34 +00:00
|
|
|
self.editionMentionTextColor = ThemeService.shared.theme.textSecondaryColor;
|
2015-12-09 15:09:46 +00:00
|
|
|
|
2016-01-21 09:34:04 +00:00
|
|
|
self.defaultTextFont = [UIFont systemFontOfSize:15];
|
2016-01-21 10:37:39 +00:00
|
|
|
self.prefixTextFont = [UIFont boldSystemFontOfSize:15];
|
2019-04-25 10:27:31 +00:00
|
|
|
self.bingTextFont = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
2016-01-21 09:34:04 +00:00
|
|
|
self.stateEventTextFont = [UIFont italicSystemFontOfSize:15];
|
2016-05-20 14:55:59 +00:00
|
|
|
self.callNoticesTextFont = [UIFont italicSystemFontOfSize:15];
|
2016-09-07 14:22:51 +00:00
|
|
|
self.encryptedMessagesTextFont = [UIFont italicSystemFontOfSize:15];
|
2017-08-08 12:14:00 +00:00
|
|
|
self.emojiOnlyTextFont = [UIFont systemFontOfSize:48];
|
2019-06-12 14:05:34 +00:00
|
|
|
self.editionMentionTextFont = [UIFont systemFontOfSize:12];
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-25 09:19:49 +00:00
|
|
|
- (NSDictionary*)stringAttributesForEventTimestamp
|
|
|
|
{
|
|
|
|
return @{
|
|
|
|
NSForegroundColorAttributeName : [UIColor lightGrayColor],
|
|
|
|
NSFontAttributeName: [UIFont systemFontOfSize:10]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-04 14:37:33 +00:00
|
|
|
#pragma mark event sender info
|
|
|
|
|
|
|
|
- (NSString*)senderAvatarUrlForEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState
|
|
|
|
{
|
|
|
|
// Override this method to ignore the identicons defined by default in matrix kit.
|
|
|
|
|
|
|
|
// Consider first the avatar url defined in provided room state (Note: this room state is supposed to not take the new event into account)
|
2018-07-11 21:52:46 +00:00
|
|
|
NSString *senderAvatarUrl = [roomState.members memberWithUserId:event.sender].avatarUrl;
|
2015-12-04 14:37:33 +00:00
|
|
|
|
|
|
|
// Check whether this avatar url is updated by the current event (This happens in case of new joined member)
|
2016-03-14 14:40:47 +00:00
|
|
|
NSString* membership = event.content[@"membership"];
|
|
|
|
if (membership && [membership isEqualToString:@"join"] && [event.content[@"avatar_url"] length])
|
2015-12-04 14:37:33 +00:00
|
|
|
{
|
|
|
|
// Use the actual avatar
|
|
|
|
senderAvatarUrl = event.content[@"avatar_url"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// We ignore non mxc avatar url (The identicons are removed here).
|
|
|
|
if (senderAvatarUrl && [senderAvatarUrl hasPrefix:kMXContentUriScheme] == NO)
|
|
|
|
{
|
|
|
|
senderAvatarUrl = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return senderAvatarUrl;
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
#pragma mark - Timestamp formatting
|
|
|
|
|
|
|
|
- (NSString*)dateStringFromDate:(NSDate *)date withTime:(BOOL)time
|
|
|
|
{
|
2016-03-03 16:39:10 +00:00
|
|
|
// Check the provided date
|
|
|
|
if (!date)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
// Retrieve today date at midnight
|
2018-05-11 08:44:05 +00:00
|
|
|
NSDate *today = [calendar startOfDayForDate:[NSDate date]];
|
2015-09-18 13:59:07 +00:00
|
|
|
|
2018-05-10 16:35:42 +00:00
|
|
|
NSTimeInterval interval = -[date timeIntervalSinceDate:today];
|
2016-01-13 11:47:50 +00:00
|
|
|
|
|
|
|
if (interval > 60*60*24*364)
|
2015-08-21 18:00:39 +00:00
|
|
|
{
|
2016-01-13 11:47:50 +00:00
|
|
|
[dateFormatter setDateFormat:@"MMM dd yyyy"];
|
|
|
|
|
|
|
|
// Ignore time information here
|
|
|
|
return [super dateStringFromDate:date withTime:NO];
|
|
|
|
}
|
|
|
|
else if (interval > 60*60*24*6)
|
|
|
|
{
|
|
|
|
[dateFormatter setDateFormat:@"MMM dd"];
|
|
|
|
|
|
|
|
// Ignore time information here
|
|
|
|
return [super dateStringFromDate:date withTime:NO];
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
|
|
|
else if (interval > 60*60*24)
|
|
|
|
{
|
2016-01-13 11:47:50 +00:00
|
|
|
if (time)
|
|
|
|
{
|
|
|
|
[dateFormatter setDateFormat:@"EEE"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[dateFormatter setDateFormat:@"EEEE"];
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
return [super dateStringFromDate:date withTime:time];
|
|
|
|
}
|
|
|
|
else if (interval > 0)
|
|
|
|
{
|
|
|
|
if (time)
|
|
|
|
{
|
2015-10-19 16:36:22 +00:00
|
|
|
[dateFormatter setDateFormat:nil];
|
2016-01-13 11:47:50 +00:00
|
|
|
return [NSString stringWithFormat:@"%@ %@", NSLocalizedStringFromTable(@"yesterday", @"Vector", nil), [super dateStringFromDate:date withTime:YES]];
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
2016-01-13 11:47:50 +00:00
|
|
|
return NSLocalizedStringFromTable(@"yesterday", @"Vector", nil);
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
|
|
|
else if (interval > - 60*60*24)
|
|
|
|
{
|
|
|
|
if (time)
|
|
|
|
{
|
2015-10-19 16:36:22 +00:00
|
|
|
[dateFormatter setDateFormat:nil];
|
2015-12-16 21:48:19 +00:00
|
|
|
return [NSString stringWithFormat:@"%@", [super dateStringFromDate:date withTime:YES]];
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
2016-01-13 11:47:50 +00:00
|
|
|
return NSLocalizedStringFromTable(@"today", @"Vector", nil);
|
2015-08-21 18:00:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Date in future
|
2015-10-19 16:36:22 +00:00
|
|
|
[dateFormatter setDateFormat:@"EEE MMM dd yyyy"];
|
2015-08-21 18:00:39 +00:00
|
|
|
return [super dateStringFromDate:date withTime:time];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 16:45:23 +00:00
|
|
|
#pragma mark - Room create predecessor
|
|
|
|
|
2018-08-07 09:23:03 +00:00
|
|
|
- (NSAttributedString*)roomCreatePredecessorAttributedStringWithPredecessorRoomId:(NSString*)predecessorRoomId
|
2018-07-27 16:45:23 +00:00
|
|
|
{
|
|
|
|
NSDictionary *roomPredecessorReasonAttributes = @{
|
|
|
|
NSFontAttributeName : self.defaultTextFont
|
|
|
|
};
|
|
|
|
|
|
|
|
NSDictionary *roomLinkAttributes = @{
|
|
|
|
NSFontAttributeName : self.defaultTextFont,
|
2019-02-04 14:49:49 +00:00
|
|
|
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle)
|
2018-07-27 16:45:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NSMutableAttributedString *roomPredecessorAttributedString = [NSMutableAttributedString new];
|
|
|
|
|
|
|
|
NSString *roomPredecessorReasonString = [NSString stringWithFormat:@"%@\n", NSLocalizedStringFromTable(@"room_predecessor_information", @"Vector", nil)];
|
|
|
|
NSAttributedString *roomPredecessorReasonAttributedString = [[NSAttributedString alloc] initWithString:roomPredecessorReasonString attributes:roomPredecessorReasonAttributes];
|
|
|
|
|
|
|
|
NSString *predecessorRoomLinkString = NSLocalizedStringFromTable(@"room_predecessor_link", @"Vector", nil);
|
|
|
|
NSAttributedString *predecessorRoomLinkAttributedString = [[NSAttributedString alloc] initWithString:predecessorRoomLinkString attributes:roomLinkAttributes];
|
|
|
|
|
|
|
|
[roomPredecessorAttributedString appendAttributedString:roomPredecessorReasonAttributedString];
|
|
|
|
[roomPredecessorAttributedString appendAttributedString:predecessorRoomLinkAttributedString];
|
|
|
|
|
|
|
|
NSRange wholeStringRange = NSMakeRange(0, roomPredecessorAttributedString.length);
|
|
|
|
[roomPredecessorAttributedString addAttribute:NSForegroundColorAttributeName value:self.defaultTextColor range:wholeStringRange];
|
|
|
|
|
|
|
|
return roomPredecessorAttributedString;
|
|
|
|
}
|
|
|
|
|
2015-08-21 18:00:39 +00:00
|
|
|
@end
|