mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Merge commit 'aaadcc73674cc8886e363693a7d7c08ac9b4f516' into feature/4260_merge_foss_1_10_2
# Conflicts: # Config/AppVersion.xcconfig # Podfile # Podfile.lock # Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved # Riot/Managers/EncryptionKeyManager/EncryptionKeyManager.swift # Riot/Modules/Application/LegacyAppDelegate.m # Riot/Modules/Authentication/AuthenticationCoordinator.swift # Riot/Modules/Authentication/Legacy/LegacyAuthenticationCoordinator.swift # Riot/Modules/ContextMenu/ActionProviders/RoomActionProvider.swift # Riot/Modules/Home/AllChats/AllChatsViewController.swift # Riot/Modules/Room/RoomInfo/RoomInfoCoordinator.swift # Riot/Modules/Room/RoomInfo/RoomInfoList/RoomInfoListViewController.swift # Riot/Modules/Room/Settings/RoomSettingsViewController.m # fastlane/Fastfile
This commit is contained in:
@@ -366,6 +366,12 @@ typedef enum : NSUInteger {
|
||||
*/
|
||||
@property (nonatomic) UIColor *sendingTextColor;
|
||||
|
||||
/**
|
||||
Color used to display links and hyperlinks contentt.
|
||||
Default is [UIColor linkColor].
|
||||
*/
|
||||
@property (nonatomic) UIColor *linksColor;
|
||||
|
||||
/**
|
||||
Color used to display error text.
|
||||
Default is red.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#import "GeneratedInterface-Swift.h"
|
||||
|
||||
static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>([^<]*)</a>";
|
||||
static NSString *const kRepliedTextPattern = @"<mx-reply>.*<blockquote>.*<br>(.*)</blockquote></mx-reply>";
|
||||
|
||||
@interface MXKEventFormatter ()
|
||||
{
|
||||
@@ -89,6 +90,7 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
_encryptingTextColor = [UIColor lightGrayColor];
|
||||
_sendingTextColor = [UIColor lightGrayColor];
|
||||
_errorTextColor = [UIColor redColor];
|
||||
_linksColor = [UIColor linkColor];
|
||||
_htmlBlockquoteBorderColor = [MXKTools colorWithRGBValue:0xDDDDDD];
|
||||
|
||||
_defaultTextFont = [UIFont systemFontOfSize:14];
|
||||
@@ -1051,8 +1053,22 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
else if ([event.decryptionError.domain isEqualToString:MXDecryptingErrorDomain]
|
||||
&& event.decryptionError.code == MXDecryptingErrorUnknownInboundSessionIdCode)
|
||||
{
|
||||
// Make the unknown inbound session id error description more user friendly
|
||||
errorDescription = [VectorL10n noticeCryptoErrorUnknownInboundSessionId];
|
||||
// Hide the decryption error for VoiceBroadcast chunks
|
||||
BOOL isVoiceBroadcastChunk = NO;
|
||||
if ([event.relatesTo.relationType isEqualToString:MXEventRelationTypeReference]) {
|
||||
MXEvent *startEvent = [mxSession.store eventWithEventId:event.relatesTo.eventId
|
||||
inRoom:event.roomId];
|
||||
|
||||
if (startEvent) {
|
||||
isVoiceBroadcastChunk = (startEvent.eventType == MXEventTypeCustom && [startEvent.type isEqualToString:VoiceBroadcastSettings.voiceBroadcastInfoContentKeyType]);
|
||||
}
|
||||
}
|
||||
if (isVoiceBroadcastChunk) {
|
||||
displayText = nil;
|
||||
} else {
|
||||
// Make the unknown inbound session id error description more user friendly
|
||||
errorDescription = [VectorL10n noticeCryptoErrorUnknownInboundSessionId];
|
||||
}
|
||||
}
|
||||
else if ([event.decryptionError.domain isEqualToString:MXDecryptingErrorDomain]
|
||||
&& event.decryptionError.code == MXDecryptingErrorDuplicateMessageIndexCode)
|
||||
@@ -1749,6 +1765,7 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
if (url.URL)
|
||||
{
|
||||
[str addAttribute:NSLinkAttributeName value:url.URL range:matchRange];
|
||||
[str addAttribute:NSForegroundColorAttributeName value:self.linksColor range:matchRange];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1806,6 +1823,7 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
}
|
||||
|
||||
html = [self renderReplyTo:html withRoomState:roomState];
|
||||
html = [self renderPollEndedReplyTo:html repliedEvent:repliedEvent];
|
||||
}
|
||||
|
||||
// Apply the css style that corresponds to the event state
|
||||
@@ -1878,6 +1896,12 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
{
|
||||
MXJSONModelSetString(repliedEventContent, repliedEvent.content[kMXMessageBodyKey]);
|
||||
}
|
||||
if (!repliedEventContent && repliedEvent.eventType == MXEventTypePollStart) {
|
||||
repliedEventContent = [MXEventContentPollStart modelFromJSON:repliedEvent.content].question;
|
||||
}
|
||||
if (!repliedEventContent && repliedEvent.eventType == MXEventTypePollEnd) {
|
||||
repliedEventContent = MXSendReplyEventDefaultStringLocalizer.new.replyToEndedPoll;
|
||||
}
|
||||
}
|
||||
|
||||
// No message content in a non-redacted event. Formatter should use fallback.
|
||||
@@ -2012,6 +2036,44 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||
return html;
|
||||
}
|
||||
|
||||
- (NSString*)renderPollEndedReplyTo:(NSString*)htmlString repliedEvent:(MXEvent*)repliedEvent {
|
||||
static NSRegularExpression *endedPollRegex;
|
||||
static dispatch_once_t onceToken;
|
||||
|
||||
dispatch_once(&onceToken, ^{
|
||||
endedPollRegex = [NSRegularExpression regularExpressionWithPattern:kRepliedTextPattern options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
});
|
||||
|
||||
NSString* finalString = htmlString;
|
||||
|
||||
if (repliedEvent.eventType != MXEventTypePollEnd) {
|
||||
return finalString;
|
||||
}
|
||||
|
||||
NSTextCheckingResult* match = [endedPollRegex firstMatchInString:htmlString options:0 range:NSMakeRange(0, htmlString.length)];
|
||||
|
||||
if (!(match && match.numberOfRanges > 1)) {
|
||||
// no useful match found
|
||||
return finalString;
|
||||
}
|
||||
|
||||
NSRange groupRange = [match rangeAtIndex:1];
|
||||
NSString* replacementText;
|
||||
|
||||
if (repliedEvent) {
|
||||
MXEvent* pollStartedEvent = [mxSession.store eventWithEventId:repliedEvent.relatesTo.eventId inRoom:repliedEvent.roomId];
|
||||
replacementText = [MXEventContentPollStart modelFromJSON:pollStartedEvent.content].question;
|
||||
}
|
||||
|
||||
if (replacementText == nil) {
|
||||
replacementText = VectorL10n.pollTimelineReplyEndedPoll;
|
||||
}
|
||||
|
||||
finalString = [htmlString stringByReplacingCharactersInRange:groupRange withString:replacementText];
|
||||
|
||||
return finalString;
|
||||
}
|
||||
|
||||
- (void)postFormatMutableAttributedString:(NSMutableAttributedString*)mutableAttributedString
|
||||
forEvent:(MXEvent*)event
|
||||
andRepliedEvent:(MXEvent*)repliedEvent
|
||||
|
||||
@@ -46,6 +46,7 @@ static NSRegularExpression *eventIdRegex;
|
||||
static NSRegularExpression *httpLinksRegex;
|
||||
// A regex to find all HTML tags
|
||||
static NSRegularExpression *htmlTagsRegex;
|
||||
static NSDataDetector *linkDetector;
|
||||
|
||||
@implementation MXKTools
|
||||
|
||||
@@ -60,7 +61,8 @@ static NSRegularExpression *htmlTagsRegex;
|
||||
eventIdRegex = [NSRegularExpression regularExpressionWithPattern:kMXToolsRegexStringForMatrixEventIdentifier options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
|
||||
httpLinksRegex = [NSRegularExpression regularExpressionWithPattern:@"(?i)\\b(https?://\\S*)\\b" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
htmlTagsRegex = [NSRegularExpression regularExpressionWithPattern:@"<(\\w+)[^>]*>" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
htmlTagsRegex = [NSRegularExpression regularExpressionWithPattern:@"<(\\w+)[^>]*>" options:NSRegularExpressionCaseInsensitive error:nil];
|
||||
linkDetector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1037,6 +1039,23 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
|
||||
{
|
||||
[MXKTools createLinksInMutableAttributedString:mutableAttributedString matchingRegex:eventIdRegex];
|
||||
}
|
||||
|
||||
// This allows to check for normal url based links (like https://element.io)
|
||||
// And set back the default link color
|
||||
NSArray *matches = [linkDetector matchesInString: [mutableAttributedString string] options:0 range: NSMakeRange(0,mutableAttributedString.length)];
|
||||
if (matches)
|
||||
{
|
||||
for (NSTextCheckingResult *match in matches)
|
||||
{
|
||||
NSRange matchRange = [match range];
|
||||
NSURL *matchUrl = [match URL];
|
||||
NSURLComponents *url = [[NSURLComponents new] initWithURL:matchUrl resolvingAgainstBaseURL:NO];
|
||||
if (url.URL)
|
||||
{
|
||||
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.colors.links range:matchRange];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)createLinksInMutableAttributedString:(NSMutableAttributedString*)mutableAttributedString matchingRegex:(NSRegularExpression*)regex
|
||||
@@ -1083,6 +1102,8 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
|
||||
// If the match is fully in the link, skip it
|
||||
if (NSIntersectionRange(match.range, linkMatch.range).length == match.range.length)
|
||||
{
|
||||
// but before we set the right color
|
||||
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.colors.links range:linkMatch.range];
|
||||
hasAlreadyLink = YES;
|
||||
break;
|
||||
}
|
||||
@@ -1097,6 +1118,7 @@ manualChangeMessageForVideo:(NSString*)manualChangeMessageForVideo
|
||||
NSString *link = [mutableAttributedString.string substringWithRange:match.range];
|
||||
link = [link stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
|
||||
[mutableAttributedString addAttribute:NSLinkAttributeName value:link range:match.range];
|
||||
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.colors.links range:match.range];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user