1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-27 00:03:48 +01:00
git-touch-android-ios-app/lib/models/notification.dart

63 lines
1.4 KiB
Dart
Raw Normal View History

2019-09-02 14:40:20 +02:00
import 'package:flutter/material.dart';
2019-09-03 05:56:25 +02:00
import 'package:timeago/timeago.dart' as timeago;
class NotificationPayload {
String id;
String type;
String owner;
String name;
int number;
String title;
String updateAt;
bool unread;
String state;
String get key => '_' + number.toString();
NotificationPayload.fromJson(input) {
id = input['id'];
type = input['subject']['type'];
name = input['repository']['name'];
owner = input['repository']['owner']['login'];
String url = input['subject']['url'];
if (type == 'Issue' || type == 'PullRequest') {
String numberStr = url.split('/').lastWhere((_) => true);
number = int.parse(numberStr);
} else {
// Fimber.d(input);
2019-09-03 05:56:25 +02:00
}
title = input['subject']['title'];
updateAt = timeago.format(DateTime.parse(input['updated_at']));
unread = input['unread'];
}
}
class NotificationGroup {
String owner;
String name;
get repo => owner + '/' + name;
List<NotificationPayload> items = [];
// Add heading _ to fix number case
// - => __
// . => ___
String get key =>
('_' + owner + '_' + name).replaceAll('-', '__').replaceAll('.', '___');
NotificationGroup(this.owner, this.name);
}
2019-09-02 14:40:20 +02:00
class NotificationModel with ChangeNotifier {
int _count = 0;
int get count => _count;
setCount(int v) {
_count = v;
notifyListeners();
}
}