Swiftgram/TelegramUI/ChatMediaInputPanelEntries.swift
2017-04-18 19:53:47 +03:00

141 lines
4.8 KiB
Swift

import Postbox
import TelegramCore
import SwiftSignalKit
import Display
enum ChatMediaInputPanelAuxiliaryNamespace: Int32 {
case recentGifs = 3
case recentStickers = 2
case trending = 4
}
enum ChatMediaInputPanelEntryStableId: Hashable {
case recentGifs
case recentPacks
case stickerPack(Int64)
static func ==(lhs: ChatMediaInputPanelEntryStableId, rhs: ChatMediaInputPanelEntryStableId) -> Bool {
switch lhs {
case .recentGifs:
if case .recentGifs = rhs {
return true
} else {
return false
}
case .recentPacks:
if case .recentPacks = rhs {
return true
} else {
return false
}
case let .stickerPack(id):
if case .stickerPack(id) = rhs {
return true
} else {
return false
}
}
}
var hashValue: Int {
switch self {
case .recentGifs:
return 0
case .recentPacks:
return 1
case let .stickerPack(id):
return id.hashValue
}
}
}
enum ChatMediaInputPanelEntry: Comparable, Identifiable {
case recentGifs
case recentPacks
case stickerPack(index: Int, info: StickerPackCollectionInfo, topItem: StickerPackItem?)
var stableId: ChatMediaInputPanelEntryStableId {
switch self {
case .recentGifs:
return .recentGifs
case .recentPacks:
return .recentPacks
case let .stickerPack(_, info, _):
return .stickerPack(info.id.id)
}
}
static func ==(lhs: ChatMediaInputPanelEntry, rhs: ChatMediaInputPanelEntry) -> Bool {
switch lhs {
case .recentGifs:
if case .recentGifs = rhs {
return true
} else {
return false
}
case .recentPacks:
if case .recentPacks = rhs {
return true
} else {
return false
}
case let .stickerPack(index, info, topItem):
if case let .stickerPack(rhsIndex, rhsInfo, rhsTopItem) = rhs, index == rhsIndex, info == rhsInfo, topItem == rhsTopItem {
return true
} else {
return false
}
}
}
static func <(lhs: ChatMediaInputPanelEntry, rhs: ChatMediaInputPanelEntry) -> Bool {
switch lhs {
case .recentGifs:
switch rhs {
case .recentGifs:
return false
default:
return true
}
return true
case .recentPacks:
switch rhs {
case .recentGifs, recentPacks:
return false
default:
return true
}
case let .stickerPack(lhsIndex, lhsInfo, _):
switch rhs {
case .recentGifs, .recentPacks:
return false
case let .stickerPack(rhsIndex, rhsInfo, _):
if lhsIndex == rhsIndex {
return lhsInfo.id.id < rhsInfo.id.id
} else {
return lhsIndex <= rhsIndex
}
}
}
}
func item(account: Account, inputNodeInteraction: ChatMediaInputNodeInteraction) -> ListViewItem {
switch self {
case .recentGifs:
return ChatMediaInputRecentGifsItem(inputNodeInteraction: inputNodeInteraction, selected: {
let collectionId = ItemCollectionId(namespace: ChatMediaInputPanelAuxiliaryNamespace.recentGifs.rawValue, id: 0)
inputNodeInteraction.navigateToCollectionId(collectionId)
})
case .recentPacks:
return ChatMediaInputRecentStickerPacksItem(inputNodeInteraction: inputNodeInteraction, selected: {
let collectionId = ItemCollectionId(namespace: ChatMediaInputPanelAuxiliaryNamespace.recentStickers.rawValue, id: 0)
inputNodeInteraction.navigateToCollectionId(collectionId)
})
case let .stickerPack(index, info, topItem):
return ChatMediaInputStickerPackItem(account: account, inputNodeInteraction: inputNodeInteraction, collectionId: info.id, stickerPackItem: topItem, index: index, selected: {
inputNodeInteraction.navigateToCollectionId(info.id)
})
}
}
}