// // Copyright 2021 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 Foundation @objcMembers public class MockRecentsListService: NSObject, RecentsListServiceProtocol { private var rooms: [MockRoomSummary] private var _invitedRoomListData: MXRoomListData? private var _favoritedRoomListData: MXRoomListData? private var _peopleRoomListData: MXRoomListData? private var _conversationRoomListData: MXRoomListData? private var _lowPriorityRoomListData: MXRoomListData? private var _serverNoticeRoomListData: MXRoomListData? // swiftlint:disable weak_delegate private let multicastDelegate: MXMulticastDelegate = MXMulticastDelegate() // swiftlint:enable weak_delegate public init(withRooms rooms: [MockRoomSummary]) { self.rooms = rooms var invited: [MockRoomSummary] = [] var favorited: [MockRoomSummary] = [] var people: [MockRoomSummary] = [] var conversation: [MockRoomSummary] = [] var lowPriority: [MockRoomSummary] = [] var serverNotice: [MockRoomSummary] = [] rooms.forEach { summary in if summary.isTyped(.invited) { invited.append(summary) } if summary.isTyped(.favorited) { favorited.append(summary) } if summary.isTyped(.direct) { people.append( summary) } if !summary.isTyped([.direct, .invited, .favorited, .lowPriority, .serverNotice]) { conversation.append(summary) } if summary.isTyped(.lowPriority) { lowPriority.append(summary) } if summary.isTyped(.serverNotice) { serverNotice.append(summary) } } _invitedRoomListData = MockRoomListData(withRooms: invited) _favoritedRoomListData = MockRoomListData(withRooms: favorited) _peopleRoomListData = MockRoomListData(withRooms: people) _conversationRoomListData = MockRoomListData(withRooms: conversation) _lowPriorityRoomListData = MockRoomListData(withRooms: lowPriority) _serverNoticeRoomListData = MockRoomListData(withRooms: serverNotice) super.init() } public static func generate(withNumberOfRooms numberOfRooms: Int) -> MockRecentsListService { var rooms: [MockRoomSummary] = [] for i in 0..