LCOV - code coverage report
Current view: top level - lib\data\remote\responses\chatwoot_event.dart - chatwoot_event.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 33 46 71.7 %
Date: Tue Jul 13 13:39:38 2021 Functions: 0 0 -

          Line data    Source code
       1             : 
       2             : 
       3             : import 'package:chatwoot_client_sdk/chatwoot_client_sdk.dart';
       4             : import 'package:equatable/equatable.dart';
       5             : import 'package:hive/hive.dart';
       6             : import 'package:json_annotation/json_annotation.dart';
       7             : 
       8             : part 'chatwoot_event.g.dart';
       9             : 
      10             : @JsonSerializable(explicitToJson: true)
      11             : class ChatwootEvent{
      12             : 
      13             :   @JsonKey(
      14             :     toJson: eventTypeToJson,
      15             :     fromJson: eventTypeFromJson
      16             :   )
      17             :   final ChatwootEventType? type;
      18             : 
      19             :   @JsonKey()
      20             :   final String? identifier;
      21             : 
      22             :   @JsonKey(
      23             :     fromJson: eventMessageFromJson
      24             :   )
      25             :   final ChatwootEventMessage? message;
      26             : 
      27           1 :   ChatwootEvent({
      28             :     this.type,
      29             :     this.message,
      30             :     this.identifier
      31             :   });
      32             : 
      33           2 :   factory ChatwootEvent.fromJson(Map<String, dynamic> json) => _$ChatwootEventFromJson(json);
      34             : 
      35           0 :   Map<String, dynamic> toJson() => _$ChatwootEventToJson(this);
      36             : 
      37             : }
      38             : 
      39           1 : ChatwootEventMessage? eventMessageFromJson(value){
      40             :   if(value == null){
      41             :     return null;
      42           1 :   }else if(value is num){
      43           1 :     return ChatwootEventMessage();
      44           1 :   }else if(value is String){
      45           0 :     return ChatwootEventMessage();
      46             :   }else{
      47           1 :     return ChatwootEventMessage.fromJson(value as Map<String,dynamic>);
      48             :   }
      49             : }
      50             : 
      51             : @JsonSerializable(explicitToJson: true)
      52             : class ChatwootEventMessage{
      53             : 
      54             :   @JsonKey()
      55             :   final ChatwootEventMessageData? data;
      56             : 
      57             :   @JsonKey(
      58             :     toJson: eventMessageTypeToJson,
      59             :     fromJson: eventMessageTypeFromJson
      60             :   )
      61             :   final ChatwootEventMessageType? event;
      62             : 
      63           1 :   ChatwootEventMessage({
      64             :     this.data,
      65             :     this.event
      66             :   });
      67             : 
      68           2 :   factory ChatwootEventMessage.fromJson(Map<String, dynamic> json) => _$ChatwootEventMessageFromJson(json);
      69             : 
      70           0 :   Map<String, dynamic> toJson() => _$ChatwootEventMessageToJson(this);
      71             : }
      72             : 
      73             : @JsonSerializable(explicitToJson: true)
      74             : class ChatwootEventMessageData{
      75             : 
      76             :   @JsonKey(name: "account_id")
      77             :   final int? accountId;
      78             : 
      79             :   @JsonKey()
      80             :   final String? content;
      81             : 
      82             :   @JsonKey(name: "content_attributes")
      83             :   final dynamic contentAttributes;
      84             : 
      85             :   @JsonKey(name: "content_type")
      86             :   final String? contentType;
      87             : 
      88             :   @JsonKey(name: "conversation_id")
      89             :   final int? conversationId;
      90             : 
      91             :   @JsonKey(name: "created_at")
      92             :   final dynamic createdAt;
      93             : 
      94             :   @JsonKey(name: "echo_id")
      95             :   final String? echoId;
      96             : 
      97             :   @JsonKey(name: "external_source_ids")
      98             :   final dynamic externalSourceIds;
      99             : 
     100             :   @JsonKey()
     101             :   final int? id;
     102             : 
     103             :   @JsonKey(name: "inbox_id")
     104             :   final int? inboxId;
     105             : 
     106             :   @JsonKey(name: "message_type")
     107             :   final int? messageType;
     108             : 
     109             :   @JsonKey(name: "private")
     110             :   final int? private;
     111             : 
     112             :   @JsonKey()
     113             :   final ChatwootEventMessageUser? sender;
     114             : 
     115             :   @JsonKey(name: "sender_id")
     116             :   final int? senderId;
     117             : 
     118             :   @JsonKey(name: "source_id")
     119             :   final String? sourceId;
     120             : 
     121             :   @JsonKey()
     122             :   final String? status;
     123             : 
     124             :   @JsonKey(name: "updated_at")
     125             :   final dynamic updatedAt;
     126             : 
     127             :   @JsonKey()
     128             :   final dynamic conversation;
     129             : 
     130             :   @JsonKey()
     131             :   final ChatwootEventMessageUser? user;
     132             : 
     133             :   @JsonKey()
     134             :   final dynamic users;
     135             : 
     136           1 :   ChatwootEventMessageData({
     137             :     this.id,
     138             :     this.user,
     139             :     this.conversation,
     140             :     this.echoId,
     141             :     this.sender,
     142             :     this.conversationId,
     143             :     this.createdAt,
     144             :     this.contentAttributes,
     145             :     this.contentType,
     146             :     this.messageType,
     147             :     this.content,
     148             :     this.inboxId,
     149             :     this.sourceId,
     150             :     this.updatedAt,
     151             :     this.status,
     152             :     this.accountId,
     153             :     this.externalSourceIds,
     154             :     this.private,
     155             :     this.senderId,
     156             :     this.users
     157             :   });
     158             : 
     159             : 
     160           2 :   factory ChatwootEventMessageData.fromJson(Map<String, dynamic> json) => _$ChatwootEventMessageDataFromJson(json);
     161             : 
     162           2 :   Map<String, dynamic> toJson() => _$ChatwootEventMessageDataToJson(this);
     163             : 
     164           1 :   getMessage(){
     165           2 :     return ChatwootMessage.fromJson(toJson());
     166             :   }
     167             : }
     168             : 
     169             : @HiveType(typeId: 4)
     170             : @JsonSerializable(explicitToJson: true)
     171             : class ChatwootEventMessageUser extends Equatable{
     172             : 
     173             :   @JsonKey(
     174             :     name: "avatar_url"
     175             :   )
     176             :   @HiveField(0)
     177             :   final String? avatarUrl;
     178             : 
     179             :   @JsonKey()
     180             :   @HiveField(1)
     181             :   final int? id;
     182             : 
     183             :   @JsonKey()
     184             :   @HiveField(2)
     185             :   final String? name;
     186             : 
     187             :   @JsonKey()
     188             :   @HiveField(3)
     189             :   final String? thumbnail;
     190             : 
     191             : 
     192           4 :   ChatwootEventMessageUser({
     193             :     this.id,
     194             :     this.avatarUrl,
     195             :     this.name,
     196             :     this.thumbnail
     197             :   });
     198             : 
     199             : 
     200           8 :   factory ChatwootEventMessageUser.fromJson(Map<String, dynamic> json) => _$ChatwootEventMessageUserFromJson(json);
     201             : 
     202           0 :   Map<String, dynamic> toJson() => _$ChatwootEventMessageUserToJson(this);
     203             : 
     204           1 :   @override
     205           1 :   List<Object?> get props => [
     206           1 :     id,
     207           1 :     avatarUrl,
     208           1 :     name,
     209           1 :     thumbnail
     210             :   ];
     211             : 
     212             : }
     213             : 
     214          15 : enum ChatwootEventType{
     215             :   welcome,
     216             :   ping,
     217             :   confirm_subscription
     218             : }
     219             : 
     220           0 : String? eventTypeToJson(ChatwootEventType? actionType){
     221           0 :   return actionType.toString();
     222             : }
     223             : 
     224           1 : ChatwootEventType? eventTypeFromJson(String? value){
     225             :   switch(value){
     226           1 :     case "welcome":
     227             :       return ChatwootEventType.welcome;
     228           1 :     case "ping":
     229             :       return ChatwootEventType.ping;
     230           1 :     case "confirm_subscription":
     231             :       return ChatwootEventType.confirm_subscription;
     232             :     default:
     233             :       return null;
     234             :   }
     235             : }
     236             : 
     237          15 : enum ChatwootEventMessageType{
     238             :   presence_update,
     239             :   message_created,
     240             :   conversation_typing_off,
     241             :   conversation_typing_on
     242             : }
     243             : 
     244           0 : String? eventMessageTypeToJson(ChatwootEventMessageType? actionType){
     245             :   switch(actionType){
     246           0 :     case null:
     247             :       return null;
     248           0 :     case ChatwootEventMessageType.conversation_typing_on:
     249             :       return "conversation.typing_on";
     250           0 :     case ChatwootEventMessageType.conversation_typing_off:
     251             :       return "conversation.typing_off";
     252           0 :     case ChatwootEventMessageType.presence_update:
     253             :       return "presence.update";
     254           0 :     case ChatwootEventMessageType.message_created:
     255             :       return "message.created";
     256             :     default:
     257           0 :       return actionType.toString();
     258             :   }
     259             : }
     260             : 
     261           1 : ChatwootEventMessageType? eventMessageTypeFromJson(String? value){
     262             :   switch(value){
     263           1 :     case "presence.update":
     264             :       return ChatwootEventMessageType.presence_update;
     265           1 :     case "message.created":
     266             :       return ChatwootEventMessageType.message_created;
     267           1 :     case "conversation.typing_on":
     268             :       return ChatwootEventMessageType.conversation_typing_on;
     269           1 :     case "conversation.typing_off":
     270             :       return ChatwootEventMessageType.conversation_typing_off;
     271             :     default:
     272             :       return null;
     273             :   }
     274             : }

Generated by: LCOV version 1.15.alpha0w