Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Threads P0 #940

Merged
merged 2 commits into from
Nov 2, 2021
Merged
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
28 changes: 22 additions & 6 deletions MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -1252,13 +1252,31 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState

NSString *body;
BOOL isHTML = NO;
NSString *eventThreadIdentifier = event.threadIdentifier;

// Use the HTML formatted string if provided
if ([event.content[@"format"] isEqualToString:kMXRoomMessageFormatHTML])
{
isHTML =YES;
MXJSONModelSetString(body, event.content[@"formatted_body"]);
}
else if (eventThreadIdentifier)
{
isHTML = YES;
MXJSONModelSetString(body, event.content[@"body"]);
MXEvent *threadRootEvent = [mxSession.store eventWithEventId:eventThreadIdentifier
inRoom:event.roomId];

NSString *threadRootEventContent;
MXJSONModelSetString(threadRootEventContent, threadRootEvent.content[@"body"]);
body = [NSString stringWithFormat:@"<mx-reply><blockquote><a href=\"%@\">In reply to</a> <a href=\"%@\">%@</a><br>%@</blockquote></mx-reply>%@",
[MXTools permalinkToEvent:eventThreadIdentifier inRoom:event.roomId],
[MXTools permalinkToUserWithUserId:threadRootEvent.sender],
threadRootEvent.sender,
threadRootEventContent,
body];

}
else
{
MXJSONModelSetString(body, event.content[@"body"]);
Expand Down Expand Up @@ -1360,7 +1378,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
// This helps us insert the emote prefix in the right place
NSDictionary *relatesTo;
MXJSONModelSetDictionary(relatesTo, event.content[@"m.relates_to"]);
if ([relatesTo[@"m.in_reply_to"] isKindOfClass:NSDictionary.class])
if ([relatesTo[@"m.in_reply_to"] isKindOfClass:NSDictionary.class] || event.isInThread)
{
[attributedDisplayText enumerateAttribute:kMXKToolsBlockquoteMarkAttribute
inRange:NSMakeRange(0, attributedDisplayText.length)
Expand Down Expand Up @@ -1694,9 +1712,7 @@ - (NSAttributedString*)renderHTMLString:(NSString*)htmlString forEvent:(MXEvent*
NSString *html = htmlString;

// Special treatment for "In reply to" message
NSDictionary *relatesTo;
MXJSONModelSetDictionary(relatesTo, event.content[@"m.relates_to"]);
if ([relatesTo[@"m.in_reply_to"] isKindOfClass:NSDictionary.class])
if (event.isReplyEvent || event.isInThread)
{
html = [self renderReplyTo:html withRoomState:roomState];
}
Expand Down Expand Up @@ -2023,7 +2039,7 @@ - (UIColor*)textColorForEvent:(MXEvent*)event
textColor = _errorTextColor;
}
// Check whether the message is highlighted.
else if (event.mxkIsHighlighted)
else if (event.mxkIsHighlighted || (event.isInThread && ![event.sender isEqualToString:mxSession.myUserId]))
{
textColor = _bingTextColor;
}
Expand Down Expand Up @@ -2087,7 +2103,7 @@ - (UIFont*)fontForEvent:(MXEvent*)event
{
font = _callNoticesTextFont;
}
else if (event.mxkIsHighlighted)
else if (event.mxkIsHighlighted || (event.isInThread && ![event.sender isEqualToString:mxSession.myUserId]))
{
font = _bingTextFont;
}
Expand Down