Compare commits
No commits in common. "3aa5aa1bc01782274228cbf9156e6dcb56a50fd1" and "863867c5226b650ec140be3dc6b4252ac83be719" have entirely different histories.
3aa5aa1bc0
...
863867c522
|
@ -21,7 +21,6 @@ class LocalData: ObservableObject {
|
|||
if ProcessInfo.processInfo.environment.keys.contains("UI_TESTING_LOGIN") {
|
||||
accounts = [
|
||||
UserAccountInfo(
|
||||
id: UUID().uuidString,
|
||||
instanceURL: URL(string: "http://localhost:8080")!,
|
||||
clientID: "client_id",
|
||||
clientSecret: "client_secret",
|
||||
|
@ -39,16 +38,15 @@ class LocalData: ObservableObject {
|
|||
get {
|
||||
if let array = defaults.array(forKey: accountsKey) as? [[String: String]] {
|
||||
return array.compactMap { (info) in
|
||||
guard let id = info["id"],
|
||||
let instanceURL = info["instanceURL"],
|
||||
guard let instanceURL = info["instanceURL"],
|
||||
let url = URL(string: instanceURL),
|
||||
let clientId = info["clientID"],
|
||||
let id = info["clientID"],
|
||||
let secret = info["clientSecret"],
|
||||
let username = info["username"],
|
||||
let accessToken = info["accessToken"] else {
|
||||
return nil
|
||||
}
|
||||
return UserAccountInfo(id: id, instanceURL: url, clientID: clientId, clientSecret: secret, username: username, accessToken: accessToken)
|
||||
return UserAccountInfo(instanceURL: url, clientID: id, clientSecret: secret, username: username, accessToken: accessToken)
|
||||
}
|
||||
} else {
|
||||
return []
|
||||
|
@ -58,7 +56,6 @@ class LocalData: ObservableObject {
|
|||
objectWillChange.send()
|
||||
let array = newValue.map { (info) in
|
||||
return [
|
||||
"id": info.id,
|
||||
"instanceURL": info.instanceURL.absoluteString,
|
||||
"clientID": info.clientID,
|
||||
"clientSecret": info.clientSecret,
|
||||
|
@ -71,7 +68,7 @@ class LocalData: ObservableObject {
|
|||
}
|
||||
|
||||
private let mostRecentAccountKey = "mostRecentAccount"
|
||||
private var mostRecentAccount: String? {
|
||||
var mostRecentAccount: String? {
|
||||
get {
|
||||
return defaults.string(forKey: mostRecentAccountKey)
|
||||
}
|
||||
|
@ -85,60 +82,41 @@ class LocalData: ObservableObject {
|
|||
return !accounts.isEmpty
|
||||
}
|
||||
|
||||
func addAccount(instanceURL url: URL, clientID: String, clientSecret secret: String, username: String, accessToken: String) -> UserAccountInfo {
|
||||
func addAccount(instanceURL url: URL, clientID id: String, clientSecret secret: String, username: String, accessToken: String) -> UserAccountInfo {
|
||||
var accounts = self.accounts
|
||||
if let index = accounts.firstIndex(where: { $0.instanceURL == url && $0.username == username }) {
|
||||
accounts.remove(at: index)
|
||||
}
|
||||
let id = UUID().uuidString
|
||||
let info = UserAccountInfo(id: id, instanceURL: url, clientID: clientID, clientSecret: secret, username: username, accessToken: accessToken)
|
||||
let info = UserAccountInfo(instanceURL: url, clientID: id, clientSecret: secret, username: username, accessToken: accessToken)
|
||||
accounts.append(info)
|
||||
self.accounts = accounts
|
||||
return info
|
||||
}
|
||||
|
||||
func removeAccount(_ info: UserAccountInfo) {
|
||||
accounts.removeAll(where: { $0.id == info.id })
|
||||
|
||||
}
|
||||
|
||||
func getMostRecentAccount() -> UserAccountInfo? {
|
||||
guard onboardingComplete else { return nil }
|
||||
let mostRecent: UserAccountInfo?
|
||||
if let id = mostRecentAccount {
|
||||
mostRecent = accounts.first { $0.id == id }
|
||||
if let accessToken = mostRecentAccount {
|
||||
return accounts.first { $0.accessToken == accessToken }
|
||||
} else {
|
||||
mostRecent = nil
|
||||
return nil
|
||||
}
|
||||
return mostRecent ?? accounts.first!
|
||||
}
|
||||
|
||||
func setMostRecentAccount(_ account: UserAccountInfo?) {
|
||||
mostRecentAccount = account?.id
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension LocalData {
|
||||
struct UserAccountInfo: Equatable, Hashable {
|
||||
let id: String
|
||||
let instanceURL: URL
|
||||
let clientID: String
|
||||
let clientSecret: String
|
||||
let username: String
|
||||
let accessToken: String
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
static func ==(lhs: UserAccountInfo, rhs: UserAccountInfo) -> Bool {
|
||||
return lhs.id == rhs.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let userLoggedOut = Notification.Name("Tusker.userLoggedOut")
|
||||
static let addAccount = Notification.Name("Tusker.addAccount")
|
||||
static let activateAccount = Notification.Name("Tusker.activateAccount")
|
||||
static let userLoggedOut = Notification.Name("userLoggedOut")
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class MastodonCache {
|
|||
let statusSubject = PassthroughSubject<Status, Never>()
|
||||
let accountSubject = PassthroughSubject<Account, Never>()
|
||||
|
||||
weak var mastodonController: MastodonController?
|
||||
let mastodonController: MastodonController
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
|
@ -43,9 +43,6 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func status(for id: String, completion: @escaping (Status?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getStatus(id: id)
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(status, _) = response else {
|
||||
|
@ -76,9 +73,6 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func account(for id: String, completion: @escaping (Account?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getAccount(id: id)
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(account, _) = response else {
|
||||
|
@ -108,9 +102,6 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
func relationship(for id: String, completion: @escaping (Relationship?) -> Void) {
|
||||
guard let mastodonController = mastodonController else {
|
||||
fatalError("The MastodonController for this cache has been deinitialized, so this cache should no longer exist. Are you storing a strong reference to it?")
|
||||
}
|
||||
let request = Client.getRelationships(accounts: [id])
|
||||
mastodonController.run(request) { response in
|
||||
guard case let .success(relationships, _) = response,
|
||||
|
|
|
@ -34,6 +34,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
|
||||
window!.makeKeyAndVisible()
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(themePrefChanged), name: .themePreferenceChanged, object: nil)
|
||||
themePrefChanged()
|
||||
|
||||
|
@ -109,20 +110,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
}
|
||||
|
||||
func activateAccount(_ account: LocalData.UserAccountInfo) {
|
||||
LocalData.shared.setMostRecentAccount(account)
|
||||
LocalData.shared.mostRecentAccount = account.accessToken
|
||||
window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account)
|
||||
showAppUI()
|
||||
}
|
||||
|
||||
func logoutCurrent() {
|
||||
LocalData.shared.removeAccount(LocalData.shared.getMostRecentAccount()!)
|
||||
if LocalData.shared.onboardingComplete {
|
||||
activateAccount(LocalData.shared.accounts.first!)
|
||||
} else {
|
||||
showOnboardingUI()
|
||||
}
|
||||
}
|
||||
|
||||
func showAppUI() {
|
||||
let mastodonController = window!.windowScene!.session.mastodonController!
|
||||
mastodonController.getOwnAccount()
|
||||
|
@ -138,6 +130,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||
window!.rootViewController = onboarding
|
||||
}
|
||||
|
||||
@objc func onUserLoggedOut() {
|
||||
showOnboardingUI()
|
||||
}
|
||||
|
||||
@objc func themePrefChanged() {
|
||||
window?.overrideUserInterfaceStyle = Preferences.shared.theme
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
protocol DraftsTableViewControllerDelegate: class {
|
||||
protocol DraftsTableViewControllerDelegate {
|
||||
func draftSelectionCanceled()
|
||||
func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void)
|
||||
func draftSelected(_ draft: DraftsManager.Draft)
|
||||
|
@ -17,7 +17,7 @@ protocol DraftsTableViewControllerDelegate: class {
|
|||
|
||||
class DraftsTableViewController: UITableViewController {
|
||||
|
||||
weak var delegate: DraftsTableViewControllerDelegate?
|
||||
var delegate: DraftsTableViewControllerDelegate?
|
||||
|
||||
init() {
|
||||
super.init(nibName: "DraftsTableViewController", bundle: nil)
|
||||
|
|
|
@ -10,7 +10,7 @@ import UIKit
|
|||
|
||||
class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate {
|
||||
|
||||
weak var mastodonController: MastodonController!
|
||||
let mastodonController: MastodonController
|
||||
|
||||
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
|
|
|
@ -14,7 +14,7 @@ class NotificationsPageViewController: SegmentedPageViewController {
|
|||
private let notificationsTitle = NSLocalizedString("Notifications", comment: "notifications tab title")
|
||||
private let mentionsTitle = NSLocalizedString("Mentions", comment: "mentions tab title")
|
||||
|
||||
weak var mastodonController: MastodonController!
|
||||
let mastodonController: MastodonController
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
|
|
|
@ -10,7 +10,7 @@ import UIKit
|
|||
import Combine
|
||||
import Pachyderm
|
||||
|
||||
protocol InstanceSelectorTableViewControllerDelegate: class {
|
||||
protocol InstanceSelectorTableViewControllerDelegate {
|
||||
func didSelectInstance(url: URL)
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ fileprivate let instanceCell = "instanceCell"
|
|||
|
||||
class InstanceSelectorTableViewController: UITableViewController {
|
||||
|
||||
weak var delegate: InstanceSelectorTableViewControllerDelegate?
|
||||
var delegate: InstanceSelectorTableViewControllerDelegate?
|
||||
|
||||
var dataSource: DataSource!
|
||||
var searchController: UISearchController!
|
||||
|
@ -55,7 +55,7 @@ class InstanceSelectorTableViewController: UITableViewController {
|
|||
tableView.rowHeight = UITableView.automaticDimension
|
||||
tableView.estimatedRowHeight = 120
|
||||
|
||||
dataSource = DataSource(tableView: tableView, cellProvider: { [weak self] (tableView, indexPath, item) -> UITableViewCell? in
|
||||
dataSource = DataSource(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in
|
||||
switch item {
|
||||
case let .selected(instance):
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: instanceCell, for: indexPath) as! InstanceTableViewCell
|
||||
|
|
|
@ -69,9 +69,9 @@ extension OnboardingViewController: InstanceSelectorTableViewControllerDelegate
|
|||
|
||||
mastodonController.authorize(authorizationCode: authCode) { (accessToken) in
|
||||
mastodonController.getOwnAccount { (account) in
|
||||
let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: account.username, accessToken: accessToken)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
let accountInfo = LocalData.shared.addAccount(instanceURL: instanceURL, clientID: clientID, clientSecret: clientSecret, username: account.username, accessToken: accessToken)
|
||||
|
||||
self.onboardingDelegate?.didFinishOnboarding(account: accountInfo)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import UIKit
|
|||
import SwiftUI
|
||||
|
||||
class PreferencesNavigationController: UINavigationController {
|
||||
|
||||
private var isSwitchingAccounts = false
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
let view = PreferencesView()
|
||||
|
@ -29,16 +27,13 @@ class PreferencesNavigationController: UINavigationController {
|
|||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(showAddAccount), name: .addAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(activateAccount(_:)), name: .activateAccount, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(userLoggedOut), name: .userLoggedOut, object: nil)
|
||||
}
|
||||
|
||||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
||||
if !isSwitchingAccounts {
|
||||
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
||||
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
||||
}
|
||||
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
||||
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
||||
}
|
||||
|
||||
@objc func donePressed() {
|
||||
|
@ -53,37 +48,26 @@ class PreferencesNavigationController: UINavigationController {
|
|||
}
|
||||
|
||||
@objc func cancelAddAccount() {
|
||||
dismiss(animated: true) // dismisses instance selector
|
||||
dismiss(animated: true)
|
||||
}
|
||||
|
||||
@objc func activateAccount(_ notification: Notification) {
|
||||
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||
isSwitchingAccounts = true
|
||||
dismiss(animated: true) { // dismiss preferences
|
||||
dismiss(animated: true) {
|
||||
sceneDelegate.activateAccount(account)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func userLoggedOut() {
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||
isSwitchingAccounts = true
|
||||
dismiss(animated: true) { // dismiss preferences
|
||||
sceneDelegate.logoutCurrent()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let addAccount = Notification.Name("Tusker.addAccount")
|
||||
static let activateAccount = Notification.Name("Tusker.activateAccount")
|
||||
}
|
||||
|
||||
extension PreferencesNavigationController: OnboardingViewControllerDelegate {
|
||||
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
||||
DispatchQueue.main.async {
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||
self.dismiss(animated: true) { // dismiss instance selector
|
||||
self.dismiss(animated: true) { // dismiss preferences
|
||||
sceneDelegate.activateAccount(account)
|
||||
}
|
||||
}
|
||||
}
|
||||
LocalData.shared.mostRecentAccount = account.accessToken
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import SwiftUI
|
|||
struct PreferencesView: View {
|
||||
@ObservedObject var localData = LocalData.shared
|
||||
@State private var showingLogoutConfirmation = false
|
||||
|
||||
|
||||
var body: some View {
|
||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||
// NavigationView {
|
||||
|
@ -24,7 +24,7 @@ struct PreferencesView: View {
|
|||
Text(account.username)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
if account == self.localData.getMostRecentAccount() {
|
||||
if account.accessToken == self.localData.mostRecentAccount {
|
||||
Image(systemName: "checkmark")
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(.secondary)
|
||||
|
@ -37,7 +37,7 @@ struct PreferencesView: View {
|
|||
}) {
|
||||
Text("Add Account...")
|
||||
}
|
||||
if localData.getMostRecentAccount() != nil {
|
||||
if localData.mostRecentAccount != nil {
|
||||
Button(action: {
|
||||
self.showingLogoutConfirmation = true
|
||||
}) {
|
||||
|
@ -73,6 +73,8 @@ struct PreferencesView: View {
|
|||
}
|
||||
|
||||
func logoutPressed() {
|
||||
// LocalData.shared.removeAccount(currentAccount)
|
||||
localData.removeAccount(localData.getMostRecentAccount()!)
|
||||
NotificationCenter.default.post(name: .userLoggedOut, object: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import SafariServices
|
|||
|
||||
class ProfileTableViewController: EnhancedTableViewController {
|
||||
|
||||
weak var mastodonController: MastodonController!
|
||||
let mastodonController: MastodonController
|
||||
|
||||
var accountID: String! {
|
||||
didSet {
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
protocol InstanceTimelineViewControllerDelegate: class {
|
||||
protocol InstanceTimelineViewControllerDelegate {
|
||||
func didSaveInstance(url: URL)
|
||||
func didUnsaveInstance(url: URL)
|
||||
}
|
||||
|
||||
class InstanceTimelineViewController: TimelineTableViewController {
|
||||
|
||||
weak var delegate: InstanceTimelineViewControllerDelegate?
|
||||
var delegate: InstanceTimelineViewControllerDelegate?
|
||||
|
||||
let instanceURL: URL
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import Pachyderm
|
|||
class TimelineTableViewController: EnhancedTableViewController {
|
||||
|
||||
var timeline: Timeline!
|
||||
weak var mastodonController: MastodonController!
|
||||
let mastodonController: MastodonController
|
||||
|
||||
var timelineSegments: [[(id: String, state: StatusState)]] = [] {
|
||||
didSet {
|
||||
|
|
|
@ -14,7 +14,7 @@ class TimelinesPageViewController: SegmentedPageViewController {
|
|||
private let federatedTitle = NSLocalizedString("Federated", comment: "federated timeline tab title")
|
||||
private let localTitle = NSLocalizedString("Local", comment: "local timeline tab title")
|
||||
|
||||
weak var mastodonController: MastodonController!
|
||||
let mastodonController: MastodonController
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
self.mastodonController = mastodonController
|
||||
|
|
|
@ -10,7 +10,7 @@ import UIKit
|
|||
import SafariServices
|
||||
import Pachyderm
|
||||
|
||||
protocol TuskerNavigationDelegate: class {
|
||||
protocol TuskerNavigationDelegate {
|
||||
|
||||
var apiController: MastodonController { get }
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import UIKit
|
|||
|
||||
class AccountTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: TuskerNavigationDelegate?
|
||||
var delegate: TuskerNavigationDelegate?
|
||||
var mastodonController: MastodonController! { delegate?.apiController }
|
||||
|
||||
@IBOutlet weak var avatarImageView: UIImageView!
|
||||
|
|
|
@ -11,13 +11,13 @@ import Pachyderm
|
|||
import Gifu
|
||||
import AVFoundation
|
||||
|
||||
protocol AttachmentViewDelegate: class {
|
||||
protocol AttachmentViewDelegate {
|
||||
func showAttachmentsGallery(startingAt index: Int)
|
||||
}
|
||||
|
||||
class AttachmentView: UIImageView, GIFAnimatable {
|
||||
|
||||
weak var delegate: AttachmentViewDelegate?
|
||||
var delegate: AttachmentViewDelegate?
|
||||
|
||||
var playImageView: UIImageView!
|
||||
|
||||
|
@ -71,8 +71,8 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
|||
}
|
||||
|
||||
func loadImage() {
|
||||
ImageCache.attachments.get(attachment.url) { [weak self] (data) in
|
||||
guard let self = self, let data = data else { return }
|
||||
ImageCache.attachments.get(attachment.url) { (data) in
|
||||
guard let data = data else { return }
|
||||
DispatchQueue.main.async {
|
||||
if self.attachment.url.pathExtension == "gif" {
|
||||
self.animate(withGIFData: data)
|
||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
|||
|
||||
class AttachmentsContainerView: UIView {
|
||||
|
||||
weak var delegate: AttachmentViewDelegate?
|
||||
var delegate: AttachmentViewDelegate?
|
||||
|
||||
var statusID: String!
|
||||
var attachments: [Attachment]!
|
||||
|
|
|
@ -10,14 +10,14 @@ import UIKit
|
|||
import Photos
|
||||
import AVFoundation
|
||||
|
||||
protocol ComposeMediaViewDelegate: class {
|
||||
protocol ComposeMediaViewDelegate {
|
||||
func didRemoveMedia(_ mediaView: ComposeMediaView)
|
||||
func descriptionTextViewDidChange(_ mediaView: ComposeMediaView)
|
||||
}
|
||||
|
||||
class ComposeMediaView: UIView {
|
||||
|
||||
weak var delegate: ComposeMediaViewDelegate?
|
||||
var delegate: ComposeMediaViewDelegate?
|
||||
|
||||
@IBOutlet weak var imageView: UIImageView!
|
||||
@IBOutlet weak var descriptionTextView: UITextView!
|
||||
|
|
|
@ -15,7 +15,8 @@ private let emojiRegex = try! NSRegularExpression(pattern: ":(\\w+):", options:
|
|||
|
||||
class ContentTextView: LinkTextView {
|
||||
|
||||
weak var navigationDelegate: TuskerNavigationDelegate?
|
||||
// todo: should be weak
|
||||
var navigationDelegate: TuskerNavigationDelegate?
|
||||
var mastodonController: MastodonController? { navigationDelegate?.apiController }
|
||||
|
||||
var defaultFont: UIFont = .systemFont(ofSize: 17)
|
||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
|||
|
||||
class HashtagTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: TuskerNavigationDelegate?
|
||||
var delegate: TuskerNavigationDelegate?
|
||||
|
||||
@IBOutlet weak var hashtagLabel: UILabel!
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import SwiftSoup
|
|||
|
||||
class ActionNotificationGroupTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: TuskerNavigationDelegate?
|
||||
var delegate: TuskerNavigationDelegate?
|
||||
var mastodonController: MastodonController! { delegate?.apiController }
|
||||
|
||||
@IBOutlet weak var actionImageView: UIImageView!
|
||||
|
@ -27,10 +27,6 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
|
|||
var authorAvatarURL: URL?
|
||||
var updateTimestampWorkItem: DispatchWorkItem?
|
||||
|
||||
deinit {
|
||||
updateTimestampWorkItem?.cancel()
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
|
@ -114,9 +110,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
|
|||
delay = nil
|
||||
}
|
||||
if let delay = delay {
|
||||
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
|
||||
self.updateTimestamp()
|
||||
}
|
||||
updateTimestampWorkItem = DispatchWorkItem(block: self.updateTimestamp)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
|
||||
} else {
|
||||
updateTimestampWorkItem = nil
|
||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
|||
|
||||
class FollowNotificationGroupTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: TuskerNavigationDelegate?
|
||||
var delegate: TuskerNavigationDelegate?
|
||||
var mastodonController: MastodonController! { delegate?.apiController }
|
||||
|
||||
@IBOutlet weak var avatarStackView: UIStackView!
|
||||
|
@ -22,10 +22,6 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
|
|||
|
||||
var updateTimestampWorkItem: DispatchWorkItem?
|
||||
|
||||
deinit {
|
||||
updateTimestampWorkItem?.cancel()
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
|
@ -102,7 +98,7 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
|
|||
delay = nil
|
||||
}
|
||||
if let delay = delay {
|
||||
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
|
||||
updateTimestampWorkItem = DispatchWorkItem {
|
||||
self.updateTimestamp()
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
|
||||
|
|
|
@ -11,7 +11,7 @@ import Pachyderm
|
|||
|
||||
class FollowRequestNotificationTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: TuskerNavigationDelegate?
|
||||
var delegate: TuskerNavigationDelegate?
|
||||
var mastodonController: MastodonController! { delegate?.apiController }
|
||||
|
||||
@IBOutlet weak var stackView: UIStackView!
|
||||
|
@ -27,10 +27,6 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
|
|||
|
||||
var updateTimestampWorkItem: DispatchWorkItem?
|
||||
|
||||
deinit {
|
||||
updateTimestampWorkItem?.cancel()
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
|
@ -76,9 +72,7 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
|
|||
delay = nil
|
||||
}
|
||||
if let delay = delay {
|
||||
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
|
||||
self.updateTimestamp()
|
||||
}
|
||||
updateTimestampWorkItem = DispatchWorkItem(block: self.updateTimestamp)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
|
||||
} else {
|
||||
updateTimestampWorkItem = nil
|
||||
|
|
|
@ -15,7 +15,7 @@ protocol ProfileHeaderTableViewCellDelegate: TuskerNavigationDelegate {
|
|||
|
||||
class ProfileHeaderTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: ProfileHeaderTableViewCellDelegate?
|
||||
var delegate: ProfileHeaderTableViewCellDelegate?
|
||||
var mastodonController: MastodonController! { delegate?.apiController }
|
||||
|
||||
@IBOutlet weak var headerImageView: UIImageView!
|
||||
|
|
|
@ -16,7 +16,7 @@ protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
|
|||
|
||||
class BaseStatusTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: StatusTableViewCellDelegate? {
|
||||
var delegate: StatusTableViewCellDelegate? {
|
||||
didSet {
|
||||
contentTextView.navigationDelegate = delegate
|
||||
}
|
||||
|
@ -100,16 +100,16 @@ class BaseStatusTableViewCell: UITableViewCell {
|
|||
open func createObserversIfNecessary() {
|
||||
if statusUpdater == nil {
|
||||
statusUpdater = mastodonController.cache.statusSubject
|
||||
.filter { [unowned self] in $0.id == self.statusID }
|
||||
.filter { $0.id == self.statusID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [unowned self] in self.updateStatusState(status: $0) }
|
||||
.sink(receiveValue: updateStatusState(status:))
|
||||
}
|
||||
|
||||
if accountUpdater == nil {
|
||||
accountUpdater = mastodonController.cache.accountSubject
|
||||
.filter { [unowned self] in $0.id == self.accountID }
|
||||
.filter { $0.id == self.accountID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [unowned self] in self.updateUI(account: $0) }
|
||||
.sink(receiveValue: updateUI(account:))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
|
||||
deinit {
|
||||
rebloggerAccountUpdater?.cancel()
|
||||
updateTimestampWorkItem?.cancel()
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
|
@ -49,9 +48,9 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
|
||||
if rebloggerAccountUpdater == nil {
|
||||
rebloggerAccountUpdater = mastodonController.cache.accountSubject
|
||||
.filter { [unowned self] in $0.id == self.rebloggerID }
|
||||
.filter { $0.id == self.rebloggerID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [unowned self] in self.updateRebloggerLabel(reblogger: $0) }
|
||||
.sink(receiveValue: updateRebloggerLabel(reblogger:))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +94,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
}
|
||||
|
||||
func updateTimestamp() {
|
||||
guard superview != nil else { return }
|
||||
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
||||
|
||||
timestampLabel.text = status.createdAt.timeAgoString()
|
||||
|
@ -111,7 +109,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
delay = nil
|
||||
}
|
||||
if let delay = delay {
|
||||
updateTimestampWorkItem = DispatchWorkItem { [unowned self] in
|
||||
updateTimestampWorkItem = DispatchWorkItem {
|
||||
self.updateTimestamp()
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
|
||||
|
|
Loading…
Reference in New Issue