From 77910eb9a4bec5161373d0aa9e7fd577096335ac Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 27 Oct 2024 11:57:29 -0700 Subject: [PATCH] =?UTF-8?q?Allow=20for=20multiple=20FreshRSS=20accounts=20?= =?UTF-8?q?with=20the=20same=20username=20=E2=80=94=C2=A0since=20a=20given?= =?UTF-8?q?=20username=20might=20be=20reused=20across=20instances.=20Fix?= =?UTF-8?q?=20#4377.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Account/AccountManager.swift | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index f341a46c9..28d95e50e 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -165,15 +165,33 @@ import Core NotificationCenter.default.post(name: .UserDidDeleteAccount, object: self, userInfo: userInfo) } - public func duplicateServiceAccount(type: AccountType, username: String?) -> Bool { + public func duplicateServiceAccount(type: AccountType, username: String?, apiURL: String? = nil) -> Bool { + guard type != .onMyMac else { return false } - for account in accounts { - if account.accountType == type && username == account.username { - return true + + if type == .freshRSS { + guard let apiURL, let endpointURL = URL(string: apiURL) else { + return false + } + for account in accounts { + // A person might use the same username with different instances of FreshRSS, + // so it’s necessary to check the endpointURL. + // https://github.com/Ranchero-Software/NetNewsWire/issues/4377 + if account.accountType == type && username == account.username && account.endpointURL == endpointURL { + return true + } } } + else { + for account in accounts { + if account.accountType == type && username == account.username { + return true + } + } + } + return false }