diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index d6a3b5cfd..1fd543a03 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -2029,6 +2029,9 @@ - (NSString*)renderReplyTo:(NSString*)htmlString withRoomState:(MXRoomState*)roo } } + // Tchap: truncate quoted reply if necessary. + html = [self tchapTruncatedQuotedReplyFrom:html]; + // Replace
In reply to // By
['In reply to' from resources] // To localize the "In reply to" string @@ -2042,6 +2045,42 @@ - (NSString*)renderReplyTo:(NSString*)htmlString withRoomState:(MXRoomState*)roo return html; } +// Tchap: truncate long quoted reply +- (NSString *)tchapTruncatedQuotedReplyFrom:(NSString *)fullQuotedReply { + static NSRegularExpression *htmlQuotedTextRegex; + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + htmlQuotedTextRegex = [NSRegularExpression regularExpressionWithPattern:kRepliedTextPattern + options:NSRegularExpressionCaseInsensitive + error:nil]; + }); + + NSTextCheckingResult * regexResults = [htmlQuotedTextRegex firstMatchInString:fullQuotedReply + options:0 + range:NSMakeRange(0, fullQuotedReply.length)]; + + // Check if a quoted text is present. + if( regexResults.numberOfRanges < 1 ) + { + // No reply found. + return fullQuotedReply; + } + + NSRange quotedTextRange = [regexResults rangeAtIndex:1]; + + NSUInteger quotedTextMaxLength = 60; // Max length of quoted text + + if( quotedTextRange.location != NSNotFound && quotedTextRange.length > quotedTextMaxLength ) + { + NSRange truncatedRange = NSMakeRange(quotedTextRange.location + quotedTextMaxLength, quotedTextRange.length - quotedTextMaxLength); + return [fullQuotedReply stringByReplacingCharactersInRange:truncatedRange withString:@"…"]; + } + + // The quoted reply is not found or already short. Return it as is. + return fullQuotedReply; +} + - (NSString*)renderPollEndedReplyTo:(NSString*)htmlString repliedEvent:(MXEvent*)repliedEvent { static NSRegularExpression *endedPollRegex; static dispatch_once_t onceToken; diff --git a/changelog.d/832.change b/changelog.d/832.change new file mode 100644 index 000000000..72cdd7a08 --- /dev/null +++ b/changelog.d/832.change @@ -0,0 +1 @@ +Limiter la longueur du message d'origine à l'affichage d'une réponse avec citation. \ No newline at end of file