mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 00:02:47 +00:00
Merge pull request #2537 from vector-im/riot_2401
Edits history: view model
This commit is contained in:
commit
bf7278ec4f
15 changed files with 821 additions and 1 deletions
|
@ -75,6 +75,16 @@
|
|||
32891D712264DF7B00C82226 /* DeviceVerificationVerifiedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32891D6F2264DF7B00C82226 /* DeviceVerificationVerifiedViewController.swift */; };
|
||||
32891D75226728EE00C82226 /* DeviceVerificationDataLoadingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32891D73226728EE00C82226 /* DeviceVerificationDataLoadingViewController.swift */; };
|
||||
32891D76226728EF00C82226 /* DeviceVerificationDataLoadingViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32891D74226728EE00C82226 /* DeviceVerificationDataLoadingViewController.storyboard */; };
|
||||
32A6001622C661100042C1D9 /* EditHistoryViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6000D22C661100042C1D9 /* EditHistoryViewState.swift */; };
|
||||
32A6001722C661100042C1D9 /* EditHistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6000E22C661100042C1D9 /* EditHistoryViewController.swift */; };
|
||||
32A6001822C661100042C1D9 /* EditHistoryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6000F22C661100042C1D9 /* EditHistoryViewModel.swift */; };
|
||||
32A6001922C661100042C1D9 /* EditHistoryViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001022C661100042C1D9 /* EditHistoryViewModelType.swift */; };
|
||||
32A6001A22C661100042C1D9 /* EditHistoryCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001122C661100042C1D9 /* EditHistoryCoordinator.swift */; };
|
||||
32A6001B22C661100042C1D9 /* EditHistoryViewAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001222C661100042C1D9 /* EditHistoryViewAction.swift */; };
|
||||
32A6001C22C661100042C1D9 /* EditHistoryViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32A6001322C661100042C1D9 /* EditHistoryViewController.storyboard */; };
|
||||
32A6001D22C661100042C1D9 /* EditHistoryCoordinatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001422C661100042C1D9 /* EditHistoryCoordinatorType.swift */; };
|
||||
32A6001E22C661100042C1D9 /* EditHistoryCoordinatorBridgePresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001522C661100042C1D9 /* EditHistoryCoordinatorBridgePresenter.swift */; };
|
||||
32A6002022C66FCF0042C1D9 /* EditHistoryMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32A6001F22C66FCF0042C1D9 /* EditHistoryMessage.swift */; };
|
||||
32B1FEDB21A46F2C00637127 /* TermsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32B1FEDA21A46F2C00637127 /* TermsView.xib */; };
|
||||
32B94DF9228EC26400716A26 /* ReactionsMenuViewAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32B94DF2228EC26400716A26 /* ReactionsMenuViewAction.swift */; };
|
||||
32B94DFA228EC26400716A26 /* ReactionsMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32B94DF3228EC26400716A26 /* ReactionsMenuButton.swift */; };
|
||||
|
@ -607,6 +617,16 @@
|
|||
32891D6F2264DF7B00C82226 /* DeviceVerificationVerifiedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceVerificationVerifiedViewController.swift; sourceTree = "<group>"; };
|
||||
32891D73226728EE00C82226 /* DeviceVerificationDataLoadingViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceVerificationDataLoadingViewController.swift; sourceTree = "<group>"; };
|
||||
32891D74226728EE00C82226 /* DeviceVerificationDataLoadingViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = DeviceVerificationDataLoadingViewController.storyboard; sourceTree = "<group>"; };
|
||||
32A6000D22C661100042C1D9 /* EditHistoryViewState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryViewState.swift; sourceTree = "<group>"; };
|
||||
32A6000E22C661100042C1D9 /* EditHistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryViewController.swift; sourceTree = "<group>"; };
|
||||
32A6000F22C661100042C1D9 /* EditHistoryViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryViewModel.swift; sourceTree = "<group>"; };
|
||||
32A6001022C661100042C1D9 /* EditHistoryViewModelType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryViewModelType.swift; sourceTree = "<group>"; };
|
||||
32A6001122C661100042C1D9 /* EditHistoryCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryCoordinator.swift; sourceTree = "<group>"; };
|
||||
32A6001222C661100042C1D9 /* EditHistoryViewAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryViewAction.swift; sourceTree = "<group>"; };
|
||||
32A6001322C661100042C1D9 /* EditHistoryViewController.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = EditHistoryViewController.storyboard; sourceTree = "<group>"; };
|
||||
32A6001422C661100042C1D9 /* EditHistoryCoordinatorType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryCoordinatorType.swift; sourceTree = "<group>"; };
|
||||
32A6001522C661100042C1D9 /* EditHistoryCoordinatorBridgePresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditHistoryCoordinatorBridgePresenter.swift; sourceTree = "<group>"; };
|
||||
32A6001F22C66FCF0042C1D9 /* EditHistoryMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditHistoryMessage.swift; sourceTree = "<group>"; };
|
||||
32B1FEDA21A46F2C00637127 /* TermsView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TermsView.xib; sourceTree = "<group>"; };
|
||||
32B94DF2228EC26400716A26 /* ReactionsMenuViewAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReactionsMenuViewAction.swift; sourceTree = "<group>"; };
|
||||
32B94DF3228EC26400716A26 /* ReactionsMenuButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReactionsMenuButton.swift; sourceTree = "<group>"; };
|
||||
|
@ -1509,6 +1529,23 @@
|
|||
path = js;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
32A6000C22C661100042C1D9 /* EditHistory */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32A6000D22C661100042C1D9 /* EditHistoryViewState.swift */,
|
||||
32A6000E22C661100042C1D9 /* EditHistoryViewController.swift */,
|
||||
32A6000F22C661100042C1D9 /* EditHistoryViewModel.swift */,
|
||||
32A6001022C661100042C1D9 /* EditHistoryViewModelType.swift */,
|
||||
32A6001122C661100042C1D9 /* EditHistoryCoordinator.swift */,
|
||||
32A6001222C661100042C1D9 /* EditHistoryViewAction.swift */,
|
||||
32A6001322C661100042C1D9 /* EditHistoryViewController.storyboard */,
|
||||
32A6001422C661100042C1D9 /* EditHistoryCoordinatorType.swift */,
|
||||
32A6001522C661100042C1D9 /* EditHistoryCoordinatorBridgePresenter.swift */,
|
||||
32A6001F22C66FCF0042C1D9 /* EditHistoryMessage.swift */,
|
||||
);
|
||||
path = EditHistory;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
32B94DF0228EC26400716A26 /* ReactionsMenu */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -2085,6 +2122,7 @@
|
|||
B1B5568E20EE6C4C00210D55 /* Room */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32A6000C22C661100042C1D9 /* EditHistory */,
|
||||
B1B5568F20EE6C4C00210D55 /* RoomViewController.h */,
|
||||
B1B556A020EE6C4C00210D55 /* RoomViewController.m */,
|
||||
B1B5569620EE6C4C00210D55 /* RoomViewController.xib */,
|
||||
|
@ -3621,6 +3659,7 @@
|
|||
B1B557C020EF5B4500210D55 /* RoomInputToolbarView.xib in Resources */,
|
||||
B1B5583D20EF6E7F00210D55 /* GroupRoomTableViewCell.xib in Resources */,
|
||||
B1B5572D20EE6C4D00210D55 /* RoomParticipantsViewController.xib in Resources */,
|
||||
32A6001C22C661100042C1D9 /* EditHistoryViewController.storyboard in Resources */,
|
||||
B1B5577220EE702800210D55 /* JitsiViewController.xib in Resources */,
|
||||
B1B557D720EF5EA900210D55 /* RoomActivitiesView.xib in Resources */,
|
||||
B1098BF821ECFE65000DDA48 /* KeyBackupSetupPassphraseViewController.storyboard in Resources */,
|
||||
|
@ -3913,6 +3952,7 @@
|
|||
B140B4A621F89E7600E3F5FE /* KeyBackupSetupCoordinatorBridgePresenter.swift in Sources */,
|
||||
B1B5577420EE702900210D55 /* WidgetViewController.m in Sources */,
|
||||
B139C21B21FE5B9200BB68EC /* KeyBackupRecoverFromPassphraseViewModel.swift in Sources */,
|
||||
32A6001E22C661100042C1D9 /* EditHistoryCoordinatorBridgePresenter.swift in Sources */,
|
||||
B1B5574A20EE6C4D00210D55 /* MediaPickerViewController.m in Sources */,
|
||||
B1B5598520EFC3E000210D55 /* RageShakeManager.m in Sources */,
|
||||
3232ABA8225730E100AD6A5C /* DeviceVerificationStartViewState.swift in Sources */,
|
||||
|
@ -3959,6 +3999,7 @@
|
|||
B1B558DD20EF768F00210D55 /* RoomIncomingEncryptedTextMsgBubbleCell.m in Sources */,
|
||||
B1098BE521ECE1FC000DDA48 /* Storyboards.swift in Sources */,
|
||||
3232ABC2225B996200AD6A5C /* Themable.swift in Sources */,
|
||||
32A6001B22C661100042C1D9 /* EditHistoryViewAction.swift in Sources */,
|
||||
3232ABA7225730E100AD6A5C /* DeviceVerificationStartCoordinator.swift in Sources */,
|
||||
B1D4752721EE4E630067973F /* KeyboardAvoider.swift in Sources */,
|
||||
B1D4752821EE4E630067973F /* KeyboardNotification.swift in Sources */,
|
||||
|
@ -4024,6 +4065,7 @@
|
|||
B1B5572620EE6C4D00210D55 /* RoomFilesSearchViewController.m in Sources */,
|
||||
B1B5583120EF66BA00210D55 /* RoomIdOrAliasTableViewCell.m in Sources */,
|
||||
B1CA3A2921EF692B000D1D89 /* UIView.swift in Sources */,
|
||||
32A6001D22C661100042C1D9 /* EditHistoryCoordinatorType.swift in Sources */,
|
||||
F083BDFA1E7009ED00A9B29C /* RoomPreviewData.m in Sources */,
|
||||
B1B557B420EF5AEF00210D55 /* EventDetailsView.m in Sources */,
|
||||
B1B5577E20EE84BF00210D55 /* IncomingCallView.m in Sources */,
|
||||
|
@ -4041,6 +4083,7 @@
|
|||
B1C562CA2289C2690037F12A /* UIGestureRecognizer.swift in Sources */,
|
||||
B1C562CC228AB3510037F12A /* UIStackView.swift in Sources */,
|
||||
B1B557BE20EF5B4500210D55 /* RoomInputToolbarView.m in Sources */,
|
||||
32A6001922C661100042C1D9 /* EditHistoryViewModelType.swift in Sources */,
|
||||
B1B5573B20EE6C4D00210D55 /* FavouritesViewController.m in Sources */,
|
||||
B1B5579920EF575B00210D55 /* AuthInputsView.m in Sources */,
|
||||
B1B5597520EFB02A00210D55 /* InviteRecentTableViewCell.m in Sources */,
|
||||
|
@ -4049,8 +4092,10 @@
|
|||
B1B5573520EE6C4D00210D55 /* GroupDetailsViewController.m in Sources */,
|
||||
B10B3B5B2201DD740072C76B /* KeyBackupBannerCell.swift in Sources */,
|
||||
B1963B32228F1C6B00CBA17F /* BubbleReactionsViewModelType.swift in Sources */,
|
||||
32A6001722C661100042C1D9 /* EditHistoryViewController.swift in Sources */,
|
||||
B1098BFA21ECFE65000DDA48 /* KeyBackupSetupPassphraseViewModel.swift in Sources */,
|
||||
B1B5575220EE6C4D00210D55 /* RoomKeyRequestViewController.m in Sources */,
|
||||
32A6001A22C661100042C1D9 /* EditHistoryCoordinator.swift in Sources */,
|
||||
F083BD1E1E7009ED00A9B29C /* AppDelegate.m in Sources */,
|
||||
B1B558E620EF768F00210D55 /* RoomIncomingAttachmentWithoutSenderInfoBubbleCell.m in Sources */,
|
||||
B1098BFB21ECFE65000DDA48 /* KeyBackupSetupCoordinatorType.swift in Sources */,
|
||||
|
@ -4060,6 +4105,7 @@
|
|||
B1B557D820EF5EA900210D55 /* RoomActivitiesView.m in Sources */,
|
||||
B1B5596620EF9E9B00210D55 /* RoomTableViewCell.m in Sources */,
|
||||
B14F143322144F6500FA0595 /* KeyBackupRecoverFromRecoveryKeyViewModel.swift in Sources */,
|
||||
32A6001822C661100042C1D9 /* EditHistoryViewModel.swift in Sources */,
|
||||
B1B558D020EF768F00210D55 /* RoomOutgoingEncryptedTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.m in Sources */,
|
||||
B1B558CF20EF768F00210D55 /* RoomIncomingEncryptedTextMsgWithPaginationTitleBubbleCell.m in Sources */,
|
||||
B140B4A221F87F7100E3F5FE /* OperationQueue.swift in Sources */,
|
||||
|
@ -4129,6 +4175,7 @@
|
|||
B1B558EE20EF768F00210D55 /* RoomOutgoingAttachmentBubbleCell.m in Sources */,
|
||||
3232ABB52257BE6400AD6A5C /* DeviceVerificationVerifyCoordinatorType.swift in Sources */,
|
||||
32BF994F21FA29A400698084 /* SettingsKeyBackupViewModel.swift in Sources */,
|
||||
32A6002022C66FCF0042C1D9 /* EditHistoryMessage.swift in Sources */,
|
||||
B1B5574920EE6C4D00210D55 /* RiotSplitViewController.m in Sources */,
|
||||
B1B5574E20EE6C4D00210D55 /* DirectoryServerPickerViewController.m in Sources */,
|
||||
B1D211E822C195B400D939BD /* ReactionMenuItemViewData.swift in Sources */,
|
||||
|
@ -4154,6 +4201,7 @@
|
|||
B1C562E8228C7CF20037F12A /* ContextualMenuItemView.swift in Sources */,
|
||||
B14F143022144F6500FA0595 /* KeyBackupRecoverFromRecoveryKeyCoordinatorType.swift in Sources */,
|
||||
B1E5368921FB1E20001F3AFF /* UIButton.swift in Sources */,
|
||||
32A6001622C661100042C1D9 /* EditHistoryViewState.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -37,6 +37,11 @@ internal enum StoryboardScene {
|
|||
|
||||
internal static let initialScene = InitialSceneType<Riot.DeviceVerificationVerifyViewController>(storyboard: DeviceVerificationVerifyViewController.self)
|
||||
}
|
||||
internal enum EditHistoryViewController: StoryboardType {
|
||||
internal static let storyboardName = "EditHistoryViewController"
|
||||
|
||||
internal static let initialScene = InitialSceneType<Riot.EditHistoryViewController>(storyboard: EditHistoryViewController.self)
|
||||
}
|
||||
internal enum KeyBackupRecoverFromPassphraseViewController: StoryboardType {
|
||||
internal static let storyboardName = "KeyBackupRecoverFromPassphraseViewController"
|
||||
|
||||
|
|
67
Riot/Modules/Room/EditHistory/EditHistoryCoordinator.swift
Normal file
67
Riot/Modules/Room/EditHistory/EditHistoryCoordinator.swift
Normal file
|
@ -0,0 +1,67 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
final class EditHistoryCoordinator: EditHistoryCoordinatorType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var editHistoryViewModel: EditHistoryViewModelType
|
||||
private let editHistoryViewController: EditHistoryViewController
|
||||
|
||||
// MARK: Public
|
||||
|
||||
// Must be used only internally
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
weak var delegate: EditHistoryCoordinatorDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(aggregations: MXAggregations,
|
||||
formatter: MXKEventFormatter,
|
||||
event: MXEvent) {
|
||||
|
||||
let editHistoryViewModel = EditHistoryViewModel(aggregations: aggregations, formatter: formatter, event: event)
|
||||
let editHistoryViewController = EditHistoryViewController.instantiate(with: editHistoryViewModel)
|
||||
self.editHistoryViewModel = editHistoryViewModel
|
||||
self.editHistoryViewController = editHistoryViewController
|
||||
}
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
func start() {
|
||||
self.editHistoryViewModel.coordinatorDelegate = self
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.editHistoryViewController
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - EditHistoryViewModelCoordinatorDelegate
|
||||
extension EditHistoryCoordinator: EditHistoryViewModelCoordinatorDelegate {
|
||||
|
||||
func editHistoryViewModelDidClose(_ viewModel: EditHistoryViewModelType) {
|
||||
self.delegate?.editHistoryCoordinatorDidComplete(self)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
// File created from FlowTemplate
|
||||
// $ createRootCoordinator.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc protocol EditHistoryCoordinatorBridgePresenterDelegate {
|
||||
func editHistoryCoordinatorBridgePresenterDelegateDidComplete(_ coordinatorBridgePresenter: EditHistoryCoordinatorBridgePresenter)
|
||||
}
|
||||
|
||||
/// EditHistoryCoordinatorBridgePresenter enables to start EditHistoryCoordinator from a view controller.
|
||||
/// This bridge is used while waiting for global usage of coordinator pattern.
|
||||
@objcMembers
|
||||
final class EditHistoryCoordinatorBridgePresenter: NSObject {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let session: MXSession
|
||||
private let event: MXEvent
|
||||
private var coordinator: EditHistoryCoordinator?
|
||||
|
||||
// MARK: Public
|
||||
|
||||
weak var delegate: EditHistoryCoordinatorBridgePresenterDelegate?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession,
|
||||
event: MXEvent) {
|
||||
self.session = session
|
||||
self.event = event
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
// NOTE: Default value feature is not compatible with Objective-C.
|
||||
// func present(from viewController: UIViewController, animated: Bool) {
|
||||
// self.present(from: viewController, animated: animated)
|
||||
// }
|
||||
|
||||
func present(from viewController: UIViewController, animated: Bool) {
|
||||
|
||||
guard let formatter = self.createEventFormatter(session: self.session) else {
|
||||
//s das
|
||||
return
|
||||
}
|
||||
|
||||
let editHistoryCoordinator = EditHistoryCoordinator(aggregations: self.session.aggregations, formatter: formatter, event: self.event)
|
||||
editHistoryCoordinator.delegate = self
|
||||
|
||||
let navigationController = UINavigationController()
|
||||
navigationController.addChild(editHistoryCoordinator.toPresentable())
|
||||
viewController.present(navigationController, animated: animated, completion: nil)
|
||||
|
||||
editHistoryCoordinator.start()
|
||||
|
||||
self.coordinator = editHistoryCoordinator
|
||||
}
|
||||
|
||||
func dismiss(animated: Bool, completion: (() -> Void)?) {
|
||||
guard let coordinator = self.coordinator else {
|
||||
return
|
||||
}
|
||||
coordinator.toPresentable().dismiss(animated: animated) {
|
||||
self.coordinator = nil
|
||||
|
||||
if let completion = completion {
|
||||
completion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func createEventFormatter(session: MXSession) -> EventFormatter? {
|
||||
guard let formatter = EventFormatter(matrixSession: session) else {
|
||||
print("[EditHistoryCoordinatorBridgePresenter] createEventFormatter: Cannot build formatter")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Use the same event formatter settings as RoomDataSource
|
||||
formatter.treatMatrixUserIdAsLink = true
|
||||
formatter.treatMatrixRoomIdAsLink = true
|
||||
formatter.treatMatrixRoomAliasAsLink = true
|
||||
formatter.treatMatrixGroupIdAsLink = true
|
||||
formatter.eventTypesFilterForMessages = MXKAppSettings.standard()?.eventsFilterForMessages
|
||||
|
||||
// But do not display "...(Edited)"
|
||||
formatter.showEditionMention = false
|
||||
|
||||
return formatter
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - EditHistoryCoordinatorDelegate
|
||||
extension EditHistoryCoordinatorBridgePresenter: EditHistoryCoordinatorDelegate {
|
||||
func editHistoryCoordinatorDidComplete(_ coordinator: EditHistoryCoordinatorType) {
|
||||
self.delegate?.editHistoryCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol EditHistoryCoordinatorDelegate: class {
|
||||
func editHistoryCoordinatorDidComplete(_ coordinator: EditHistoryCoordinatorType)
|
||||
}
|
||||
|
||||
/// `EditHistoryCoordinatorType` is a protocol describing a Coordinator that handle keybackup setup navigation flow.
|
||||
protocol EditHistoryCoordinatorType: Coordinator, Presentable {
|
||||
var delegate: EditHistoryCoordinatorDelegate? { get }
|
||||
}
|
22
Riot/Modules/Room/EditHistory/EditHistoryMessage.swift
Normal file
22
Riot/Modules/Room/EditHistory/EditHistoryMessage.swift
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
struct EditHistoryMessage {
|
||||
let date: Date
|
||||
let message: NSAttributedString
|
||||
}
|
25
Riot/Modules/Room/EditHistory/EditHistoryViewAction.swift
Normal file
25
Riot/Modules/Room/EditHistory/EditHistoryViewAction.swift
Normal file
|
@ -0,0 +1,25 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/// EditHistoryViewController view actions exposed to view model
|
||||
enum EditHistoryViewAction {
|
||||
case loadMore
|
||||
case close
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="V8j-Lb-PgC">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Edit History View Controller-->
|
||||
<scene sceneID="mt5-wz-YKA">
|
||||
<objects>
|
||||
<viewController extendedLayoutIncludesOpaqueBars="YES" automaticallyAdjustsScrollViewInsets="NO" id="V8j-Lb-PgC" customClass="EditHistoryViewController" customModule="Riot" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="EL9-GA-lwo">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9U2-KL-ZVA">
|
||||
<rect key="frame" x="0.0" y="20" width="375" height="647"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e7g-um-WO4">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="500"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="voD-3Q-ryt">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="500"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="A message" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bxI-mu-qng">
|
||||
<rect key="frame" x="20" y="86" width="335" height="250"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="15"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DOt-5E-FjF">
|
||||
<rect key="frame" x="104" y="368" width="167" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<state key="normal" title="Load more"/>
|
||||
<connections>
|
||||
<action selector="loadMoreButtonAction:" destination="V8j-Lb-PgC" eventType="touchUpInside" id="uvI-tt-Nfj"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" priority="750" constant="500" id="glD-Sz-73O"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="voD-3Q-ryt" secondAttribute="bottom" id="63a-5e-ptU"/>
|
||||
<constraint firstItem="voD-3Q-ryt" firstAttribute="centerX" secondItem="e7g-um-WO4" secondAttribute="centerX" id="P2G-mq-gQW"/>
|
||||
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="voD-3Q-ryt" secondAttribute="trailing" id="QgV-SO-5yf"/>
|
||||
<constraint firstItem="voD-3Q-ryt" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="e7g-um-WO4" secondAttribute="leading" id="YPo-u1-PtT"/>
|
||||
<constraint firstAttribute="height" constant="500" id="n8g-KW-BYU"/>
|
||||
<constraint firstItem="voD-3Q-ryt" firstAttribute="top" secondItem="e7g-um-WO4" secondAttribute="top" id="rhQ-96-szL"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailing" secondItem="e7g-um-WO4" secondAttribute="trailing" id="GyG-Fh-PME"/>
|
||||
<constraint firstItem="e7g-um-WO4" firstAttribute="width" secondItem="9U2-KL-ZVA" secondAttribute="width" id="Ok2-WQ-Zgc"/>
|
||||
<constraint firstAttribute="bottom" secondItem="e7g-um-WO4" secondAttribute="bottom" constant="147" id="Y46-NP-zAc"/>
|
||||
<constraint firstItem="e7g-um-WO4" firstAttribute="leading" secondItem="9U2-KL-ZVA" secondAttribute="leading" id="aoV-Yh-AcD"/>
|
||||
<constraint firstItem="e7g-um-WO4" firstAttribute="top" secondItem="9U2-KL-ZVA" secondAttribute="top" id="pFN-bA-SHw"/>
|
||||
</constraints>
|
||||
</scrollView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="0.94509803921568625" green="0.96078431372549022" blue="0.97254901960784312" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="9U2-KL-ZVA" secondAttribute="bottom" id="7Cb-nY-CsO"/>
|
||||
<constraint firstItem="9U2-KL-ZVA" firstAttribute="leading" secondItem="bFg-jh-JZB" secondAttribute="leading" id="GdQ-hK-muG"/>
|
||||
<constraint firstItem="bFg-jh-JZB" firstAttribute="trailing" secondItem="9U2-KL-ZVA" secondAttribute="trailing" id="sbD-ek-vGJ"/>
|
||||
<constraint firstItem="bFg-jh-JZB" firstAttribute="top" secondItem="9U2-KL-ZVA" secondAttribute="top" id="wTB-V6-IHV"/>
|
||||
</constraints>
|
||||
<viewLayoutGuide key="safeArea" id="bFg-jh-JZB"/>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="loadMoreButton" destination="DOt-5E-FjF" id="ktw-U4-efQ"/>
|
||||
<outlet property="messageLabel" destination="bxI-mu-qng" id="pbX-aZ-inC"/>
|
||||
<outlet property="scrollView" destination="9U2-KL-ZVA" id="ojG-2y-X7b"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="zK0-v6-7Wt" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="-3198" y="-647"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
196
Riot/Modules/Room/EditHistory/EditHistoryViewController.swift
Normal file
196
Riot/Modules/Room/EditHistory/EditHistoryViewController.swift
Normal file
|
@ -0,0 +1,196 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
|
||||
final class EditHistoryViewController: UIViewController {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
static let aConstant: Int = 666
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Outlets
|
||||
|
||||
@IBOutlet private weak var scrollView: UIScrollView!
|
||||
|
||||
@IBOutlet private weak var messageLabel: UILabel!
|
||||
@IBOutlet private weak var loadMoreButton: UIButton!
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var viewModel: EditHistoryViewModelType!
|
||||
private var theme: Theme!
|
||||
private var keyboardAvoider: KeyboardAvoider?
|
||||
private var errorPresenter: MXKErrorPresentation!
|
||||
private var activityPresenter: ActivityIndicatorPresenter!
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
class func instantiate(with viewModel: EditHistoryViewModelType) -> EditHistoryViewController {
|
||||
let viewController = StoryboardScene.EditHistoryViewController.initialScene.instantiate()
|
||||
viewController.viewModel = viewModel
|
||||
viewController.theme = ThemeService.shared().theme
|
||||
return viewController
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
self.title = "Edits history"
|
||||
|
||||
self.setupViews()
|
||||
self.keyboardAvoider = KeyboardAvoider(scrollViewContainerView: self.view, scrollView: self.scrollView)
|
||||
self.activityPresenter = ActivityIndicatorPresenter()
|
||||
self.errorPresenter = MXKErrorAlertPresentation()
|
||||
|
||||
self.registerThemeServiceDidChangeThemeNotification()
|
||||
self.update(theme: self.theme)
|
||||
|
||||
self.viewModel.viewDelegate = self
|
||||
|
||||
self.viewModel.process(viewAction: .loadMore)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
self.keyboardAvoider?.startAvoiding()
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
|
||||
self.keyboardAvoider?.stopAvoiding()
|
||||
}
|
||||
|
||||
override var preferredStatusBarStyle: UIStatusBarStyle {
|
||||
return self.theme.statusBarStyle
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func update(theme: Theme) {
|
||||
self.theme = theme
|
||||
|
||||
self.view.backgroundColor = theme.headerBackgroundColor
|
||||
|
||||
if let navigationBar = self.navigationController?.navigationBar {
|
||||
theme.applyStyle(onNavigationBar: navigationBar)
|
||||
}
|
||||
|
||||
|
||||
// TODO:
|
||||
self.messageLabel.textColor = theme.textPrimaryColor
|
||||
|
||||
self.loadMoreButton.backgroundColor = theme.backgroundColor
|
||||
theme.applyStyle(onButton: self.loadMoreButton)
|
||||
}
|
||||
|
||||
private func registerThemeServiceDidChangeThemeNotification() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: .themeServiceDidChangeTheme, object: nil)
|
||||
}
|
||||
|
||||
@objc private func themeDidChange() {
|
||||
self.update(theme: ThemeService.shared().theme)
|
||||
}
|
||||
|
||||
private func setupViews() {
|
||||
let closeBarButtonItem = MXKBarButtonItem(title: "Close", style: .plain) { [weak self] in
|
||||
self?.closeButtonAction()
|
||||
}
|
||||
|
||||
self.navigationItem.rightBarButtonItem = closeBarButtonItem
|
||||
|
||||
self.scrollView.keyboardDismissMode = .interactive
|
||||
|
||||
self.messageLabel.text = "VectorL10n.editHistoryTitle"
|
||||
self.messageLabel.isHidden = true
|
||||
}
|
||||
|
||||
private func render(viewState: EditHistoryViewState) {
|
||||
switch viewState {
|
||||
case .loading:
|
||||
self.renderLoading()
|
||||
case .loaded(let messages, let addedCount):
|
||||
self.renderLoaded(messages: messages, addedCount: addedCount)
|
||||
case .allLoaded:
|
||||
self.renderAllLoaded()
|
||||
case .error(let error):
|
||||
self.render(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func renderLoading() {
|
||||
self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)
|
||||
}
|
||||
|
||||
private func renderLoaded(messages: [EditHistoryMessage], addedCount: Int) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
|
||||
let calendar = Calendar.current
|
||||
|
||||
let attributedText = NSMutableAttributedString()
|
||||
for message in messages {
|
||||
let time=calendar.dateComponents([.hour, .minute], from: message.date)
|
||||
attributedText.append(NSAttributedString(string: "\(time.hour!):\(time.minute!)"))
|
||||
attributedText.append(NSAttributedString(string: " - "))
|
||||
attributedText.append(message.message)
|
||||
attributedText.append(NSAttributedString(string: "\n"))
|
||||
}
|
||||
|
||||
self.messageLabel.attributedText = attributedText
|
||||
self.messageLabel.isHidden = false
|
||||
}
|
||||
|
||||
private func renderAllLoaded() {
|
||||
self.loadMoreButton.isHidden = true
|
||||
}
|
||||
|
||||
private func render(error: Error) {
|
||||
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
|
||||
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction private func loadMoreButtonAction(_ sender: Any) {
|
||||
self.viewModel.process(viewAction: .loadMore)
|
||||
}
|
||||
|
||||
private func closeButtonAction() {
|
||||
self.viewModel.process(viewAction: .close)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - EditHistoryViewModelViewDelegate
|
||||
extension EditHistoryViewController: EditHistoryViewModelViewDelegate {
|
||||
|
||||
func editHistoryViewModel(_ viewModel: EditHistoryViewModelType, didUpdateViewState viewSate: EditHistoryViewState) {
|
||||
self.render(viewState: viewSate)
|
||||
}
|
||||
}
|
147
Riot/Modules/Room/EditHistory/EditHistoryViewModel.swift
Normal file
147
Riot/Modules/Room/EditHistory/EditHistoryViewModel.swift
Normal file
|
@ -0,0 +1,147 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
final class EditHistoryViewModel: EditHistoryViewModelType {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Pagination {
|
||||
static let count: UInt = 2
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let aggregations: MXAggregations
|
||||
private let formatter: MXKEventFormatter
|
||||
private let roomId: String
|
||||
private let event: MXEvent
|
||||
private let messageFormattingQueue: DispatchQueue
|
||||
|
||||
private var nextBatch: String?
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var messages: [EditHistoryMessage] = []
|
||||
var operation: MXHTTPOperation?
|
||||
|
||||
weak var viewDelegate: EditHistoryViewModelViewDelegate?
|
||||
weak var coordinatorDelegate: EditHistoryViewModelCoordinatorDelegate?
|
||||
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(aggregations: MXAggregations,
|
||||
formatter: MXKEventFormatter,
|
||||
event: MXEvent) {
|
||||
self.aggregations = aggregations
|
||||
self.formatter = formatter
|
||||
self.event = event
|
||||
self.roomId = event.roomId
|
||||
self.messageFormattingQueue = DispatchQueue(label: "\(type(of: self)).messageFormattingQueue")
|
||||
}
|
||||
|
||||
deinit {
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func process(viewAction: EditHistoryViewAction) {
|
||||
switch viewAction {
|
||||
case .loadMore:
|
||||
self.loadMoreHistory()
|
||||
case .close:
|
||||
self.coordinatorDelegate?.editHistoryViewModelDidClose(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func loadMoreHistory() {
|
||||
if self.operation != nil {
|
||||
print("[EditHistoryViewModel] loadMoreHistory: operation already pending")
|
||||
return
|
||||
}
|
||||
|
||||
self.update(viewState: .loading)
|
||||
self.operation = self.aggregations.replaceEvents(forEvent: self.event.eventId, inRoom: self.roomId, from: self.nextBatch, limit: Pagination.count, success: { [weak self] (response) in
|
||||
guard let sself = self else {
|
||||
return
|
||||
}
|
||||
|
||||
sself.nextBatch = response.nextBatch
|
||||
sself.operation = nil
|
||||
|
||||
sself.process(editEvents: response.chunk)
|
||||
|
||||
if sself.nextBatch == nil {
|
||||
sself.update(viewState: .allLoaded)
|
||||
}
|
||||
|
||||
}, failure: { [weak self] error in
|
||||
guard let sself = self else {
|
||||
return
|
||||
}
|
||||
|
||||
sself.operation = nil
|
||||
sself.update(viewState: .error(error))
|
||||
})
|
||||
}
|
||||
|
||||
func process(editEvents: [MXEvent]) {
|
||||
self.messageFormattingQueue.async {
|
||||
|
||||
let newMessages = editEvents.reversed()
|
||||
.compactMap { (editEvent) -> EditHistoryMessage? in
|
||||
return self.process(editEvent: editEvent)
|
||||
}
|
||||
|
||||
if newMessages.count > 0 {
|
||||
DispatchQueue.main.async {
|
||||
self.messages = newMessages + self.messages
|
||||
self.update(viewState: .loaded(messages: self.messages, addedCount: newMessages.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func process(editEvent: MXEvent) -> EditHistoryMessage? {
|
||||
// Create a temporary MXEvent that represents this edition
|
||||
guard let editedEvent = self.event.editedEvent(fromReplacementEvent: editEvent) else {
|
||||
print("[EditHistoryViewModel] processEditEvent: Cannot build edited event: \(editEvent.eventId ?? "")")
|
||||
return nil
|
||||
}
|
||||
|
||||
let formatterError = UnsafeMutablePointer<MXKEventFormatterError>.allocate(capacity: 1)
|
||||
guard let message = self.formatter.attributedString(from: editedEvent, with: nil, error: formatterError) else {
|
||||
print("[EditHistoryViewModel] processEditEvent: cannot format(error: \(formatterError)) edited event: \(editEvent.eventId ?? "")")
|
||||
return nil
|
||||
}
|
||||
|
||||
let date = Date(timeIntervalSince1970: TimeInterval(editEvent.originServerTs) / 1000)
|
||||
|
||||
return EditHistoryMessage(date: date, message: message)
|
||||
}
|
||||
|
||||
private func update(viewState: EditHistoryViewState) {
|
||||
self.viewDelegate?.editHistoryViewModel(self, didUpdateViewState: viewState)
|
||||
}
|
||||
}
|
38
Riot/Modules/Room/EditHistory/EditHistoryViewModelType.swift
Normal file
38
Riot/Modules/Room/EditHistory/EditHistoryViewModelType.swift
Normal file
|
@ -0,0 +1,38 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol EditHistoryViewModelViewDelegate: class {
|
||||
func editHistoryViewModel(_ viewModel: EditHistoryViewModelType, didUpdateViewState viewSate: EditHistoryViewState)
|
||||
}
|
||||
|
||||
protocol EditHistoryViewModelCoordinatorDelegate: class {
|
||||
func editHistoryViewModelDidClose(_ viewModel: EditHistoryViewModelType)
|
||||
}
|
||||
|
||||
/// Protocol describing the view model used by `EditHistoryViewController`
|
||||
protocol EditHistoryViewModelType {
|
||||
|
||||
var messages: [EditHistoryMessage] { get set }
|
||||
|
||||
var viewDelegate: EditHistoryViewModelViewDelegate? { get set }
|
||||
var coordinatorDelegate: EditHistoryViewModelCoordinatorDelegate? { get set }
|
||||
|
||||
func process(viewAction: EditHistoryViewAction)
|
||||
}
|
27
Riot/Modules/Room/EditHistory/EditHistoryViewState.swift
Normal file
27
Riot/Modules/Room/EditHistory/EditHistoryViewState.swift
Normal file
|
@ -0,0 +1,27 @@
|
|||
// File created from ScreenTemplate
|
||||
// $ createScreen.sh Room/EditHistory EditHistory
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
/// EditHistoryViewController view state
|
||||
enum EditHistoryViewState {
|
||||
case loading
|
||||
case loaded(messages: [EditHistoryMessage], addedCount: Int)
|
||||
case allLoaded
|
||||
case error(Error)
|
||||
}
|
|
@ -12,3 +12,4 @@
|
|||
#import "RecentsDataSource.h"
|
||||
#import "AvatarGenerator.h"
|
||||
#import "EncryptionInfoView.h"
|
||||
#import "EventFormatter.h"
|
||||
|
|
|
@ -36,6 +36,12 @@ FOUNDATION_EXPORT NSString *const EventFormatterEditedEventLinkAction;
|
|||
*/
|
||||
@interface EventFormatter : MXKEventFormatter
|
||||
|
||||
/**
|
||||
Add a "(Edited)" mention to edited message.
|
||||
Default is YES.
|
||||
*/
|
||||
@property (nonatomic) BOOL showEditionMention;
|
||||
|
||||
/**
|
||||
Text color used to display message edited mention.
|
||||
Default is `textSecondaryColor`.
|
||||
|
|
|
@ -182,7 +182,7 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
attributedString = attributedStringWithRerequestMessage;
|
||||
}
|
||||
}
|
||||
else if (event.contentHasBeenEdited)
|
||||
else if (self.showEditionMention && event.contentHasBeenEdited)
|
||||
{
|
||||
NSMutableAttributedString *attributedStringWithEditMention = [attributedString mutableCopy];
|
||||
|
||||
|
@ -255,6 +255,7 @@ static NSString *const kEventFormatterTimeFormat = @"HH:mm";
|
|||
self.encryptingTextColor = ThemeService.shared.theme.tintColor;
|
||||
self.sendingTextColor = ThemeService.shared.theme.textSecondaryColor;
|
||||
self.errorTextColor = ThemeService.shared.theme.warningColor;
|
||||
self.showEditionMention = YES;
|
||||
self.editionMentionTextColor = ThemeService.shared.theme.textSecondaryColor;
|
||||
|
||||
self.defaultTextFont = [UIFont systemFontOfSize:15];
|
||||
|
|
Loading…
Reference in a new issue