mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 00:49:44 +00:00
Fixes #1342 - Remove custom last message for rooms that don't have one
This commit is contained in:
committed by
Stefan Ceriu
parent
da29c7efde
commit
9fbf70282e
@@ -105,23 +105,7 @@ struct HomeScreenViewStateBindings {
|
|||||||
|
|
||||||
struct HomeScreenRoom: Identifiable, Equatable {
|
struct HomeScreenRoom: Identifiable, Equatable {
|
||||||
static let placeholderLastMessage = AttributedString("Hidden last message")
|
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
|
/// 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
|
/// or a completely unique one for empty items and skeletons
|
||||||
let id: String
|
let id: String
|
||||||
@@ -135,7 +119,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
|||||||
|
|
||||||
var timestamp: String?
|
var timestamp: String?
|
||||||
|
|
||||||
var lastMessage: LastMessage
|
var lastMessage: AttributedString?
|
||||||
|
|
||||||
var avatarURL: URL?
|
var avatarURL: URL?
|
||||||
|
|
||||||
@@ -155,7 +139,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
|||||||
name: "Placeholder room name",
|
name: "Placeholder room name",
|
||||||
hasUnreads: false,
|
hasUnreads: false,
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
lastMessage: .loading,
|
lastMessage: placeholderLastMessage,
|
||||||
isPlaceholder: true)
|
isPlaceholder: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
|||||||
name: details.name,
|
name: details.name,
|
||||||
hasUnreads: details.unreadNotificationCount > 0,
|
hasUnreads: details.unreadNotificationCount > 0,
|
||||||
timestamp: details.lastMessageFormattedTimestamp,
|
timestamp: details.lastMessageFormattedTimestamp,
|
||||||
lastMessage: .init(attributedString: details.lastMessage, isLoading: false),
|
lastMessage: details.lastMessage,
|
||||||
avatarURL: details.avatarURL,
|
avatarURL: details.avatarURL,
|
||||||
notificationMode: notificationMode)
|
notificationMode: notificationMode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder @MainActor
|
@ViewBuilder @MainActor
|
||||||
var avatar: some View {
|
private var avatar: some View {
|
||||||
if dynamicTypeSize < .accessibility3 {
|
if dynamicTypeSize < .accessibility3 {
|
||||||
LoadableAvatarImage(url: room.avatarURL,
|
LoadableAvatarImage(url: room.avatarURL,
|
||||||
name: room.name,
|
name: room.name,
|
||||||
@@ -67,7 +67,7 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var content: some View {
|
private var content: some View {
|
||||||
VStack(alignment: .leading, spacing: 2) {
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
header
|
header
|
||||||
footer
|
footer
|
||||||
@@ -85,7 +85,7 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var header: some View {
|
private var header: some View {
|
||||||
HStack(alignment: .top, spacing: 16) {
|
HStack(alignment: .top, spacing: 16) {
|
||||||
Text(room.name)
|
Text(room.name)
|
||||||
.font(.compound.bodyLGSemibold)
|
.font(.compound.bodyLGSemibold)
|
||||||
@@ -102,7 +102,7 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var footer: some View {
|
private var footer: some View {
|
||||||
HStack(alignment: .firstTextBaseline) {
|
HStack(alignment: .firstTextBaseline) {
|
||||||
ZStack(alignment: .topLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
// Hidden text with 2 lines to maintain consistent height, scaling with dynamic text.
|
// Hidden text with 2 lines to maintain consistent height, scaling with dynamic text.
|
||||||
@@ -138,7 +138,7 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var notificationModeIcon: some View {
|
private var notificationModeIcon: some View {
|
||||||
switch room.notificationMode {
|
switch room.notificationMode {
|
||||||
case .none, .allMessages:
|
case .none, .allMessages:
|
||||||
EmptyView()
|
EmptyView()
|
||||||
@@ -154,18 +154,10 @@ struct HomeScreenRoomCell: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var lastMessage: some View {
|
private var lastMessage: some View {
|
||||||
switch room.lastMessage {
|
if let lastMessage = room.lastMessage {
|
||||||
case .loaded(let lastMessage):
|
|
||||||
Text(lastMessage)
|
Text(lastMessage)
|
||||||
.lastMessageFormatting()
|
.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,
|
name: details.name,
|
||||||
hasUnreads: details.unreadNotificationCount > 0,
|
hasUnreads: details.unreadNotificationCount > 0,
|
||||||
timestamp: Date.now.formattedMinimal(),
|
timestamp: Date.now.formattedMinimal(),
|
||||||
lastMessage: .init(attributedString: details.lastMessage,
|
lastMessage: details.lastMessage,
|
||||||
isLoading: false),
|
|
||||||
notificationMode: details.notificationMode)
|
notificationMode: details.notificationMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user