/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import Foundation import Shared import Deferred public struct ClientAndTabs: Equatable, CustomStringConvertible { public let client: RemoteClient public let tabs: [RemoteTab] public var description: String { return "" } // See notes in RemoteTabsPanel.swift. public func approximateLastSyncTime() -> Timestamp { if tabs.isEmpty { return client.modified } return tabs.reduce(Timestamp(0), { m, tab in return max(m, tab.lastUsed) }) } } public func ==(lhs: ClientAndTabs, rhs: ClientAndTabs) -> Bool { return (lhs.client == rhs.client) && (lhs.tabs == rhs.tabs) } public protocol RemoteClientsAndTabs: SyncCommands { func wipeClients() -> Deferred> func wipeRemoteTabs() -> Deferred> func wipeTabs() -> Deferred> func getClientGUIDs() -> Deferred>> func getClients() -> Deferred> func getClient(guid: GUID) -> Deferred> func getClient(fxaDeviceId: String) -> Deferred> @available(*, deprecated, message: "use getClient(guid:) instead") func getClientWithId(_ clientID: GUID) -> Deferred> func getClientsAndTabs() -> Deferred> func getTabsForClientWithGUID(_ guid: GUID?) -> Deferred> func insertOrUpdateClient(_ client: RemoteClient) -> Deferred> func insertOrUpdateClients(_ clients: [RemoteClient]) -> Deferred> // Returns number of tabs inserted. func insertOrUpdateTabs(_ tabs: [RemoteTab]) -> Deferred> // Insert into the local client. func insertOrUpdateTabsForClientGUID(_ clientGUID: String?, tabs: [RemoteTab]) -> Deferred> func deleteClient(guid: GUID) -> Success } public struct RemoteTab: Equatable { public let clientGUID: String? public let URL: Foundation.URL public let title: String public let history: [Foundation.URL] public let lastUsed: Timestamp public let icon: Foundation.URL? public static func shouldIncludeURL(_ url: Foundation.URL) -> Bool { let scheme = url.scheme if scheme == "about" { return false } if scheme == "javascript" { return false } if let hostname = url.host?.lowercased() { if hostname == "localhost" { return false } return true } return false } public init(clientGUID: String?, URL: Foundation.URL, title: String, history: [Foundation.URL], lastUsed: Timestamp, icon: Foundation.URL?) { self.clientGUID = clientGUID self.URL = URL self.title = title self.history = history self.lastUsed = lastUsed self.icon = icon } public func withClientGUID(_ clientGUID: String?) -> RemoteTab { return RemoteTab(clientGUID: clientGUID, URL: URL, title: title, history: history, lastUsed: lastUsed, icon: icon) } } public func ==(lhs: RemoteTab, rhs: RemoteTab) -> Bool { return lhs.clientGUID == rhs.clientGUID && lhs.URL == rhs.URL && lhs.title == rhs.title && lhs.history == rhs.history && lhs.lastUsed == rhs.lastUsed && lhs.icon == rhs.icon } extension RemoteTab: CustomStringConvertible { public var description: String { return "" } }