mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
feat: Render declined calls in DM timeline (#5512)
* feat: Render declined calls in DM timeline * Record preview snapshots * review: Use CallIntent constant * review: clean-up * Record preview snapshots * review: Move private field to the bottom with MARK: - Private * review: Male CallIntent a string enum to use rawValue --------- Co-authored-by: Element CI <ci@element.io>
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
enum CallIntent: Codable, CaseIterable {
|
||||
enum CallIntent: String, Codable, CaseIterable {
|
||||
case video, audio
|
||||
}
|
||||
|
||||
+114
-26
@@ -17,29 +17,17 @@ struct CallNotificationRoomTimelineView: View {
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
LoadableAvatarImage(url: timelineItem.sender.avatarURL,
|
||||
name: timelineItem.sender.displayName ?? timelineItem.sender.id,
|
||||
contentID: timelineItem.sender.id,
|
||||
avatarSize: .user(on: .timeline),
|
||||
mediaProvider: context?.mediaProvider)
|
||||
CompoundIcon(iconKeyPath, size: .medium, relativeTo: .compound.headingMDBold)
|
||||
.foregroundStyle(.compound.iconSecondary)
|
||||
.accessibilityHidden(true)
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text(timelineItem.sender.disambiguatedDisplayName ?? timelineItem.sender.id)
|
||||
.font(.compound.bodyLGSemibold)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Label(title: { Text(L10n.commonCallStarted) },
|
||||
icon: { CompoundIcon(\.videoCallSolid, size: .medium, relativeTo: .compound.bodyMD) })
|
||||
.font(.compound.bodyMD)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
.labelStyle(.custom(spacing: 4))
|
||||
}
|
||||
|
||||
|
||||
Text(tileTitle)
|
||||
.font(.compound.bodyMD)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
.labelStyle(.custom(spacing: 4))
|
||||
|
||||
Spacer()
|
||||
|
||||
|
||||
Text(timelineItem.timestamp.formattedTime())
|
||||
.font(.compound.bodyXS)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
@@ -49,6 +37,32 @@ struct CallNotificationRoomTimelineView: View {
|
||||
.stroke(.compound.borderInteractiveSecondary, lineWidth: 1))
|
||||
.padding(16)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var tileTitle: String {
|
||||
if timelineItem.isDM {
|
||||
// As per design only have declined variants in DM
|
||||
if timelineItem.isDeclinedByMe {
|
||||
L10n.commonCallYouDeclined
|
||||
} else if timelineItem.isDeclined {
|
||||
L10n.commonCallDeclined
|
||||
} else {
|
||||
L10n.commonCallStarted
|
||||
}
|
||||
} else {
|
||||
L10n.commonCallStarted
|
||||
}
|
||||
}
|
||||
|
||||
private var iconKeyPath: KeyPath<CompoundIcons, Image> {
|
||||
if timelineItem.isDM, timelineItem.isDeclined || timelineItem.isDeclinedByMe {
|
||||
// As per design only have declined variants in DM
|
||||
timelineItem.isVoiceCall ? \.voiceCallDeclinedSolid : \.videoCallDeclinedSolid
|
||||
} else {
|
||||
timelineItem.isVoiceCall ? \.voiceCallSolid : \.videoCallSolid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CallNotificationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
|
||||
@@ -59,10 +73,84 @@ struct CallNotificationRoomTimelineView_Previews: PreviewProvider, TestablePrevi
|
||||
}
|
||||
|
||||
static var body: some View {
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
sender: .init(id: "Bob")))
|
||||
VStack(spacing: 0) {
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: false,
|
||||
isDeclinedByMe: false,
|
||||
isDeclined: false,
|
||||
isVoiceCall: false))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: true,
|
||||
isDeclinedByMe: false,
|
||||
isDeclined: false,
|
||||
isVoiceCall: true))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: false,
|
||||
isDeclinedByMe: true,
|
||||
isDeclined: true,
|
||||
isVoiceCall: false))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: true,
|
||||
isDeclinedByMe: false,
|
||||
isDeclined: true,
|
||||
isVoiceCall: true))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: true,
|
||||
isDeclinedByMe: true,
|
||||
isDeclined: true,
|
||||
isVoiceCall: true))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: true,
|
||||
isDeclinedByMe: false,
|
||||
isDeclined: true,
|
||||
isVoiceCall: false))
|
||||
|
||||
Divider()
|
||||
|
||||
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
|
||||
timestamp: .mock,
|
||||
isEditable: false,
|
||||
canBeRepliedTo: false,
|
||||
isDM: true,
|
||||
isDeclinedByMe: true,
|
||||
isDeclined: true,
|
||||
isVoiceCall: false))
|
||||
|
||||
Divider()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -14,7 +14,10 @@ struct CallNotificationRoomTimelineItem: RoomTimelineItemProtocol, Equatable {
|
||||
let isEditable: Bool
|
||||
let canBeRepliedTo: Bool
|
||||
|
||||
let sender: TimelineItemSender
|
||||
let isDM: Bool
|
||||
let isDeclinedByMe: Bool
|
||||
let isDeclined: Bool
|
||||
let isVoiceCall: Bool
|
||||
|
||||
var properties = RoomTimelineItemProperties()
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
isOutgoing: isOutgoing)
|
||||
case .callInvite:
|
||||
return buildCallInviteTimelineItem(for: eventItemProxy)
|
||||
case .rtcNotification:
|
||||
return buildCallNotificationTimelineItem(for: eventItemProxy)
|
||||
case .rtcNotification(let callIntent, let declinedBy):
|
||||
return buildCallNotificationTimelineItem(for: eventItemProxy, isDM: isDM, callIntent: callIntent, declinedBy: declinedBy)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,12 +771,20 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
sender: eventItemProxy.sender)
|
||||
}
|
||||
|
||||
private func buildCallNotificationTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol {
|
||||
CallNotificationRoomTimelineItem(id: eventItemProxy.id,
|
||||
timestamp: eventItemProxy.timestamp,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
|
||||
sender: eventItemProxy.sender)
|
||||
private func buildCallNotificationTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||
isDM: Bool,
|
||||
callIntent: String?,
|
||||
declinedBy: [String]) -> RoomTimelineItemProtocol {
|
||||
let isVoiceCall = callIntent == CallIntent.audio.rawValue
|
||||
return CallNotificationRoomTimelineItem(id: eventItemProxy.id,
|
||||
timestamp: eventItemProxy.timestamp,
|
||||
isEditable: eventItemProxy.isEditable,
|
||||
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
|
||||
isDM: isDM,
|
||||
isDeclinedByMe: declinedBy.contains(userID),
|
||||
isDeclined: declinedBy.count > 0,
|
||||
isVoiceCall: isVoiceCall,
|
||||
properties: .init())
|
||||
}
|
||||
|
||||
// MARK: - State Events
|
||||
|
||||
Reference in New Issue
Block a user