LCOV - code coverage report
Current view: top level - lib/src/utils - push_notification.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 1 66 1.5 %
Date: 2024-11-12 07:37:08 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : 
       3             : /// Push Notification object from https://spec.matrix.org/v1.2/push-gateway-api/
       4             : class PushNotification {
       5             :   final Map<String, dynamic>? content;
       6             :   final PushNotificationCounts? counts;
       7             :   final List<PushNotificationDevice> devices;
       8             :   final String? eventId;
       9             :   final String? prio;
      10             :   final String? roomAlias;
      11             :   final String? roomId;
      12             :   final String? roomName;
      13             :   final String? sender;
      14             :   final String? senderDisplayName;
      15             :   final String? type;
      16             : 
      17           1 :   const PushNotification({
      18             :     this.content,
      19             :     this.counts,
      20             :     required this.devices,
      21             :     this.eventId,
      22             :     this.prio,
      23             :     this.roomAlias,
      24             :     this.roomId,
      25             :     this.roomName,
      26             :     this.sender,
      27             :     this.senderDisplayName,
      28             :     this.type,
      29             :   });
      30             : 
      31             :   /// Generate a Push Notification object from JSON. It also supports a
      32             :   /// <String, String> map which usually comes from Firebase Cloud Messaging.
      33           0 :   factory PushNotification.fromJson(Map<String, dynamic> json) =>
      34           0 :       PushNotification(
      35           0 :         content: json['content'] is Map
      36           0 :             ? Map<String, dynamic>.from(json['content'])
      37           0 :             : json['content'] is String
      38           0 :                 ? jsonDecode(json['content'])
      39             :                 : null,
      40           0 :         counts: json['counts'] is Map
      41           0 :             ? PushNotificationCounts.fromJson(json['counts'])
      42           0 :             : json['counts'] is String
      43           0 :                 ? PushNotificationCounts.fromJson(jsonDecode(json['counts']))
      44             :                 : null,
      45           0 :         devices: json['devices'] is List
      46           0 :             ? (json['devices'] as List)
      47           0 :                 .map((d) => PushNotificationDevice.fromJson(d))
      48           0 :                 .toList()
      49           0 :             : (jsonDecode(json['devices']) as List)
      50           0 :                 .map((d) => PushNotificationDevice.fromJson(d))
      51           0 :                 .toList(),
      52           0 :         eventId: json['event_id'],
      53           0 :         prio: json['prio'],
      54           0 :         roomAlias: json['room_alias'],
      55           0 :         roomId: json['room_id'],
      56           0 :         roomName: json['room_name'],
      57           0 :         sender: json['sender'],
      58           0 :         senderDisplayName: json['sender_display_name'],
      59           0 :         type: json['type'],
      60             :       );
      61             : 
      62           0 :   Map<String, dynamic> toJson() => {
      63           0 :         if (content != null) 'content': content,
      64           0 :         if (counts != null) 'counts': counts?.toJson(),
      65           0 :         'devices': devices.map((i) => i.toJson()).toList(),
      66           0 :         if (eventId != null) 'event_id': eventId,
      67           0 :         if (prio != null) 'prio': prio,
      68           0 :         if (roomAlias != null) 'room_alias': roomAlias,
      69           0 :         if (roomId != null) 'room_id': roomId,
      70           0 :         if (roomName != null) 'room_name': roomName,
      71           0 :         if (sender != null) 'sender': sender,
      72           0 :         if (senderDisplayName != null) 'sender_display_name': senderDisplayName,
      73           0 :         if (type != null) 'type': type,
      74             :       };
      75             : }
      76             : 
      77             : class PushNotificationCounts {
      78             :   final int? missedCalls;
      79             :   final int? unread;
      80             : 
      81           0 :   const PushNotificationCounts({
      82             :     this.missedCalls,
      83             :     this.unread,
      84             :   });
      85             : 
      86           0 :   factory PushNotificationCounts.fromJson(Map<String, dynamic> json) =>
      87           0 :       PushNotificationCounts(
      88           0 :         missedCalls: json['missed_calls'],
      89           0 :         unread: json['unread'],
      90             :       );
      91             : 
      92           0 :   Map<String, dynamic> toJson() => {
      93           0 :         if (missedCalls != null) 'missed_calls': missedCalls,
      94           0 :         if (unread != null) 'unread': unread,
      95             :       };
      96             : }
      97             : 
      98             : class PushNotificationDevice {
      99             :   final String appId;
     100             :   final Map<String, dynamic>? data;
     101             :   final String pushkey;
     102             :   final int? pushkeyTs;
     103             :   final Tweaks? tweaks;
     104             : 
     105           0 :   const PushNotificationDevice({
     106             :     required this.appId,
     107             :     this.data,
     108             :     required this.pushkey,
     109             :     this.pushkeyTs,
     110             :     this.tweaks,
     111             :   });
     112             : 
     113           0 :   factory PushNotificationDevice.fromJson(Map<String, dynamic> json) =>
     114           0 :       PushNotificationDevice(
     115           0 :         appId: json['app_id'],
     116           0 :         data: json['data'] == null
     117             :             ? null
     118           0 :             : Map<String, dynamic>.from(json['data']),
     119           0 :         pushkey: json['pushkey'],
     120           0 :         pushkeyTs: json['pushkey_ts'],
     121           0 :         tweaks: json['tweaks'] == null ? null : Tweaks.fromJson(json['tweaks']),
     122             :       );
     123             : 
     124           0 :   Map<String, dynamic> toJson() => {
     125           0 :         'app_id': appId,
     126           0 :         if (data != null) 'data': data,
     127           0 :         'pushkey': pushkey,
     128           0 :         if (pushkeyTs != null) 'pushkey_ts': pushkeyTs,
     129           0 :         if (tweaks != null) 'tweaks': tweaks?.toJson(),
     130             :       };
     131             : }
     132             : 
     133             : class Tweaks {
     134             :   final String? sound;
     135             : 
     136           0 :   const Tweaks({
     137             :     this.sound,
     138             :   });
     139             : 
     140           0 :   factory Tweaks.fromJson(Map<String, dynamic> json) => Tweaks(
     141           0 :         sound: json['sound'],
     142             :       );
     143             : 
     144           0 :   Map<String, dynamic> toJson() => {
     145           0 :         if (sound != null) 'sound': sound,
     146             :       };
     147             : }

Generated by: LCOV version 1.14