mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Improvements to logging (#457)
* Use `.info` logging in most places. * Remove old objc logging support. * Fix table view controller. * Make sure timeline item content isn't logged. * Add tests.
This commit is contained in:
@@ -37,15 +37,15 @@ final class AnalyticsPromptCoordinator: CoordinatorProtocol {
|
||||
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] result in
|
||||
MXLog.debug("AnalyticsPromptViewModel did complete with result: \(result).")
|
||||
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .enable:
|
||||
MXLog.info("Enable Analytics")
|
||||
Analytics.shared.optIn(with: self.parameters.userSession)
|
||||
self.callback?()
|
||||
case .disable:
|
||||
MXLog.info("Disable Analytics")
|
||||
Analytics.shared.optOut()
|
||||
self.callback?()
|
||||
}
|
||||
|
||||
@@ -63,7 +63,6 @@ final class LoginCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("LoginViewModel did callback with result: \(action).")
|
||||
|
||||
switch action {
|
||||
case .selectServer:
|
||||
@@ -118,6 +117,8 @@ final class LoginCoordinator: CoordinatorProtocol {
|
||||
|
||||
/// Processes an error to either update the flow or display it to the user.
|
||||
private func handleError(_ error: AuthenticationServiceError) {
|
||||
MXLog.info("Error occurred: \(error)")
|
||||
|
||||
switch error {
|
||||
case .invalidCredentials:
|
||||
viewModel.displayError(.alert(ElementL10n.authInvalidLoginParam))
|
||||
@@ -150,6 +151,7 @@ final class LoginCoordinator: CoordinatorProtocol {
|
||||
|
||||
/// Requests the authentication coordinator to log in using the specified credentials.
|
||||
private func login(username: String, password: String) {
|
||||
MXLog.info("Starting login with password.")
|
||||
startLoading(isInteractionBlocking: true)
|
||||
|
||||
Task {
|
||||
|
||||
+2
-1
@@ -49,7 +49,6 @@ final class ServerSelectionCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("ServerSelectionViewModel did callback with action: \(action).")
|
||||
|
||||
switch action {
|
||||
case .confirm(let homeserverAddress):
|
||||
@@ -87,9 +86,11 @@ final class ServerSelectionCoordinator: CoordinatorProtocol {
|
||||
Task {
|
||||
switch await authenticationService.configure(for: homeserverAddress) {
|
||||
case .success:
|
||||
MXLog.info("Selected homeserver: \(homeserverAddress)")
|
||||
callback?(.updated)
|
||||
stopLoading()
|
||||
case .failure(let error):
|
||||
MXLog.info("Invalid homeserver: \(homeserverAddress)")
|
||||
stopLoading()
|
||||
handleError(error)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ final class SoftLogoutCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] result in
|
||||
guard let self else { return }
|
||||
MXLog.debug("[SoftLogoutCoordinator] SoftLogoutViewModel did complete with result: \(result).")
|
||||
MXLog.info("[SoftLogoutCoordinator] SoftLogoutViewModel did complete with result: \(result).")
|
||||
|
||||
switch result {
|
||||
case .login(let password):
|
||||
@@ -112,8 +112,6 @@ final class SoftLogoutCoordinator: CoordinatorProtocol {
|
||||
|
||||
/// Shows the forgot password screen.
|
||||
@MainActor private func showForgotPasswordScreen() {
|
||||
MXLog.debug("[SoftLogoutCoordinator] showForgotPasswordScreen")
|
||||
|
||||
viewModel.displayError(.alert("Not implemented."))
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ final class BugReportCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] result in
|
||||
guard let self else { return }
|
||||
MXLog.debug("BugReportViewModel did complete with result: \(result).")
|
||||
MXLog.info("BugReportViewModel did complete with result: \(result).")
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.completion?(.cancel)
|
||||
|
||||
@@ -41,7 +41,7 @@ final class EmojiPickerScreenCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("EmojiPickerScreenViewModel did complete with result: \(action).")
|
||||
|
||||
switch action {
|
||||
case let .emojiSelected(emoji: emoji):
|
||||
self.callback?(.emojiSelected(emoji: emoji, itemId: self.parameters.itemId))
|
||||
|
||||
@@ -42,7 +42,7 @@ final class FilePreviewCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("FilePreviewViewModel did complete with result: \(action).")
|
||||
|
||||
switch action {
|
||||
case .cancel:
|
||||
self.callback?(.cancel)
|
||||
|
||||
@@ -29,8 +29,8 @@ final class OnboardingCoordinator: CoordinatorProtocol {
|
||||
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
MXLog.debug("OnboardingViewModel did complete with result: \(action).")
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .login:
|
||||
self.callback?(.login)
|
||||
|
||||
@@ -45,6 +45,7 @@ final class RoomDetailsCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .requestMemberDetailsPresentation(let members):
|
||||
self.presentRoomMemberDetails(members)
|
||||
|
||||
@@ -47,7 +47,7 @@ class RoomDetailsViewModel: RoomDetailsViewModelType, RoomDetailsViewModelProtoc
|
||||
case .success(let members):
|
||||
self.members = members
|
||||
case .failure(let error):
|
||||
MXLog.debug("Failed to retrieve room members: \(error)")
|
||||
MXLog.error("Failed retrieving room members: \(error)")
|
||||
state.bindings.alertInfo = AlertInfo(id: .alert(ElementL10n.unknownError))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ final class RoomMemberDetailsCoordinator: CoordinatorProtocol {
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("RoomMemberDetailsViewModel did complete with result: \(action).")
|
||||
|
||||
switch action {
|
||||
case .cancel:
|
||||
self.callback?(.cancel)
|
||||
|
||||
@@ -60,7 +60,7 @@ class RoomMemberDetailsViewModel: RoomMemberDetailsViewModelType, RoomMemberDeta
|
||||
state.members[index].avatar = image
|
||||
}
|
||||
case .failure(let error):
|
||||
MXLog.debug("Failed to retrieve room member avatar: \(error)")
|
||||
MXLog.error("Failed to retrieve room member avatar: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
viewModel?.callback = { [weak self] result in
|
||||
viewModel?.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("RoomScreenViewModel did complete with result: \(result).")
|
||||
switch result {
|
||||
|
||||
switch action {
|
||||
case .displayRoomDetails:
|
||||
self.displayRoomDetails()
|
||||
case .displayVideo(let fileURL, let title), .displayFile(let fileURL, let title):
|
||||
@@ -103,8 +103,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
|
||||
coordinator.callback = { [weak self] action in
|
||||
switch action {
|
||||
case let .emojiSelected(emoji: emoji, itemId: itemId):
|
||||
MXLog.debug("Selected \(emoji) for \(itemId)")
|
||||
self?.navigationStackCoordinator.setSheetCoordinator(nil)
|
||||
MXLog.debug("Save \(emoji) for \(itemId)")
|
||||
Task {
|
||||
await timelineController.sendReaction(emoji, for: itemId)
|
||||
}
|
||||
|
||||
@@ -242,8 +242,6 @@ class TimelineTableViewController: UIViewController {
|
||||
|
||||
updateTopPadding()
|
||||
|
||||
guard snapshot.numberOfItems != previousLayout.numberOfItems else { return }
|
||||
|
||||
if previousLayout.isBottomVisible {
|
||||
scrollToBottom(animated: false)
|
||||
} else if let pinnedItem = previousLayout.pinnedItem {
|
||||
@@ -357,15 +355,19 @@ class TimelineTableViewController: UIViewController {
|
||||
|
||||
extension TimelineTableViewController: UITableViewDelegate {
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
let isAtBottom = isAtBottom()
|
||||
|
||||
// Only update the binding on changes to avoid needlessly recomputing the hierarchy when scrolling.
|
||||
if scrollToBottomButtonVisible != isAtBottom {
|
||||
// Dispatch to fix runtime warning about making changes during a view update.
|
||||
DispatchQueue.main.async { self.scrollToBottomButtonVisible = isAtBottom }
|
||||
}
|
||||
|
||||
paginateBackwardsPublisher.send(())
|
||||
|
||||
// Dispatch to fix runtime warning about making changes during a view update.
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let self else { return }
|
||||
|
||||
let isAtBottom = self.isAtBottom()
|
||||
|
||||
// Only update the binding on changes to avoid needlessly recomputing the hierarchy when scrolling.
|
||||
if self.scrollToBottomButtonVisible != isAtBottom {
|
||||
self.scrollToBottomButtonVisible = isAtBottom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: ScrollViewAdapter Methods
|
||||
|
||||
@@ -40,10 +40,10 @@ final class SettingsCoordinator: CoordinatorProtocol {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SettingsViewModel(withUserSession: parameters.userSession)
|
||||
viewModel.callback = { [weak self] result in
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
MXLog.debug("SettingsViewModel did complete with result: \(result).")
|
||||
switch result {
|
||||
|
||||
switch action {
|
||||
case .close:
|
||||
self.callback?(.dismiss)
|
||||
case .toggleAnalytics:
|
||||
|
||||
Reference in New Issue
Block a user