mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
EventFormatter: Add edit mention suffix for edited messages.
This commit is contained in:
parent
3625bc439a
commit
b6d7a14e75
2 changed files with 46 additions and 6 deletions
|
@ -19,18 +19,35 @@
|
|||
/**
|
||||
Link string used in attributed strings to mark a keys re-request action.
|
||||
*/
|
||||
FOUNDATION_EXPORT NSString *const kEventFormatterOnReRequestKeysLinkAction;
|
||||
FOUNDATION_EXPORT NSString *const EventFormatterOnReRequestKeysLinkAction;
|
||||
|
||||
/**
|
||||
Parameters separator in the link string.
|
||||
*/
|
||||
FOUNDATION_EXPORT NSString *const kEventFormatterOnReRequestKeysLinkActionSeparator;
|
||||
FOUNDATION_EXPORT NSString *const EventFormatterLinkActionSeparator;
|
||||
|
||||
/**
|
||||
Link string used in attributed strings to mark an edited event action.
|
||||
*/
|
||||
FOUNDATION_EXPORT NSString *const EventFormatterEditedEventLinkAction;
|
||||
|
||||
/**
|
||||
`EventFormatter` class inherits from `MXKEventFormatter` to define Vector formatting
|
||||
*/
|
||||
@interface EventFormatter : MXKEventFormatter
|
||||
|
||||
/**
|
||||
Text color used to display message edited mention.
|
||||
Default is `textSecondaryColor`.
|
||||
*/
|
||||
@property (nonatomic) UIColor *editionMentionTextColor;
|
||||
|
||||
/**
|
||||
Text font used to display message edited mention.
|
||||
Default is system font 12.
|
||||
*/
|
||||
@property (nonatomic) UIFont *editionMentionTextFont;
|
||||
|
||||
/**
|
||||
String attributes for event timestamp displayed in chat history.
|
||||
*/
|
||||
|
|
|
@ -27,8 +27,9 @@
|
|||
|
||||
#pragma mark - Constants definitions
|
||||
|
||||
NSString *const kEventFormatterOnReRequestKeysLinkAction = @"kEventFormatterOnReRequestKeysLinkAction";
|
||||
NSString *const kEventFormatterOnReRequestKeysLinkActionSeparator = @"/";
|
||||
NSString *const EventFormatterOnReRequestKeysLinkAction = @"EventFormatterOnReRequestKeysLinkAction";
|
||||
NSString *const EventFormatterLinkActionSeparator = @"/";
|
||||
NSString *const EventFormatterEditedEventLinkAction = @"EventFormatterEditedEventLinkAction";
|
||||
|
||||
static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
||||
|
||||
|
@ -159,8 +160,8 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
NSMutableAttributedString *attributedStringWithRerequestMessage = [attributedString mutableCopy];
|
||||
[attributedStringWithRerequestMessage appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n"]];
|
||||
|
||||
NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", kEventFormatterOnReRequestKeysLinkAction,
|
||||
kEventFormatterOnReRequestKeysLinkActionSeparator,
|
||||
NSString *linkActionString = [NSString stringWithFormat:@"%@%@%@", EventFormatterOnReRequestKeysLinkAction,
|
||||
EventFormatterLinkActionSeparator,
|
||||
event.eventId];
|
||||
|
||||
[attributedStringWithRerequestMessage appendAttributedString:
|
||||
|
@ -181,6 +182,26 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
attributedString = attributedStringWithRerequestMessage;
|
||||
}
|
||||
}
|
||||
else if (event.contentHasBeenEdited)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
return attributedString;
|
||||
}
|
||||
|
@ -234,6 +255,7 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
self.encryptingTextColor = ThemeService.shared.theme.tintColor;
|
||||
self.sendingTextColor = ThemeService.shared.theme.textSecondaryColor;
|
||||
self.errorTextColor = ThemeService.shared.theme.warningColor;
|
||||
self.editionMentionTextColor = ThemeService.shared.theme.textSecondaryColor;
|
||||
|
||||
self.defaultTextFont = [UIFont systemFontOfSize:15];
|
||||
self.prefixTextFont = [UIFont boldSystemFontOfSize:15];
|
||||
|
@ -242,6 +264,7 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
self.callNoticesTextFont = [UIFont italicSystemFontOfSize:15];
|
||||
self.encryptedMessagesTextFont = [UIFont italicSystemFontOfSize:15];
|
||||
self.emojiOnlyTextFont = [UIFont systemFontOfSize:48];
|
||||
self.editionMentionTextFont = [UIFont systemFontOfSize:12];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue