Files
element-x-ios/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift
T
Stefan Ceriu 00cd2ab707 Set visible ranges on the home screen sliding sync view (#342)
* Set visible ranges on the home screen sliding sync view
* Prevent the visible items from being updated while in search mode
* Enable diffs on invalidations as they seem to fix duplicated events in the home screen room list
* Promoted some diffing logs to info from verbose
2022-11-25 17:50:43 +02:00

77 lines
3.2 KiB
Swift

//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Combine
import Foundation
enum MockRoomSummaryProviderState {
case loading
case loaded
}
class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
let roomListPublisher: CurrentValueSubject<[RoomSummary], Never>
let statePublisher: CurrentValueSubject<RoomSummaryProviderState, Never>
let countPublisher: CurrentValueSubject<UInt, Never>
convenience init() {
self.init(state: .loading)
}
init(state: MockRoomSummaryProviderState) {
switch state {
case .loading:
roomListPublisher = .init([])
statePublisher = .init(.cold)
countPublisher = .init(0)
case .loaded:
roomListPublisher = .init(Self.rooms)
statePublisher = .init(.live)
countPublisher = .init(UInt(Self.rooms.count))
}
}
func updateRoomsWithIdentifiers(_ identifiers: [String]) { }
func updateVisibleRange(_ range: ClosedRange<Int>) { }
// MARK: - Private
static let rooms: [RoomSummary] = [
.filled(details: RoomSummaryDetails(id: "1", name: "First room",
isDirect: true,
avatarURLString: nil,
lastMessage: AttributedString("Prosciutto beef ribs pancetta filet mignon kevin hamburger, chuck ham venison picanha. Beef ribs chislic turkey biltong tenderloin."),
lastMessageTimestamp: .now,
unreadNotificationCount: 4)),
.filled(details: RoomSummaryDetails(id: "2",
name: "Second room",
isDirect: true,
avatarURLString: "mockImageURLString",
lastMessage: nil,
lastMessageTimestamp: nil,
unreadNotificationCount: 1)),
.filled(details: RoomSummaryDetails(id: "3",
name: "Third room",
isDirect: true,
avatarURLString: nil,
lastMessage: try? AttributedString(markdown: "**@mock:client.com**: T-bone beef ribs bacon"),
lastMessageTimestamp: .now,
unreadNotificationCount: 0)),
.empty(id: "3")
]
}