-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reactions users view not paginating results (#712)
* Fix reactions users view not paginating results * Update CHANGELOG.md * Create seperate file for the view model
- Loading branch information
1 parent
ff23f48
commit f566ec1
Showing
5 changed files
with
105 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Sources/StreamChatSwiftUI/ChatChannel/Reactions/ReactionsUsersViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright © 2025 Stream.io Inc. All rights reserved. | ||
// | ||
|
||
import StreamChat | ||
import SwiftUI | ||
|
||
class ReactionsUsersViewModel: ObservableObject, ChatMessageControllerDelegate { | ||
@Published var reactions: [ChatMessageReaction] = [] | ||
|
||
var totalReactionsCount: Int { | ||
messageController?.message?.totalReactionsCount ?? 0 | ||
} | ||
|
||
var isRightAligned: Bool { | ||
messageController?.message?.isRightAligned == true | ||
} | ||
|
||
private var isLoading = false | ||
private let messageController: ChatMessageController? | ||
|
||
init(message: ChatMessage) { | ||
if let cid = message.cid { | ||
messageController = InjectedValues[\.chatClient].messageController( | ||
cid: cid, | ||
messageId: message.id | ||
) | ||
} else { | ||
messageController = nil | ||
} | ||
messageController?.delegate = self | ||
loadMoreReactions() | ||
} | ||
|
||
func loadMoreReactions() { | ||
guard let messageController = self.messageController else { | ||
return | ||
} | ||
guard !isLoading && messageController.hasLoadedAllReactions == false else { | ||
return | ||
} | ||
|
||
isLoading = true | ||
messageController.loadNextReactions { [weak self] _ in | ||
self?.isLoading = false | ||
} | ||
} | ||
|
||
func messageController(_ controller: ChatMessageController, didChangeReactions reactions: [ChatMessageReaction]) { | ||
self.reactions = reactions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters