How to Make a Social Media App
The Global Feed
To make a Social Media style app, you could make a Global Feed where all Posts (Activities) are viewable by everyone. The Global Feed Group would have a Feed Type of Flat. Every Post to the Global Feed would be coupled with a Post to a User Feed, which means that every Post to a User Feed - ‘user:zachery’ - could have a ‘to’ field of [‘global:all’] so that every viewer of the Global Feed will be viewing the same Feed. Ranking can be used to sort Posts with a 'popularity' field.
The User Feed
A User Feed would be specific to every user and would be viewable by everyone. The User Feed Group would have a Feed Type of Flat. It would contain only all the Posts from the Owner plus the Reactions to those Posts - and Reactions to those Reactions. Reactions could include Comments on a Post and Likes to Posts and Comments. The Owner is the only user with permission to write to a User Feed - other than Reactions to Posts. Everyone has permission to read Posts & Reactions as well as write Reactions. Posts to a User Feed would be in reverse chronological order.
Instantiate a Client, Get Or Create a Feed, and Add an Activity
const client = stream.connect(key, userToken, appId);
const userFeed = client.feed("user", client.userId);
await userFeed.addActivity({
verb: "post",
object: "text:9",
foreign_id: "text:9",
time: new Date(),
tweet: message,
popularity: 1,
to: ["global:all"],
});
Add a Reaction (comment) to an Activity
await userFeed.client.reactions.add(
"comment",
activity.id,
{ text: comment },
{ targetFeeds: [`notification:${activity.actor.id}`] },
);
The Timeline Feed
A Timeline Feed would be specific to every user - ‘timeline:zachery’ - and would contain Posts from the User Feeds that the Timeline Feed Follows. The Timeline Feed Group would have a Feed Type of Flat. A Timeline Feed may Follow another User Feed from the Global Feed or from a User Feed (which is accessed from the Global Feed). Following a User Feed will add the Posts and their Reactions from the Followed User Feed to the Follower’s Timeline Feed (this is logic built into the Stream Feeds API). Only the Owner of a Timeline Feed would be allowed to view this Feed. The Owner would not write Posts to a Timeline Feed, but may write Reactions to any Post.
Get Or Create a Timeline and Notification Feed and Create a Follow Relationship
const timelineFeed = client.feed("timeline", client.userId);
const notificationFeed = client.feed("notification", client.userId);
await timelineFeed.follow("user", activity.actor.id);
await notificationFeed.follow("user", activity.actor.id);
The Notification Feed
A Notification Feed would be specific to every user - ‘notification:zachery’ - and would contain information about a user's Posts & Reactions, your Followers Posts & Reactions, as well as the Posts & Reactions of the people you Follow. The Notification Feed Group would have a Feed Type of Notification. This Feed will have real-time counts of Seen and Unseen properties as well as is_read and is_unread properties that would be updated accordingly. A Notification Feed is only viewable to the Owner. No writes - Posts or Reactions - to a Notification Feed would be allowed - Only read. In order for the Notification Feed to receive Reactions as Activities, the 'targetFeeds' property would be used when adding Reactions.
Fetch Notification Feed and mark Activity Groups as Read
await notificationFeed.get({ mark_read: true });
Comments
0 comments
Please sign in to leave a comment.