LCOV - code coverage report
Current view: top level - lib\data\local\entity\chatwoot_message.dart - chatwoot_message.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 22 25 88.0 %
Date: Tue Jul 13 13:39:38 2021 Functions: 0 0 -

          Line data    Source code
       1             : 
       2             : import 'package:chatwoot_client_sdk/data/remote/responses/chatwoot_event.dart';
       3             : import 'package:equatable/equatable.dart';
       4             : import 'package:hive/hive.dart';
       5             : import 'package:json_annotation/json_annotation.dart';
       6             : 
       7             : part 'chatwoot_message.g.dart';
       8             : 
       9             : @JsonSerializable(explicitToJson: true)
      10             : @HiveType(typeId: 2)
      11             : class ChatwootMessage extends Equatable{
      12             : 
      13             :   @JsonKey(
      14             :     fromJson: idFromJson
      15             :   )
      16             :   @HiveField(0)
      17             :   final int id;
      18             : 
      19             :   @JsonKey()
      20             :   @HiveField(1)
      21             :   final String? content;
      22             : 
      23             :   @JsonKey(
      24             :       name:"message_type",
      25             :     fromJson: messageTypeFromJson
      26             :   )
      27             :   @HiveField(2)
      28             :   final int? messageType;
      29             : 
      30             :   @JsonKey(name:"content_type")
      31             :   @HiveField(3)
      32             :   final String? contentType;
      33             : 
      34             :   @JsonKey(name:"content_attributes")
      35             :   @HiveField(4)
      36             :   final dynamic contentAttributes;
      37             : 
      38             :   @JsonKey(
      39             :     name:"created_at",
      40             :     fromJson: createdAtFromJson
      41             :   )
      42             :   @HiveField(5)
      43             :   final String createdAt;
      44             : 
      45             :   @JsonKey(
      46             :     name:"conversation_id",
      47             :     fromJson: idFromJson
      48             :   )
      49             :   @HiveField(6)
      50             :   final int? conversationId;
      51             : 
      52             :   @JsonKey()
      53             :   @HiveField(7)
      54             :   final List<dynamic>? attachments;
      55             : 
      56             :   @JsonKey(name:"sender")
      57             :   @HiveField(8)
      58             :   final ChatwootEventMessageUser? sender;
      59             : 
      60           3 :   bool get isMine => messageType == 1;
      61             : 
      62           4 :   ChatwootMessage({
      63             :     required this.id,
      64             :     required this.content,
      65             :     required this.messageType,
      66             :     required this.contentType,
      67             :     required this.contentAttributes,
      68             :     required this.createdAt,
      69             :     required this.conversationId,
      70             :     required this.attachments,
      71             :     required this.sender
      72             :   });
      73             : 
      74             : 
      75           8 :   factory ChatwootMessage.fromJson(Map<String, dynamic> json) => _$ChatwootMessageFromJson(json);
      76             : 
      77           0 :   Map<String, dynamic> toJson() => _$ChatwootMessageToJson(this);
      78             : 
      79           1 :   @override
      80           1 :   List<Object?> get props => [
      81           1 :     id,
      82           1 :     content,
      83           1 :     messageType,
      84           1 :     contentType,
      85           1 :     contentAttributes,
      86           1 :     createdAt,
      87           1 :     conversationId,
      88           1 :     attachments,
      89           1 :     sender
      90             :   ];
      91             : 
      92             : }
      93             : 
      94           4 : int idFromJson(value){
      95           4 :   if(value is String){
      96           0 :     return int.tryParse(value) ?? 0;
      97             :   }
      98             :   return value;
      99             : }
     100             : 
     101           4 : int messageTypeFromJson(value){
     102           4 :   if(value is String){
     103           0 :     return int.tryParse(value) ?? 0;
     104             :   }
     105             :   return value;
     106             : }
     107             : 
     108           4 : String createdAtFromJson(value){
     109           4 :   if(value is int){
     110           8 :     return DateTime.fromMillisecondsSinceEpoch(value).toString();
     111             :   }
     112           1 :   return value.toString();
     113             : }

Generated by: LCOV version 1.15.alpha0w