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

Limiter la longueur du message d'origine à l'affichage d'une réponse … #1012

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,9 @@ - (NSString*)renderReplyTo:(NSString*)htmlString withRoomState:(MXRoomState*)roo
}
}

// Tchap: truncate quoted reply if necessary.
html = [self tchapTruncatedQuotedReplyFrom:html];

// Replace <mx-reply><blockquote><a href=\"__permalink__\">In reply to</a>
// By <mx-reply><blockquote><a href=\"__permalink__\">['In reply to' from resources]</a>
// To localize the "In reply to" string
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions changelog.d/832.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Limiter la longueur du message d'origine à l'affichage d'une réponse avec citation.
Loading