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
@@ -8056,6 +8056,11 @@ class RoomProxyMock: RoomProxyProtocol {
var underlyingOwnUserID: String!
var name: String?
var topic: String?
var avatar: RoomAvatar {
get { return underlyingAvatar }
set(value) { underlyingAvatar = value }
}
var underlyingAvatar: RoomAvatar!
var avatarURL: URL?
var membersPublisher: CurrentValuePublisher<[RoomMemberProxyProtocol], Never> {
get { return underlyingMembersPublisher }
@@ -10733,6 +10733,71 @@ open class RoomSDKMock: MatrixRustSDK.Room {
}
}
//MARK: - heroes
var heroesUnderlyingCallsCount = 0
open var heroesCallsCount: Int {
get {
if Thread.isMainThread {
return heroesUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = heroesUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
heroesUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
heroesUnderlyingCallsCount = newValue
}
}
}
}
open var heroesCalled: Bool {
return heroesCallsCount > 0
}
var heroesUnderlyingReturnValue: [RoomHero]!
open var heroesReturnValue: [RoomHero]! {
get {
if Thread.isMainThread {
return heroesUnderlyingReturnValue
} else {
var returnValue: [RoomHero]? = nil
DispatchQueue.main.sync {
returnValue = heroesUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
heroesUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
heroesUnderlyingReturnValue = newValue
}
}
}
}
open var heroesClosure: (() -> [RoomHero])?
open override func heroes() -> [RoomHero] {
heroesCallsCount += 1
if let heroesClosure = heroesClosure {
return heroesClosure()
} else {
return heroesReturnValue
}
}
//MARK: - id
var idUnderlyingCallsCount = 0
@@ -54,6 +54,7 @@ extension RoomProxyMock {
id = configuration.id
name = configuration.name
topic = configuration.topic
avatar = .room(id: configuration.id, name: configuration.name, avatarURL: configuration.avatarURL) // Note: This doesn't replicate the real proxy logic.
avatarURL = configuration.avatarURL
isDirect = configuration.isDirect
isSpace = configuration.isSpace
@@ -84,6 +84,7 @@ extension Array where Element == RoomSummary {
name: "Foundation 🔭🪐🌌",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"),
lastMessageFormattedTimestamp: "14:56",
unreadMessagesCount: 0,
@@ -100,6 +101,7 @@ extension Array where Element == RoomSummary {
name: "Foundation and Empire",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
lastMessageFormattedTimestamp: "2:56 PM",
unreadMessagesCount: 2,
@@ -116,6 +118,7 @@ extension Array where Element == RoomSummary {
name: "Second Foundation",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
lastMessageFormattedTimestamp: "Some time ago",
unreadMessagesCount: 3,
@@ -132,6 +135,7 @@ extension Array where Element == RoomSummary {
name: "Foundation's Edge",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("There's an archaic measure of time that's called the month"),
lastMessageFormattedTimestamp: "Just now",
unreadMessagesCount: 2,
@@ -148,6 +152,7 @@ extension Array where Element == RoomSummary {
name: "Foundation and Earth",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Clearly, if Earth is powerful enough to do that, it might also be capable of adjusting minds in order to force belief in its radioactivity"),
lastMessageFormattedTimestamp: "1986",
unreadMessagesCount: 1,
@@ -164,6 +169,7 @@ extension Array where Element == RoomSummary {
name: "Prelude to Foundation",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
unreadMessagesCount: 6,
@@ -180,6 +186,7 @@ extension Array where Element == RoomSummary {
name: "Unknown",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
@@ -229,6 +236,7 @@ extension Array where Element == RoomSummary {
name: "First room",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
@@ -245,6 +253,7 @@ extension Array where Element == RoomSummary {
name: "Second room",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,