Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs_code_snippets/04_01_feeds.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ignore_for_file: unused_local_variable, avoid_redundant_argument_values
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

Expand Down
30 changes: 30 additions & 0 deletions docs_code_snippets/04_02_feeds_and_activity_visibility.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;

Future<void> feedVisibilityLevels() async {
// More options
const query = FeedQuery(
fid: FeedId(group: 'user', id: 'jack'),
data: FeedInputData(
visibility: FeedVisibility.public,
),
);
final feed = client.feedFromQuery(query);
await feed.getOrCreate();
}

Future<void> activityVisibilityLevels() async {
// Premium users can see full activity, others a preview
final privateActivity = await feed.addActivity(
request: const FeedAddActivityRequest(
text: 'Premium content',
type: 'post',
visibility: AddActivityRequestVisibility.tag,
visibilityTag: 'premium',
),
);
}
68 changes: 68 additions & 0 deletions docs_code_snippets/04_03_follows.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late StreamFeedsClient saraClient;
late StreamFeedsClient adamClient;
late Feed feed;
late Feed timeline;

Future<void> followsAndUnfollows() async {
// Follow a user
final timeline = client.feed(group: 'timeline', id: 'john');
await timeline.follow(targetFid: const FeedId(group: 'user', id: 'tom'));
// Follow a stock
await timeline.follow(targetFid: const FeedId(group: 'stock', id: 'apple'));
// Follow with more fields
await timeline.follow(
targetFid: const FeedId(group: 'stock', id: 'apple'),
custom: {'reason': 'investment'},
);
}

Future<void> queryFollows() async {
// Do I follow a list of feeds
// My feed is timeline:john
const followQuery = FollowsQuery(
filter: Filter.and([
Filter.equal(FollowsFilterField.sourceFeed, 'timeline:john'),
Filter.in_(FollowsFilterField.targetFeed, ['user:sara', 'user:adam']),
]),
);
final followList = client.followList(followQuery);
final page1 = await followList.get();
final page2 = await followList.queryMoreFollows();
final page1And2 = followList.state.follows;
// Paginating through followers for a feed
// My feed is timeline:john
const followerQuery = FollowsQuery(
filter: Filter.equal(FollowsFilterField.targetFeed, 'timeline:john'),
);
final followerList = client.followList(followerQuery);
final followerPage1 = await followerList.get();
}

Future<void> followRequests() async {
// Sara needs to configure the feed with visibility = followers for enabling follow requests
const saraFeedQuery = FeedQuery(
fid: FeedId(group: 'user', id: 'sara'),
data: FeedInputData(visibility: FeedVisibility.followers),
);
final saraFeed = saraClient.feedFromQuery(saraFeedQuery);
await saraFeed.getOrCreate();

// Adam requesting to follow the feed
final adamTimeline = adamClient.feed(group: 'timeline', id: 'adam');
await adamTimeline.getOrCreate();
final followRequest =
await adamTimeline.follow(targetFid: saraFeed.fid); // user:sara
print(followRequest.getOrNull()?.status); // .pending
// Sara accepting
await saraFeed.acceptFollow(
sourceFid: adamTimeline.fid, // timeline:adam
role: 'feed_member', // optional
);
// or rejecting the request
await saraFeed.rejectFollow(sourceFid: adamTimeline.fid); // timeline:adam
}
25 changes: 25 additions & 0 deletions docs_code_snippets/05_01_intro_defaults.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;
late Feed notificationFeed;

Future<void> notificationFeedExample() async {
final notificationFeed = client.feed(group: 'notification', id: 'john');
await notificationFeed.getOrCreate();
}

Future<void> markNotificationsAsRead() async {
await notificationFeed.markActivity(
request: const MarkActivityRequest(
// Mark all notifications as read...
markAllRead: true,
// ...or only selected ones
markRead: [
// group names to mark as read
],
),
);
}
15 changes: 15 additions & 0 deletions docs_code_snippets/05_02_feed_views.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;

Future<void> whenToUseFeedViews() async {
const query = FeedQuery(
fid: FeedId(group: 'user', id: 'john'),
view: '<id of a feed view>', // Override the default view id
);
final feed = client.feedFromQuery(query);
await feed.getOrCreate();
}
78 changes: 78 additions & 0 deletions docs_code_snippets/05_06_notification_feeds.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;
late Feed ericFeed;
late Feed janeFeed;
late Feed notificationFeed;
late Activity janeActivity;
late Activity saraComment;

Future<void> creatingNotificationActivities() async {
// Eric follows Jane
await ericFeed.follow(
targetFid: janeFeed.fid,
createNotificationActivity:
true, // When true Jane's notification feed will be updated with follow activity
);
// Eric comments on Jane's activity
await ericFeed.addComment(
request: ActivityAddCommentRequest(
comment: 'Agree!',
activityId: janeActivity.activityId,
createNotificationActivity:
true, // When true Jane's notification feed will be updated with comment activity
),
);
// Eric reacts to Jane's activity
await ericFeed.addReaction(
activityId: janeActivity.activityId,
request: const AddReactionRequest(
type: 'like',
createNotificationActivity:
true, // When true Jane's notification feed will be updated with reaction activity
),
);
// Eric reacts to a comment posted to Jane's activity by Sara
await ericFeed.addCommentReaction(
commentId: saraComment.activityId,
request: const AddCommentReactionRequest(
type: 'like',
createNotificationActivity:
true, // When true Sara's notification feed will be updated with comment reaction activity
),
);
}

