logViewed method

Future<bool> logViewed(
  1. List<NotificationMessage> messages
)

logViewed @since 4.5.0

Implementation

Future<bool> logViewed(List<NotificationMessage> messages) async {
  if (messages.isNotEmpty && messages.length <= _logImpressionMessagesLimit) {
    bool result = true;
    for (final message in messages) {
      final Map<String, dynamic> data = {
        'action': 'viewed',
        'template_key': message.notificationData?.templateKey ?? '',
        'channel_url': message.channelUrl,
        'tags': message.notificationData?.tags ?? [],
        'message_id': message.notificationId,
        'source': 'notification',
        'message_ts': message.createdAt,
      };

      if (!await SendbirdStatistics.appendStat(
        type: SendbirdStatistics.notiStatsType,
        data: data,
      )) {
        result = false;
      }
    }
    return result;
  }
  return false;
}