updateUserPropertiesCount method

Future<void> updateUserPropertiesCount({
  1. required String uid,
  2. int onboardingStep = 0,
  3. int followers = 0,
  4. int following = 0,
  5. int notifCount = 0,
  6. int reactionsReceivedFromFeeds = 0,
  7. int commentsReceivedFromFeeds = 0,
  8. int repliesReceivedFromFeeds = 0,
  9. int sharesReceivedFromFeeds = 0,
  10. int viewsReceivedFromFeeds = 0,
})

Implementation

Future<void> updateUserPropertiesCount({
  required final String uid,
  final int onboardingStep = 0,
  final int followers = 0,
  final int following = 0,
  final int notifCount = 0,
  final int reactionsReceivedFromFeeds = 0,
  final int commentsReceivedFromFeeds = 0,
  final int repliesReceivedFromFeeds = 0,
  final int sharesReceivedFromFeeds = 0,
  final int viewsReceivedFromFeeds = 0,
}) async {
  try {
    final _usersRef = PeamanReferenceHelper.usersCol.doc(uid);
    final _data = <String, dynamic>{
      'onboarding_step': FieldValue.increment(onboardingStep),
      'followers': FieldValue.increment(followers),
      'following': FieldValue.increment(following),
      'notif_count': FieldValue.increment(notifCount),
      'reactions_received_from_feeds':
          FieldValue.increment(reactionsReceivedFromFeeds),
      'comments_received_from_feeds':
          FieldValue.increment(commentsReceivedFromFeeds),
      'replies_received_from_feeds':
          FieldValue.increment(repliesReceivedFromFeeds),
      'shares_received_from_feeds':
          FieldValue.increment(sharesReceivedFromFeeds),
      'views_received_from_feeds':
          FieldValue.increment(viewsReceivedFromFeeds),
    };

    _data.removeWhere((key, value) => value == 0);

    await _usersRef.update(_data);
    print('Success: Updating user properties count $uid');
  } catch (e) {
    print(e);
    print('Error: Updating user properties count');
  }
}