onRemoveChildReaction method

Future<void> onRemoveChildReaction({
  1. required String kind,
  2. required String lookupValue,
  3. required Reaction childReaction,
  4. required Reaction parentReaction,
})

Remove child reactions from the feed in a reactive way

For example to unlike a comment

FeedProvider.of(context).bloc.onRemoveChildReaction()

Implementation

Future<void> onRemoveChildReaction({
  required String kind,
  required String lookupValue,
  required Reaction childReaction,
  required Reaction parentReaction,
}) async {
  await client.reactions.delete(childReaction.id!);
  // await trackAnalytics(
  //     label: kind, foreignId: activity.foreignId, feedGroup: feedGroup);
  final _reactions = getReactions(lookupValue, parentReaction);
  final reactionPath = _reactions.getReactionPath(parentReaction);
  final indexPath = _reactions.indexWhere(
      (r) => r.id! == parentReaction.id); //TODO: handle null safety

  final reactionCounts =
      reactionPath.childrenCounts.unshiftByKind(kind, ShiftType.decrement);
  final latestReactions = reactionPath.latestChildren
      .unshiftByKind(kind, childReaction, ShiftType.decrement);
  final ownReactions = reactionPath.ownChildren
      .unshiftByKind(kind, childReaction, ShiftType.decrement);

  final updatedReaction = reactionPath.copyWith(
    ownChildren: ownReactions,
    latestChildren: latestReactions,
    childrenCounts: reactionCounts,
  );

  // adds reaction to the stream
  reactionsManager
    ..unshiftById(lookupValue, childReaction, ShiftType.decrement)
    ..update(
        lookupValue,
        _reactions //TODO: handle null safety
            .updateIn(updatedReaction, indexPath));
}