⬆️ Support new notification APIs

This commit is contained in:
LittleSheep 2024-07-19 23:38:25 +08:00
parent 6811d8e9b1
commit 5a7432e330
3 changed files with 25 additions and 82 deletions
.github/workflows
lib

@ -59,22 +59,4 @@ jobs:
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: build-output-windows name: build-output-windows
path: build/windows/x64/runner/Release path: build/windows/x64/runner/Release
build-linux:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev libsqlite3-0 libsqlite3-dev
- run: flutter build linux
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
name: build-output-windows
path: build/linux/x64/release/bundle

@ -3,10 +3,11 @@ class Notification {
DateTime createdAt; DateTime createdAt;
DateTime updatedAt; DateTime updatedAt;
DateTime? deletedAt; DateTime? deletedAt;
String subject; String title;
String content; String? subtitle;
List<Link>? links; String body;
DateTime? readAt; String? avatar;
String? picture;
int? senderId; int? senderId;
int recipientId; int recipientId;
@ -15,10 +16,11 @@ class Notification {
required this.createdAt, required this.createdAt,
required this.updatedAt, required this.updatedAt,
required this.deletedAt, required this.deletedAt,
required this.subject, required this.title,
required this.content, required this.subtitle,
required this.links, required this.body,
required this.readAt, required this.avatar,
required this.picture,
required this.senderId, required this.senderId,
required this.recipientId, required this.recipientId,
}); });
@ -32,12 +34,11 @@ class Notification {
? DateTime.now() ? DateTime.now()
: DateTime.parse(json['updated_at']), : DateTime.parse(json['updated_at']),
deletedAt: json['deleted_at'], deletedAt: json['deleted_at'],
subject: json['subject'], title: json['title'],
content: json['content'], subtitle: json['subtitle'],
links: json['links'] != null body: json['body'],
? List<Link>.from(json['links'].map((x) => Link.fromJson(x))) avatar: json['avatar'],
: List.empty(), picture: json['picture'],
readAt: json['read_at'],
senderId: json['sender_id'], senderId: json['sender_id'],
recipientId: json['recipient_id'], recipientId: json['recipient_id'],
); );
@ -47,33 +48,12 @@ class Notification {
'created_at': createdAt.toIso8601String(), 'created_at': createdAt.toIso8601String(),
'updated_at': updatedAt.toIso8601String(), 'updated_at': updatedAt.toIso8601String(),
'deleted_at': deletedAt, 'deleted_at': deletedAt,
'subject': subject, 'title': title,
'content': content, 'subtitle': subtitle,
'links': links != null 'body': body,
? List<dynamic>.from(links!.map((x) => x.toJson())) 'avatar': avatar,
: List.empty(), 'picture': picture,
'read_at': readAt,
'sender_id': senderId, 'sender_id': senderId,
'recipient_id': recipientId, 'recipient_id': recipientId,
}; };
} }
class Link {
String label;
String url;
Link({
required this.label,
required this.url,
});
factory Link.fromJson(Map<String, dynamic> json) => Link(
label: json['label'],
url: json['url'],
);
Map<String, dynamic> toJson() => {
'label': label,
'url': url,
};
}

@ -4,7 +4,6 @@ import 'package:get/get.dart';
import 'package:solian/providers/websocket.dart'; import 'package:solian/providers/websocket.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/models/notification.dart' as notify; import 'package:solian/models/notification.dart' as notify;
import 'package:url_launcher/url_launcher_string.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class NotificationScreen extends StatefulWidget { class NotificationScreen extends StatefulWidget {
@ -126,31 +125,13 @@ class _NotificationScreenState extends State<NotificationScreen> {
horizontal: 24, horizontal: 24,
vertical: 8, vertical: 8,
), ),
title: Text(element.subject), title: Text(element.title),
subtitle: Column( subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(element.content), if (element.subtitle != null)
if (element.links != null) Text(element.subtitle!),
Row( Text(element.body),
children: element.links!
.map((e) => InkWell(
child: Text(
e.label,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondaryContainer,
decoration:
TextDecoration.underline,
),
),
onTap: () {
launchUrlString(e.url);
},
).paddingOnly(right: 5))
.toList(),
),
], ],
), ),
), ),