mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Add replacement logic for “Ended poll” text
This commit is contained in:
parent
8ad5489a5e
commit
a8d041da3b
1 changed files with 35 additions and 0 deletions
|
@ -31,6 +31,7 @@
|
||||||
#import "GeneratedInterface-Swift.h"
|
#import "GeneratedInterface-Swift.h"
|
||||||
|
|
||||||
static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>([^<]*)</a>";
|
static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>([^<]*)</a>";
|
||||||
|
static NSString *const kEndedPollPattern = @"<mx-reply>.*<blockquote>.*<br>(.*)</blockquote></mx-reply>";
|
||||||
|
|
||||||
@interface MXKEventFormatter ()
|
@interface MXKEventFormatter ()
|
||||||
{
|
{
|
||||||
|
@ -1808,6 +1809,7 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||||
}
|
}
|
||||||
|
|
||||||
html = [self renderReplyTo:html withRoomState:roomState];
|
html = [self renderReplyTo:html withRoomState:roomState];
|
||||||
|
html = [self renderPollEndedReplyTo:html repliedEvent:repliedEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the css style that corresponds to the event state
|
// Apply the css style that corresponds to the event state
|
||||||
|
@ -2014,6 +2016,39 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)renderPollEndedReplyTo:(NSString*)htmlString repliedEvent:(MXEvent*)repliedEvent {
|
||||||
|
static NSRegularExpression *endedPollRegex;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
endedPollRegex = [NSRegularExpression regularExpressionWithPattern:kEndedPollPattern options:NSRegularExpressionCaseInsensitive error:nil];
|
||||||
|
});
|
||||||
|
|
||||||
|
NSTextCheckingResult* match = [endedPollRegex firstMatchInString:htmlString options:0 range:NSMakeRange(0, htmlString.length)];
|
||||||
|
NSString* finalString = htmlString;
|
||||||
|
|
||||||
|
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
|
- (void)postFormatMutableAttributedString:(NSMutableAttributedString*)mutableAttributedString
|
||||||
forEvent:(MXEvent*)event
|
forEvent:(MXEvent*)event
|
||||||
andRepliedEvent:(MXEvent*)repliedEvent
|
andRepliedEvent:(MXEvent*)repliedEvent
|
||||||
|
|
Loading…
Reference in a new issue