Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-175: Remove CoreData status edit #1148

Merged
merged 4 commits into from
Nov 10, 2023
Merged
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
1 change: 1 addition & 0 deletions Mastodon/Coordinator/SceneCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ private extension SceneCoordinator {
//MARK: - Loading

public extension SceneCoordinator {
@MainActor
kimar marked this conversation as resolved.
Show resolved Hide resolved
func showLoading() {
guard let rootViewController else { return }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,19 +670,30 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte

func tableViewCell(_ cell: UITableViewCell, statusView: StatusView, statusMetricView: StatusMetricView, showEditHistory button: UIButton) {
Task {


await coordinator.showLoading()
kimar marked this conversation as resolved.
Show resolved Hide resolved

let source = DataSourceItem.Source(tableViewCell: cell, indexPath: nil)
guard let item = await self.item(from: source),
case let .status(status) = item else {
assertionFailure("only works for status data provider")
return
}

guard let status = status.object(in: context.managedObjectContext) else {
return await coordinator.hideLoading()
}

do {
let edits = try await context.apiService.getHistory(forStatusID: status.id, authenticationBox: authContext.mastodonAuthenticationBox).value

guard let status = status.object(in: context.managedObjectContext),
let edits = status.editHistory?.sorted(by: { $0.createdAt > $1.createdAt }) else { return }
await coordinator.hideLoading()

let viewModel = StatusEditHistoryViewModel(status: status, edits: edits, appContext: context, authContext: authContext)
_ = await coordinator.present(scene: .editHistory(viewModel: viewModel), from: self, transition: .show)
let viewModel = StatusEditHistoryViewModel(status: status, edits: edits, appContext: context, authContext: authContext)
_ = await coordinator.present(scene: .editHistory(viewModel: viewModel), from: self, transition: .show)
} catch {
await coordinator.hideLoading()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import CoreDataStack
import MetaTextKit
import MastodonCore
import MastodonUI
import MastodonSDK

extension PollOptionView {
public func configure(pollOption option: PollOption) {
Expand Down Expand Up @@ -103,7 +104,7 @@ extension PollOptionView {
}

extension PollOptionView {
public func configure(historyPollOption option: StatusEdit.Poll.Option) {
public func configure(historyPollOption option: Mastodon.Entity.StatusEdit.Poll.Option) {
// background
viewModel.roundedBackgroundViewColor = SystemTheme.systemElevatedBackgroundColor
// metaContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class StatusEditHistoryTableViewCell: UITableViewCell {
NSLayoutConstraint.activate(constraints)
}

func configure(status: Status, statusEdit: StatusEdit, dateText: String) {
func configure(status: Status, statusEdit: Mastodon.Entity.StatusEdit, dateText: String) {
dateLabel.text = dateText
statusHistoryView.statusView.configure(status: status, statusEdit: statusEdit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StatusEditHistoryViewController: UIViewController {

private let tableView: UITableView

var tableViewDataSource: UITableViewDiffableDataSource<Int, StatusEdit>?
var tableViewDataSource: UITableViewDiffableDataSource<Int, Mastodon.Entity.StatusEdit>?
var viewModel: StatusEditHistoryViewModel
private let dateFormatter: DateFormatter

Expand All @@ -28,7 +28,7 @@ class StatusEditHistoryViewController: UIViewController {

super.init(nibName: nil, bundle: nil)

let tableViewDataSource = UITableViewDiffableDataSource<Int, StatusEdit>(tableView: tableView) {tableView, indexPath, itemIdentifier in
let tableViewDataSource = UITableViewDiffableDataSource<Int, Mastodon.Entity.StatusEdit>(tableView: tableView) {tableView, indexPath, itemIdentifier in
guard let cell = tableView.dequeueReusableCell(withIdentifier: StatusEditHistoryTableViewCell.identifier, for: indexPath) as? StatusEditHistoryTableViewCell else {
fatalError("Wrong cell")
}
Expand Down Expand Up @@ -71,7 +71,7 @@ class StatusEditHistoryViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

var snapshot = NSDiffableDataSourceSnapshot<Int, StatusEdit>()
var snapshot = NSDiffableDataSourceSnapshot<Int, Mastodon.Entity.StatusEdit>()
snapshot.appendSections([0])
snapshot.appendItems(viewModel.edits)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import CoreDataStack
import MastodonCore
import MastodonUI
import UIKit
import MastodonSDK

struct StatusEditHistoryViewModel {
let status: Status
let edits: [StatusEdit]
let edits: [Mastodon.Entity.StatusEdit]

let appContext: AppContext
let authContext: AuthContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="22G74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="22222" systemVersion="23B74" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Application" representedClassName="CoreDataStack.Application" syncable="YES">
<attribute name="identifier" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="name" attributeType="String"/>
Expand Down Expand Up @@ -225,7 +225,6 @@
<relationship name="author" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="statuses" inverseEntity="MastodonUser"/>
<relationship name="bookmarkedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="bookmarked" inverseEntity="MastodonUser"/>
<relationship name="card" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Card" inverseName="status" inverseEntity="Card"/>
<relationship name="editHistory" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="StatusEdit" inverseName="status" inverseEntity="StatusEdit"/>
<relationship name="favouritedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="favourite" inverseEntity="MastodonUser"/>
<relationship name="feeds" toMany="YES" deletionRule="Cascade" destinationEntity="Feed" inverseName="status" inverseEntity="Feed"/>
<relationship name="mutedBy" toMany="YES" deletionRule="Nullify" destinationEntity="MastodonUser" inverseName="muted" inverseEntity="MastodonUser"/>
Expand All @@ -239,17 +238,6 @@
<relationship name="replyTo" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="replyFrom" inverseEntity="Status"/>
<relationship name="searchHistories" toMany="YES" deletionRule="Cascade" destinationEntity="SearchHistory" inverseName="status" inverseEntity="SearchHistory"/>
</entity>
<entity name="StatusEdit" representedClassName="CoreDataStack.StatusEdit" syncable="YES">
kimar marked this conversation as resolved.
Show resolved Hide resolved
<attribute name="attachments" optional="YES" attributeType="Binary"/>
<attribute name="content" optional="YES" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="emojis" optional="YES" attributeType="Binary"/>
<attribute name="poll" optional="YES" attributeType="Binary"/>
<attribute name="sensitive" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="spoilerText" optional="YES" attributeType="String"/>
<relationship name="author" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="MastodonUser"/>
<relationship name="status" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Status" inverseName="editHistory" inverseEntity="Status"/>
</entity>
<entity name="Subscription" representedClassName="CoreDataStack.Subscription" syncable="YES">
<attribute name="activedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public final class Status: NSManagedObject {
@NSManaged public private(set) var replyFrom: Set<Status>
@NSManaged public private(set) var notifications: Set<Notification>
@NSManaged public private(set) var searchHistories: Set<SearchHistory>

@NSManaged public private(set) var editHistory: Set<StatusEdit>?

// sourcery: autoUpdatableObject, autoGenerateProperty
@NSManaged public private(set) var updatedAt: Date
Expand Down Expand Up @@ -590,10 +588,6 @@ extension Status: AutoUpdatableObject {
public func update(isReveal: Bool) {
revealedAt = isReveal ? Date() : nil
}

public func update(editHistory: Set<StatusEdit>) {
self.editHistory = editHistory
}
}

extension Status {
Expand Down
226 changes: 0 additions & 226 deletions MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/StatusEdit.swift

This file was deleted.

Loading
Loading