From d31dfd031990d689a69ff72f0b6c01f6c454e17c Mon Sep 17 00:00:00 2001 From: ismailgulek Date: Mon, 14 Sep 2020 14:12:14 +0300 Subject: [PATCH] Configure attributed text for room creation event and for multiple events --- Riot/Utils/EventFormatter.m | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Riot/Utils/EventFormatter.m b/Riot/Utils/EventFormatter.m index 1d076e947..284d9c9ff 100644 --- a/Riot/Utils/EventFormatter.m +++ b/Riot/Utils/EventFormatter.m @@ -180,7 +180,7 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm"; } else { - return nil; + return [super attributedStringFromEvent:event withRoomState:roomState error:error]; } } @@ -260,7 +260,30 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm"; if (events.count) { - if (events[0].eventType == MXEventTypeRoomMember) + MXEvent *roomCreateEvent = [events filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"type == %@", kMXEventTypeStringRoomCreate]].firstObject; + + if (roomCreateEvent) + { + MXKEventFormatterError tmpError; + displayText = [super attributedStringFromEvent:roomCreateEvent withRoomState:roomState error:&tmpError].string; + + NSAttributedString *rendered = [self renderString:displayText forEvent:roomCreateEvent]; + NSMutableAttributedString *result = [[NSMutableAttributedString alloc] initWithAttributedString:rendered]; + [result setAttributes:@{ + NSFontAttributeName: [UIFont systemFontOfSize:13], + NSForegroundColorAttributeName: ThemeService.shared.theme.textSecondaryColor + } range:NSMakeRange(0, rendered.length)]; + // add one char space + [result appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]]; + // add more link + NSAttributedString *linkMore = [[NSAttributedString alloc] initWithString:@"More" attributes:@{ + NSFontAttributeName: [UIFont systemFontOfSize:13], + NSForegroundColorAttributeName: ThemeService.shared.theme.tintColor + }]; + [result appendAttributedString:linkMore]; + return result; + } + else if (events[0].eventType == MXEventTypeRoomMember) { // This is a series for cells tagged with RoomBubbleCellDataTagMembership // TODO: Build a complete summary like Riot-web