Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amélioration de la troncature des réponses à messages #1059

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
#import "GeneratedInterface-Swift.h"

static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>([^<]*)</a>";
static NSString *const kRepliedTextPattern = @"<mx-reply>.*<blockquote>.*<br>(.*)</blockquote></mx-reply>";
// Tchap: modify regex to define reply paqttern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

une typo sur pattern

// static NSString *const kRepliedTextPattern = @"<mx-reply>.*<blockquote>.*<br>(.*)</blockquote></mx-reply>";
// The Tchap pattern takes in account:
// - a text can span on multiple lines -> (?s) modifier make regex '.' to match any char or newline char.
// - the pattern doesn't truncate any quoted user defined by <a> tag at the begining of the replied to text
// else, truncating in first quoted users (if they exists) breaks the tyext rendering.
static NSString *const kRepliedTextPattern = @"(?s)<mx-reply>.*<blockquote>.*<br>(?:<a .*?/a>[: ]*)*(.*)</blockquote></mx-reply>";

@interface MXKEventFormatter ()
{
Expand Down Expand Up @@ -2074,6 +2080,23 @@ - (NSString *)tchapTruncatedQuotedReplyFrom:(NSString *)fullQuotedReply {
if( quotedTextRange.location != NSNotFound && quotedTextRange.length > quotedTextMaxLength )
{
NSRange truncatedRange = NSMakeRange(quotedTextRange.location + quotedTextMaxLength, quotedTextRange.length - quotedTextMaxLength);

NSRange remainingRange = NSMakeRange(quotedTextRange.location, quotedTextMaxLength);

// Check if truncation is in the middle of an HTML <a> tag
NSRange lastOpeningTag = [fullQuotedReply rangeOfString:@"<a" options:NSBackwardsSearch range:remainingRange];
NSRange lastClosingTag = [fullQuotedReply rangeOfString:@"/a>" options:NSBackwardsSearch range:remainingRange];

if( lastOpeningTag.location != NSNotFound &&
(lastClosingTag.location == NSNotFound || lastOpeningTag.location > lastClosingTag.location) )
{
// An opening tag has no closing tag. This can break the display of the message.
// Cut at the beginning of the incomplete tag.
NSUInteger excedentLength = truncatedRange.location - lastOpeningTag.location;
truncatedRange.location -= excedentLength;
truncatedRange.length += excedentLength;
}

return [fullQuotedReply stringByReplacingCharactersInRange:truncatedRange withString:@"…"];
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/1056.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Amélioration de la troncature des réponses à messages (certains messages tronqués apparaissaient vides).
Loading