GetStream / stream-js

JS / Browser Client - Build Activity Feeds & Streams with GetStream.io
https://getstream.io
BSD 3-Clause "New" or "Revised" License
329 stars 110 forks source link

Feature Request: Add option to enrich reaction object withOwnReactions, withReactionCounts, etc. #592

Open SahidMiller opened 8 months ago

SahidMiller commented 8 months ago

Please add the option to enrich a reaction's activity object with the activity's reactions so clients can display the original activity's reaction counts and current user's own reactions. This is necessary to implement common features in popular social media platforms like Twitter, such as "reposts" (displaying the original activity's reaction counts) and similar features.

Currently, the code below allows reposting but does not allow client.feed('user_likes', userId).get({}) to retrieve the original activity's reaction counts or the current user's own reactions to the original activity. Enrichment only returns the original activity's basic information (via object) without it's reactions.

await client.reactions.add('like', activityId, {}, {
    userId,
    targetFeeds: ['user_likes:' + userId],
  }
)

client.feed('user_likes', userId).get({
  user_id: currentUserId || undefined,
  id_lte: cursor2?.fromId,
  limit: 20,
  enrich: true,
  withOwnReactions: true,
  withReactionCounts: true,
  withOwnChildren: true,
})

/**
Returns: 
{
   foreign_id: 'reaction:...',
   id: '...',
   actor: {
     //reaction's actor
   },
   object: {
    //original activity info
    actor: '...',
    foreign_id: '...',
    id: '...',
    object: '...',
    origin: null,
    target: '',
    time: '...',
    verb: 'post'
   },
   origin: null,
   own_reactions: {},
   reaction: {
    //reaction's info
    created_at: '...',
    updated_at: '...',
    id: '...',
    user_id: '...',
    kind: 'like',
    activity_id: '...',
    data: {},
    target_feeds: [..],
    parent: '',
    latest_children: {},
    children_counts: {}
   },
  //child reaction count of current reaction
  reaction_counts: {},
  verb: 'like'
}
**/

The code below also allows for a reposting type feature with the original's reactions but does not maintain the order of when the activity was added to the additional feed. Rather, it orders based on the activity's original create date. (ie. liking post2 and then post1, will return post1 before post2 when fetched).

client.feed('user', authorId).updateActivityToTargets(postId, createdAt.toISOString(), undefined, [`user_likes:${userId}`])

Please add the option to enrich reactions with activity objects with that activity objects reactions such as with the following options:

client.feed('user', id).get({
  user_id: currentUserId || undefined,
  id_lte: cursor2?.fromId,
  limit: 20,
  enrich: true,

  //EXISTING: For current activity
  withOwnReactions: true,
  withReactionCounts: true,
  withOwnChildren: true,

  //NEW: for nested activity
  withActivityObjectReactions: true,
  withOwnActivityObjectReactions: true
})

/**
Returns: same as previous code snippet but adding the following:
{
  object: {
   //NEW: for nested activity (original activity reacted to)
   reaction_counts: {},
   own_reactions: {}
  }
}
**/