Skip to content

Commit

Permalink
Merge pull request #1136 from mastodon/remove_coredata/following
Browse files Browse the repository at this point in the history
Don't persist following
  • Loading branch information
zeitschlag authored Nov 9, 2023
2 parents a3733ea + 77bf1ab commit 7004a22
Show file tree
Hide file tree
Showing 45 changed files with 853 additions and 461 deletions.
74 changes: 34 additions & 40 deletions Mastodon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@
D8318A882A4468D300C0FB73 /* NotificationSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8318A872A4468D300C0FB73 /* NotificationSettingsViewController.swift */; };
D8318A8A2A4468DC00C0FB73 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8318A892A4468DC00C0FB73 /* AboutViewController.swift */; };
D8363B1629469CE200A74079 /* OnboardingNextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8363B1529469CE200A74079 /* OnboardingNextView.swift */; };
D84FA0932AE6915800987F47 /* MBProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = D84FA0922AE6915800987F47 /* MBProgressHUD */; };
D852C23C2AC5D02C00309232 /* AboutInstanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23B2AC5D02C00309232 /* AboutInstanceViewController.swift */; };
D852C23E2AC5D03300309232 /* InstanceRulesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23D2AC5D03300309232 /* InstanceRulesViewController.swift */; };
D87364F92AE28DB500C8F919 /* Kanna in Frameworks */ = {isa = PBXBuildFile; productRef = D87364F82AE28DB500C8F919 /* Kanna */; };
D87BFC8B291D5C6B00FEE264 /* MastodonLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */; };
D87BFC8D291EB81200FEE264 /* MastodonLoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8C291EB81200FEE264 /* MastodonLoginViewModel.swift */; };
D87BFC8F291EC26A00FEE264 /* MastodonLoginServerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8E291EC26A00FEE264 /* MastodonLoginServerTableViewCell.swift */; };
Expand Down Expand Up @@ -316,7 +318,6 @@
DB63F7452799056400455B82 /* HashtagTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F7442799056400455B82 /* HashtagTableViewCell.swift */; };
DB63F74727990B0600455B82 /* DataSourceFacade+Hashtag.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F74627990B0600455B82 /* DataSourceFacade+Hashtag.swift */; };
DB63F7492799126300455B82 /* FollowerListViewController+DataSourceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F7482799126300455B82 /* FollowerListViewController+DataSourceProvider.swift */; };
DB63F74B279914A000455B82 /* FollowingListViewController+DataSourceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F74A279914A000455B82 /* FollowingListViewController+DataSourceProvider.swift */; };
DB63F74D27993F5B00455B82 /* SearchHistoryUserCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F74C27993F5B00455B82 /* SearchHistoryUserCollectionViewCell.swift */; };
DB63F74F2799405600455B82 /* SearchHistoryViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F74E2799405600455B82 /* SearchHistoryViewModel+Diffable.swift */; };
DB63F752279944AA00455B82 /* SearchHistorySectionHeaderCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB63F751279944AA00455B82 /* SearchHistorySectionHeaderCollectionReusableView.swift */; };
Expand Down Expand Up @@ -1021,7 +1022,6 @@
DB63F7442799056400455B82 /* HashtagTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagTableViewCell.swift; sourceTree = "<group>"; };
DB63F74627990B0600455B82 /* DataSourceFacade+Hashtag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+Hashtag.swift"; sourceTree = "<group>"; };
DB63F7482799126300455B82 /* FollowerListViewController+DataSourceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FollowerListViewController+DataSourceProvider.swift"; sourceTree = "<group>"; };
DB63F74A279914A000455B82 /* FollowingListViewController+DataSourceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FollowingListViewController+DataSourceProvider.swift"; sourceTree = "<group>"; };
DB63F74C27993F5B00455B82 /* SearchHistoryUserCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistoryUserCollectionViewCell.swift; sourceTree = "<group>"; };
DB63F74E2799405600455B82 /* SearchHistoryViewModel+Diffable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchHistoryViewModel+Diffable.swift"; sourceTree = "<group>"; };
DB63F751279944AA00455B82 /* SearchHistorySectionHeaderCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistorySectionHeaderCollectionReusableView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1289,6 +1289,8 @@
files = (
357FEEAF29523D470021C9DC /* MastodonSDKDynamic in Frameworks */,
DBF96326262EC0A6001D8D25 /* AuthenticationServices.framework in Frameworks */,
D84FA0932AE6915800987F47 /* MBProgressHUD in Frameworks */,
D87364F92AE28DB500C8F919 /* Kanna in Frameworks */,
71458AF57697DB405CFEC37C /* Pods_Mastodon.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -2316,7 +2318,6 @@
isa = PBXGroup;
children = (
DB5B7294273112B100081888 /* FollowingListViewController.swift */,
DB63F74A279914A000455B82 /* FollowingListViewController+DataSourceProvider.swift */,
DB5B7297273112C800081888 /* FollowingListViewModel.swift */,
DB5B729B273113C200081888 /* FollowingListViewModel+Diffable.swift */,
DB5B729D273113F300081888 /* FollowingListViewModel+State.swift */,
Expand Down Expand Up @@ -3120,7 +3121,6 @@
buildConfigurationList = DB427DFC25BAA00100D1B89D /* Build configuration list for PBXNativeTarget "Mastodon" */;
buildPhases = (
7A04933A2AB1D5B758D4F908 /* [CP] Check Pods Manifest.lock */,
5532CB85BBE168B25B20720B /* [CP] Embed Pods Frameworks */,
DB427DD025BAA00100D1B89D /* Resources */,
DB427DCE25BAA00100D1B89D /* Sources */,
DB427DCF25BAA00100D1B89D /* Frameworks */,
Expand All @@ -3142,6 +3142,8 @@
name = Mastodon;
packageProductDependencies = (
357FEEAE29523D470021C9DC /* MastodonSDKDynamic */,
D87364F82AE28DB500C8F919 /* Kanna */,
D84FA0922AE6915800987F47 /* MBProgressHUD */,
);
productName = Mastodon;
productReference = DB427DD225BAA00100D1B89D /* Mastodon.app */;
Expand Down Expand Up @@ -3178,7 +3180,6 @@
DB427DEF25BAA00100D1B89D /* Sources */,
DB427DF025BAA00100D1B89D /* Frameworks */,
DB427DF125BAA00100D1B89D /* Resources */,
ECC2E90D421B45415C311BED /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -3326,6 +3327,8 @@
mainGroup = DB427DC925BAA00100D1B89D;
packageReferences = (
2AB501192992322500346092 /* XCRemoteSwiftPackageReference "LightChart" */,
D87364F72AE28DB500C8F919 /* XCRemoteSwiftPackageReference "Kanna" */,
D84FA0912AE6915800987F47 /* XCRemoteSwiftPackageReference "MBProgressHUD" */,
);
productRefGroup = DB427DD325BAA00100D1B89D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3419,23 +3422,6 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
5532CB85BBE168B25B20720B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Mastodon/Pods-Mastodon-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Mastodon/Pods-Mastodon-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Mastodon/Pods-Mastodon-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
6E033728B42BA1C0018B6131 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -3556,23 +3542,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
ECC2E90D421B45415C311BED /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -3997,7 +3966,6 @@
DB98EB5927B109890082E365 /* ReportSupplementaryViewController.swift in Sources */,
DB0617EB277EF3820030EE79 /* GradientBorderView.swift in Sources */,
DB789A1225F9F2CC0071ACA0 /* ComposeViewModel.swift in Sources */,
DB63F74B279914A000455B82 /* FollowingListViewController+DataSourceProvider.swift in Sources */,
DBEFCD7D282A2A3B00C0ABEA /* ReportServerRulesViewController.swift in Sources */,
DBB525362611ECEB002F1F29 /* UserTimelineViewController.swift in Sources */,
D8F917122A4C6B67008A5370 /* GeneralSettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -5463,6 +5431,22 @@
kind = branch;
};
};
D84FA0912AE6915800987F47 /* XCRemoteSwiftPackageReference "MBProgressHUD" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/jdg/MBProgressHUD.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.2.0;
};
};
D87364F72AE28DB500C8F919 /* XCRemoteSwiftPackageReference "Kanna" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/tid-kijyun/Kanna.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.2.7;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -5499,6 +5483,16 @@
isa = XCSwiftPackageProductDependency;
productName = MastodonSDKDynamic;
};
D84FA0922AE6915800987F47 /* MBProgressHUD */ = {
isa = XCSwiftPackageProductDependency;
package = D84FA0912AE6915800987F47 /* XCRemoteSwiftPackageReference "MBProgressHUD" */;
productName = MBProgressHUD;
};
D87364F82AE28DB500C8F919 /* Kanna */ = {
isa = XCSwiftPackageProductDependency;
package = D87364F72AE28DB500C8F919 /* XCRemoteSwiftPackageReference "Kanna" */;
productName = Kanna;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = DB427DCA25BAA00100D1B89D /* Project object */;
Expand Down
18 changes: 18 additions & 0 deletions Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
"version": "1.6.0"
}
},
{
"package": "Kanna",
"repositoryURL": "https://github.com/tid-kijyun/Kanna.git",
"state": {
"branch": null,
"revision": "f9e4922223dd0d3dfbf02ca70812cf5531fc0593",
"version": "5.2.7"
}
},
{
"package": "KeychainAccess",
"repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess.git",
Expand All @@ -73,6 +82,15 @@
"version": null
}
},
{
"package": "MBProgressHUD",
"repositoryURL": "https://github.com/jdg/MBProgressHUD.git",
"state": {
"branch": null,
"revision": "bca42b801100b2b3a4eda0ba8dd33d858c780b0d",
"version": "1.2.0"
}
},
{
"package": "MetaTextKit",
"repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git",
Expand Down
31 changes: 25 additions & 6 deletions Mastodon/Coordinator/SceneCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import MastodonSDK
import MastodonCore
import MastodonAsset
import MastodonLocalization
import MBProgressHUD

final public class SceneCoordinator {

Expand All @@ -28,7 +29,8 @@ final public class SceneCoordinator {

private(set) weak var tabBarController: MainTabBarController!
private(set) weak var splitViewController: RootSplitViewController?

private(set) weak var rootViewController: UIViewController?

private(set) var secondaryStackHashValues = Set<Int>()
var childCoordinator: Coordinator?

Expand Down Expand Up @@ -198,7 +200,7 @@ extension SceneCoordinator {
case safari(url: URL)
case alertController(alertController: UIAlertController)
case activityViewController(activityViewController: UIActivityViewController, sourceView: UIView?, barButtonItem: UIBarButtonItem?)

var isOnboarding: Bool {
switch self {
case .welcome,
Expand Down Expand Up @@ -239,6 +241,7 @@ extension SceneCoordinator {
rootViewController = splitViewController
}
sceneDelegate.window?.rootViewController = rootViewController // base: main
self.rootViewController = rootViewController

if _authContext == nil { // entry #1: welcome
DispatchQueue.main.async {
Expand Down Expand Up @@ -465,9 +468,8 @@ private extension SceneCoordinator {
_viewController.viewModel = viewModel
viewController = _viewController
case .following(let viewModel):
let _viewController = FollowingListViewController()
_viewController.viewModel = viewModel
viewController = _viewController
let followingListViewController = FollowingListViewController(viewModel: viewModel, coordinator: self, context: appContext)
viewController = followingListViewController
case .familiarFollowers(let viewModel):
let _viewController = FamiliarFollowersViewController()
_viewController.viewModel = viewModel
Expand Down Expand Up @@ -559,13 +561,30 @@ private extension SceneCoordinator {

return viewController
}

private func setupDependency(for needs: NeedsDependency?) {
needs?.context = appContext
needs?.coordinator = self
}
}

//MARK: - Loading

public extension SceneCoordinator {
func showLoading() {
guard let rootViewController else { return }

MBProgressHUD.showAdded(to: rootViewController.view, animated: true)
}

@MainActor
func hideLoading() {
guard let rootViewController else { return }

MBProgressHUD.hide(for: rootViewController.view, animated: true)
}
}

//MARK: - MastodonLoginViewControllerDelegate

extension SceneCoordinator: MastodonLoginViewControllerDelegate {
Expand Down
2 changes: 2 additions & 0 deletions Mastodon/Diffable/User/UserItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import Foundation
import CoreData
import CoreDataStack
import MastodonSDK

enum UserItem: Hashable {
case user(record: ManagedObjectRecord<MastodonUser>)
case account(account: Mastodon.Entity.Account, relationship: Mastodon.Entity.Relationship?)
case bottomLoader
case bottomHeader(text: String)
}
46 changes: 30 additions & 16 deletions Mastodon/Diffable/User/UserSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,37 @@ enum UserSection: Hashable {
}

extension UserSection {
struct Configuration {
weak var userTableViewCellDelegate: UserTableViewCellDelegate?
}

static func diffableDataSource(
tableView: UITableView,
context: AppContext,
authContext: AuthContext,
configuration: Configuration
userTableViewCellDelegate: UserTableViewCellDelegate?
) -> UITableViewDiffableDataSource<UserSection, UserItem> {
tableView.register(UserTableViewCell.self, forCellReuseIdentifier: String(describing: UserTableViewCell.self))
tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self))
tableView.register(TimelineFooterTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineFooterTableViewCell.self))

return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
return UITableViewDiffableDataSource(tableView: tableView) {
tableView,
indexPath,
item -> UITableViewCell? in
switch item {
case .account(let account, let relationship):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as! UserTableViewCell

guard let me = authContext.mastodonAuthenticationBox.authentication.user(in: context.managedObjectContext) else { return cell }

cell.userView.setButtonState(.loading)
cell.configure(
me: me,
tableView: tableView,
account: account,
relationship: relationship,
delegate: userTableViewCellDelegate
)

return cell

case .user(let record):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as! UserTableViewCell
context.managedObjectContext.performAndWait {
Expand All @@ -50,7 +65,7 @@ extension UserSection {
blockedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$blockedUserIds.eraseToAnyPublisher(),
followRequestedUsers: authContext.mastodonAuthenticationBox.inMemoryCache.$followRequestedUserIDs.eraseToAnyPublisher()
),
configuration: configuration
userTableViewCellDelegate: userTableViewCellDelegate
)
}

Expand All @@ -60,13 +75,12 @@ extension UserSection {
cell.startAnimating()
return cell
case .bottomHeader(let text):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as! TimelineFooterTableViewCell
cell.messageLabel.text = text
return cell
} // end switch
} // end UITableViewDiffableDataSource
} // end static func tableViewDiffableDataSource { … }

let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as! TimelineFooterTableViewCell
cell.messageLabel.text = text
return cell
}
}
}
}

extension UserSection {
Expand All @@ -77,13 +91,13 @@ extension UserSection {
tableView: UITableView,
cell: UserTableViewCell,
viewModel: UserTableViewCell.ViewModel,
configuration: Configuration
userTableViewCellDelegate: UserTableViewCellDelegate?
) {
cell.configure(
me: authContext.mastodonAuthenticationBox.authentication.user(in: context.managedObjectContext),
tableView: tableView,
viewModel: viewModel,
delegate: configuration.userTableViewCellDelegate
delegate: userTableViewCellDelegate
)
}

Expand Down
Loading

0 comments on commit 7004a22

Please sign in to comment.