Navigate back after deleting context parent

This commit is contained in:
Justin Mazzocchi 2021-03-22 21:08:09 -07:00
parent 3bb0d1edc7
commit 9cde68da85
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
3 changed files with 19 additions and 4 deletions

View file

@ -520,11 +520,13 @@ private extension TableViewController {
} }
} }
// swiftlint:disable:next cyclomatic_complexity // swiftlint:disable:next cyclomatic_complexity function_body_length
func handle(event: CollectionItemEvent) { func handle(event: CollectionItemEvent) {
switch event { switch event {
case .ignorableOutput: case .ignorableOutput:
break break
case .contextParentDeleted:
navigationController?.popViewController(animated: true)
case .refresh: case .refresh:
refreshIfAble() refreshIfAble()
case let .share(url): case let .share(url):
@ -533,10 +535,11 @@ private extension TableViewController {
handle(navigation: navigation) handle(navigation: navigation)
case let .attachment(attachmentViewModel, statusViewModel): case let .attachment(attachmentViewModel, statusViewModel):
present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel) present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel)
case let .compose(identity, inReplyToViewModel, redraft, directMessageTo): case let .compose(identity, inReplyToViewModel, redraft, redraftWasContextParent, directMessageTo):
compose(identity: identity, compose(identity: identity,
inReplyToViewModel: inReplyToViewModel, inReplyToViewModel: inReplyToViewModel,
redraft: redraft, redraft: redraft,
redraftWasContextParent: redraftWasContextParent,
directMessageTo: directMessageTo) directMessageTo: directMessageTo)
case let .confirmDelete(statusViewModel, redraft): case let .confirmDelete(statusViewModel, redraft):
confirmDelete(statusViewModel: statusViewModel, redraft: redraft) confirmDelete(statusViewModel: statusViewModel, redraft: redraft)
@ -619,7 +622,12 @@ private extension TableViewController {
func compose(identity: Identity?, func compose(identity: Identity?,
inReplyToViewModel: StatusViewModel?, inReplyToViewModel: StatusViewModel?,
redraft: Status?, redraft: Status?,
redraftWasContextParent: Bool,
directMessageTo: AccountViewModel?) { directMessageTo: AccountViewModel?) {
if redraftWasContextParent {
navigationController?.popViewController(animated: true)
}
rootViewModel?.navigationViewModel?.presentedNewStatusViewModel = rootViewModel?.newStatusViewModel( rootViewModel?.navigationViewModel?.presentedNewStatusViewModel = rootViewModel?.newStatusViewModel(
identityContext: viewModel.identityContext, identityContext: viewModel.identityContext,
identity: identity, identity: identity,

View file

@ -6,12 +6,14 @@ import ServiceLayer
public enum CollectionItemEvent { public enum CollectionItemEvent {
case ignorableOutput case ignorableOutput
case contextParentDeleted
case refresh case refresh
case navigation(Navigation) case navigation(Navigation)
case attachment(AttachmentViewModel, StatusViewModel) case attachment(AttachmentViewModel, StatusViewModel)
case compose(identity: Identity? = nil, case compose(identity: Identity? = nil,
inReplyTo: StatusViewModel? = nil, inReplyTo: StatusViewModel? = nil,
redraft: Status? = nil, redraft: Status? = nil,
redraftWasContextParent: Bool = false,
directMessageTo: AccountViewModel? = nil) directMessageTo: AccountViewModel? = nil)
case confirmDelete(StatusViewModel, redraft: Bool) case confirmDelete(StatusViewModel, redraft: Bool)
case confirmUnfollow(AccountViewModel) case confirmUnfollow(AccountViewModel)

View file

@ -315,14 +315,17 @@ public extension StatusViewModel {
} }
func delete() { func delete() {
let isContextParent = configuration.isContextParent
eventsSubject.send( eventsSubject.send(
statusService.delete() statusService.delete()
.map { _ in .ignorableOutput } .map { _ in isContextParent ? .contextParentDeleted : .ignorableOutput }
.eraseToAnyPublisher()) .eraseToAnyPublisher())
} }
func deleteAndRedraft() { func deleteAndRedraft() {
let identityContext = self.identityContext let identityContext = self.identityContext
let isContextParent = configuration.isContextParent
eventsSubject.send( eventsSubject.send(
statusService.deleteAndRedraft() statusService.deleteAndRedraft()
@ -339,7 +342,9 @@ public extension StatusViewModel {
inReplyToViewModel = nil inReplyToViewModel = nil
} }
return .compose(inReplyTo: inReplyToViewModel, redraft: redraft) return .compose(inReplyTo: inReplyToViewModel,
redraft: redraft,
redraftWasContextParent: isContextParent)
} }
.eraseToAnyPublisher()) .eraseToAnyPublisher())
} }