Skip to content

Commit

Permalink
Simplify MasotodonAuthenticationBox
Browse files Browse the repository at this point in the history
  • Loading branch information
whattherestimefor committed Nov 14, 2024
1 parent cf9b947 commit 5dcc64b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 45 deletions.
7 changes: 1 addition & 6 deletions MastodonIntent/Handler/SendPostIntentHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,21 @@ 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 init(
authentication: MastodonAuthentication,
domain: String,
userID: String,
appAuthorization: Mastodon.API.OAuth.Authorization,
userAuthorization: Mastodon.API.OAuth.Authorization,
inMemoryCache: MastodonAccountInMemoryCache
) {
self.authentication = authentication
self.domain = domain
self.userID = userID
self.appAuthorization = appAuthorization
self.userAuthorization = userAuthorization
self.inMemoryCache = inMemoryCache
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 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 init(authentication: MastodonAuthentication) {
self.authentication = authentication
}

}

public class MastodonAccountInMemoryCache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down

0 comments on commit 5dcc64b

Please sign in to comment.