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

View file

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

View file

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