2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Simplify MasotodonAuthenticationBox

This commit is contained in:
shannon 2024-11-14 11:17:22 -05:00
parent cf9b947d94
commit 5dcc64b094
3 changed files with 14 additions and 45 deletions

View File

@ -64,12 +64,7 @@ extension SendPostIntentHandler: SendPostIntentHandling {
let authenticationBoxes = mastodonAuthentications.map { authentication in
MastodonAuthenticationBox(
authentication: authentication,
domain: authentication.domain,
userID: authentication.userID,
appAuthorization: .init(accessToken: authentication.appAccessToken),
userAuthorization: .init(accessToken: authentication.userAccessToken),
inMemoryCache: .sharedCache(for: authentication.userAccessToken)
authentication: authentication
)
}

View File

@ -15,44 +15,23 @@ public protocol AuthContextProvider {
public struct MastodonAuthenticationBox: UserIdentifier {
public let authentication: MastodonAuthentication
public let domain: String
public let userID: String
public let appAuthorization: Mastodon.API.OAuth.Authorization
public let userAuthorization: Mastodon.API.OAuth.Authorization
public let inMemoryCache: MastodonAccountInMemoryCache
public var domain: String { authentication.domain }
public var userID: String { authentication.userID }
public var appAuthorization: Mastodon.API.OAuth.Authorization {
Mastodon.API.OAuth.Authorization(accessToken: authentication.appAccessToken)
}
public var userAuthorization: Mastodon.API.OAuth.Authorization {
Mastodon.API.OAuth.Authorization(accessToken: authentication.userAccessToken)
}
public var inMemoryCache: MastodonAccountInMemoryCache {
.sharedCache(for: authentication.userID) // TODO: make sure this is really unique
}
public init(
authentication: MastodonAuthentication,
domain: String,
userID: String,
appAuthorization: Mastodon.API.OAuth.Authorization,
userAuthorization: Mastodon.API.OAuth.Authorization,
inMemoryCache: MastodonAccountInMemoryCache
) {
public init(authentication: MastodonAuthentication) {
self.authentication = authentication
self.domain = domain
self.userID = userID
self.appAuthorization = appAuthorization
self.userAuthorization = userAuthorization
self.inMemoryCache = inMemoryCache
}
}
public extension MastodonAuthenticationBox {
init(authentication: MastodonAuthentication) {
self = MastodonAuthenticationBox(
authentication: authentication,
domain: authentication.domain,
userID: authentication.userID,
appAuthorization: Mastodon.API.OAuth.Authorization(accessToken: authentication.appAccessToken),
userAuthorization: Mastodon.API.OAuth.Authorization(accessToken: authentication.userAccessToken),
inMemoryCache: .sharedCache(for: authentication.userID) // TODO: make sure this is really unique
)
}
}
public class MastodonAccountInMemoryCache {
@Published public var followingUserIds: [String] = []
@Published public var blockedUserIds: [String] = []

View File

@ -240,12 +240,7 @@ extension NotificationService {
guard let authentication = results.first else { return nil }
return MastodonAuthenticationBox(
authentication: authentication,
domain: authentication.domain,
userID: authentication.userID,
appAuthorization: .init(accessToken: authentication.appAccessToken),
userAuthorization: .init(accessToken: authentication.userAccessToken),
inMemoryCache: .sharedCache(for: authentication.userAccessToken)
authentication: authentication
)
}