Use the room heroes when computing a DM avatar. (#2900)

* Use room heroes for DM avatar content ID.

* Use RoomAvatar.heroes for the DM Details stack.
This commit is contained in:
Doug
2024-06-19 11:27:10 +01:00
committed by GitHub
parent 17d96b0f4b
commit 834260c144
55 changed files with 524 additions and 198 deletions
@@ -36,6 +36,7 @@ class HomeScreenRoomTests: XCTestCase {
name: "Test room",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: unreadMessagesCount,
+3
View File
@@ -86,12 +86,14 @@ class LoggingTests: XCTestCase {
// Given a room summary that contains sensitive information
let roomName = "Private Conversation"
let lastMessage = "Secret information"
let heroName = "Pseudonym"
let roomSummary = RoomSummaryDetails(id: "myroomid",
isInvite: false,
inviter: nil,
name: roomName,
isDirect: true,
avatarURL: nil,
heroes: [.init(userID: "", displayName: heroName)],
lastMessage: AttributedString(lastMessage),
lastMessageFormattedTimestamp: "Now",
unreadMessagesCount: 0,
@@ -116,6 +118,7 @@ class LoggingTests: XCTestCase {
XCTAssertTrue(content.contains(roomSummary.id))
XCTAssertFalse(content.contains(roomName))
XCTAssertFalse(content.contains(lastMessage))
XCTAssertFalse(content.contains(heroName))
}
func validateTimelineContentIsRedacted() throws {
@@ -0,0 +1,84 @@
//
// Copyright 2024 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 ElementX
class RoomSummaryDetailsTests: XCTestCase {
// swiftlint:disable:next large_tuple
let roomDetails: (id: String, name: String, avatarURL: URL) = ("room_id", "Room Name", "mxc://hs.tld/room/avatar")
let heroes = [UserProfileProxy(userID: "hero_1", displayName: "Hero 1", avatarURL: "mxc://hs.tld/user/avatar")]
func testRoomAvatar() {
let details = makeDetails(isDirect: false, hasRoomAvatar: true)
switch details.avatar {
case .room(let id, let name, let avatarURL):
XCTAssertEqual(id, roomDetails.id)
XCTAssertEqual(name, roomDetails.name)
XCTAssertEqual(avatarURL, roomDetails.avatarURL)
case .heroes:
XCTFail("A room shouldn't use the heroes for its avatar.")
}
}
func testDMAvatarSet() {
let details = makeDetails(isDirect: true, hasRoomAvatar: true)
switch details.avatar {
case .room(let id, let name, let avatarURL):
XCTAssertEqual(id, roomDetails.id)
XCTAssertEqual(name, roomDetails.name)
XCTAssertEqual(avatarURL, roomDetails.avatarURL)
case .heroes:
XCTFail("A DM with an avatar set shouldn't use the heroes instead.")
}
}
func testDMAvatarNotSet() {
let details = makeDetails(isDirect: true, hasRoomAvatar: false)
switch details.avatar {
case .room:
XCTFail("A DM without an avatar should defer to the hero for the correct placeholder tint colour.")
case .heroes(let heroes):
XCTAssertEqual(heroes, self.heroes)
}
}
// MARK: - Helpers
func makeDetails(isDirect: Bool, hasRoomAvatar: Bool) -> RoomSummaryDetails {
RoomSummaryDetails(id: roomDetails.id,
isInvite: false,
inviter: nil,
name: roomDetails.name,
isDirect: isDirect,
avatarURL: hasRoomAvatar ? roomDetails.avatarURL : nil,
heroes: heroes,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)
}
}