add block/unblock toast

pull/1023/head
Ryan ZHAO 2 years ago
parent 1904a795b8
commit 1358bc2648

@ -147,9 +147,6 @@ extension ConversationVC:
self.viewModel.threadData.threadIsBlocked == true self.viewModel.threadData.threadIsBlocked == true
else { return false } else { return false }
let message = "blockUnblockDescription"
.put(key: "name", value: self.viewModel.threadData.displayName)
.localized()
let confirmationModal: ConfirmationModal = ConfirmationModal( let confirmationModal: ConfirmationModal = ConfirmationModal(
info: ConfirmationModal.Info( info: ConfirmationModal.Info(
title: String( title: String(
@ -157,11 +154,9 @@ extension ConversationVC:
self.viewModel.threadData.displayName self.viewModel.threadData.displayName
), ),
body: .attributedText( body: .attributedText(
NSAttributedString(string: message) "blockUnblockDescription"
.adding( .put(key: "name", value: self.viewModel.threadData.displayName)
attributes: [ .font: UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize))
range: (message as NSString).range(of: self.viewModel.threadData.displayName)
)
), ),
confirmTitle: "blockUnblock".localized(), confirmTitle: "blockUnblock".localized(),
confirmAccessibility: Accessibility(identifier: "Confirm block"), confirmAccessibility: Accessibility(identifier: "Confirm block"),
@ -904,7 +899,7 @@ extension ConversationVC:
if messageDisappearingConfig.isEnabled { if messageDisappearingConfig.isEnabled {
return "disappearingMessagesFollowSettingOn" return "disappearingMessagesFollowSettingOn"
.put(key: "time", value: expirationTimerString) .put(key: "time", value: expirationTimerString)
.put(key: "disappearing messages type", value: expirationTypeString) .put(key: "disappearingmessagestype", value: expirationTypeString)
.localized() .localized()
} else { } else {
return "disappearingMessagesFollowSettingOff" return "disappearingMessagesFollowSettingOff"

@ -7,7 +7,7 @@ import DifferenceKit
import SessionMessagingKit import SessionMessagingKit
import SessionUtilitiesKit import SessionUtilitiesKit
public class ConversationViewModel: OWSAudioPlayerDelegate { public class ConversationViewModel: OWSAudioPlayerDelegate, NavigatableStateHolder {
public typealias SectionModel = ArraySection<Section, MessageViewModel> public typealias SectionModel = ArraySection<Section, MessageViewModel>
// MARK: - FocusBehaviour // MARK: - FocusBehaviour
@ -46,6 +46,8 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
public static let pageSize: Int = 50 public static let pageSize: Int = 50
public let navigatableState: NavigatableState = NavigatableState()
private var threadId: String private var threadId: String
public let initialThreadVariant: SessionThread.Variant public let initialThreadVariant: SessionThread.Variant
public var sentMessageBeforeUpdate: Bool = false public var sentMessageBeforeUpdate: Bool = false
@ -851,12 +853,23 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
guard self._threadData.wrappedValue.threadVariant == .contact else { return } guard self._threadData.wrappedValue.threadVariant == .contact else { return }
let threadId: String = self.threadId let threadId: String = self.threadId
let displayName: String = self._threadData.wrappedValue.displayName
Storage.shared.writeAsync { db in Storage.shared.writeAsync(
updates: { db in
try Contact try Contact
.filter(id: threadId) .filter(id: threadId)
.updateAllAndConfig(db, Contact.Columns.isBlocked.set(to: false)) .updateAllAndConfig(db, Contact.Columns.isBlocked.set(to: false))
},
completion: { [weak self] _, _ in
self?.showToast(
text: "blockUnblockedUser"
.put(key: "name", value: displayName)
.localized(),
backgroundColor: .backgroundSecondary
)
} }
)
} }
public func expandReactions(for interactionId: Int64) { public func expandReactions(for interactionId: Int64) {

@ -695,10 +695,10 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigationItemSource, Navi
) )
}(), }(),
body: (threadViewModel.threadIsBlocked == true ? .none : body: (threadViewModel.threadIsBlocked == true ? .none :
.text( .attributedText(
"blockDescription" "blockDescription"
.put(key: "name", value: threadViewModel.displayName) .put(key: "name", value: threadViewModel.displayName)
.localized() .localizedFormatted(baseFont: .systemFont(ofSize: Values.smallFontSize))
) )
), ),
confirmTitle: (threadViewModel.threadIsBlocked == true ? confirmTitle: (threadViewModel.threadIsBlocked == true ?
@ -826,13 +826,29 @@ class ThreadSettingsViewModel: SessionTableViewModel, NavigationItemSource, Navi
) { ) {
guard oldBlockedState != isBlocked else { return } guard oldBlockedState != isBlocked else { return }
dependencies.storage.writeAsync{ db in dependencies.storage.writeAsync(
updates: { db in
try Contact try Contact
.filter(id: threadId) .filter(id: threadId)
.updateAllAndConfig( .updateAllAndConfig(
db, db,
Contact.Columns.isBlocked.set(to: isBlocked) Contact.Columns.isBlocked.set(to: isBlocked)
) )
},
completion: { [weak self] _, _ in
self?.showToast(
text: (
isBlocked ?
"blockBlockedUser"
.put(key: "name", value: displayName)
.localized() :
"blockUnblockedUser"
.put(key: "name", value: displayName)
.localized()
),
backgroundColor: .backgroundSecondary
)
} }
)
} }
} }

@ -624,11 +624,12 @@
"emojiReactsCoolDown" = "Slow down! You've sent too many emoji reacts. Try again soon."; "emojiReactsCoolDown" = "Slow down! You've sent too many emoji reacts. Try again soon.";
"disappearingMessagesDescription1" = "This setting applies to messages you send in this conversation."; "disappearingMessagesDescription1" = "This setting applies to messages you send in this conversation.";
"disappearingMessagesFollowSetting" = "Follow Setting"; "disappearingMessagesFollowSetting" = "Follow Setting";
"disappearingMessagesFollowSettingOn" = "Set your messages to disappear <b>{time}</b> after they have been <b>{disappearing messages type}</b>?"; "disappearingMessagesFollowSettingOn" = "Set your messages to disappear <b>{time}</b> after they have been <b>{disappearingmessagestype}</b>?";
"disappearingMessagesFollowSettingOff" = "Messages you send will no longer disappear. Are you sure you want to turn <b>off</b> disappearing messages?"; "disappearingMessagesFollowSettingOff" = "Messages you send will no longer disappear. Are you sure you want to turn <b>off</b> disappearing messages?";
"groupInviteVersion" = "Users must have version {version} or higher to receive invitations"; "groupInviteVersion" = "Users must have version {version} or higher to receive invitations";
"blockBlockedUser" = "Blocked {name}"; "blockBlockedUser" = "Blocked {name}";
"blockUnblockedUser" = "Unblocked {name}"; "blockUnblockedUser" = "Unblocked {name}";
"contentDescriptionCamera" = "Camera";
// NOT IN THE LIST YET // NOT IN THE LIST YET
"APP_STARTUP_EXIT" = "Exit"; "APP_STARTUP_EXIT" = "Exit";

Loading…
Cancel
Save