mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Identity change guards
This commit is contained in:
parent
6b4e17e41e
commit
127fef7078
5 changed files with 48 additions and 2 deletions
|
@ -46,6 +46,7 @@
|
|||
"camera-access.open-system-settings" = "Open system settings";
|
||||
"cancel" = "Cancel";
|
||||
"compose.attachment.uploading" = "Uploading";
|
||||
"compose.attachments-will-be-discarded" = "Attachments will be discarded when changing accounts";
|
||||
"compose.browse" = "Browse";
|
||||
"compose.mark-media-sensitive" = "Mark media as sensitive";
|
||||
"compose.photo-library" = "Photo Library";
|
||||
|
|
|
@ -433,7 +433,7 @@ private extension NewStatusViewController {
|
|||
.map { identity in
|
||||
UIDeferredMenuElement { completion in
|
||||
let action = UIAction(title: identity.handle) { [weak self] _ in
|
||||
self?.viewModel.setIdentity(identity)
|
||||
self?.changeIdentity(identity)
|
||||
}
|
||||
|
||||
if let image = identity.image {
|
||||
|
@ -460,6 +460,34 @@ private extension NewStatusViewController {
|
|||
return changeIdentityButton
|
||||
}
|
||||
|
||||
func changeIdentity(_ identity: Identity) {
|
||||
if viewModel.compositionViewModels.contains(where: { !$0.attachmentViewModels.isEmpty }) {
|
||||
let alertController = UIAlertController(
|
||||
title: nil,
|
||||
message: NSLocalizedString("compose.attachments-will-be-discarded", comment: ""),
|
||||
preferredStyle: .alert)
|
||||
|
||||
let okAction = UIAlertAction(
|
||||
title: NSLocalizedString("ok", comment: ""),
|
||||
style: .destructive) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
|
||||
for compositionViewModel in self.viewModel.compositionViewModels {
|
||||
compositionViewModel.discardAttachments()
|
||||
}
|
||||
|
||||
self.viewModel.setIdentity(identity)
|
||||
}
|
||||
let cancelAction = UIAlertAction(title: NSLocalizedString("cancel", comment: ""), style: .cancel) { _ in }
|
||||
|
||||
alertController.addAction(okAction)
|
||||
alertController.addAction(cancelAction)
|
||||
present(alertController, animated: true)
|
||||
} else {
|
||||
viewModel.setIdentity(identity)
|
||||
}
|
||||
}
|
||||
|
||||
func adjustContentInset(notification: Notification) {
|
||||
guard let keyboardFrameEnd = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect
|
||||
else { return }
|
||||
|
|
|
@ -191,6 +191,10 @@ public extension CompositionViewModel {
|
|||
|
||||
eventsSubject.send(.updateAttachment(publisher))
|
||||
}
|
||||
|
||||
func discardAttachments() {
|
||||
attachmentViewModels = []
|
||||
}
|
||||
}
|
||||
|
||||
public extension CompositionViewModel.PollOption {
|
||||
|
|
|
@ -11,9 +11,9 @@ public final class NewStatusViewModel: ObservableObject {
|
|||
@Published public private(set) var identityContext: IdentityContext
|
||||
@Published public private(set) var authenticatedIdentities = [Identity]()
|
||||
@Published public var canPost = false
|
||||
@Published public var canChangeIdentity = true
|
||||
@Published public var alertItem: AlertItem?
|
||||
@Published public private(set) var postingState = PostingState.composing
|
||||
public let canChangeIdentity: Bool
|
||||
public let inReplyToViewModel: StatusViewModel?
|
||||
public let events: AnyPublisher<Event, Never>
|
||||
|
||||
|
@ -36,6 +36,17 @@ public final class NewStatusViewModel: ObservableObject {
|
|||
events = eventsSubject.eraseToAnyPublisher()
|
||||
visibility = identityContext.identity.preferences.postingDefaultVisibility
|
||||
|
||||
if let inReplyTo = inReplyTo {
|
||||
switch inReplyTo.visibility {
|
||||
case .public, .unlisted:
|
||||
canChangeIdentity = true
|
||||
default:
|
||||
canChangeIdentity = false
|
||||
}
|
||||
} else {
|
||||
canChangeIdentity = true
|
||||
}
|
||||
|
||||
let compositionViewModel: CompositionViewModel
|
||||
|
||||
if let redraft = redraft {
|
||||
|
|
|
@ -101,6 +101,8 @@ public extension StatusViewModel {
|
|||
return URL(string: website)
|
||||
}
|
||||
|
||||
var visibility: Status.Visibility { statusService.status.displayStatus.visibility }
|
||||
|
||||
var repliesCount: Int { statusService.status.displayStatus.repliesCount }
|
||||
|
||||
var reblogsCount: Int { statusService.status.displayStatus.reblogsCount }
|
||||
|
|
Loading…
Reference in a new issue