Future<void> readingNotificationActivities() async {
final notificationFeed = client.feed(group: 'notification', id: 'jane');
final notifications = await notificationFeed.getOrCreate();
}

Future<void> markNotificationsAsSeen() async {
await notificationFeed.markActivity(
request: const MarkActivityRequest(
// Mark all notifications as seen...
markAllSeen: true,
// ...or only selected ones
markSeen: [
/* group names to mark as seen */
],
),
);
}

Future<void> markNotificationsAsRead() async {
await notificationFeed.markActivity(
request: const MarkActivityRequest(
// Mark all notifications as seen...
markAllRead: true,
// ...or only selected ones
markRead: [
/* group names to mark as seen */
],
),
);
}
19 changes: 19 additions & 0 deletions docs_code_snippets/05_07_processors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;
late ActivityData activity;

Future<void> readingTopics() async {
await feed.addActivity(
request: const FeedAddActivityRequest(
text: 'check out my 10 fitness tips for reducing lower back pain',
type: 'post',
),
);

// Wait for feeds.activity.updated event
print(activity.interestTags); // ["fitness", "health", "tips"]
}
24 changes: 24 additions & 0 deletions docs_code_snippets/06_01_reactions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;

Future<void> overview() async {
// Add a reaction to an activity
final reaction = await feed.addReaction(
activityId: 'activity_123',
request: const AddReactionRequest(custom: {'emoji': '❤️'}, type: 'like'),
);
// Remove a reaction
await feed.deleteReaction(activityId: 'activity_123', type: 'like');
}

Future<void> overviewRead() async {
final feedData = await feed.getOrCreate();
// Last 15 reactions on the first activity
print(feed.state.activities[0].latestReactions);
// Count of reactions by type
print(feed.state.activities[0].reactionGroups);
}
82 changes: 82 additions & 0 deletions docs_code_snippets/06_02_bookmarks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// ignore_for_file: file_names, unused_local_variable, avoid_redundant_argument_values

import 'package:stream_feeds/stream_feeds.dart';

late StreamFeedsClient client;
late Feed feed;

Future<void> addingBookmarks() async {
// Adding a bookmark to a new folder
final bookmark = await feed.addBookmark(activityId: 'activity_123');
// Adding to an existing folder
final bookmarkWithFolder = await feed.addBookmark(
activityId: 'activity_123',
request: const AddBookmarkRequest(folderId: 'folder_456'),
);
// Update a bookmark (without a folder initially) - add custom data and move it to a new folder
final updatedBookmark = await feed.updateBookmark(
activityId: 'activity_123',
request: const UpdateBookmarkRequest(
custom: {'color': 'blue'},
newFolder: AddFolderRequest(
custom: {'icon': '📁'},
name: 'New folder name',
),
),
);
// Update a bookmark - move it from one existing folder to another existing folder
final movedBookmark = await feed.updateBookmark(
activityId: 'activity_123',
request: const UpdateBookmarkRequest(
folderId: 'folder_456',
newFolderId: 'folder_789',
),
);
}

Future<void> removingBookmarks() async {
// Removing a bookmark
await feed.deleteBookmark(activityId: 'activity_123', folderId: 'folder_456');
// When you read a feed we include the bookmark
final feedData = await feed.getOrCreate();
print(feed.state.activities[0].ownBookmarks);
}

Future<void> queryingBookmarks() async {
// Query bookmarks
const query = BookmarksQuery(limit: 5);
final bookmarkList = client.bookmarkList(query);
final page1 = await bookmarkList.get();
// Get next page
final page2 = await bookmarkList.queryMoreBookmarks(limit: 3);
// Query by activity ID
final activityBookmarkList = client.bookmarkList(
const BookmarksQuery(
filter: Filter.equal(BookmarksFilterField.activityId, 'activity_123'),
),
);
final activityBookmarks = await activityBookmarkList.get();
// Query by folder ID
final folderBookmarkList = client.bookmarkList(
const BookmarksQuery(
filter: Filter.equal(BookmarksFilterField.folderId, 'folder_456'),
),
);
final folderBookmarks = await folderBookmarkList.get();
}

Future<void> queryingBookmarkFolders() async {
// Query bookmark folders
const query = BookmarkFoldersQuery(limit: 5);
final bookmarkFolderList = client.bookmarkFolderList(query);
final page1 = await bookmarkFolderList.get();
// Get next page
final page2 = await bookmarkFolderList.queryMoreBookmarkFolders(limit: 3);
// Query by folder name (partial matching)
final projectFolderList = client.bookmarkFolderList(
const BookmarkFoldersQuery(
filter: Filter.contains(BookmarkFoldersFilterField.name, 'project'),
),
);
final projectFolders = await projectFolderList.get();
}
Loading
Loading