LCOV - code coverage report
Current view: top level - lib/src/utils - push_notification.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 1.4 % 70 1
Test Date: 2025-01-14 13:39:53 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, Object?>? 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              :     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              :   /// `map<String, String>` which usually comes from Firebase Cloud Messaging.
      33            0 :   factory PushNotification.fromJson(Map<String, Object?> json) =>
      34            0 :       PushNotification(
      35            0 :         content: json['content'] is Map
      36            0 :             ? Map<String, Object?>.from(json['content'] as Map)
      37            0 :             : json['content'] is String
      38            0 :                 ? jsonDecode(json['content'] as String)
      39              :                 : null,
      40            0 :         counts: json['counts'] is Map
      41            0 :             ? PushNotificationCounts.fromJson(
      42            0 :                 json['counts'] as Map<String, Object?>,
      43              :               )
      44            0 :             : json['counts'] is String
      45            0 :                 ? PushNotificationCounts.fromJson(
      46            0 :                     jsonDecode(json['counts'] as String),
      47              :                   )
      48              :                 : null,
      49            0 :         devices: json['devices'] is List
      50            0 :             ? (json['devices'] as List)
      51            0 :                 .map((d) => PushNotificationDevice.fromJson(d))
      52            0 :                 .toList()
      53            0 :             : (jsonDecode(json['devices'] as String) as List)
      54            0 :                 .map((d) => PushNotificationDevice.fromJson(d))
      55            0 :                 .toList(),
      56            0 :         eventId: json['event_id'] as String?,
      57            0 :         prio: json['prio'] as String?,
      58            0 :         roomAlias: json['room_alias'] as String?,
      59            0 :         roomId: json['room_id'] as String?,
      60            0 :         roomName: json['room_name'] as String?,
      61            0 :         sender: json['sender'] as String?,
      62            0 :         senderDisplayName: json['sender_display_name'] as String?,
      63            0 :         type: json['type'] as String?,
      64              :       );
      65              : 
      66            0 :   Map<String, Object?> toJson() => {
      67            0 :         if (content != null) 'content': content,
      68            0 :         if (counts != null) 'counts': counts?.toJson(),
      69            0 :         if (devices != null)
      70            0 :           'devices': devices?.map((i) => i.toJson()).toList(),
      71            0 :         if (eventId != null) 'event_id': eventId,
      72            0 :         if (prio != null) 'prio': prio,
      73            0 :         if (roomAlias != null) 'room_alias': roomAlias,
      74            0 :         if (roomId != null) 'room_id': roomId,
      75            0 :         if (roomName != null) 'room_name': roomName,
      76            0 :         if (sender != null) 'sender': sender,
      77            0 :         if (senderDisplayName != null) 'sender_display_name': senderDisplayName,
      78            0 :         if (type != null) 'type': type,
      79              :       };
      80              : }
      81              : 
      82              : class PushNotificationCounts {
      83              :   final int? missedCalls;
      84              :   final int? unread;
      85              : 
      86            0 :   const PushNotificationCounts({
      87              :     this.missedCalls,
      88              :     this.unread,
      89              :   });
      90              : 
      91            0 :   factory PushNotificationCounts.fromJson(Map<String, Object?> json) =>
      92            0 :       PushNotificationCounts(
      93            0 :         missedCalls: json['missed_calls'] as int?,
      94            0 :         unread: json['unread'] as int?,
      95              :       );
      96              : 
      97            0 :   Map<String, Object?> toJson() => {
      98            0 :         if (missedCalls != null) 'missed_calls': missedCalls,
      99            0 :         if (unread != null) 'unread': unread,
     100              :       };
     101              : }
     102              : 
     103              : class PushNotificationDevice {
     104              :   final String? appId;
     105              :   final Map<String, Object?>? data;
     106              :   final String? pushkey;
     107              :   final int? pushkeyTs;
     108              :   final Tweaks? tweaks;
     109              : 
     110            0 :   const PushNotificationDevice({
     111              :     this.appId,
     112              :     this.data,
     113              :     this.pushkey,
     114              :     this.pushkeyTs,
     115              :     this.tweaks,
     116              :   });
     117              : 
     118            0 :   factory PushNotificationDevice.fromJson(Map<String, Object?> json) =>
     119            0 :       PushNotificationDevice(
     120            0 :         appId: json['app_id'] as String?,
     121            0 :         data: json['data'] == null
     122              :             ? null
     123            0 :             : Map<String, Object?>.from(json['data'] as Map),
     124            0 :         pushkey: json['pushkey'] as String?,
     125            0 :         pushkeyTs: json['pushkey_ts'] as int?,
     126            0 :         tweaks: json['tweaks'] == null
     127              :             ? null
     128            0 :             : Tweaks.fromJson(json['tweaks'] as Map<String, Object?>),
     129              :       );
     130              : 
     131            0 :   Map<String, Object?> toJson() => {
     132            0 :         'app_id': appId,
     133            0 :         if (data != null) 'data': data,
     134            0 :         'pushkey': pushkey,
     135            0 :         if (pushkeyTs != null) 'pushkey_ts': pushkeyTs,
     136            0 :         if (tweaks != null) 'tweaks': tweaks?.toJson(),
     137              :       };
     138              : }
     139              : 
     140              : class Tweaks {
     141              :   final String? sound;
     142              : 
     143            0 :   const Tweaks({
     144              :     this.sound,
     145              :   });
     146              : 
     147            0 :   factory Tweaks.fromJson(Map<String, Object?> json) => Tweaks(
     148            0 :         sound: json['sound'] as String?,
     149              :       );
     150              : 
     151            0 :   Map<String, Object?> toJson() => {
     152            0 :         if (sound != null) 'sound': sound,
     153              :       };
     154              : }
        

Generated by: LCOV version 2.0-1