LCOV - code coverage report
Current view: top level - client - reactions_client.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 25 29 86.2 %
Date: 2021-04-14 08:03:52 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:stream_feed_dart/src/core/api/reactions_api.dart';
       2             : import 'package:stream_feed_dart/src/core/http/token.dart';
       3             : import 'package:stream_feed_dart/src/core/index.dart';
       4             : import 'package:stream_feed_dart/src/core/models/paginated.dart';
       5             : import 'package:stream_feed_dart/src/core/util/default.dart';
       6             : import 'package:stream_feed_dart/src/core/util/token_helper.dart';
       7             : 
       8             : /// Manage api calls for all things related to reactions
       9             : /// The ReactionsClientImpl object contains convenient functions
      10             : /// such add, delete, get, update ... reactions
      11             : class ReactionsClient {
      12             :   ///Initialize a reaction client
      13           2 :   ReactionsClient(this.reactions, {this.userToken, this.secret})
      14             :       : assert(
      15           0 :           userToken != null || secret != null,
      16             :           'At least a secret or userToken must be provided',
      17             :         );
      18             :   final Token? userToken;
      19             : 
      20             :   final ReactionsApi reactions;
      21             : 
      22             :   /// Your API secret. You can get it in your Stream Dashboard [here](https://dashboard.getstream.io/dashboard/v2/)
      23             :   final String? secret;
      24             : 
      25             :   /// Add reaction
      26             :   ///
      27             :   /// Parameters:
      28             :   /// [kind] : kind of reaction
      29             :   /// [activityId] :  an ActivityID
      30             :   /// [data] : extra data related to target feeds
      31             :   /// [targetFeeds] : an array of feeds to which to send
      32             :   /// an activity with the reaction
      33             :   ///
      34             :   /// Examples:
      35             :   /// - Add a like reaction to the activity
      36             :   /// with id activityId
      37             :   ///
      38             :   /// ```dart
      39             :   /// final like = await client.reactions.add('like', activity.id, 'john-doe');
      40             :   /// ```
      41             :   /// - Add a comment reaction to the activity with id activityId
      42             :   ///```dart
      43             :   /// final comment = await client.reactions.add(
      44             :   ///   'comment',
      45             :   ///   activity.id,
      46             :   ///   'john-doe',
      47             :   ///   data: {'text': 'awesome post!'},
      48             :   /// );
      49             :   ///```
      50             :   ///
      51             :   /// API docs: [adding-reactions](https://getstream.io/activity-feeds/docs/flutter-dart/reactions_introduction/?language=dart#adding-reactions)
      52           1 :   Future<Reaction> add(
      53             :     String kind,
      54             :     String activityId,
      55             :     String userId, {
      56             :     Map<String, Object>? data,
      57             :     Iterable<FeedId>? targetFeeds,
      58             :   }) {
      59           1 :     final reaction = Reaction(
      60             :       kind: kind,
      61             :       activityId: activityId,
      62             :       userId: userId,
      63             :       data: data,
      64             :       targetFeeds: targetFeeds as List<FeedId>?,
      65             :     );
      66             :     final token =
      67           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.write);
      68           2 :     return reactions.add(token, reaction);
      69             :   }
      70             : 
      71             :   /// Adds a like to the previously created comment
      72             :   ///
      73             :   ///Example:
      74             :   ///```dart
      75             :   ///final reaction = await client.reactions.addChild(
      76             :   ///'like',
      77             :   ///comment.id,
      78             :   ///'john-doe',
      79             :   ///);
      80             :   ///```
      81             :   ///
      82             :   /// API docs: [reactions_add_child](https://getstream.io/activity-feeds/docs/flutter-dart/reactions_add_child/?language=dart)
      83           1 :   Future<Reaction> addChild(
      84             :     String kind,
      85             :     String parentId,
      86             :     String userId, {
      87             :     Map<String, Object>? data,
      88             :     Iterable<FeedId>? targetFeeds,
      89             :   }) {
      90           1 :     final reaction = Reaction(
      91             :       kind: kind,
      92             :       parent: parentId,
      93             :       userId: userId,
      94             :       data: data,
      95             :       targetFeeds: targetFeeds as List<FeedId>?,
      96             :     );
      97             :     final token =
      98           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.write);
      99           2 :     return reactions.add(token, reaction);
     100             :   }
     101             : 
     102             :   /// Delete reaction
     103             :   ///
     104             :   /// It takes in parameters:
     105             :   /// - [id] : Reaction Id
     106             :   ///
     107             :   /// Example:
     108             :   /// ```dart
     109             :   /// reactions.delete("67b3e3b5-b201-4697-96ac-482eb14f88ec");
     110             :   /// ```
     111             :   ///
     112             :   /// API docs: [removing-reactions](https://getstream.io/activity-feeds/docs/flutter-dart/reactions_introduction/?language=dart#removing-reactions)
     113           1 :   Future<void> delete(String id) {
     114           1 :     final token = userToken ??
     115           0 :         TokenHelper.buildReactionToken(secret!, TokenAction.delete);
     116           2 :     return reactions.delete(token, id);
     117             :   }
     118             : 
     119             :   /// Get reaction
     120             :   /// [retrieving-reactions](https://getstream.io/activity-feeds/docs/flutter-dart/reactions_introduction/?language=dart#retrieving-reactions)
     121           1 :   Future<Reaction> get(String id) {
     122             :     final token =
     123           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.read);
     124           2 :     return reactions.get(token, id);
     125             :   }
     126             : 
     127           1 :   Future<void> update(
     128             :     String? reactionId, {
     129             :     Map<String, Object>? data,
     130             :     Iterable<FeedId>? targetFeeds,
     131             :   }) {
     132           1 :     final reaction = Reaction(
     133             :       id: reactionId,
     134             :       data: data,
     135             :       targetFeeds: targetFeeds as List<FeedId>?,
     136             :     );
     137             :     final token =
     138           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.write);
     139           2 :     return reactions.update(token, reaction);
     140             :   }
     141             : 
     142           1 :   Future<List<Reaction>> filter(
     143             :     LookupAttribute lookupAttr,
     144             :     String lookupValue, {
     145             :     Filter? filter,
     146             :     int? limit,
     147             :     String? kind,
     148             :   }) {
     149             :     final token =
     150           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.read);
     151           2 :     return reactions.filter(token, lookupAttr, lookupValue,
     152           0 :         filter ?? Default.filter, limit ?? Default.limit, kind ?? '');
     153             :   }
     154             : 
     155             :   //Server side functions
     156           1 :   Future<PaginatedReactions> paginatedFilter(
     157             :     LookupAttribute lookupAttr,
     158             :     String lookupValue, {
     159             :     Filter? filter,
     160             :     int? limit,
     161             :     String? kind,
     162             :   }) {
     163             :     final token =
     164           1 :         userToken ?? TokenHelper.buildReactionToken(secret!, TokenAction.read);
     165           2 :     return reactions.paginatedFilter(token, lookupAttr, lookupValue,
     166           0 :         filter ?? Default.filter, limit ?? Default.limit, kind ?? '');
     167             :   }
     168             : }

Generated by: LCOV version 1.15