Skip to content

Commit f558ea4

Browse files
author
overtake
committed
- bug fixes and improvments
1 parent 9633d15 commit f558ea4

31 files changed

+498
-386
lines changed

‎Telegram-Mac/ApplicationContext.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,9 @@ final class AuthorizedApplicationContext: NSObject, SplitViewDelegate {
352352
}, with: self, for: .F, priority: .supreme, modifierFlags: [.command, .option])
353353

354354
#if DEBUG
355-
window.set(handler: { () -> KeyHandlerResult in
356-
alert(for: window, info: evaluateApiHash())
357-
return .invoked
358-
}, with: self, for: .T, priority: .supreme, modifierFlags: .command)
355+
// window.set(handler: { () -> KeyHandlerResult in
356+
// return .invoked
357+
// }, with: self, for: .T, priority: .supreme, modifierFlags: .command)
359358
#endif
360359

361360

‎Telegram-Mac/ChannelBlacklistViewController.swift

+115-27
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import SyncCore
1414
import SwiftSignalKit
1515

1616

17+
18+
19+
1720
private final class ChannelBlacklistControllerArguments {
1821
let context: AccountContext
1922

@@ -188,11 +191,11 @@ private struct ChannelBlacklistControllerState: Equatable {
188191
}
189192
}
190193

