Make screen name entry tolerant of @ usage.

This commit is contained in:
Maurice Parker 2020-04-23 11:42:00 -05:00
parent c451cb38d9
commit 211a9c329f
1 changed files with 13 additions and 6 deletions

View File

@ -106,8 +106,13 @@ class AddTwitterFeedWindowController : NSWindowController, AddFeedWindowControll
let atUsername = accountPopupButton.selectedItem?.title else { return } let atUsername = accountPopupButton.selectedItem?.title else { return }
let username = String(atUsername[atUsername.index(atUsername.startIndex, offsetBy: 1)..<atUsername.endIndex]) let username = String(atUsername[atUsername.index(atUsername.startIndex, offsetBy: 1)..<atUsername.endIndex])
guard let url = TwitterFeedProvider.buildURL(type, username: username, screenName: userEnteredScreenSearch, searchField: userEnteredScreenSearch) else { return } var screenSearch = userEnteredScreenSearch
if let screenName = screenSearch, type == .screenName && screenName.starts(with: "@") {
screenSearch = String(screenName[screenName.index(screenName.startIndex, offsetBy: 1)..<screenName.endIndex])
}
guard let url = TwitterFeedProvider.buildURL(type, username: username, screenName: screenSearch, searchField: screenSearch) else { return }
let container = selectedContainer()! let container = selectedContainer()!
AddWebFeedDefaultContainer.saveDefaultContainer(container) AddWebFeedDefaultContainer.saveDefaultContainer(container)
@ -150,10 +155,12 @@ private extension AddTwitterFeedWindowController {
accountLabel.isHidden = true accountLabel.isHidden = true
accountPopupButton.isHidden = true accountPopupButton.isHidden = true
var screenName = screenSearchTextField.stringValue var screenSearch = userEnteredScreenSearch
if !screenName.isEmpty && !screenName.starts(with: "@") { if screenSearch != nil {
screenName = "@\(screenName)" if let screenName = screenSearch, screenName.starts(with: "@") {
typeDescriptionLabel.stringValue = NSLocalizedString("Tweets from \(screenName)", comment: "Home Timeline") screenSearch = String(screenName[screenName.index(screenName.startIndex, offsetBy: 1)..<screenName.endIndex])
}
typeDescriptionLabel.stringValue = NSLocalizedString("Tweets from @\(screenSearch!)", comment: "Home Timeline")
} else { } else {
typeDescriptionLabel.stringValue = "" typeDescriptionLabel.stringValue = ""
} }