Add username storage on WebFeed
This commit is contained in:
parent
d43bf5d57a
commit
660cf29305
|
@ -25,7 +25,6 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||||
private static let userPaths = ["/home", "/notifications"]
|
private static let userPaths = ["/home", "/notifications"]
|
||||||
private static let reservedPaths = ["/search", "/explore", "/messages", "/i", "/compose"]
|
private static let reservedPaths = ["/search", "/explore", "/messages", "/i", "/compose"]
|
||||||
|
|
||||||
public var userID: String
|
|
||||||
public var screenName: String
|
public var screenName: String
|
||||||
|
|
||||||
private var oauthToken: String
|
private var oauthToken: String
|
||||||
|
@ -34,20 +33,18 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||||
private var client: OAuthSwiftClient
|
private var client: OAuthSwiftClient
|
||||||
|
|
||||||
public init?(tokenSuccess: OAuthSwift.TokenSuccess) {
|
public init?(tokenSuccess: OAuthSwift.TokenSuccess) {
|
||||||
guard let userID = tokenSuccess.parameters["user_id"] as? String,
|
guard let screenName = tokenSuccess.parameters["screen_name"] as? String else {
|
||||||
let screenName = tokenSuccess.parameters["screen_name"] as? String else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
self.userID = userID
|
|
||||||
self.screenName = screenName
|
self.screenName = screenName
|
||||||
self.oauthToken = tokenSuccess.credential.oauthToken
|
self.oauthToken = tokenSuccess.credential.oauthToken
|
||||||
self.oauthTokenSecret = tokenSuccess.credential.oauthTokenSecret
|
self.oauthTokenSecret = tokenSuccess.credential.oauthTokenSecret
|
||||||
|
|
||||||
let tokenCredentials = Credentials(type: .oauthAccessToken, username: userID, secret: oauthToken)
|
let tokenCredentials = Credentials(type: .oauthAccessToken, username: screenName, secret: oauthToken)
|
||||||
try? CredentialsManager.storeCredentials(tokenCredentials, server: Self.server)
|
try? CredentialsManager.storeCredentials(tokenCredentials, server: Self.server)
|
||||||
|
|
||||||
let tokenSecretCredentials = Credentials(type: .oauthAccessTokenSecret, username: userID, secret: oauthTokenSecret)
|
let tokenSecretCredentials = Credentials(type: .oauthAccessTokenSecret, username: screenName, secret: oauthTokenSecret)
|
||||||
try? CredentialsManager.storeCredentials(tokenSecretCredentials, server: Self.server)
|
try? CredentialsManager.storeCredentials(tokenSecretCredentials, server: Self.server)
|
||||||
|
|
||||||
client = OAuthSwiftClient(consumerKey: Secrets.twitterConsumerKey,
|
client = OAuthSwiftClient(consumerKey: Secrets.twitterConsumerKey,
|
||||||
|
@ -57,12 +54,11 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||||
version: .oauth1)
|
version: .oauth1)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init?(userID: String, screenName: String) {
|
public init?(screenName: String) {
|
||||||
self.userID = userID
|
|
||||||
self.screenName = screenName
|
self.screenName = screenName
|
||||||
|
|
||||||
guard let tokenCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessToken, server: Self.server, username: userID),
|
guard let tokenCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessToken, server: Self.server, username: screenName),
|
||||||
let tokenSecretCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessTokenSecret, server: Self.server, username: userID) else {
|
let tokenSecretCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessTokenSecret, server: Self.server, username: screenName) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +78,7 @@ public struct TwitterFeedProvider: FeedProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
let bestUserName = username != nil ? username : urlComponents.user
|
let bestUserName = username != nil ? username : urlComponents.user
|
||||||
if bestUserName == userID {
|
if bestUserName == screenName {
|
||||||
return .owner
|
return .owner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,8 +122,18 @@ final class LocalAccountDelegate: AccountDelegate {
|
||||||
switch result {
|
switch result {
|
||||||
|
|
||||||
case .success(let name):
|
case .success(let name):
|
||||||
let feed = account.createWebFeed(with: name, url: url.absoluteString, webFeedID: url.absoluteString, homePageURL: nil)
|
|
||||||
|
// Move the user to the WebFeed and out of the URL
|
||||||
|
var newURLComponents = urlComponents
|
||||||
|
newURLComponents.user = nil
|
||||||
|
guard let newURL = newURLComponents.url else {
|
||||||
|
completion(.failure(AccountError.createErrorNotFound))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let feed = account.createWebFeed(with: name, url: newURL.absoluteString, webFeedID: newURL.absoluteString, homePageURL: nil)
|
||||||
feed.editedName = name
|
feed.editedName = name
|
||||||
|
feed.username = urlComponents.user
|
||||||
|
|
||||||
feedProvider.refresh(feed) { result in
|
feedProvider.refresh(feed) { result in
|
||||||
self.refreshProgress.completeTask()
|
self.refreshProgress.completeTask()
|
||||||
|
|
|
@ -77,6 +77,15 @@ public final class WebFeed: Feed, Renamable, Hashable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var username: String? {
|
||||||
|
get {
|
||||||
|
return metadata.username
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
metadata.username = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var name: String?
|
public var name: String?
|
||||||
|
|
||||||
public var authors: Set<Author>? {
|
public var authors: Set<Author>? {
|
||||||
|
|
|
@ -21,6 +21,7 @@ final class WebFeedMetadata: Codable {
|
||||||
case homePageURL
|
case homePageURL
|
||||||
case iconURL
|
case iconURL
|
||||||
case faviconURL
|
case faviconURL
|
||||||
|
case username
|
||||||
case editedName
|
case editedName
|
||||||
case authors
|
case authors
|
||||||
case contentHash
|
case contentHash
|
||||||
|
@ -63,6 +64,14 @@ final class WebFeedMetadata: Codable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var username: String? {
|
||||||
|
didSet {
|
||||||
|
if username != oldValue {
|
||||||
|
valueDidChange(.username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var editedName: String? {
|
var editedName: String? {
|
||||||
didSet {
|
didSet {
|
||||||
if editedName != oldValue {
|
if editedName != oldValue {
|
||||||
|
|
|
@ -15,7 +15,7 @@ enum ExtensionPointIdentifer: Hashable {
|
||||||
case marsEdit
|
case marsEdit
|
||||||
case microblog
|
case microblog
|
||||||
#endif
|
#endif
|
||||||
case twitter(String, String)
|
case twitter(String)
|
||||||
|
|
||||||
var extensionPointType: ExtensionPoint.Type {
|
var extensionPointType: ExtensionPoint.Type {
|
||||||
switch self {
|
switch self {
|
||||||
|
@ -42,10 +42,9 @@ enum ExtensionPointIdentifer: Hashable {
|
||||||
"type": "microblog"
|
"type": "microblog"
|
||||||
]
|
]
|
||||||
#endif
|
#endif
|
||||||
case .twitter(let userID, let screenName):
|
case .twitter(let screenName):
|
||||||
return [
|
return [
|
||||||
"type": "twitter",
|
"type": "twitter",
|
||||||
"userID": userID,
|
|
||||||
"screenName": screenName
|
"screenName": screenName
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -62,8 +61,8 @@ enum ExtensionPointIdentifer: Hashable {
|
||||||
self = ExtensionPointIdentifer.microblog
|
self = ExtensionPointIdentifer.microblog
|
||||||
#endif
|
#endif
|
||||||
case "twitter":
|
case "twitter":
|
||||||
guard let userID = userInfo["userID"] as? String, let screenName = userInfo["screenName"] as? String else { return nil }
|
guard let screenName = userInfo["screenName"] as? String else { return nil }
|
||||||
self = ExtensionPointIdentifer.twitter(userID, screenName)
|
self = ExtensionPointIdentifer.twitter(screenName)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -77,9 +76,8 @@ enum ExtensionPointIdentifer: Hashable {
|
||||||
case .microblog:
|
case .microblog:
|
||||||
hasher.combine("microblog")
|
hasher.combine("microblog")
|
||||||
#endif
|
#endif
|
||||||
case .twitter(let userID, let screenName):
|
case .twitter(let screenName):
|
||||||
hasher.combine("twitter")
|
hasher.combine("twitter")
|
||||||
hasher.combine(userID)
|
|
||||||
hasher.combine(screenName)
|
hasher.combine(screenName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ final class ExtensionPointManager: FeedProviderManagerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
return available
|
return available
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var activeSendToCommands: [SendToCommand] {
|
var activeSendToCommands: [SendToCommand] {
|
||||||
|
@ -122,8 +123,8 @@ private extension ExtensionPointManager {
|
||||||
case .microblog:
|
case .microblog:
|
||||||
return SendToMicroBlogCommand()
|
return SendToMicroBlogCommand()
|
||||||
#endif
|
#endif
|
||||||
case .twitter(let userID, let screenName):
|
case .twitter(let screenName):
|
||||||
return TwitterFeedProvider(userID: userID, screenName: screenName)
|
return TwitterFeedProvider(screenName: screenName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ extension TwitterFeedProvider: ExtensionPoint {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var extensionPointID: ExtensionPointIdentifer {
|
var extensionPointID: ExtensionPointIdentifer {
|
||||||
return ExtensionPointIdentifer.twitter(userID, screenName)
|
return ExtensionPointIdentifer.twitter(screenName)
|
||||||
}
|
}
|
||||||
|
|
||||||
var title: String {
|
var title: String {
|
||||||
|
|
Loading…
Reference in New Issue