Skip to content

Commit f8e0ec1

Browse files
committed
feat(llc): refactor FilterField and SortField to support local filtering
This commit refactors `FilterField` and `SortField` from `extension type` to `class` to enable local, client-side filtering and sorting capabilities. Key changes: - `FilterField` and `SortField` in all query files are now classes that hold both a remote string value for the API and a local value accessor function. - `QueryConfiguration` is now generic over the data type `T` (`QueryConfiguration<T>`) instead of separate `Sort` and `FilterField` types. - Typedefs for filters (e.g., `ActivitiesFilter = Filter<ActivityData>`) have been added for clarity. - `FeedData.fid` has been renamed to `FeedData.feed` for consistency. - Updated various state holders and doc snippets to align with the new generic query and field structures.
1 parent 6926cb7 commit f8e0ec1

File tree

53 files changed

+745
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+745
-373
lines changed

docs/code_snippets/03_02_querying_activities.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ late Feed feed;
55

66
Future<void> activitySearchAndQueries() async {
77
final query = ActivitiesQuery(
8-
filter: const Filter.equal(ActivitiesFilterField.type, 'post'),
8+
filter: Filter.equal(ActivitiesFilterField.type, 'post'),
99
sort: [ActivitiesSort.desc(ActivitiesSortField.createdAt)],
1010
limit: 10,
1111
);
@@ -16,7 +16,7 @@ Future<void> activitySearchAndQueries() async {
1616

1717
Future<void> queryActivitiesByText() async {
1818
// search for activities where the text includes the word 'popularity'.
19-
const query = ActivitiesQuery(
19+
final query = ActivitiesQuery(
2020
filter: Filter.equal(ActivitiesFilterField.text, 'popularity'),
2121
);
2222

@@ -38,7 +38,7 @@ Future<void> queryActivitiesBySearchData() async {
3838
final activities = await activityList.get();
3939

4040
// search for activities where the campaign took place in a mall
41-
const query2 = ActivitiesQuery(
41+
final query2 = ActivitiesQuery(
4242
filter: Filter.pathExists(
4343
ActivitiesFilterField.searchData,
4444
'campaign.location.mall',

docs/code_snippets/04_01_feeds.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Future<void> readingAFeed() async {
3434
}
3535

3636
Future<void> readingAFeedMoreOptions() async {
37-
const query = FeedQuery(
38-
fid: FeedId(group: 'user', id: 'john'),
37+
final query = FeedQuery(
38+
fid: const FeedId.user('john'),
3939
// filter activities with filter tag green
4040
activityFilter: Filter.in_(
4141
ActivitiesFilterField.filterTags,
@@ -106,7 +106,7 @@ Future<void> filteringExamples() async {
106106
],
107107
);
108108
// Now read the feed, this will fetch activity 1 and 2
109-
const query = FeedQuery(
109+
final query = FeedQuery(
110110
fid: feedId,
111111
activityFilter: Filter.in_(ActivitiesFilterField.filterTags, ['blue']),
112112
);
@@ -119,8 +119,8 @@ Future<void> filteringExamples() async {
119119

120120
Future<void> moreComplexFilterExamples() async {
121121
// Get all the activities where filter tags contain both "green" and "orange"
122-
const query = FeedQuery(
123-
fid: FeedId(group: 'user', id: 'john'),
122+
final query = FeedQuery(
123+
fid: const FeedId.user('john'),
124124
activityFilter: Filter.and([
125125
Filter.in_(ActivitiesFilterField.filterTags, ['green']),
126126
Filter.in_(ActivitiesFilterField.filterTags, ['orange']),
@@ -190,7 +190,7 @@ Future<void> memberInvites() async {
190190

191191
Future<void> queryMyFeeds() async {
192192
final query = FeedsQuery(
193-
filter: const Filter.equal(FeedsFilterField.createdById, 'john'),
193+
filter: Filter.equal(FeedsFilterField.createdById, 'john'),
194194
sort: [FeedsSort.desc(FeedsSortField.createdAt)],
195195
limit: 10,
196196
watch: true,
@@ -208,15 +208,15 @@ Future<void> queryMyFeeds() async {
208208
}
209209

210210
Future<void> queryFeedsWhereIAmAMember() async {
211-
const query = FeedsQuery(
211+
final query = FeedsQuery(
212212
filter: Filter.contains(FeedsFilterField.members, 'john'),
213213
);
214214
final feedList = client.feedList(query);
215215
final feeds = await feedList.get();
216216
}
217217

218218
Future<void> queryFeedsByNameOrVisibility() async {
219-
const sportsQuery = FeedsQuery(
219+
final sportsQuery = FeedsQuery(
220220
filter: Filter.and([
221221
Filter.equal(FeedsFilterField.visibility, 'public'),
222222
Filter.query(FeedsFilterField.name, 'Sports'),
@@ -226,7 +226,7 @@ Future<void> queryFeedsByNameOrVisibility() async {
226226
final sportsFeedList = client.feedList(sportsQuery);
227227
final sportsFeeds = await sportsFeedList.get();
228228

229-
const techQuery = FeedsQuery(
229+
final techQuery = FeedsQuery(
230230
filter: Filter.and([
231231
Filter.equal(FeedsFilterField.visibility, 'public'),
232232
Filter.autoComplete(FeedsFilterField.description, 'tech'),
@@ -238,7 +238,7 @@ Future<void> queryFeedsByNameOrVisibility() async {
238238
}
239239

240240
Future<void> queryFeedsByCreatorName() async {
241-
const query = FeedsQuery(
241+
final query = FeedsQuery(
242242
filter: Filter.and([
243243
Filter.equal(FeedsFilterField.visibility, 'public'),
244244
Filter.query(FeedsFilterField.createdByName, 'Thompson'),

docs/code_snippets/04_03_follows.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Future<void> followsAndUnfollows() async {
2222
Future<void> queryFollows() async {
2323
// Do I follow a list of feeds
2424
// My feed is timeline:john
25-
const followQuery = FollowsQuery(
25+
final followQuery = FollowsQuery(
2626
filter: Filter.and([
2727
Filter.equal(FollowsFilterField.sourceFeed, 'timeline:john'),
2828
Filter.in_(FollowsFilterField.targetFeed, ['user:sara', 'user:adam']),
@@ -34,7 +34,7 @@ Future<void> queryFollows() async {
3434
final page1And2 = followList.state.follows;
3535
// Paginating through followers for a feed
3636
// My feed is timeline:john
37-
const followerQuery = FollowsQuery(
37+
final followerQuery = FollowsQuery(
3838
filter: Filter.equal(FollowsFilterField.targetFeed, 'timeline:john'),
3939
);
4040
final followerList = client.followList(followerQuery);

docs/code_snippets/06_02_bookmarks.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ Future<void> queryingBookmarks() async {
4949
final page2 = await bookmarkList.queryMoreBookmarks(limit: 3);
5050
// Query by activity ID
5151
final activityBookmarkList = client.bookmarkList(
52-
const BookmarksQuery(
52+
BookmarksQuery(
5353
filter: Filter.equal(BookmarksFilterField.activityId, 'activity_123'),
5454
),
5555
);
5656
final activityBookmarks = await activityBookmarkList.get();
5757
// Query by folder ID
5858
final folderBookmarkList = client.bookmarkList(
59-
const BookmarksQuery(
59+
BookmarksQuery(
6060
filter: Filter.equal(BookmarksFilterField.folderId, 'folder_456'),
6161
),
6262
);
@@ -72,8 +72,8 @@ Future<void> queryingBookmarkFolders() async {
7272
final page2 = await bookmarkFolderList.queryMoreBookmarkFolders(limit: 3);
7373
// Query by folder name (partial matching)
7474
final projectFolderList = client.bookmarkFolderList(
75-
const BookmarkFoldersQuery(
76-
filter: Filter.contains(BookmarkFoldersFilterField.name, 'project'),
75+
BookmarkFoldersQuery(
76+
filter: Filter.contains(BookmarkFoldersFilterField.folderName, 'project'),
7777
),
7878
);
7979
final projectFolders = await projectFolderList.get();

docs/code_snippets/06_03_comments.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ Future<void> readingComments() async {
5454
Future<void> queryingComments() async {
5555
// Search in comment texts
5656
final list1 = client.commentList(
57-
const CommentsQuery(
57+
CommentsQuery(
5858
filter: Filter.query(CommentsFilterField.commentText, 'oat'),
5959
),
6060
);
6161
final comments1 = await list1.get();
6262

6363
// All comments for an activity
6464
final list2 = client.commentList(
65-
const CommentsQuery(
65+
CommentsQuery(
6666
filter: Filter.and([
6767
Filter.equal(CommentsFilterField.objectId, 'activity_123'),
6868
Filter.equal(CommentsFilterField.objectType, 'activity'),
@@ -73,15 +73,15 @@ Future<void> queryingComments() async {
7373

7474
// Replies to a parent activity
7575
final list3 = client.commentList(
76-
const CommentsQuery(
76+
CommentsQuery(
7777
filter: Filter.equal(CommentsFilterField.parentId, 'parent_id'),
7878
),
7979
);
8080
final comments3 = await list3.get();
8181

8282
// Comments from an user
8383
final list4 = client.commentList(
84-
const CommentsQuery(
84+
CommentsQuery(
8585
filter: Filter.equal(CommentsFilterField.userId, 'jane'),
8686
),
8787
);

docs/code_snippets/09_01_polls.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Future<void> deletePollOption() async {
132132
Future<void> queryingVotes() async {
133133
// Retrieve all votes on either option1Id or option2Id
134134
final pollVoteList = client.pollVoteList(
135-
const PollVotesQuery(
135+
PollVotesQuery(
136136
pollId: 'poll_456',
137137
filter: Filter.in_(
138138
PollVotesFilterField.optionId,
@@ -148,7 +148,7 @@ Future<void> queryingVotes() async {
148148
Future<void> queryingPolls() async {
149149
// Retrieve all polls that are closed for voting sorted by created_at
150150
final pollList = client.pollList(
151-
const PollsQuery(
151+
PollsQuery(
152152
filter: Filter.equal(PollsFilterField.isClosed, true),
153153
),
154154
);

packages/stream_feeds/lib/src/models/feed_data.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FeedData with _$FeedData {
1919
required this.createdBy,
2020
this.deletedAt,
2121
required this.description,
22-
required this.fid,
22+
required this.feed,
2323
this.filterTags = const [],
2424
required this.followerCount,
2525
required this.followingCount,
@@ -52,7 +52,7 @@ class FeedData with _$FeedData {
5252

5353
/// The unique identifier for the feed.
5454
@override
55-
final FeedId fid;
55+
final FeedId feed;
5656

5757
/// A list of tags used to filter the feed.
5858
@override
@@ -115,7 +115,7 @@ extension FeedResponseMapper on FeedResponse {
115115
createdBy: createdBy.toModel(),
116116
deletedAt: deletedAt,
117117
description: description,
118-
fid: FeedId.fromRawValue(feed),
118+
feed: FeedId.fromRawValue(feed),
119119
filterTags: [...?filterTags],
120120
followerCount: followerCount,
121121
followingCount: followingCount,

packages/stream_feeds/lib/src/models/feed_data.freezed.dart

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/stream_feeds/lib/src/models/follow_data.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class FollowData with _$FollowData {
7272
/// and the creation timestamp.
7373
/// Used for simpler identification of follow relationships.
7474
String get id {
75-
final sourceFid = sourceFeed.fid;
76-
final targetFid = targetFeed.fid;
75+
final sourceFid = sourceFeed.feed;
76+
final targetFid = targetFeed.feed;
7777
final createdAt = this.createdAt.millisecondsSinceEpoch;
7878
return '$sourceFid-$targetFid-$createdAt';
7979
}
@@ -92,14 +92,14 @@ class FollowData with _$FollowData {
9292
/// - Parameters:
9393
/// - fid: The feed ID to check against.
9494
/// - Returns: true if this is an accepted follow relationship where the target feed matches the given ID.
95-
bool isFollowerOf(FeedId fid) => isFollower && targetFeed.fid == fid;
95+
bool isFollowerOf(FeedId feed) => isFollower && targetFeed.feed == feed;
9696

9797
/// Checks if this follow relationship represents following the specified feed.
9898
///
9999
/// - Parameters:
100100
/// - fid: The feed ID to check against.
101101
/// - Returns: true if this is an accepted follow relationship where the source feed matches the given ID.
102-
bool isFollowingFeed(FeedId fid) => isFollowing && sourceFeed.fid == fid;
102+
bool isFollowingFeed(FeedId fid) => isFollowing && sourceFeed.feed == fid;
103103
}
104104

105105
/// Extension type representing the status of a follow relationship.

packages/stream_feeds/lib/src/models/get_or_create_feed_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class GetOrCreateFeedData with _$GetOrCreateFeedData {
4343

4444
/// The configuration used to query activities.
4545
@override
46-
final QueryConfiguration<ActivitiesSort, ActivitiesFilterField>
47-
activitiesQueryConfig;
46+
final QueryConfiguration<ActivityData> activitiesQueryConfig;
4847

4948
/// The feed data associated with the feed.
5049
@override

0 commit comments

Comments
 (0)