mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Make timeline reactions and reaction senders identifiable
This commit is contained in:
committed by
Stefan Ceriu
parent
9bb177bff5
commit
2a33ee1f63
@@ -38,7 +38,7 @@ enum RoomTimelineItemFixtures {
|
||||
sender: .init(id: "", displayName: "Helena"),
|
||||
content: .init(body: "Let’s get lunch soon! New salad place opened up 🥗. When are y’all free? 🤗"),
|
||||
properties: RoomTimelineItemProperties(reactions: [
|
||||
AggregatedReaction(accountOwnerID: "me", key: "🙌", senders: [ReactionSender(senderID: "me", timestamp: Date())])
|
||||
AggregatedReaction(accountOwnerID: "me", key: "🙌", senders: [ReactionSender(id: "me", timestamp: Date())])
|
||||
])),
|
||||
TextRoomTimelineItem(id: .random,
|
||||
timestamp: "10:11 AM",
|
||||
@@ -49,13 +49,13 @@ enum RoomTimelineItemFixtures {
|
||||
sender: .init(id: "", displayName: "Helena"),
|
||||
content: .init(body: "I can be around on Wednesday. How about some 🌮 instead? Like https://www.tortilla.co.uk/"),
|
||||
properties: RoomTimelineItemProperties(reactions: [
|
||||
AggregatedReaction(accountOwnerID: "me", key: "🙏", senders: [ReactionSender(senderID: "helena", timestamp: Date())]),
|
||||
AggregatedReaction(accountOwnerID: "me", key: "🙏", senders: [ReactionSender(id: "helena", timestamp: Date())]),
|
||||
AggregatedReaction(accountOwnerID: "me",
|
||||
key: "🙌",
|
||||
senders: [
|
||||
ReactionSender(senderID: "me", timestamp: Date()),
|
||||
ReactionSender(senderID: "helena", timestamp: Date()),
|
||||
ReactionSender(senderID: "jacob", timestamp: Date())
|
||||
ReactionSender(id: "me", timestamp: Date()),
|
||||
ReactionSender(id: "helena", timestamp: Date()),
|
||||
ReactionSender(id: "jacob", timestamp: Date())
|
||||
])
|
||||
])),
|
||||
SeparatorRoomTimelineItem(id: .init(timelineID: "Today"), text: "Today"),
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
import Foundation
|
||||
|
||||
/// Represents all reactions of the same type for a single event.
|
||||
struct AggregatedReaction: Hashable {
|
||||
struct AggregatedReaction: Hashable, Identifiable {
|
||||
/// Length at which we ellipsize a reaction key for display
|
||||
/// Reactions can be free text, so we need to limit the length
|
||||
/// displayed on screen.
|
||||
private static let maxDisplayChars = 16
|
||||
|
||||
var id: String {
|
||||
key
|
||||
}
|
||||
|
||||
/// The id of the account owner
|
||||
let accountOwnerID: String
|
||||
/// The reaction that was sent.
|
||||
@@ -32,9 +36,9 @@ struct AggregatedReaction: Hashable {
|
||||
}
|
||||
|
||||
/// Details of who sent the reaction
|
||||
struct ReactionSender: Hashable {
|
||||
struct ReactionSender: Hashable, Identifiable {
|
||||
/// The id of the user who sent the reaction
|
||||
let senderID: String
|
||||
let id: String
|
||||
/// The time that the reaction was received on the original homeserver
|
||||
let timestamp: Date
|
||||
}
|
||||
@@ -47,7 +51,7 @@ extension AggregatedReaction {
|
||||
|
||||
/// Whether to highlight the reaction, indicating that the current user sent this reaction.
|
||||
var isHighlighted: Bool {
|
||||
senders.contains(where: { $0.senderID == accountOwnerID })
|
||||
senders.contains(where: { $0.id == accountOwnerID })
|
||||
}
|
||||
|
||||
/// The key to be displayed on screen. See `maxDisplayChars`.
|
||||
|
||||
@@ -418,7 +418,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
reactions.map { reaction in
|
||||
let senders = reaction.senders
|
||||
.map { senderData in
|
||||
ReactionSender(senderID: senderData.senderId, timestamp: Date(timeIntervalSince1970: TimeInterval(senderData.timestamp / 1000)))
|
||||
ReactionSender(id: senderData.senderId, timestamp: Date(timeIntervalSince1970: TimeInterval(senderData.timestamp / 1000)))
|
||||
}
|
||||
.sorted { a, b in
|
||||
// Sort reactions within an aggregation by timestamp descending.
|
||||
|
||||
Reference in New Issue
Block a user