diff --git a/Frameworks/Account/FeedProvider/Twitter/TwitterFeedProvider.swift b/Frameworks/Account/FeedProvider/Twitter/TwitterFeedProvider.swift index 654810e5b..a5d326ceb 100644 --- a/Frameworks/Account/FeedProvider/Twitter/TwitterFeedProvider.swift +++ b/Frameworks/Account/FeedProvider/Twitter/TwitterFeedProvider.swift @@ -25,7 +25,6 @@ public struct TwitterFeedProvider: FeedProvider { private static let userPaths = ["/home", "/notifications"] private static let reservedPaths = ["/search", "/explore", "/messages", "/i", "/compose"] - public var userID: String public var screenName: String private var oauthToken: String @@ -34,20 +33,18 @@ public struct TwitterFeedProvider: FeedProvider { private var client: OAuthSwiftClient public init?(tokenSuccess: OAuthSwift.TokenSuccess) { - guard let userID = tokenSuccess.parameters["user_id"] as? String, - let screenName = tokenSuccess.parameters["screen_name"] as? String else { + guard let screenName = tokenSuccess.parameters["screen_name"] as? String else { return nil } - self.userID = userID self.screenName = screenName self.oauthToken = tokenSuccess.credential.oauthToken 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) - 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) client = OAuthSwiftClient(consumerKey: Secrets.twitterConsumerKey, @@ -57,12 +54,11 @@ public struct TwitterFeedProvider: FeedProvider { version: .oauth1) } - public init?(userID: String, screenName: String) { - self.userID = userID + public init?(screenName: String) { self.screenName = screenName - guard let tokenCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessToken, server: Self.server, username: userID), - let tokenSecretCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessTokenSecret, server: Self.server, username: userID) else { + guard let tokenCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessToken, server: Self.server, username: screenName), + let tokenSecretCredentials = try? CredentialsManager.retrieveCredentials(type: .oauthAccessTokenSecret, server: Self.server, username: screenName) else { return nil } @@ -82,7 +78,7 @@ public struct TwitterFeedProvider: FeedProvider { } let bestUserName = username != nil ? username : urlComponents.user - if bestUserName == userID { + if bestUserName == screenName { return .owner } diff --git a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift index e5c269478..cc59efa67 100644 --- a/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Frameworks/Account/LocalAccount/LocalAccountDelegate.swift @@ -122,8 +122,18 @@ final class LocalAccountDelegate: AccountDelegate { switch result { 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.username = urlComponents.user feedProvider.refresh(feed) { result in self.refreshProgress.completeTask() diff --git a/Frameworks/Account/WebFeed.swift b/Frameworks/Account/WebFeed.swift index a964bc70b..1d3dec88d 100644 --- a/Frameworks/Account/WebFeed.swift +++ b/Frameworks/Account/WebFeed.swift @@ -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 authors: Set? { diff --git a/Frameworks/Account/WebFeedMetadata.swift b/Frameworks/Account/WebFeedMetadata.swift index 424cdc638..30323d8a7 100644 --- a/Frameworks/Account/WebFeedMetadata.swift +++ b/Frameworks/Account/WebFeedMetadata.swift @@ -21,6 +21,7 @@ final class WebFeedMetadata: Codable { case homePageURL case iconURL case faviconURL + case username case editedName case authors case contentHash @@ -63,6 +64,14 @@ final class WebFeedMetadata: Codable { } } + var username: String? { + didSet { + if username != oldValue { + valueDidChange(.username) + } + } + } + var editedName: String? { didSet { if editedName != oldValue { diff --git a/Shared/ExtensionPoints/ExtensionPointIdentifer.swift b/Shared/ExtensionPoints/ExtensionPointIdentifer.swift index 4709ffd2b..a23328a48 100644 --- a/Shared/ExtensionPoints/ExtensionPointIdentifer.swift +++ b/Shared/ExtensionPoints/ExtensionPointIdentifer.swift @@ -15,7 +15,7 @@ enum ExtensionPointIdentifer: Hashable { case marsEdit case microblog #endif - case twitter(String, String) + case twitter(String) var extensionPointType: ExtensionPoint.Type { switch self { @@ -42,10 +42,9 @@ enum ExtensionPointIdentifer: Hashable { "type": "microblog" ] #endif - case .twitter(let userID, let screenName): + case .twitter(let screenName): return [ "type": "twitter", - "userID": userID, "screenName": screenName ] } @@ -62,8 +61,8 @@ enum ExtensionPointIdentifer: Hashable { self = ExtensionPointIdentifer.microblog #endif case "twitter": - guard let userID = userInfo["userID"] as? String, let screenName = userInfo["screenName"] as? String else { return nil } - self = ExtensionPointIdentifer.twitter(userID, screenName) + guard let screenName = userInfo["screenName"] as? String else { return nil } + self = ExtensionPointIdentifer.twitter(screenName) default: return nil } @@ -77,9 +76,8 @@ enum ExtensionPointIdentifer: Hashable { case .microblog: hasher.combine("microblog") #endif - case .twitter(let userID, let screenName): + case .twitter(let screenName): hasher.combine("twitter") - hasher.combine(userID) hasher.combine(screenName) } } diff --git a/Shared/ExtensionPoints/ExtensionPointManager.swift b/Shared/ExtensionPoints/ExtensionPointManager.swift index ee87e1c89..723d3180c 100644 --- a/Shared/ExtensionPoints/ExtensionPointManager.swift +++ b/Shared/ExtensionPoints/ExtensionPointManager.swift @@ -36,6 +36,7 @@ final class ExtensionPointManager: FeedProviderManagerDelegate { } return available + } var activeSendToCommands: [SendToCommand] { @@ -122,8 +123,8 @@ private extension ExtensionPointManager { case .microblog: return SendToMicroBlogCommand() #endif - case .twitter(let userID, let screenName): - return TwitterFeedProvider(userID: userID, screenName: screenName) + case .twitter(let screenName): + return TwitterFeedProvider(screenName: screenName) } } diff --git a/Shared/ExtensionPoints/TwitterFeedProvider-Extensions.swift b/Shared/ExtensionPoints/TwitterFeedProvider-Extensions.swift index aa014d7c0..92bd77e20 100644 --- a/Shared/ExtensionPoints/TwitterFeedProvider-Extensions.swift +++ b/Shared/ExtensionPoints/TwitterFeedProvider-Extensions.swift @@ -19,7 +19,7 @@ extension TwitterFeedProvider: ExtensionPoint { }() var extensionPointID: ExtensionPointIdentifer { - return ExtensionPointIdentifer.twitter(userID, screenName) + return ExtensionPointIdentifer.twitter(screenName) } var title: String {