mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-29 07:42:40 +00:00
[EventFormatter] Handle room create predecessor string building
This commit is contained in:
parent
9ccfa7c86e
commit
56672d604e
1 changed files with 45 additions and 1 deletions
|
@ -115,6 +115,11 @@ NSString *const kEventFormatterOnReRequestKeysLinkActionSeparator = @"/";
|
|||
}
|
||||
}
|
||||
|
||||
if (event.eventType == MXEventTypeRoomCreate && roomState.hasRoomPredecessor)
|
||||
{
|
||||
return [self roomCreatePredecessorAttributedStringFromRoomCreateContent:roomState.roomCreateContent];
|
||||
}
|
||||
|
||||
NSAttributedString *attributedString = [super attributedStringFromEvent:event withRoomState:roomState error:error];
|
||||
|
||||
if (event.sentState == MXEventSentStateSent
|
||||
|
@ -552,4 +557,43 @@ NSString *const kEventFormatterOnReRequestKeysLinkActionSeparator = @"/";
|
|||
}
|
||||
}
|
||||
|
||||
#pragma mark - Room create predecessor
|
||||
|
||||
- (NSAttributedString*)roomCreatePredecessorAttributedStringFromRoomCreateContent:(MXRoomCreateContent*)roomCreateContent
|
||||
{
|
||||
if (!roomCreateContent)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *predecessorRoomId = roomCreateContent.roomPredecessorInfo.roomId;
|
||||
NSString *predecessorRoomPermalink = [MXTools permalinkToRoom:predecessorRoomId];
|
||||
|
||||
NSDictionary *roomPredecessorReasonAttributes = @{
|
||||
NSFontAttributeName : self.defaultTextFont
|
||||
};
|
||||
|
||||
NSDictionary *roomLinkAttributes = @{
|
||||
NSFontAttributeName : self.defaultTextFont,
|
||||
NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),
|
||||
NSLinkAttributeName : predecessorRoomPermalink,
|
||||
};
|
||||
|
||||
NSMutableAttributedString *roomPredecessorAttributedString = [NSMutableAttributedString new];
|
||||
|
||||
NSString *roomPredecessorReasonString = [NSString stringWithFormat:@"%@\n", NSLocalizedStringFromTable(@"room_predecessor_information", @"Vector", nil)];
|
||||
NSAttributedString *roomPredecessorReasonAttributedString = [[NSAttributedString alloc] initWithString:roomPredecessorReasonString attributes:roomPredecessorReasonAttributes];
|
||||
|
||||
NSString *predecessorRoomLinkString = NSLocalizedStringFromTable(@"room_predecessor_link", @"Vector", nil);
|
||||
NSAttributedString *predecessorRoomLinkAttributedString = [[NSAttributedString alloc] initWithString:predecessorRoomLinkString attributes:roomLinkAttributes];
|
||||
|
||||
[roomPredecessorAttributedString appendAttributedString:roomPredecessorReasonAttributedString];
|
||||
[roomPredecessorAttributedString appendAttributedString:predecessorRoomLinkAttributedString];
|
||||
|
||||
NSRange wholeStringRange = NSMakeRange(0, roomPredecessorAttributedString.length);
|
||||
[roomPredecessorAttributedString addAttribute:NSForegroundColorAttributeName value:self.defaultTextColor range:wholeStringRange];
|
||||
|
||||
return roomPredecessorAttributedString;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue