Skip to content

Commit

Permalink
• An update without dancing is not an update worth having.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed Mar 10, 2020
1 parent 2decf15 commit 17a2f7d
Show file tree
Hide file tree
Showing 23 changed files with 217 additions and 176 deletions.
1 change: 1 addition & 0 deletions Telegram-Mac/Appearance.swift
Expand Up @@ -2107,6 +2107,7 @@ private func generateIcons(from palette: ColorPalette, bubbled: Bool) -> Telegra
poll_selected_outgoing: { generatePollIcon(NSImage(named: "Icon_PollSelected")!, backgound: palette.webPreviewActivityBubble_outgoing) },
poll_selected_correct_outgoing: { generatePollIcon(NSImage(named: "Icon_PollSelected")!, backgound: palette.greenBubble_outgoing) },
poll_selected_incorrect_outgoing: { generatePollIcon(NSImage(named: "Icon_PollSelectedIncorrect")!, backgound: palette.redBubble_outgoing) },
chat_filter_edit: { NSImage(named: "Icon_FilterEdit")!.precomposed(palette.accentIcon) },
chat_filter_add: { NSImage(named: "Icon_FilterAdd")!.precomposed(palette.accentIcon) },
chat_filter_bots: { NSImage(named: "Icon_FilterBots")!.precomposed(palette.accentIcon) },
chat_filter_channels: { NSImage(named: "Icon_FilterChannels")!.precomposed(palette.accentIcon) },
Expand Down
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_customlist.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_customlist@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 25 additions & 23 deletions Telegram-Mac/ChatListController.swift
Expand Up @@ -559,22 +559,24 @@ class ChatListController : PeersListController {
}))
items.append(.init(L10n.chatListFilterAddChats, handler: {
showModal(with: ShareModalController(SelectCallbackObject(context, excludePeerIds: Set(filter.data.includePeers), additionTopItems: nil, limit: 100 - filter.data.includePeers.count, limitReachedText: L10n.chatListFilterIncludeLimitReached, callback: { peerIds in
return combineLatest(updateChatListFilterSettingsInteractively(postbox: context.account.postbox, { state in
var state = state
return updateChatListFiltersInteractively(postbox: context.account.postbox, { filters in
var filters = filters
filter.data.includePeers = filter.data.includePeers + peerIds
state.withAddedFilter(filter, onlyReplace: true)
return state
}), replaceRemoteChatListFilters(account: context.account)) |> ignoreValues
if let index = filters.firstIndex(where: {$0.id == filter.id }) {
filters[index] = filter
}
return filters
}) |> ignoreValues

})), for: context.window)
}))
items.append(.init(L10n.chatListFilterDelete, handler: {
confirm(for: context.window, header: L10n.chatListFilterConfirmRemoveHeader, information: L10n.chatListFilterConfirmRemoveText, okTitle: L10n.chatListFilterConfirmRemoveOK, successHandler: { _ in
_ = combineLatest(updateChatListFilterSettingsInteractively(postbox: context.account.postbox, { state in
var state = state
state.withRemovedFilter(filter)
return state
}), replaceRemoteChatListFilters(account: context.account)).start()
_ = updateChatListFiltersInteractively(postbox: context.account.postbox, { filters in
var filters = filters
filters.removeAll(where: { $0.id == filter.id })
return filters
}).start()
})

}))
Expand Down Expand Up @@ -670,11 +672,11 @@ class ChatListController : PeersListController {
$0.withUpdatedTabs([]).withUpdatedFilter(nil)
} )
case let .filter(filterId):
filterDisposable.set(filterView.start(next: { [weak self] settings in
filterDisposable.set(filterView.start(next: { [weak self] filters in
var shouldBack: Bool = false
self?.updateFilter { current in
var current = current
if let updated = settings.filters.first(where: { $0.id == filterId }) {
if let updated = filters.first(where: { $0.id == filterId }) {
current = current.withUpdatedFilter(updated)
} else {
shouldBack = true
Expand All @@ -688,18 +690,18 @@ class ChatListController : PeersListController {
}
}))
default:
filterDisposable.set(filterView.start(next: { [weak self] settings in
filterDisposable.set(filterView.start(next: { [weak self] filters in
self?.updateFilter( { current in
var current = current
if let filter = current.filter {
if let updated = settings.filters.first(where: { $0.id == filter.id }) {
if let updated = filters.first(where: { $0.id == filter.id }) {
current = current.withUpdatedFilter(updated)
} else {
current = current.withUpdatedFilter(nil)
}
}

current = current.withUpdatedTabs(settings.filters)
current = current.withUpdatedTabs(filters)
return current
} )
}))
Expand Down Expand Up @@ -936,12 +938,12 @@ class ChatListController : PeersListController {
return combineLatest(chatListFilterPreferences(postbox: context.account.postbox), isEnabled)
|> take(1)
|> deliverOnMainQueue
|> map { [weak self] settings, isEnabled -> [SPopoverItem] in
|> map { [weak self] filters, isEnabled -> [SPopoverItem] in
var items:[SPopoverItem] = []
if isEnabled {
items.append(SPopoverItem(settings.filters.isEmpty ? L10n.chatListFilterSetupEmpty : L10n.chatListFilterSetup, {
items.append(SPopoverItem(filters.isEmpty ? L10n.chatListFilterSetupEmpty : L10n.chatListFilterSetup, {
context.sharedContext.bindings.rootNavigation().push(ChatListFiltersListController(context: context))
}, theme.icons.chat_filter_add))
}, filters.isEmpty ? theme.icons.chat_filter_add : theme.icons.chat_filter_edit))

if self?.filterValue?.filter != nil {
items.append(SPopoverItem(L10n.chatListFilterAll, {
Expand All @@ -951,10 +953,10 @@ class ChatListController : PeersListController {
}))
}

if !settings.filters.isEmpty {
if !filters.isEmpty {
items.append(SPopoverItem(false))
}
for filter in settings.filters {
for filter in filters {
let badge = GlobalBadgeNode(context.account, sharedContext: context.sharedContext, view: View(), layoutChanged: {

}, getColor: { isSelected in
Expand Down Expand Up @@ -1220,15 +1222,15 @@ class ChatListController : PeersListController {
} else {
let prefs = chatListFilterPreferences(postbox: context.account.postbox) |> deliverOnMainQueue |> take(1)

_ = prefs.start(next: { [weak self] settings in
_ = prefs.start(next: { [weak self] filters in
if index == 0 {
self?.updateFilter {
$0.withUpdatedFilter(nil)
}
self?.scrollup()
} else if settings.filters.count >= index {
} else if filters.count >= index {
self?.updateFilter {
$0.withUpdatedFilter(settings.filters[index - 1])
$0.withUpdatedFilter(filters[index - 1])
}
self?.scrollup()
} else {
Expand Down
119 changes: 38 additions & 81 deletions Telegram-Mac/ChatListFilterController.swift
Expand Up @@ -52,23 +52,23 @@ private extension ChatListFilter {
}
}

extension ChatListFiltersState {
mutating func withAddedFilter(_ filter: ChatListFilter, onlyReplace: Bool = false) {
if let index = filters.firstIndex(where: {$0.id == filter.id}) {
filters[index] = filter
} else if !onlyReplace {
filters.append(filter)
}
}
mutating func withRemovedFilter(_ filter: ChatListFilter) {
filters.removeAll(where: {$0.id == filter.id })
}
mutating func withMoveFilter(_ from: Int, _ to: Int) {
filters.insert(filters.remove(at: from), at: to)
}
}
//extension ChatListFiltersState {
// mutating func withAddedFilter(_ filter: ChatListFilter, onlyReplace: Bool = false) {
// if let index = filters.firstIndex(where: {$0.id == filter.id}) {
// filters[index] = filter
// } else if !onlyReplace {
// filters.append(filter)
// }
// }
//
// mutating func withRemovedFilter(_ filter: ChatListFilter) {
// filters.removeAll(where: {$0.id == filter.id })
// }
//
// mutating func withMoveFilter(_ from: Int, _ to: Int) {
// filters.insert(filters.remove(at: from), at: to)
// }
//}

class SelectCallbackObject : ShareObject {
private let callback:([PeerId])->Signal<Never, NoError>
Expand Down Expand Up @@ -237,8 +237,9 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
entries.append(.desc(sectionId: sectionId, index: index, text: .plain(L10n.chatListFilterIncludeHeader), data: .init(color: theme.colors.listGrayText, detectBold: true, viewType: .textTopItem)))
index += 1

let hasAddInclude = state.filter.data.includePeers.count < maximumPeers || state.filter.data.categories != .all

if state.filter.data.includePeers.count < maximumPeers {
if hasAddInclude {
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_add_include, equatable: InputDataEquatable(state), item: { initialSize, stableId in
return GeneralInteractedRowItem(initialSize, stableId: stableId, name: L10n.chatListFilterIncludeAddChat, nameStyle: blueActionButton, type: .none, viewType: includePeers.isEmpty ? .singleItem : .firstItem, action: arguments.addInclude, thumb: GeneralThumbAdditional(thumb: theme.icons.chat_filter_add, textInset: 46, thumbInset: 4))
}))
Expand All @@ -250,7 +251,7 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
var fake:[Int] = []
fake.append(0)
for (i, _) in includePeers.enumerated() {
if state.filter.data.includePeers.count < maximumPeers {
if hasAddInclude {
fake.append(i + 1)
} else {
fake.append(i)
Expand All @@ -271,7 +272,7 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
index += 1
break
} else {
let viewType = bestGeneralViewType(fake, for: state.filter.data.includePeers.count < maximumPeers ? i + 1 : i)
let viewType = bestGeneralViewType(fake, for: hasAddInclude ? i + 1 : i)
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_include(peer.id), equatable: InputDataEquatable(E(viewType: viewType, peer: PeerEquatable(peer))), item: { initialSize, stableId in
return ShortPeerRowItem(initialSize, peer: peer, account: arguments.context.account, stableId: stableId, height: 44, photoSize: NSMakeSize(30, 30), inset: NSEdgeInsets(left: 30, right: 30), viewType: viewType, action: {
arguments.openInfo(peer.id)
Expand All @@ -297,7 +298,10 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
entries.append(.desc(sectionId: sectionId, index: index, text: .plain(L10n.chatListFilterExcludeHeader), data: .init(color: theme.colors.listGrayText, detectBold: true, viewType: .textTopItem)))
index += 1

if state.filter.data.excludePeers.count < maximumPeers {
let hasAddExclude = state.filter.data.excludePeers.count < maximumPeers || !state.filter.data.excludeRead || !state.filter.data.excludeMuted || !state.filter.data.excludeArchived


if hasAddExclude {
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_add_exclude, equatable: InputDataEquatable(state), item: { initialSize, stableId in
return GeneralInteractedRowItem(initialSize, stableId: stableId, name: L10n.chatListFilterExcludeAddChat, nameStyle: blueActionButton, type: .none, viewType: excludePeers.isEmpty ? .singleItem : .firstItem, action: arguments.addExclude, thumb: GeneralThumbAdditional(thumb: theme.icons.chat_filter_add, textInset: 46, thumbInset: 2))
}))
Expand All @@ -309,7 +313,7 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
fake = []
fake.append(0)
for (i, _) in excludePeers.enumerated() {
if state.filter.data.excludePeers.count < maximumPeers {
if hasAddExclude {
fake.append(i + 1)
} else {
fake.append(i)
Expand All @@ -328,7 +332,7 @@ private func chatListFilterEntries(state: ChatListFiltersListState, includePeers
index += 1
break
} else {
let viewType = bestGeneralViewType(fake, for: state.filter.data.excludePeers.count < maximumPeers ? i + 1 : i)
let viewType = bestGeneralViewType(fake, for: hasAddExclude ? i + 1 : i)
entries.append(.custom(sectionId: sectionId, index: index, value: .none, identifier: _id_exclude(peer.id), equatable: InputDataEquatable(E(viewType: viewType, peer: PeerEquatable(peer))), item: { initialSize, stableId in
return ShortPeerRowItem(initialSize, peer: peer, account: arguments.context.account, stableId: stableId, height: 44, photoSize: NSMakeSize(30, 30), inset: NSEdgeInsets(left: 30, right: 30), viewType: viewType, action: {
arguments.openInfo(peer.id)
Expand Down Expand Up @@ -367,12 +371,16 @@ func ChatListFilterController(context: AccountContext, filter: ChatListFilter, i
let updateDisposable = MetaDisposable()

let save:(Bool)->Void = { replace in

_ = combineLatest(updateChatListFilterSettingsInteractively(postbox: context.account.postbox, { state in
var state = state
state.withAddedFilter(stateValue.with { $0.filter }, onlyReplace: replace)
return state
}), replaceRemoteChatListFilters(account: context.account)).start()
_ = updateChatListFiltersInteractively(postbox: context.account.postbox, { filters in
let filter = stateValue.with { $0.filter }
var filters = filters
if let index = filters.firstIndex(where: {$0.id == filter.id}) {
filters[index] = filter
} else if !replace {
filters.append(filter)
}
return filters
}).start()
}


Expand Down Expand Up @@ -611,7 +619,7 @@ func ChatListFilterController(context: AccountContext, filter: ChatListFilter, i
alert(for: context.window, info: L10n.chatListFilterErrorEmpty)
f(.fail(.fields([_id_add_include : .shake])))
} else {
_ = showModalProgress(signal: requestUpdateChatListFilter(account: context.account, id: filter.id, filter: filter), for: context.window).start(error: { error in
_ = showModalProgress(signal: requestUpdateChatListFilter(postbox: context.account.postbox, network: context.account.network, id: filter.id, filter: filter), for: context.window).start(error: { error in
switch error {
case .generic:
alert(for: context.window, info: L10n.unknownError)
Expand All @@ -634,54 +642,3 @@ func ChatListFilterController(context: AccountContext, filter: ChatListFilter, i




/*
// entries.append(.desc(sectionId: sectionId, index: index, text: .plain(L10n.chatListFilterCategoriesHeader), data: .init(color: theme.colors.listGrayText, detectBold: true, viewType: .textTopItem)))
// index += 1
//
//
//
// entries.append(.sectionId(sectionId, type: .normal))
// sectionId += 1
//
// entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_exclude_muted, data: .init(name: L10n.chatListFilterExcludeMuted, color: theme.colors.text, type: .switchable(state.filter.data.excludeMuted), viewType: .firstItem, enabled: true, action: {
// arguments.toggleExcludeMuted(!state.filter.data.excludeMuted)
// })))
// index += 1
//
// entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_exclude_read, data: .init(name: L10n.chatListFilterExcludeRead, color: theme.colors.text, type: .switchable(state.filter.data.excludeRead), viewType: .lastItem, enabled: true, action: {
// arguments.toggleExcludeRead(!state.filter.data.excludeRead)
// })))
// index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_private_chats, data: .init(name: L10n.chatListFilterPrivateChats, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.privateChats)), viewType: .firstItem, enabled: true, action: {
arguments.toggleOption(.privateChats)
})))
index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_secret_chats, data: .init(name: L10n.chatListFilterSecretChat, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.secretChats)), viewType: .innerItem, enabled: true, action: {
arguments.toggleOption(.secretChats)
})))
index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_public_groups, data: .init(name: L10n.chatListFilterPublicGroups, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.publicGroups)), viewType: .innerItem, enabled: true, action: {
arguments.toggleOption(.publicGroups)
})))
index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_private_groups, data: .init(name: L10n.chatListFilterPrivateGroups, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.privateGroups)), viewType: .innerItem, enabled: true, action: {
arguments.toggleOption(.privateGroups)
})))
index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_channels, data: .init(name: L10n.chatListFilterChannels, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.channels)), viewType: .innerItem, enabled: true, action: {
arguments.toggleOption(.channels)
})))
index += 1
entries.append(.general(sectionId: sectionId, index: index, value: .none, error: nil, identifier: _id_bots, data: .init(name: L10n.chatListFilterBots, color: theme.colors.text, type: .selectable(state.filter.data.categories.contains(.bots)), viewType: .lastItem, enabled: true, action: {
arguments.toggleOption(.bots)
})))
index += 1
*/

0 comments on commit 17a2f7d

Please sign in to comment.