Skip to content

Commit

Permalink
Get rid of commonglog
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Sep 22, 2023
1 parent a46a0ca commit 74c324f
Show file tree
Hide file tree
Showing 28 changed files with 7 additions and 82 deletions.
9 changes: 0 additions & 9 deletions Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
"version": "4.2.0"
}
},
{
"package": "CommonOSLog",
"repositoryURL": "https://github.com/MainasuK/CommonOSLog",
"state": {
"branch": null,
"revision": "c121624a30698e9886efe38aebb36ff51c01b6c2",
"version": "0.1.1"
}
},
{
"package": "FaviconFinder",
"repositoryURL": "https://github.com/will-lumley/FaviconFinder.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import UIKit
import Combine
import CoreDataStack
import CommonOSLog
import MastodonCore

final class SearchHistoryViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Combine
import CoreData
import CoreDataStack
import GameplayKit
import CommonOSLog
import MastodonSDK
import MastodonCore

Expand Down
2 changes: 0 additions & 2 deletions MastodonSDK/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ let package = Package(
.package(url: "https://github.com/kean/Nuke-FLAnimatedImage-Plugin.git", from: "8.0.0"),
.package(url: "https://github.com/kean/Nuke.git", from: "10.3.1"),
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess.git", from: "4.2.2"),
.package(url: "https://github.com/MainasuK/CommonOSLog", from: "0.1.1"),
.package(url: "https://github.com/MainasuK/FPSIndicator.git", from: "1.0.0"),
.package(url: "https://github.com/slackhq/PanModal.git", from: "1.2.7"),
.package(url: "https://github.com/TimOliver/TOCropViewController.git", from: "2.6.1"),
Expand Down Expand Up @@ -93,7 +92,6 @@ let package = Package(
"MastodonSDK",
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "AlamofireImage", package: "AlamofireImage"),
.product(name: "CommonOSLog", package: "CommonOSLog"),
.product(name: "ArkanaKeys", package: "ArkanaKeys"),
.product(name: "KeychainAccess", package: "KeychainAccess"),
.product(name: "MetaTextKit", package: "MetaTextKit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import os.log
import CoreDataStack
import Foundation
import Combine
import CommonOSLog
import MastodonCommon
import MastodonSDK

Expand Down Expand Up @@ -49,8 +48,6 @@ extension APIService {
)

let flag = result.isNewInsertion ? "+" : "-"
let logger = Logger(subsystem: "APIService", category: "AccountInfo")
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch mastodon user [\(flag)](\(response.value.id))\(response.value.username)")
}

return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down Expand Up @@ -65,7 +64,6 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Block")

let managedObjectContext = backgroundManagedObjectContext
let blockContext: MastodonBlockContext = try await managedObjectContext.performChanges {
Expand All @@ -84,7 +82,7 @@ extension APIService {
// will do block action. set to unfollow
user.update(isFollowing: false, by: me)
}
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user[\(user.id)](\(user.username)) block state: \(!isBlocking)")

return MastodonBlockContext(
sourceUserID: me.id,
targetUserID: user.id,
Expand Down Expand Up @@ -115,7 +113,6 @@ extension APIService {
}
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block failure: \(error.localizedDescription)")
}

try await managedObjectContext.performChanges {
Expand All @@ -135,12 +132,10 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block state: \(relationship.blocking)")
case .failure:
// rollback
user.update(isBlocking: blockContext.isBlocking, by: me)
user.update(isFollowing: blockContext.isFollowing, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user[\(blockContext.targetUserID)](\(blockContext.targetUsername)) block state")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Combine
import MastodonSDK
import CoreData
import CoreDataStack
import CommonOSLog

extension APIService {

Expand All @@ -23,8 +22,7 @@ extension APIService {
record: ManagedObjectRecord<Status>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
let logger = Logger(subsystem: "APIService", category: "Bookmark")


let managedObjectContext = backgroundManagedObjectContext

// update bookmark state and retrieve bookmark context
Expand All @@ -42,7 +40,6 @@ extension APIService {
statusID: status.id,
isBookmarked: isBookmarked
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status bookmark: \(!isBookmarked)")
return context
}

Expand All @@ -59,7 +56,6 @@ extension APIService {
result = .success(response)
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update bookmark failure: \(error.localizedDescription)")
}

// update bookmark state
Expand All @@ -83,11 +79,9 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status bookmark: \(response.value.bookmarked.debugDescription)")
case .failure:
// rollback
status.update(bookmarked: bookmarkContext.isBookmarked, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): rollback status bookmark")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import Combine
import CommonOSLog
import CoreData
import CoreDataStack
import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Combine
import MastodonSDK
import CoreData
import CoreDataStack
import CommonOSLog

extension APIService {

Expand All @@ -25,8 +24,7 @@ extension APIService {
record: ManagedObjectRecord<Status>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Status> {
let logger = Logger(subsystem: "APIService", category: "Favorite")


let managedObjectContext = backgroundManagedObjectContext

// update like state and retrieve like context
Expand All @@ -48,7 +46,6 @@ extension APIService {
isFavorited: isFavorited,
favoritedCount: favoritedCount
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status favorite: \(!isFavorited), \(favoriteCount)")
return context
}

Expand All @@ -65,7 +62,6 @@ extension APIService {
result = .success(response)
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update favorite failure: \(error.localizedDescription)")
}

// update like state
Expand All @@ -92,12 +88,10 @@ extension APIService {
if favoriteContext.isFavorited {
status.update(favouritesCount: max(0, status.favouritesCount - 1)) // undo API return count has delay. Needs -1 local
}
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): update status favorite: \(response.value.favourited.debugDescription)")
case .failure:
// rollback
status.update(liked: favoriteContext.isFavorited, by: me)
status.update(favouritesCount: favoriteContext.favoritedCount)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): rollback status favorite")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand All @@ -34,8 +33,7 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Follow")


let managedObjectContext = backgroundManagedObjectContext
let _followContext: MastodonFollowContext? = try await managedObjectContext.performChanges {
guard let me = authenticationBox.authenticationRecord.object(in: managedObjectContext)?.user else { return nil }
Expand All @@ -49,17 +47,14 @@ extension APIService {
// unfollow
user.update(isFollowing: false, by: me)
user.update(isFollowRequested: false, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: undo follow")
} else {
// follow
if user.locked {
user.update(isFollowing: false, by: me)
user.update(isFollowRequested: true, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: pending follow")
} else {
user.update(isFollowing: true, by: me)
user.update(isFollowRequested: false, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user friendship: following")
}
}
let context = MastodonFollowContext(
Expand Down Expand Up @@ -88,7 +83,6 @@ extension APIService {
).singleOutput()
result = .success(response)
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update friendship failure: \(error.localizedDescription)")
result = .failure(error)
}

Expand All @@ -109,12 +103,10 @@ extension APIService {
)
)
let following = response.value.following
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user friendship: following \(following)")
case .failure:
// rollback
user.update(isFollowing: followContext.isFollowing, by: me)
user.update(isFollowRequested: followContext.isPending, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user friendship")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import UIKit
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down Expand Up @@ -64,8 +63,7 @@ extension APIService {
user: ManagedObjectRecord<MastodonUser>,
authenticationBox: MastodonAuthenticationBox
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Relationship> {
let logger = Logger(subsystem: "APIService", category: "Mute")


let managedObjectContext = backgroundManagedObjectContext
let muteContext: MastodonMuteContext = try await managedObjectContext.performChanges {
guard let user = user.object(in: managedObjectContext),
Expand All @@ -79,7 +77,6 @@ extension APIService {

// toggle mute state
user.update(isMuting: !isMuting, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Local] update user[\(user.id)](\(user.username)) mute state: \(!isMuting)")
return MastodonMuteContext(
sourceUserID: me.id,
targetUserID: user.id,
Expand Down Expand Up @@ -111,7 +108,6 @@ extension APIService {
}
} catch {
result = .failure(error)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute failure: \(error.localizedDescription)")
}

try await managedObjectContext.performChanges {
Expand All @@ -131,11 +127,9 @@ extension APIService {
networkDate: response.networkDate
)
)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] update user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute state: \(relationship.muting.debugDescription)")
case .failure:
// rollback
user.update(isMuting: muteContext.isMuting, by: me)
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): [Remote] rollback user[\(muteContext.targetUserID)](\(muteContext.targetUsername)) mute state")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import Combine
import CoreData
import CoreDataStack
import CommonOSLog
import MastodonSDK

extension APIService {
Expand Down
Loading

0 comments on commit 74c324f

Please sign in to comment.