Skip to content

Commit

Permalink
Change the order of the latest votes so that the first one is the mos…
Browse files Browse the repository at this point in the history
…t recent one
  • Loading branch information
nuno-vieira committed Sep 29, 2024
1 parent f698986 commit 12aa799
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Sources/StreamChat/Database/DTOs/PollDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ extension PollDTO {
latestAnswers: latestVotes
.filter { $0.isAnswer }
.map { try $0.asModel() }
.sorted(by: { $0.createdAt < $1.createdAt }),
.sorted(by: { $0.createdAt > $1.createdAt }),
options: optionsArray.map { try $0.asModel() },
latestVotesByOption: latestVotesByOption.map { try $0.asModel() },
latestVotes: latestVotesByOption
.map(\.latestVotes)
.joined()
.map { try $0.asModel() }
.sorted(by: { $0.createdAt < $1.createdAt }),
.sorted(by: { $0.createdAt > $1.createdAt }),
ownVotes: latestVotes
.filter { !$0.isAnswer && $0.user?.id == currentUserId }
.map { try $0.asModel() }
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamChat/Database/DTOs/PollOptionDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension PollOptionDTO {
text: text,
latestVotes: try latestVotes
.map { try $0.asModel() }
.sorted(by: { $0.createdAt < $1.createdAt }),
.sorted(by: { $0.createdAt > $1.createdAt }),
extraData: extraData
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ open class ChatChannelListItemView: _View, ThemeProvider, SwiftUIRepresentable {
open func pollAttachmentPreviewText(for previewMessage: ChatMessage) -> String? {
guard let poll = previewMessage.poll, !previewMessage.isDeleted else { return nil }
var components = ["📊"]
if let latestVoter = poll.latestVotes.last?.user {
if let latestVoter = poll.latestVotes.first?.user {
if latestVoter.id == content?.currentUserId {
components.append(L10n.Message.Preview.pollYouVoted)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@ final class ChatChannelListItemView_Tests: XCTestCase {
poll: .mock(
name: "Poll",
latestVotes: [
.mock(user: currentUser),
.mock(user: .unique),
.mock(user: .unique),
.mock(user: currentUser)
.mock(user: .unique)
]
),
messageAuthor: currentUser,
Expand All @@ -782,9 +782,9 @@ final class ChatChannelListItemView_Tests: XCTestCase {
poll: .mock(
name: "Poll",
latestVotes: [
.mock(user: .unique),
.mock(user: .mock(id: .unique, name: "Someone")),
.mock(user: currentUser),
.mock(user: .mock(id: .unique, name: "Someone"))
.mock(user: .unique)
]
),
messageAuthor: currentUser,
Expand Down

0 comments on commit 12aa799

Please sign in to comment.