Skip to content

Conversation

@xsahil03x
Copy link
Member

No description provided.

@xsahil03x xsahil03x requested a review from a team as a code owner August 25, 2025 15:57
@xsahil03x xsahil03x changed the title refactor(llc): refactor client refactor(llc): refactor client and add client impl Aug 25, 2025
@xsahil03x xsahil03x changed the title refactor(llc): refactor client and add client impl refactor(llc): refactor client and add impl Aug 25, 2025
This commit introduces client-side state management for all list types:
- `ActivityList`
- `ActivityCommentList`
- `ActivityReactionList`
- `BookmarkList`
- `BookmarkFolderList`
- `CommentReplyList`
- `CommentReactionList`
- `FollowList`
- `PollList`
- `PollVoteList`

It also implements the `Activity` state object.

Each list type and the `Activity` object now have:
- A dedicated state notifier (e.g., `ActivityListStateNotifier`).
- A corresponding state class (e.g., `ActivityListState`) using `freezed`.
- Event handlers for real-time updates via WebSockets (e.g., `ActivityListEventHandler`).

Key changes:
- `FeedsClientImpl`:
  - Instantiates and returns the new stateful list objects.
  - Passes necessary repositories and event emitters to these objects.
  - Adds `pollAnswerCastedFeedEventResolver` and `pollAnswerRemovedFeedEventResolver` to WebSocket event resolvers.
  - Corrects user image field in `_authenticateUser`.
  - Handles `ClientException` for anonymous user connection attempts.
- State notifiers:
  - Manage the data (e.g., activities, comments) and pagination state.
  - Provide methods to update the state based on API responses and WebSocket events.
  - Utilize `QueryConfiguration` to store and use filter and sort parameters.
- State classes:
  - Define the structure of the observable state (e.g., list of items, pagination data).
  - Include a `canLoadMore` getter.
- Event handlers:
  - Process specific WebSocket events relevant to their list type.
  - Call appropriate methods on the state notifier to update the state.
- Model updates:
  - `ThreadedCommentData`: Added mutation methods for reactions and replies, and a `setCommentData` method.
  - `ActivitiesSortField`: `createdAt` now uses `data.createdAt`, `popularity` uses `data.popularity`.
  - `ReactionGroupData`: Improved logic in `decrement` and `increment` methods.
  - `PollData`: Added `ownVotesAndAnswers`, `ownVotes`, `ownAnswers`, and `latestVotes` getters. Added mutation methods for options and answers.
  - `PollVoteData`: `isAnswer` is now a getter based on `answerText`.
- Repository updates:
  - `CommentsRepository`: `deleteComment` now accepts an optional `hardDelete` parameter.
  - `PollsRepository`: Removed `userId` parameter from `deletePoll`, `getPoll`, `deletePollOption`, `getPollOption`, and `deletePollVote`.
- New event resolvers:
  - `pollAnswerCastedFeedEventResolver`: Resolves `PollAnswerCastedFeedEvent` from `PollVoteCastedFeedEvent` or `PollVoteChangedFeedEvent`.
  - `pollAnswerRemovedFeedEventResolver`: Resolves `PollAnswerRemovedFeedEvent` from `PollVoteRemovedFeedEvent`.

This provides a reactive way to interact with lists of data from Stream Feeds, automatically handling updates and pagination.
The `event_resolvers` directory and its contents have been moved to a new directory named `resolvers`. This change aims to improve the project structure and clarity.

Imports in affected files have been updated to reflect the new location of the resolver utilities.
The FeedsStateNotifier class was identical to StateNotifier and thus redundant. This commit removes FeedsStateNotifier and updates ActivityReactionListStateNotifier to directly extend StateNotifier.
The `collection` package was being imported but not used in several state management files. This commit removes those unnecessary imports.
This commit introduces significant improvements to the script used for generating the Dart client for Stream Feeds.

Key changes:
- **Configuration:** Moved the `CHAT_DIR` configuration to the top of the script for easier modification by developers.
- **Path Handling:** Implemented more robust path handling using `SCRIPT_DIR` and `REPO_ROOT` to make the script less dependent on absolute paths.
- **Validation:** Added checks for the existence of `CHAT_DIR`, `renamed-models.json`, and the presence of `go` and `dart` in the system PATH.
- **Clarity:** Added `echo` statements to provide better feedback to the user during the generation process.
- **Sed Portability:** Replaced `sed -i ''` with a more portable `sed_inplace` function that works on both macOS and Linux.
- **Scoped Build & Format:** Limited `build_runner` and `dart format` to only run on the `stream_feeds` package, improving efficiency.
- **Output Directory:** Ensured the output directory for generated code is created if it doesn't exist.
- **Error Handling:** Utilized `set -euo pipefail` for better script error handling.
- **Melos Integration:** Added a new melos script `gen:feeds` to trigger this generation script.

The script now performs the following steps:
1. Generates the OpenAPI spec and Dart client from the chat repository.
2. Applies post-generation fixes (e.g., removing duplicate fields in generated models).
3. Runs `build_runner` specifically for the `stream_feeds` package.
4. Formats the generated code within the `stream_feeds` package.
The User.imageUrl field has been renamed to User.image to better reflect its purpose and potentially support non-URL image sources in the future.

This commit updates the sample_app to use the new field name.
This script is no longer needed as the OpenAPI client generation process has been consolidated into the `chat-manager` tool within the `stream-chat-go` repository.
melos.yaml Outdated
git:
url: https://github.com/GetStream/stream-core-flutter.git
path: packages/stream_core
ref: main
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a branch for ref is not so nice. You have to delete your pubspec.lock to update the package when there is a new version on that branch because the lock file refers to a specific commit.

Better to use commit hash, or maybe even add pre-release tags, but I would go for the hash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# =========================
CHAT_DIR="/ABSOLUTE/PATH/TO/YOUR/chat/repo"
if [[ "$CHAT_DIR" == "/ABSOLUTE/PATH/TO/YOUR/chat/repo" ]]; then
echo "❌ Please edit scripts/gen-feeds.sh and set CHAT_DIR to your local chat repo path"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of the scripts/gen-feeds.sh?
Good to add some explanation to the readme in the root of the repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a typo, it should be scripts/generate.sh. I additionally added a melos script to call it directly.

melos gen:feeds

This commit updates the `stream_core` dependency in both `melos.yaml` and `packages/stream_feeds/pubspec.yaml` to point to a specific commit hash (`3b59846b89070fdd542945dbc1228a0a472e9b37`) instead of the `main` branch. This ensures that the project uses a consistent and tested version of the `stream_core` package.
@xsahil03x xsahil03x merged commit 1932eeb into main Aug 29, 2025
3 of 6 checks passed
@xsahil03x xsahil03x deleted the refactor/client branch September 1, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants