notifications now do as i want (i think)
This commit is contained in:
parent
1b164411ea
commit
5ca039aadf
|
@ -1,5 +1,3 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/business_logic/network_tools/get_post_from_url.dart';
|
||||
|
|
|
@ -13,8 +13,8 @@ class NotificationModel implements Comparable {
|
|||
late NotificationType type;
|
||||
late AccountModel account;
|
||||
late PostModel? post;
|
||||
late String? accountid;
|
||||
NotificationModel.fromJson(Map<String, dynamic> json) {
|
||||
late String identity;
|
||||
NotificationModel.fromJson(Map<String, dynamic> json, String identity) {
|
||||
post = null;
|
||||
time = json["created_at"];
|
||||
id = json["id"];
|
||||
|
@ -22,7 +22,7 @@ class NotificationModel implements Comparable {
|
|||
type = NotificationType.values.firstWhere(
|
||||
(element) => element.name == "NotificationType.${json["type"]}");
|
||||
if (json["status"] != null) {
|
||||
post = PostModel.fromJson(json["status"], id);
|
||||
post = PostModel.fromJson(json["status"], identity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ Future<NotificationData> loadOldNotifications(
|
|||
if (response.statusCode == 200) {
|
||||
List<dynamic> json = jsonDecode(response.body);
|
||||
for (int n = 0; n < json.length; n++) {
|
||||
NotificationModel model = NotificationModel.fromJson(json[n]);
|
||||
model.accountid = idkey;
|
||||
NotificationModel model = NotificationModel.fromJson(json[n], idkey);
|
||||
model.identity = idkey;
|
||||
models.add(model);
|
||||
}
|
||||
}
|
||||
|
@ -90,12 +90,12 @@ Future<NotificationData> loadOldNotifications(
|
|||
models.removeRange(global.settings!.batchSize, models.length);
|
||||
|
||||
for (NotificationModel m in models) {
|
||||
if (map[m.accountid!] == null) {
|
||||
if (map[m.identity] == null) {
|
||||
map.addAll({
|
||||
m.accountid!: m.id,
|
||||
m.identity: m.id,
|
||||
});
|
||||
} else if (m.id.compareTo(map[m.accountid]!) < 0) {
|
||||
map.addAll({m.accountid!: m.id});
|
||||
} else if (m.id.compareTo(map[m.identity]!) < 0) {
|
||||
map.addAll({m.identity: m.id});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,9 @@
|
|||
"requested-to-folow-you": "requested to follow you",
|
||||
"made-a-status": "made a post",
|
||||
"poll-has-ended": "poll has ended",
|
||||
"interacted-with-you": "interacted with you"
|
||||
|
||||
"interacted-with-you": "interacted with you",
|
||||
"on-remote-instance": "on remote instance",
|
||||
"reblog": "reblog",
|
||||
"like": "like"
|
||||
}
|
||||
|
|
@ -50,7 +50,10 @@ class _NotificationsState extends State<Notifications> {
|
|||
Map<String, dynamic> json = jsonDecode(event);
|
||||
if (json["event"] == "notification") {
|
||||
SingleNotif notif = SingleNotif(
|
||||
model: NotificationModel.fromJson(jsonDecode(json["payload"])),
|
||||
model: NotificationModel.fromJson(
|
||||
jsonDecode(json["payload"]),
|
||||
keyI,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/business_logic/network_tools/get_post_from_url.dart';
|
||||
import 'package:loris/business_logic/timeline/timeline.dart';
|
||||
import '../business_logic/interactions/interactions.dart' as interactions;
|
||||
|
@ -68,11 +68,11 @@ class _InteractionButtonState extends State<InteractionButton> {
|
|||
widget.type,
|
||||
revoke: active,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
}
|
||||
if (status == 200 && mounted) {
|
||||
setState(() {
|
||||
active = !active;
|
||||
|
@ -88,13 +88,17 @@ class _InteractionButtonState extends State<InteractionButton> {
|
|||
Future<void> showError(int status) async {
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text("error: $status")));
|
||||
setState(() {
|
||||
icon = Icons.dangerous;
|
||||
});
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
setState(() {
|
||||
icon = active ? widget.type.revokeIcon : widget.type.icon;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
icon = Icons.dangerous;
|
||||
});
|
||||
}
|
||||
if (mounted) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
setState(() {
|
||||
icon = active ? widget.type.revokeIcon : widget.type.icon;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, PostModel?>> updateIdentities() async {
|
||||
|
@ -112,13 +116,19 @@ class _InteractionButtonState extends State<InteractionButton> {
|
|||
}
|
||||
|
||||
Future<void> showSuccess() async {
|
||||
setState(() {
|
||||
success = true;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
success = true;
|
||||
});
|
||||
}
|
||||
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
setState(() {
|
||||
success = false;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
success = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -156,66 +166,77 @@ class _InteractionButtonState extends State<InteractionButton> {
|
|||
);
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
return TextButton.icon(
|
||||
label: Text("${widget.type.name} ${"on-remote-instance".i18n()}"),
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
busy = true;
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
busy = true;
|
||||
});
|
||||
}
|
||||
final idList = await updateIdentities();
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: ((context) {
|
||||
List<Widget> c = [
|
||||
SelectableText(
|
||||
widget.type.name,
|
||||
style: Theme.of(context).textTheme.displayLarge,
|
||||
)
|
||||
];
|
||||
idList.forEach(
|
||||
(key, value) {
|
||||
if (value != null) {
|
||||
c.add(
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
setState(() {
|
||||
busy = true;
|
||||
});
|
||||
final result =
|
||||
await interactions.makeInteractionFromId(
|
||||
key,
|
||||
value.id,
|
||||
widget.type,
|
||||
revoke: isActive(value),
|
||||
);
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
if (result != 200) {
|
||||
showError(result);
|
||||
} else {
|
||||
showSuccess();
|
||||
}
|
||||
},
|
||||
icon: Icon(
|
||||
isActive(value)
|
||||
? widget.type.revokeIcon
|
||||
: widget.type.icon,
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
}
|
||||
if (mounted) {
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: ((context) {
|
||||
List<Widget> c = [
|
||||
SelectableText(
|
||||
widget.type.name,
|
||||
style: Theme.of(context).textTheme.displayLarge,
|
||||
)
|
||||
];
|
||||
idList.forEach(
|
||||
(key, value) {
|
||||
if (value != null) {
|
||||
c.add(
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
busy = true;
|
||||
});
|
||||
}
|
||||
final result =
|
||||
await interactions.makeInteractionFromId(
|
||||
key,
|
||||
value.id,
|
||||
widget.type,
|
||||
revoke: isActive(value),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
busy = false;
|
||||
});
|
||||
}
|
||||
if (result != 200) {
|
||||
showError(result);
|
||||
} else {
|
||||
showSuccess();
|
||||
}
|
||||
},
|
||||
icon: Icon(
|
||||
isActive(value)
|
||||
? widget.type.revokeIcon
|
||||
: widget.type.icon,
|
||||
),
|
||||
label: Text(key),
|
||||
),
|
||||
label: Text(key),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: c,
|
||||
);
|
||||
}));
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: c,
|
||||
);
|
||||
}));
|
||||
}
|
||||
},
|
||||
icon: Icon(icon));
|
||||
}
|
||||
|
|
|
@ -1,31 +1,46 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:localization/localization.dart';
|
||||
import 'package:loris/business_logic/interactions/interactions.dart';
|
||||
import 'package:loris/business_logic/timeline/timeline.dart';
|
||||
import 'package:loris/partials/interaction_button.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void popupPostOptions(context, PostModel model) {
|
||||
showDialog(
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return SimpleDialog(
|
||||
titleTextStyle: Theme.of(context).textTheme.titleMedium,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
title: SelectableText("post-options".i18n()),
|
||||
alignment: Alignment.center,
|
||||
contentPadding: const EdgeInsetsDirectional.all(8),
|
||||
children: [
|
||||
SelectableText(model.createdAt),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
launchUrl(
|
||||
Uri.parse(model.uri),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser),
|
||||
label: Text("show-in-browser".i18n()),
|
||||
),
|
||||
],
|
||||
);
|
||||
List<Widget?> c = [
|
||||
SelectableText("post-options".i18n(),
|
||||
style: Theme.of(context).textTheme.displayMedium),
|
||||
SelectableText(model.createdAt),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
launchUrl(
|
||||
Uri.parse(model.uri),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.open_in_browser),
|
||||
label: Text("show-in-browser".i18n()),
|
||||
),
|
||||
model.visibility.boostable
|
||||
? InteractionButton(
|
||||
model: model,
|
||||
type: InteractionType.reblog,
|
||||
extended: true,
|
||||
)
|
||||
: null,
|
||||
InteractionButton(
|
||||
model: model,
|
||||
type: InteractionType.favorite,
|
||||
extended: true,
|
||||
),
|
||||
];
|
||||
return Scrollable(
|
||||
viewportBuilder: ((context, position) =>
|
||||
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
for (var i in c)
|
||||
if (i != null) i
|
||||
])));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue