Fixes #1342 - Remove custom last message for rooms that don't have one

This commit is contained in:
Stefan Ceriu
2023-09-13 12:06:50 +03:00
committed by Stefan Ceriu
parent da29c7efde
commit 9fbf70282e
3 changed files with 11 additions and 36 deletions
@@ -105,23 +105,7 @@ struct HomeScreenViewStateBindings {
struct HomeScreenRoom: Identifiable, Equatable {
static let placeholderLastMessage = AttributedString("Hidden last message")
enum LastMessage: Equatable {
case loaded(AttributedString)
case loading
case unknown
init(attributedString: AttributedString?, isLoading: Bool) {
if let message = attributedString, !message.characters.isEmpty {
self = .loaded(message)
} else if isLoading {
self = .loading
} else {
self = .unknown
}
}
}
/// The list item identifier can be a real room identifier, a custom one for invalidated entries
/// or a completely unique one for empty items and skeletons
let id: String
@@ -135,7 +119,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
var timestamp: String?
var lastMessage: LastMessage
var lastMessage: AttributedString?
var avatarURL: URL?
@@ -155,7 +139,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
name: "Placeholder room name",
hasUnreads: false,
timestamp: "Now",
lastMessage: .loading,
lastMessage: placeholderLastMessage,
isPlaceholder: true)
}
}
@@ -275,7 +275,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
name: details.name,
hasUnreads: details.unreadNotificationCount > 0,
timestamp: details.lastMessageFormattedTimestamp,
lastMessage: .init(attributedString: details.lastMessage, isLoading: false),
lastMessage: details.lastMessage,
avatarURL: details.avatarURL,
notificationMode: notificationMode)
}
@@ -55,7 +55,7 @@ struct HomeScreenRoomCell: View {
}
@ViewBuilder @MainActor
var avatar: some View {
private var avatar: some View {
if dynamicTypeSize < .accessibility3 {
LoadableAvatarImage(url: room.avatarURL,
name: room.name,
@@ -67,7 +67,7 @@ struct HomeScreenRoomCell: View {
}
}
var content: some View {
private var content: some View {
VStack(alignment: .leading, spacing: 2) {
header
footer
@@ -85,7 +85,7 @@ struct HomeScreenRoomCell: View {
}
@ViewBuilder
var header: some View {
private var header: some View {
HStack(alignment: .top, spacing: 16) {
Text(room.name)
.font(.compound.bodyLGSemibold)
@@ -102,7 +102,7 @@ struct HomeScreenRoomCell: View {
}
@ViewBuilder
var footer: some View {
private var footer: some View {
HStack(alignment: .firstTextBaseline) {
ZStack(alignment: .topLeading) {
// Hidden text with 2 lines to maintain consistent height, scaling with dynamic text.
@@ -138,7 +138,7 @@ struct HomeScreenRoomCell: View {
}
@ViewBuilder
var notificationModeIcon: some View {
private var notificationModeIcon: some View {
switch room.notificationMode {
case .none, .allMessages:
EmptyView()
@@ -154,18 +154,10 @@ struct HomeScreenRoomCell: View {
}
@ViewBuilder
var lastMessage: some View {
switch room.lastMessage {
case .loaded(let lastMessage):
private var lastMessage: some View {
if let lastMessage = room.lastMessage {
Text(lastMessage)
.lastMessageFormatting()
case .loading:
Text(HomeScreenRoom.placeholderLastMessage)
.lastMessageFormatting()
.redacted(reason: .placeholder)
case .unknown:
Text(L10n.commonMessage)
.lastMessageFormatting()
}
}
}
@@ -214,8 +206,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider {
name: details.name,
hasUnreads: details.unreadNotificationCount > 0,
timestamp: Date.now.formattedMinimal(),
lastMessage: .init(attributedString: details.lastMessage,
isLoading: false),
lastMessage: details.lastMessage,
notificationMode: details.notificationMode)
}
}