fix issues

pull/1061/head
Ryan ZHAO 2 weeks ago
parent 251869d3ea
commit 448b830716

@ -72,7 +72,7 @@ extension ContextMenuVC {
"resend".localized()
),
accessibilityLabel: (cellViewModel.state == .failedToSync ? "Resync message" : "Resend message")
) { _ in delegate?.retry(cellViewModel) }
) { completion in delegate?.retry(cellViewModel, completion: completion) }
}
static func reply(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?) -> Action {
@ -81,7 +81,7 @@ extension ContextMenuVC {
title: "reply".localized(),
shouldDismissInfoScreen: true,
accessibilityLabel: "Reply to message"
) { _ in delegate?.reply(cellViewModel) }
) { completion in delegate?.reply(cellViewModel, completion: completion) }
}
static func copy(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?) -> Action {
@ -90,7 +90,7 @@ extension ContextMenuVC {
title: "copy".localized(),
feedback: "copied".localized(),
accessibilityLabel: "Copy text"
) { _ in delegate?.copy(cellViewModel) }
) { completion in delegate?.copy(cellViewModel, completion: completion) }
}
static func copySessionID(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?) -> Action {
@ -99,7 +99,7 @@ extension ContextMenuVC {
title: "accountIDCopy".localized(),
feedback: "copied".localized(),
accessibilityLabel: "Copy Session ID"
) { _ in delegate?.copySessionID(cellViewModel) }
) { completion in delegate?.copySessionID(cellViewModel, completion: completion) }
}
static func delete(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?) -> Action {
@ -122,7 +122,7 @@ extension ContextMenuVC {
title: "save".localized(),
feedback: "saved".localized(),
accessibilityLabel: "Save attachment"
) { _ in delegate?.save(cellViewModel) }
) { completion in delegate?.save(cellViewModel, completion: completion) }
}
static func ban(_ cellViewModel: MessageViewModel, _ delegate: ContextMenuActionDelegate?) -> Action {
@ -307,12 +307,12 @@ extension ContextMenuVC {
protocol ContextMenuActionDelegate {
func info(_ cellViewModel: MessageViewModel)
func retry(_ cellViewModel: MessageViewModel)
func reply(_ cellViewModel: MessageViewModel)
func copy(_ cellViewModel: MessageViewModel)
func copySessionID(_ cellViewModel: MessageViewModel)
func retry(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func reply(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func copy(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func copySessionID(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func delete(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func save(_ cellViewModel: MessageViewModel)
func save(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func ban(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func banAndDeleteAllMessages(_ cellViewModel: MessageViewModel, completion: (() -> Void)?)
func react(_ cellViewModel: MessageViewModel, with emoji: EmojiWithSkinTones)

@ -1309,7 +1309,7 @@ extension ConversationVC:
}
func handleReplyButtonTapped(for cellViewModel: MessageViewModel) {
reply(cellViewModel)
reply(cellViewModel, completion: nil)
}
func startThread(
@ -1883,7 +1883,7 @@ extension ConversationVC:
}
}
func retry(_ cellViewModel: MessageViewModel) {
func retry(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
guard cellViewModel.id != MessageViewModel.optimisticUpdateId else {
guard
let optimisticMessageId: UUID = cellViewModel.optimisticMessageId,
@ -1895,7 +1895,10 @@ extension ConversationVC:
title: "theError".localized(),
body: .text("shareExtensionDatabaseError".localized()),
cancelTitle: "okay".localized(),
cancelStyle: .alert_text
cancelStyle: .alert_text,
afterClosed: {
completion?()
}
)
)
@ -1905,6 +1908,7 @@ extension ConversationVC:
// Try to send the optimistic message again
sendMessage(optimisticData: optimisticMessageData)
completion?()
return
}
@ -1953,9 +1957,11 @@ extension ConversationVC:
using: dependencies
)
}
completion?()
}
func reply(_ cellViewModel: MessageViewModel) {
func reply(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
let maybeQuoteDraft: QuotedReplyModel? = QuotedReplyModel.quotedReplyForSending(
threadId: self.viewModel.threadData.threadId,
authorId: cellViewModel.authorId,
@ -1976,9 +1982,10 @@ extension ConversationVC:
isOutgoing: (cellViewModel.variant == .standardOutgoing)
)
_ = snInputView.becomeFirstResponder()
completion?()
}
func copy(_ cellViewModel: MessageViewModel) {
func copy(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
switch cellViewModel.cellType {
case .typingIndicator, .dateHeader, .unreadMarker: break
@ -2014,9 +2021,11 @@ extension ConversationVC:
inset: Values.largeSpacing + (self?.inputAccessoryView?.frame.height ?? 0)
)
}
completion?()
}
func copySessionID(_ cellViewModel: MessageViewModel) {
func copySessionID(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
guard cellViewModel.variant == .standardIncoming else { return }
UIPasteboard.general.string = cellViewModel.authorId
@ -2028,6 +2037,8 @@ extension ConversationVC:
inset: Values.largeSpacing + (self?.inputAccessoryView?.frame.height ?? 0)
)
}
completion?()
}
func delete(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
@ -2114,12 +2125,12 @@ extension ConversationVC:
inset: (self?.inputAccessoryView?.frame.height ?? Values.mediumSpacing) + Values.smallSpacing
)
}
completion?()
}
}
)
},
afterClosed: { [weak self] in
completion?()
self?.becomeFirstResponder()
}
)
@ -2132,7 +2143,7 @@ extension ConversationVC:
}
}
func save(_ cellViewModel: MessageViewModel) {
func save(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
guard cellViewModel.cellType == .mediaMessage else { return }
let mediaAttachments: [(Attachment, String)] = (cellViewModel.attachments ?? [])
@ -2191,6 +2202,8 @@ extension ConversationVC:
)
}
}
completion?()
}
func ban(_ cellViewModel: MessageViewModel, completion: (() -> Void)?) {
@ -2226,23 +2239,22 @@ extension ConversationVC:
.receive(on: DispatchQueue.main, using: dependencies)
.sinkUntilComplete(
receiveCompletion: { result in
switch result {
case .finished:
DispatchQueue.main.async { [weak self] in
DispatchQueue.main.async { [weak self] in
switch result {
case .finished:
self?.viewModel.showToast(
text: "banUserBanned".localized(),
backgroundColor: .backgroundSecondary,
inset: (self?.inputAccessoryView?.frame.height ?? Values.mediumSpacing) + Values.smallSpacing
)
}
case .failure:
DispatchQueue.main.async { [weak self] in
case .failure:
self?.viewModel.showToast(
text: "banErrorFailed".localized(),
backgroundColor: .backgroundSecondary,
inset: (self?.inputAccessoryView?.frame.height ?? Values.mediumSpacing) + Values.smallSpacing
)
}
}
completion?()
}
}
)
@ -2291,23 +2303,22 @@ extension ConversationVC:
.receive(on: DispatchQueue.main, using: dependencies)
.sinkUntilComplete(
receiveCompletion: { result in
switch result {
case .finished:
DispatchQueue.main.async { [weak self] in
DispatchQueue.main.async { [weak self] in
switch result {
case .finished:
self?.viewModel.showToast(
text: "banUserBanned".localized(),
backgroundColor: .backgroundSecondary,
inset: (self?.inputAccessoryView?.frame.height ?? Values.mediumSpacing) + Values.smallSpacing
)
}
case .failure:
DispatchQueue.main.async { [weak self] in
case .failure:
self?.viewModel.showToast(
text: "banErrorFailed".localized(),
backgroundColor: .backgroundSecondary,
inset: (self?.inputAccessoryView?.frame.height ?? Values.mediumSpacing) + Values.smallSpacing
)
}
}
completion?()
}
}
)
@ -2315,7 +2326,6 @@ extension ConversationVC:
self?.becomeFirstResponder()
},
afterClosed: { [weak self] in
completion?()
self?.becomeFirstResponder()
}
)

Loading…
Cancel
Save