Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

fixed two bugs when switching accounts from the ComposeView #123

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class CompositionViewModel: AttachmentsRenderingViewModel, Observab
public let canRemoveAttachments = true

private let eventsSubject: PassthroughSubject<Event, Never>
private let maxCharacters: Int
@Published private var maxCharacters: Int
private var cancellables = Set<AnyCancellable>()

init(eventsSubject: PassthroughSubject<Event, Never>, maxCharacters: Int?) {
Expand Down Expand Up @@ -62,8 +62,8 @@ public final class CompositionViewModel: AttachmentsRenderingViewModel, Observab

return tokens.map(\.countShorteningIfURL).reduce(tokens.count - 1, +)
}
.combineLatest($displayContentWarning, $contentWarning)
.map { (maxCharacters ?? Self.defaultMaxCharacters) - ($0 + ($1 ? $2.count : 0)) }
.combineLatest($displayContentWarning, $contentWarning, $maxCharacters)
.map { ($3) - ($0 + ($1 ? $2.count : 0)) }
.assign(to: &$remainingCharacters)

$displayContentWarning.filter { $0 }.assign(to: &$sensitive)
Expand All @@ -86,6 +86,10 @@ public final class CompositionViewModel: AttachmentsRenderingViewModel, Observab
public func removeAttachment(viewModel: AttachmentViewModel) {
attachmentViewModels.removeAll { $0 === viewModel }
}

public func setMaxCharactersOrDefault(_ newMaxCharacters: Int?) {
maxCharacters = newMaxCharacters ?? Self.defaultMaxCharacters
}
}

public extension CompositionViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public final class NewStatusViewModel: ObservableObject {
.sink { [weak self] in self?.handle(event: $0) }
.store(in: &cancellables)

$identityContext
.map { $0.identity.instance?.maxTootChars }
.sink { [weak self] maxTootChars in
self?.compositionViewModels.forEach { cvm in
cvm.setMaxCharactersOrDefault(maxTootChars)
}
}
.store(in: &cancellables)

if let identity = identity {
setIdentity(identity)
}
Expand Down
11 changes: 7 additions & 4 deletions Views/UIKit/CompositionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,14 @@ private extension CompositionView {
self.changeIdentityButton.accessibilityLabel = $0.identity.handle
self.changeIdentityButton.accessibilityHint =
NSLocalizedString("compose.change-identity-button.accessibility-hint", comment: "")
}
.store(in: &cancellables)

parentViewModel.identityContext.$authenticatedOtherIdentities
.sink { [weak self] in self?.changeIdentityButton.menu = self?.changeIdentityMenu(identities: $0) }
$0.$authenticatedOtherIdentities
.sink { [weak self] authenticatedOtherIdentities in
self?.changeIdentityButton.menu =
self?.changeIdentityMenu(identities: authenticatedOtherIdentities)
}
.store(in: &self.cancellables)
}
.store(in: &cancellables)

viewModel.$attachmentViewModels
Expand Down