191-
private func channelBlacklistControllerEntries(view: PeerView, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?) -> [ChannelBlacklistEntry] {
194+
private func channelBlacklistControllerEntries(view: PeerView, state: ChannelBlacklistControllerState, participants: [RenderedChannelParticipant]?, inSearch: Bool) -> [ChannelBlacklistEntry] {
192195

193196
var entries: [ChannelBlacklistEntry] = []
194197

195-
var index:Int32 = 0
198+
var index:Int32 = 10
196199
var sectionId:Int32 = 1
197200

198201

@@ -201,16 +204,12 @@ private func channelBlacklistControllerEntries(view: PeerView, state: ChannelBla
201204
entries.append(.section(sectionId))
202205
sectionId += 1
203206

204-
if peer.hasPermission(.banMembers) {
205-
entries.append(.addMember(sectionId, index, .singleItem))
206-
index += 1
207-
208-
entries.append(.header(sectionId, index, peer.isGroup ? L10n.channelBlacklistDescGroup : L10n.channelBlacklistDescChannel, .textBottomItem))
209-
index += 1
210-
207+
if peer.hasPermission(.banMembers), !inSearch {
208+
entries.append(.addMember(sectionId, 0, .singleItem))
209+
entries.append(.header(sectionId, 1, peer.isGroup ? L10n.channelBlacklistDescGroup : L10n.channelBlacklistDescChannel, .textBottomItem))
211210
}
212211
if let participants = participants {
213-
if !participants.isEmpty {
212+
if !participants.isEmpty, peer.hasPermission(.banMembers) || inSearch {
214213
entries.append(.section(sectionId))
215214
sectionId += 1
216215
}
@@ -245,13 +244,19 @@ private func channelBlacklistControllerEntries(view: PeerView, state: ChannelBla
245244
return entries
246245
}
247246

248-
fileprivate func prepareTransition(left:[AppearanceWrapperEntry<ChannelBlacklistEntry>], right: [AppearanceWrapperEntry<ChannelBlacklistEntry>], initialSize:NSSize, arguments:ChannelBlacklistControllerArguments) -> TableUpdateTransition {
247+
fileprivate func prepareTransition(left:[AppearanceWrapperEntry<ChannelBlacklistEntry>], right: [AppearanceWrapperEntry<ChannelBlacklistEntry>], initialSize:NSSize, arguments:ChannelBlacklistControllerArguments, inSearch: Bool, searchData: TableSearchVisibleData) -> TableUpdateTransition {
249248

250249
let (removed, inserted, updated) = proccessEntriesWithoutReverse(left, right: right) { entry -> TableRowItem in
251250
return entry.entry.item(arguments, initialSize: initialSize)
252251
}
252+
let searchState: TableSearchViewState?
253+
if inSearch {
254+
searchState = .visible(searchData)
255+
} else {
256+
searchState = .none
257+
}
253258

254-
return TableUpdateTransition(deleted: removed, inserted: inserted, updated: updated, animated: true)
259+
return TableUpdateTransition(deleted: removed, inserted: inserted, updated: updated, animated: true, searchState: searchState)
255260
}
256261

257262

@@ -265,6 +270,12 @@ class ChannelBlacklistViewController: EditableViewController<TableView> {
265270
private let updatePeerDisposable = MetaDisposable()
266271
private let disposable:MetaDisposable = MetaDisposable()
267272

273+
private let _inSearch: ValuePromise<Bool> = ValuePromise(false)
274+
private var inSearch: Bool = false {
275+
didSet {
276+
_inSearch.set(self.inSearch)
277+
}
278+
}
268279
init(_ context:AccountContext, peerId:PeerId) {
269280
self.peerId = peerId
270281
super.init(context)
@@ -275,6 +286,8 @@ class ChannelBlacklistViewController: EditableViewController<TableView> {
275286
let context = self.context
276287
let peerId = self.peerId
277288

289+
290+
278291
genericView.getBackgroundColor = {
279292
theme.colors.listBackground
280293
}
@@ -288,6 +301,8 @@ class ChannelBlacklistViewController: EditableViewController<TableView> {
288301
}
289302

290303
let blacklistPromise = Promise<[RenderedChannelParticipant]?>(nil)
304+
let listDisposable = MetaDisposable()
305+
291306
let viewValue:Atomic<PeerView?> = Atomic(value: nil)
292307

293308
let restrict:(PeerId, Bool) -> Void = { [weak self] memberId, unban in
@@ -360,38 +375,85 @@ class ChannelBlacklistViewController: EditableViewController<TableView> {
360375
let peerView = context.account.viewTracker.peerView(peerId)
361376

362377

363-
let (listDisposable, loadMoreControl) = context.peerChannelMemberCategoriesContextsManager.banned(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId, updated: { listState in
378+
var (disposable, loadMoreControl) = context.peerChannelMemberCategoriesContextsManager.banned(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId, updated: { listState in
364379
if case .loading(true) = listState.loadingState, listState.list.isEmpty {
365380
blacklistPromise.set(.single(nil))
366381
} else {
367382
blacklistPromise.set(.single(listState.list))
368383
}
369384
})
385+
386+
listDisposable.set(disposable)
387+
370388
actionsDisposable.add(listDisposable)
371-
389+
372390
let initialSize = atomicSize
373391
let previousEntries:Atomic<[AppearanceWrapperEntry<ChannelBlacklistEntry>]> = Atomic(value: [])
374392

375393

376-
let signal = combineLatest(statePromise.get(), peerView, blacklistPromise.get(), appearanceSignal)
394+
let searchData = TableSearchVisibleData(cancelImage: theme.icons.chatSearchCancel, cancel: { [weak self] in
395+
guard let strongSelf = self else {
396+
return
397+
}
398+
strongSelf.inSearch = !strongSelf.inSearch
399+
400+
(disposable, loadMoreControl) = context.peerChannelMemberCategoriesContextsManager.banned(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId, updated: { listState in
401+
if case .loading(true) = listState.loadingState, listState.list.isEmpty {
402+
blacklistPromise.set(.single(nil))
403+
} else {
404+
blacklistPromise.set(.single(listState.list))
405+
}
406+
})
407+
listDisposable.set(disposable)
408+
409+
}, updateState: { state in
410+
if !state.request.isEmpty {
411+
(disposable, loadMoreControl) = context.peerChannelMemberCategoriesContextsManager.restrictedAndBanned(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.peerId, peerId: peerId, searchQuery: state.request, updated: { listState in
412+
blacklistPromise.set(.single(listState.list))
413+
})
414+
listDisposable.set(disposable)
415+
} else {
416+
(disposable, loadMoreControl) = context.peerChannelMemberCategoriesContextsManager.banned(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId, updated: { listState in
417+
if case .loading(true) = listState.loadingState, listState.list.isEmpty {
418+
blacklistPromise.set(.single(nil))
419+
} else {
420+
blacklistPromise.set(.single(listState.list))
421+
}
422+
})
423+
listDisposable.set(disposable)
424+
}
425+
})
426+
427+
428+
let signal = combineLatest(statePromise.get(), peerView, blacklistPromise.get(), appearanceSignal, _inSearch.get())
377429
|> deliverOnMainQueue
378-
|> map { state, view, blacklist, appearance -> (TableUpdateTransition, PeerView) in
430+
|> map { state, view, blacklist, appearance, inSearch -> (TableUpdateTransition, PeerView) in
379431
_ = viewValue.swap(view)
380-
let entries = channelBlacklistControllerEntries(view: view, state: state, participants: blacklist).map {AppearanceWrapperEntry(entry: $0, appearance: appearance)}
381-
return (prepareTransition(left: previousEntries.swap(entries), right: entries, initialSize: initialSize.modify{$0}, arguments: arguments), view)
432+
let entries = channelBlacklistControllerEntries(view: view, state: state, participants: blacklist, inSearch: inSearch).map {AppearanceWrapperEntry(entry: $0, appearance: appearance)}
433+
return (prepareTransition(left: previousEntries.swap(entries), right: entries, initialSize: initialSize.modify{$0}, arguments: arguments, inSearch: inSearch, searchData: searchData), view)
382434
} |> afterDisposed {
383435
actionsDisposable.dispose()
384-
}
436+
} |> deliverOnMainQueue
385437

386-
disposable.set((signal |> deliverOnMainQueue).start(next: { [weak self] transition, peerView in
387-
if let strongSelf = self {
388-
strongSelf.genericView.merge(with: transition)
389-
strongSelf.readyOnce()
390-
strongSelf.rightBarView.isHidden = strongSelf.genericView.item(at: 0) is SearchEmptyRowItem
391-
if let peer = peerViewMainPeer(peerView) as? TelegramChannel {
392-
strongSelf.rightBarView.isHidden = strongSelf.rightBarView.isHidden || !peer.hasPermission(.banMembers)
393-
}
438+
self.disposable.set(signal.start(next: { [weak self] transition, peerView in
439+
guard let `self` = self else {
440+
return
441+
}
442+
self.genericView.merge(with: transition)
443+
self.readyOnce()
444+
self.rightBarView.isHidden = self.genericView.item(at: 0) is SearchEmptyRowItem
445+
if let peer = peerViewMainPeer(peerView) as? TelegramChannel {
446+
self.rightBarView.isHidden = self.rightBarView.isHidden || !peer.hasPermission(.banMembers)
394447
}
448+
449+
var hasItems: Bool = false
450+
self.genericView.enumerateItems(with: { item -> Bool in
451+
if item is ShortPeerRowItem {
452+
hasItems = true
453+
}
454+
return !hasItems
455+
})
456+
(self.centerBarView as? SearchTitleBarView)?.updateSearchVisibility(hasItems || self.inSearch)
395457
}))
396458

397459
genericView.setScrollHandler { position in
@@ -406,6 +468,32 @@ class ChannelBlacklistViewController: EditableViewController<TableView> {
406468
}
407469
}
408470

471+
override func viewDidAppear(_ animated: Bool) {
472+
super.viewDidAppear(animated)
473+
474+
window?.set(handler: { [weak self] () -> KeyHandlerResult in
475+
guard let `self` = self else {
476+
return .rejected
477+
}
478+
self.inSearch = !self.inSearch
479+
return .invoked
480+
}, with: self, for: .F, modifierFlags: [.command])
481+
}
482+
483+
override func viewWillDisappear(_ animated: Bool) {
484+
super.viewWillDisappear(animated)
485+
window?.removeAllHandlers(for: self)
486+
}
487+
488+
override func getCenterBarViewOnce() -> TitledBarView {
489+
return SearchTitleBarView(controller: self, title:.initialize(string: defaultBarTitle, color: theme.colors.text, font: .medium(.title)), handler: { [weak self] in
490+
guard let strongSelf = self else {
491+
return
492+
}
493+
strongSelf.inSearch = !strongSelf.inSearch
494+
})
495+
}
496+
409497
deinit {
410498
disposable.dispose()
411499
removePeerDisposable.dispose()

‎Telegram-Mac/ChannelMembersViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class ChannelMembersViewController: EditableViewController<TableView> {
420420
}
421421

422422
override func getCenterBarViewOnce() -> TitledBarView {
423-
return PeerInfoTitleBarView(controller: self, title:.initialize(string: defaultBarTitle, color: theme.colors.text, font: .medium(.title)), handler: { [weak self] in
423+
return SearchTitleBarView(controller: self, title:.initialize(string: defaultBarTitle, color: theme.colors.text, font: .medium(.title)), handler: { [weak self] in
424424
self?.searchChannelUsers()
425425
})
426426
}

‎Telegram-Mac/ChatController.swift

+31-6
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
15041504
apply(strongSelf, atDate: atDate)
15051505
} else if presentation.state != .editing, let peer = chatInteraction.peer {
15061506
DispatchQueue.main.async {
1507-
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
1507+
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
15081508
if let strongSelf = strongSelf {
15091509
apply(strongSelf, atDate: date)
15101510
}
@@ -1831,7 +1831,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
18311831
apply(strongSelf, atDate: nil)
18321832
case .scheduled:
18331833
if let peer = strongSelf.chatInteraction.peer {
1834-
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
1834+
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
18351835
if let strongSelf = strongSelf {
18361836
apply(strongSelf, atDate: Int32(date.timeIntervalSince1970))
18371837
}
@@ -2061,7 +2061,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
20612061

20622062
switch strongSelf.mode {
20632063
case .scheduled:
2064-
showModal(with: ScheduledMessageModalController(context: strongSelf.context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
2064+
showModal(with: ScheduledMessageModalController(context: strongSelf.context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
20652065
if let strongSelf = strongSelf {
20662066
let _ = (Sender.enqueue(media: media, context: context, peerId: strongSelf.chatInteraction.peerId, chatInteraction: strongSelf.chatInteraction, atDate: date) |> deliverOnMainQueue).start(completed: scrollAfterSend)
20672067
strongSelf.nextTransaction.set(handler: {})
@@ -2162,7 +2162,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
21622162
}
21632163
switch strongSelf.mode {
21642164
case .scheduled:
2165-
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
2165+
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
21662166
if let controller = strongSelf {
21672167
apply(controller, atDate: date)
21682168
}
@@ -2191,7 +2191,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
21912191
if let atDate = atDate {
21922192
apply(strongSelf, atDate: atDate)
21932193
} else {
2194-
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
2194+
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
21952195
if let strongSelf = strongSelf {
21962196
apply(strongSelf, atDate: date)
21972197
}
@@ -2232,7 +2232,7 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
22322232
switch strongSelf.mode {
22332233
case .scheduled:
22342234
DispatchQueue.main.async {
2235-
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser, scheduleAt: { [weak strongSelf] date in
2235+
showModal(with: ScheduledMessageModalController(context: context, sendWhenOnline: peer.isUser && peer.id != context.peerId, scheduleAt: { [weak strongSelf] date in
22362236
if let strongSelf = strongSelf {
22372237
apply(strongSelf, atDate: date)
22382238
}
@@ -4228,7 +4228,21 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
42284228
return false
42294229
}
42304230

4231+
if list.count == 1, let editState = chatInteraction.presentation.interfaceState.editState, editState.canEditMedia {
4232+
return [DragItem(title: L10n.chatDropEditTitle, desc: L10n.chatDropEditDesc, handler: { [weak self] in
4233+
guard let strongSelf = self else {
4234+
return
4235+
}
4236+
_ = (Sender.generateMedia(for: MediaSenderContainer(path: list[0], isFile: false), account: strongSelf.chatInteraction.context.account) |> deliverOnMainQueue).start(next: { media, _ in
4237+
self?.chatInteraction.update({$0.updatedInterfaceState({$0.updatedEditState({$0?.withUpdatedMedia(media)})})})
4238+
})
4239+
})]
4240+
}
4241+
4242+
42314243
if !list.isEmpty {
4244+
4245+
42324246
let asMediaItem = DragItem(title:tr(L10n.chatDropTitle), desc: tr(L10n.chatDropQuickDesc), handler:{ [weak self] in
42334247
let shift = NSApp.currentEvent?.modifierFlags.contains(.shift) ?? false
42344248
if shift {
@@ -4280,6 +4294,17 @@ class ChatController: EditableViewController<ChatControllerView>, Notifable, Tab
42804294
let data = pasteboard.data(forType: .tiff)
42814295
if let data = data, let image = NSImage(data: data) {
42824296

4297+
if let editState = chatInteraction.presentation.interfaceState.editState, editState.canEditMedia {
4298+
return [DragItem(title: L10n.chatDropEditTitle, desc: L10n.chatDropEditDesc, handler: { [weak self] in
4299+
guard let strongSelf = self else {
4300+
return
4301+
}
4302+
_ = (putToTemp(image: image) |> mapToSignal {Sender.generateMedia(for: MediaSenderContainer(path: $0, isFile: false), account: strongSelf.chatInteraction.context.account)} |> deliverOnMainQueue).start(next: { media, _ in
4303+
self?.chatInteraction.update({$0.updatedInterfaceState({$0.updatedEditState({$0?.withUpdatedMedia(media)})})})
4304+
})
4305+
})]
4306+
}
4307+
42834308
var items:[DragItem] = []
42844309

42854310
let asMediaItem = DragItem(title:tr(L10n.chatDropTitle), desc: tr(L10n.chatDropQuickDesc), handler:{ [weak self] in

0 commit comments

Comments
 (0)