mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Show user statuses in the rooms list.
This commit is contained in:
@@ -219,6 +219,8 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
|||||||
|
|
||||||
let avatar: RoomAvatar
|
let avatar: RoomAvatar
|
||||||
|
|
||||||
|
let statusEmoji: Character?
|
||||||
|
|
||||||
let canonicalAlias: String?
|
let canonicalAlias: String?
|
||||||
|
|
||||||
let isTombstoned: Bool
|
let isTombstoned: Bool
|
||||||
@@ -246,6 +248,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
|||||||
lastMessage: placeholderLastMessage,
|
lastMessage: placeholderLastMessage,
|
||||||
lastMessageState: nil,
|
lastMessageState: nil,
|
||||||
avatar: .room(id: "", name: "", avatarURL: nil),
|
avatar: .room(id: "", name: "", avatarURL: nil),
|
||||||
|
statusEmoji: nil,
|
||||||
canonicalAlias: nil,
|
canonicalAlias: nil,
|
||||||
isTombstoned: false)
|
isTombstoned: false)
|
||||||
}
|
}
|
||||||
@@ -298,6 +301,7 @@ extension HomeScreenRoom {
|
|||||||
lastMessage: summary.lastMessage,
|
lastMessage: summary.lastMessage,
|
||||||
lastMessageState: summary.homeScreenLastMessageState,
|
lastMessageState: summary.homeScreenLastMessageState,
|
||||||
avatar: summary.avatar,
|
avatar: summary.avatar,
|
||||||
|
statusEmoji: summary.statusEmoji,
|
||||||
canonicalAlias: summary.canonicalAlias,
|
canonicalAlias: summary.canonicalAlias,
|
||||||
isTombstoned: summary.isTombstoned)
|
isTombstoned: summary.isTombstoned)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,16 @@ struct HomeScreenRoomCell: View {
|
|||||||
|
|
||||||
private var header: some View {
|
private var header: some View {
|
||||||
HStack(alignment: .top, spacing: 16) {
|
HStack(alignment: .top, spacing: 16) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
Text(room.name)
|
Text(room.name)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
if let statusEmoji = room.statusEmoji {
|
||||||
|
Text(String(statusEmoji))
|
||||||
|
}
|
||||||
|
}
|
||||||
.font(headerFont)
|
.font(headerFont)
|
||||||
.foregroundColor(.compound.textPrimary)
|
.foregroundColor(.compound.textPrimary)
|
||||||
.lineLimit(1)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
|
||||||
if let timestamp = room.timestamp {
|
if let timestamp = room.timestamp {
|
||||||
@@ -218,6 +224,8 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
|
|||||||
|
|
||||||
static let lastMessageStateRooms = [makeRoom(lastMessageState: .sending), makeRoom(lastMessageState: .failed)]
|
static let lastMessageStateRooms = [makeRoom(lastMessageState: .sending), makeRoom(lastMessageState: .failed)]
|
||||||
|
|
||||||
|
static let roomHeroRooms = [makeRoom(heroes: [.mockDan]), makeRoom(heroes: [.mockErin])]
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
ForEach(genericRooms) { room in
|
ForEach(genericRooms) { room in
|
||||||
@@ -244,6 +252,14 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
|
|||||||
}
|
}
|
||||||
.previewLayout(.sizeThatFits)
|
.previewLayout(.sizeThatFits)
|
||||||
.previewDisplayName("Last Message State")
|
.previewDisplayName("Last Message State")
|
||||||
|
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
ForEach(roomHeroRooms) { room in
|
||||||
|
HomeScreenRoomCell(room: room, isSelected: false, mediaProvider: MediaProviderMock(.init())) { _ in }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.previewLayout(.sizeThatFits)
|
||||||
|
.previewDisplayName("Room Heroes")
|
||||||
}
|
}
|
||||||
|
|
||||||
static func mockRoom(summary: RoomSummary) -> HomeScreenRoom? {
|
static func mockRoom(summary: RoomSummary) -> HomeScreenRoom? {
|
||||||
@@ -261,15 +277,21 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
|
|||||||
userIndicatorController: UserIndicatorControllerMock())
|
userIndicatorController: UserIndicatorControllerMock())
|
||||||
}
|
}
|
||||||
|
|
||||||
static func makeRoom(lastMessageState: RoomSummary.LastMessageState) -> HomeScreenRoom {
|
static func makeRoom(lastMessageState: RoomSummary.LastMessageState? = nil,
|
||||||
|
heroes: [UserProfile] = []) -> HomeScreenRoom {
|
||||||
|
let name = if heroes.count == 1 {
|
||||||
|
heroes[0].displayName ?? heroes[0].id
|
||||||
|
} else {
|
||||||
|
"Foundation and Empire"
|
||||||
|
}
|
||||||
let summary = RoomSummary(room: RoomSDKMock(),
|
let summary = RoomSummary(room: RoomSDKMock(),
|
||||||
id: UUID().uuidString,
|
id: UUID().uuidString,
|
||||||
joinRequestType: nil,
|
joinRequestType: nil,
|
||||||
name: "Foundation and Empire",
|
name: name,
|
||||||
isDirect: false,
|
isDirect: heroes.count == 1,
|
||||||
isSpace: false,
|
isSpace: false,
|
||||||
avatarURL: .mockMXCAvatar,
|
avatarURL: heroes.count == 1 ? nil : .mockMXCAvatar,
|
||||||
heroes: [],
|
heroes: heroes,
|
||||||
activeMembersCount: 0,
|
activeMembersCount: 0,
|
||||||
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
|
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
|
||||||
lastMessageDate: .mock,
|
lastMessageDate: .mock,
|
||||||
|
|||||||
@@ -191,4 +191,9 @@ nonisolated extension RoomSummary {
|
|||||||
return .room(id: id, name: name, avatarURL: avatarURL)
|
return .room(id: id, name: name, avatarURL: avatarURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var statusEmoji: Character? {
|
||||||
|
guard isDirect, case let .heroes(heroes) = avatar, heroes.count == 1 else { return nil }
|
||||||
|
return heroes.first?.status.displayed?.emoji
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user