[EventFormatter] Handle room create predecessor string building

This commit is contained in:
SBiOSoftWhare 2018-07-27 18:45:23 +02:00
parent 9ccfa7c86e
commit 56672d604e

View file

@ -114,7 +114,12 @@ NSString *const kEventFormatterOnReRequestKeysLinkActionSeparator = @"/";
return [self renderString:displayText forEvent:event];
}
}
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