Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the room description in the rooms list in case of live broadcast (incoming or outgoing) #7160

Merged
merged 4 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,9 @@ To enable access, tap Settings> Location and select Always";
"notice_crypto_error_unknown_inbound_session_id" = "The sender's session has not sent us the keys for this message.";
"notice_sticker" = "sticker";
"notice_in_reply_to" = "In reply to";
"notice_voice_broadcast_live" = "Live broadcast";
"notice_voice_broadcast_ended" = "%@ ended a voice broadcast.";
"notice_voice_broadcast_ended_by_you" = "You ended a voice broadcast.";

// room display name
"room_displayname_empty_room" = "Empty room";
Expand Down
12 changes: 12 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4323,6 +4323,18 @@ public class VectorL10n: NSObject {
public static var noticeVideoAttachment: String {
return VectorL10n.tr("Vector", "notice_video_attachment")
}
/// %@ ended a voice broadcast.
public static func noticeVoiceBroadcastEnded(_ p1: String) -> String {
return VectorL10n.tr("Vector", "notice_voice_broadcast_ended", p1)
}
/// You ended a voice broadcast.
public static var noticeVoiceBroadcastEndedByYou: String {
return VectorL10n.tr("Vector", "notice_voice_broadcast_ended_by_you")
}
/// Live broadcast
public static var noticeVoiceBroadcastLive: String {
return VectorL10n.tr("Vector", "notice_voice_broadcast_live")
}
/// Always notify
public static var notificationSettingsAlwaysNotify: String {
return VectorL10n.tr("Vector", "notification_settings_always_notify")
Expand Down
5 changes: 1 addition & 4 deletions Riot/Modules/Common/Recents/Views/RecentTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ - (void)render:(MXKCellData *)cellData
// Manage lastEventAttributedTextMessage optional property
if (!roomCellData.roomSummary.spaceChildInfo && [roomCellData respondsToSelector:@selector(lastEventAttributedTextMessage)])
{
// Force the default text color for the last message (cancel highlighted message color)
NSMutableAttributedString *lastEventDescription = [[NSMutableAttributedString alloc] initWithAttributedString:roomCellData.lastEventAttributedTextMessage];
[lastEventDescription addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.textSecondaryColor range:NSMakeRange(0, lastEventDescription.length)];
self.lastEventDescription.attributedText = lastEventDescription;
self.lastEventDescription.attributedText = roomCellData.lastEventAttributedTextMessage;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions Riot/Modules/MatrixKit/MatrixKit-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
#import "MXKImageView.h"
#import "MXKRoomBubbleCellData.h"
#import "UserIndicatorCancel.h"
#import "VoiceBroadcastInfo.h"
95 changes: 95 additions & 0 deletions Riot/Utils/EventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,40 @@ - (NSString*)senderAvatarUrlForEvent:(MXEvent*)event withRoomState:(MXRoomState*
}

#pragma mark - MXRoomSummaryUpdating
- (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary withLastEvent:(MXEvent *)event eventState:(MXRoomState *)eventState roomState:(MXRoomState *)roomState {

// Do not display voice broadcast chunk in last message.
if (event.eventType == MXEventTypeRoomMessage && event.content[VoiceBroadcastSettings.voiceBroadcastContentKeyChunkType])
{
return NO;
}

// Update last message if we have a voice broadcast in the room.
if ([event.type isEqualToString:VoiceBroadcastSettings.voiceBroadcastInfoContentKeyType])
{
return [self session:session updateRoomSummary:summary withVoiceBroadcastInfoStateEvent:event roomState:roomState];
}
else
{
MXEvent *stateEvent = [roomState stateEventsWithType:VoiceBroadcastSettings.voiceBroadcastInfoContentKeyType].lastObject;
if (stateEvent && ![VoiceBroadcastInfo isStoppedFor:[VoiceBroadcastInfo modelFromJSON: stateEvent.content].state])
{
return [self session:session updateRoomSummary:summary withVoiceBroadcastInfoStateEvent:stateEvent roomState:roomState];
}
}

BOOL updated = [super session:session updateRoomSummary:summary withLastEvent:event eventState:eventState roomState:roomState];

if (updated) {
// Force the default text color for the last message (cancel highlighted message color)
NSMutableAttributedString *lastEventDescription = [[NSMutableAttributedString alloc] initWithAttributedString:summary.lastMessage.attributedText];
[lastEventDescription addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.textSecondaryColor range:NSMakeRange(0, lastEventDescription.length)];
summary.lastMessage.attributedText = lastEventDescription;
}

return updated;
}

- (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary withStateEvents:(NSArray<MXEvent *> *)stateEvents roomState:(MXRoomState *)roomState
{
BOOL updated = [super session:session updateRoomSummary:summary withStateEvents:stateEvents roomState:roomState];
Expand All @@ -569,6 +603,67 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
return updated;
}

- (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary withVoiceBroadcastInfoStateEvent:(MXEvent *)stateEvent roomState:(MXRoomState *)roomState
{
[summary updateLastMessage:[[MXRoomLastMessage alloc] initWithEvent:stateEvent]];
if (summary.lastMessage.others == nil)
{
summary.lastMessage.others = [NSMutableDictionary dictionary];
}
summary.lastMessage.others[@"lastEventDate"] = [self dateStringFromEvent:stateEvent withTime:YES];

NSAttributedString *attachmentString = nil;
UIColor *textColor;
if ([VoiceBroadcastInfo isStoppedFor:[VoiceBroadcastInfo modelFromJSON: stateEvent.content].state])
{
textColor = ThemeService.shared.theme.textSecondaryColor;
NSString *senderDisplayName;
if ([stateEvent.stateKey isEqualToString:session.myUser.userId])
{
summary.lastMessage.text = VectorL10n.noticeVoiceBroadcastEndedByYou;
}
else
{
senderDisplayName = [self senderDisplayNameForEvent:stateEvent withRoomState:roomState];
summary.lastMessage.text = [VectorL10n noticeVoiceBroadcastEnded:senderDisplayName];
}
}
else
{
textColor = ThemeService.shared.theme.colors.alert;
UIImage *liveImage = AssetImages.voiceBroadcastLive.image;

NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [liveImage imageWithTintColor:textColor renderingMode:UIImageRenderingModeAlwaysTemplate];
attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];

summary.lastMessage.text = VectorL10n.noticeVoiceBroadcastLive;
}

// Compute the attribute text message
NSMutableAttributedString *lastMessage;
if (attachmentString)
{
lastMessage = [[NSMutableAttributedString alloc] initWithAttributedString:attachmentString];
// Change base line
[lastMessage addAttribute:NSBaselineOffsetAttributeName value:@(-3.0f) range:NSMakeRange(0, attachmentString.length)];

NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", summary.lastMessage.text]];
[lastMessage appendAttributedString:attributedText];
[lastMessage addAttribute:NSFontAttributeName value:self.defaultTextFont range:NSMakeRange(0, lastMessage.length)];
}
else
{
NSAttributedString *attributedText = [self renderString:summary.lastMessage.text forEvent:stateEvent];
lastMessage = [[NSMutableAttributedString alloc] initWithAttributedString:attributedText];
}

[lastMessage addAttribute:NSForegroundColorAttributeName value:textColor range:NSMakeRange(0, lastMessage.length)];
summary.lastMessage.attributedText = lastMessage;

return YES;
}

- (NSAttributedString *)redactedMessageReplacementAttributedString
{
UIFont *font = self.defaultTextFont;
Expand Down
2 changes: 1 addition & 1 deletion RiotNSE/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ targets:
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Modules/Room/TimelineCells/Styles/RoomTimelineStyleIdentifier.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastSettings.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK
2 changes: 1 addition & 1 deletion RiotShareExtension/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ targets:
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Modules/Room/TimelineCells/Styles/RoomTimelineStyleIdentifier.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastSettings.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK
2 changes: 1 addition & 1 deletion RiotSwiftUI/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ targets:
- path: ../Riot/Modules/Analytics/AnalyticsScreen.swift
- path: ../Riot/Modules/LocationSharing/LocationAuthorizationStatus.swift
- path: ../Riot/Modules/QRCode/QRCodeGenerator.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastInfoState.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK/VoiceBroadcastInfoState.swift
- path: ../Riot/Assets/en.lproj/Untranslated.strings
buildPhase: resources
- path: ../Riot/Assets/Images.xcassets
Expand Down
2 changes: 1 addition & 1 deletion RiotSwiftUI/targetUITests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ targets:
- path: ../Riot/Modules/Analytics/AnalyticsScreen.swift
- path: ../Riot/Modules/LocationSharing/LocationAuthorizationStatus.swift
- path: ../Riot/Modules/QRCode/QRCodeGenerator.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastInfoState.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK/VoiceBroadcastInfoState.swift
- path: ../Riot/Assets/en.lproj/Untranslated.strings
buildPhase: resources
- path: ../Riot/Assets/Images.xcassets
Expand Down
2 changes: 1 addition & 1 deletion RiotTests/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ targets:
- path: ../Riot/Modules/Room/TimelineCells/Styles/RoomTimelineStyleIdentifier.swift
- path: ../Riot/Modules/Room/EventMenu/EventMenuBuilder.swift
- path: ../Riot/Modules/Room/EventMenu/EventMenuItemType.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastSettings.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK/VoiceBroadcastSettings.swift
2 changes: 1 addition & 1 deletion SiriIntents/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ targets:
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Modules/Room/TimelineCells/Styles/RoomTimelineStyleIdentifier.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/VoiceBroadcastSettings.swift
- path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK
1 change: 1 addition & 0 deletions changelog.d/pr-7160.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update the room description in the rooms list in case of live broadcast (incoming or outgoing)