Use latest user data for mention pills

This commit is contained in:
aringenbach
2022-06-16 17:07:47 +02:00
parent 87915a9e30
commit 4c8bed38c2
24 changed files with 357 additions and 97 deletions
@@ -182,30 +182,42 @@ typedef enum : NSUInteger {
@param event the event to format.
@param roomState the room state right before the event.
@param latestRoomState the latest room state of the room containing this event.
@param error the error code. In case of formatting error, the formatter may return non nil string as a proposal.
@return the display text for the event.
*/
- (NSString*)stringFromEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error;
- (NSString*)stringFromEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError*)error;
/**
Generate a displayable attributed string representating the event.
@param event the event to format.
@param roomState the room state right before the event.
@param latestRoomState the latest room state of the room containing this event.
@param error the error code. In case of formatting error, the formatter may return non nil string as a proposal.
@return the attributed string for the event.
*/
- (NSAttributedString*)attributedStringFromEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error;
- (NSAttributedString*)attributedStringFromEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError*)error;
/**
Generate a displayable attributed string representating a summary for the provided events.
@param events the series of events to format.
@param roomState the room state right before the first event in the series.
@param latestRoomState the latest room state of the room containing this event.
@param error the error code. In case of formatting error, the formatter may return non nil string as a proposal.
@return the attributed string.
*/
- (NSAttributedString*)attributedStringFromEvents:(NSArray<MXEvent*>*)events withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error;
- (NSAttributedString*)attributedStringFromEvents:(NSArray<MXEvent*>*)events
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError*)error;
/**
Render a random string into an attributed string with the font and the text color
@@ -226,7 +238,10 @@ typedef enum : NSUInteger {
@param roomState the room state right before the event. If nil, replies will not get constructed or formatted.
@return an attributed string.
*/
- (NSAttributedString*)renderHTMLString:(NSString*)htmlString forEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState;
- (NSAttributedString*)renderHTMLString:(NSString*)htmlString
forEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState;
/**
Defines the replacement attributed string for a redacted message.
@@ -296,10 +296,16 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
#pragma mark - Events to strings conversion methods
- (NSString*)stringFromEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error
- (NSString*)stringFromEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError*)error
{
NSString *stringFromEvent;
NSAttributedString *attributedStringFromEvent = [self attributedStringFromEvent:event withRoomState:roomState error:error];
NSAttributedString *attributedStringFromEvent = [self attributedStringFromEvent:event
withRoomState:roomState
andLatestRoomState:latestRoomState
error:error];
if (*error == MXKEventFormatterErrorNone)
{
stringFromEvent = attributedStringFromEvent.string;
@@ -308,7 +314,10 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
return stringFromEvent;
}
- (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState:(MXRoomState *)roomState error:(MXKEventFormatterError *)error
- (NSAttributedString *)attributedStringFromEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError *)error
{
// Check we can output the error
NSParameterAssert(error);
@@ -1360,7 +1369,10 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
if (isHTML)
{
// Build the attributed string from the HTML string
attributedDisplayText = [self renderHTMLString:body forEvent:event withRoomState:roomState];
attributedDisplayText = [self renderHTMLString:body
forEvent:event
withRoomState:roomState
andLatestRoomState:latestRoomState];
}
else
{
@@ -1664,7 +1676,10 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
return attributedDisplayText;
}
- (NSAttributedString*)attributedStringFromEvents:(NSArray<MXEvent*>*)events withRoomState:(MXRoomState*)roomState error:(MXKEventFormatterError*)error
- (NSAttributedString*)attributedStringFromEvents:(NSArray<MXEvent*>*)events
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
error:(MXKEventFormatterError*)error
{
// TODO: Do a full summary
return nil;
@@ -1752,7 +1767,10 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
return str;
}
- (NSAttributedString*)renderHTMLString:(NSString*)htmlString forEvent:(MXEvent*)event withRoomState:(MXRoomState*)roomState
- (NSAttributedString*)renderHTMLString:(NSString*)htmlString
forEvent:(MXEvent*)event
withRoomState:(MXRoomState*)roomState
andLatestRoomState:(MXRoomState*)latestRoomState
{
NSString *html = htmlString;
MXEvent *repliedEvent;
@@ -2126,7 +2144,10 @@ static NSString *const kHTMLATagRegexPattern = @"<a href=(?:'|\")(.*?)(?:'|\")>(
// Note that we use the current room state (roomState) because when we display
// users displaynames, we want current displaynames
MXKEventFormatterError error;
NSString *lastMessageString = [self stringFromEvent:event withRoomState:roomState error:&error];
NSString *lastMessageString = [self stringFromEvent:event
withRoomState:roomState
andLatestRoomState:nil
error:&error];
if (0 == lastMessageString.length)
{