diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 415b5b52e4..f4c79b7a68 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -2441,6 +2441,11 @@ To enable access, tap Settings> Location and select Always"; "device_name_mobile" = "%@ Mobile"; "device_name_unknown" = "Unknown client"; +"device_type_name_desktop" = "Desktop"; +"device_type_name_web" = "Web"; +"device_type_name_mobile" = "Mobile"; +"device_type_name_unknown" = "Unknown"; + "user_session_details_title" = "Session details"; "user_session_details_session_section_header" = "Session"; "user_session_details_application_section_header" = "Application"; diff --git a/Riot/Categories/String.swift b/Riot/Categories/String.swift index a6e48d0aa8..3379234933 100644 --- a/Riot/Categories/String.swift +++ b/Riot/Categories/String.swift @@ -63,6 +63,11 @@ extension String { func vc_reversed() -> String { return String(self.reversed()) } + + /// Returns nil if the string is empty or the string itself otherwise + func vc_nilIfEmpty() -> String? { + isEmpty ? nil : self + } } extension Optional where Wrapped == String { diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 0d4e4ac192..ff14b2f0e5 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -1575,6 +1575,22 @@ public class VectorL10n: NSObject { public static func deviceNameWeb(_ p1: String) -> String { return VectorL10n.tr("Vector", "device_name_web", p1) } + /// Desktop + public static var deviceTypeNameDesktop: String { + return VectorL10n.tr("Vector", "device_type_name_desktop") + } + /// Mobile + public static var deviceTypeNameMobile: String { + return VectorL10n.tr("Vector", "device_type_name_mobile") + } + /// Unknown + public static var deviceTypeNameUnknown: String { + return VectorL10n.tr("Vector", "device_type_name_unknown") + } + /// Web + public static var deviceTypeNameWeb: String { + return VectorL10n.tr("Vector", "device_type_name_web") + } /// The other party cancelled the verification. public static var deviceVerificationCancelled: String { return VectorL10n.tr("Vector", "device_verification_cancelled") diff --git a/RiotSwiftUI/Modules/UserSessions/Common/DeviceType.swift b/RiotSwiftUI/Modules/UserSessions/Common/DeviceType.swift index 0f0685778a..f3b003ff3a 100644 --- a/RiotSwiftUI/Modules/UserSessions/Common/DeviceType.swift +++ b/RiotSwiftUI/Modules/UserSessions/Common/DeviceType.swift @@ -38,17 +38,15 @@ enum DeviceType { } var name: String { - let appName = AppInfo.current.displayName - switch self { case .desktop: - return VectorL10n.deviceNameDesktop(appName) + return VectorL10n.deviceTypeNameDesktop case .web: - return VectorL10n.deviceNameWeb(appName) + return VectorL10n.deviceTypeNameWeb case .mobile: - return VectorL10n.deviceNameMobile(appName) + return VectorL10n.deviceTypeNameMobile case .unknown: - return VectorL10n.deviceNameUnknown + return VectorL10n.deviceTypeNameUnknown } } } diff --git a/RiotSwiftUI/Modules/UserSessions/Common/Test/Unit/UserSessionNameFormatterTests.swift b/RiotSwiftUI/Modules/UserSessions/Common/Test/Unit/UserSessionNameFormatterTests.swift new file mode 100644 index 0000000000..c40bb2fa35 --- /dev/null +++ b/RiotSwiftUI/Modules/UserSessions/Common/Test/Unit/UserSessionNameFormatterTests.swift @@ -0,0 +1,33 @@ +// +// Copyright 2022 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import XCTest + +@testable import RiotSwiftUI + +class UserSessionNameFormatterTests: XCTestCase { + func testSessionDisplayNameTrumpsDeviceTypeName() { + XCTAssertEqual("Johnny's iPhone", UserSessionNameFormatter.sessionName(deviceType: .mobile, sessionDisplayName: "Johnny's iPhone")) + } + + func testEmptySessionDisplayNameFallsBackToDeviceTypeName() { + XCTAssertEqual(DeviceType.mobile.name, UserSessionNameFormatter.sessionName(deviceType: .mobile, sessionDisplayName: "")) + } + + func testNilSessionDisplayNameFallsBackToDeviceTypeName() { + XCTAssertEqual(DeviceType.mobile.name, UserSessionNameFormatter.sessionName(deviceType: .mobile, sessionDisplayName: nil)) + } +} diff --git a/RiotSwiftUI/Modules/UserSessions/Common/UserSessionNameFormatter.swift b/RiotSwiftUI/Modules/UserSessions/Common/UserSessionNameFormatter.swift index 492e272261..db7f2e1e6a 100644 --- a/RiotSwiftUI/Modules/UserSessions/Common/UserSessionNameFormatter.swift +++ b/RiotSwiftUI/Modules/UserSessions/Common/UserSessionNameFormatter.swift @@ -20,16 +20,6 @@ import Foundation enum UserSessionNameFormatter { /// Session name with client name and session display name static func sessionName(deviceType: DeviceType, sessionDisplayName: String?) -> String { - let sessionName: String - - let clientName = deviceType.name - - if let sessionDisplayName = sessionDisplayName { - sessionName = VectorL10n.userSessionName(clientName, sessionDisplayName) - } else { - sessionName = clientName - } - - return sessionName + sessionDisplayName?.vc_nilIfEmpty() ?? deviceType.name } } diff --git a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift index 6f73638471..dec49f4459 100644 --- a/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift +++ b/RiotSwiftUI/Modules/UserSessions/UserOtherSessions/Test/UI/UserOtherSessionsUITests.swift @@ -28,7 +28,7 @@ class UserOtherSessionsUITests: MockScreenTestCase { func test_whenOtherSessionsWithInactiveSessionFilterPresented_correctItemsDisplayed() { app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.inactiveSessions.title) - XCTAssertTrue(app.buttons["RiotSwiftUI Mobile: iOS, Inactive for 90+ days"].exists) + XCTAssertTrue(app.buttons["iOS, Inactive for 90+ days"].exists) } func test_whenOtherSessionsWithUnverifiedSessionFilterPresented_correctHeaderDisplayed() { @@ -41,6 +41,6 @@ class UserOtherSessionsUITests: MockScreenTestCase { func test_whenOtherSessionsWithUnverifiedSessionFilterPresented_correctItemsDisplayed() { app.goToScreenWithIdentifier(MockUserOtherSessionsScreenState.unverifiedSessions.title) - XCTAssertTrue(app.buttons["RiotSwiftUI Mobile: iOS, Unverified · Your current session"].exists) + XCTAssertTrue(app.buttons["iOS, Unverified · Your current session"].exists) } } diff --git a/RiotTests/String+Element.swift b/RiotTests/String+Element.swift index fdf45f44cd..c532e37c07 100644 --- a/RiotTests/String+Element.swift +++ b/RiotTests/String+Element.swift @@ -45,4 +45,10 @@ class String_Element: XCTestCase { let string3 = "ab" XCTAssertEqual(string3.vc_reversed(), "ba") } + + func testNilIfEmpty() { + XCTAssertNil("".vc_nilIfEmpty()) + XCTAssertNotNil(" ".vc_nilIfEmpty()) + XCTAssertNotNil("Johnny was here".vc_nilIfEmpty()) + } } diff --git a/changelog.d/6820.change b/changelog.d/6820.change new file mode 100644 index 0000000000..b41cd857e7 --- /dev/null +++ b/changelog.d/6820.change @@ -0,0 +1 @@ + Only use device type name as fallback for session display name