kopia lustrzana https://gitlab.com/mysocialportal/relatica
Add support for the connection request type.
rodzic
52bc8a20e1
commit
0704539a47
|
@ -19,6 +19,22 @@ class NotificationControl extends StatelessWidget {
|
|||
required this.notification,
|
||||
});
|
||||
|
||||
Future<void> _goToStatus(BuildContext context) async {
|
||||
final manager = getIt<TimelineManager>();
|
||||
final existingPostData = manager.getPostTreeEntryBy(notification.iid);
|
||||
if (existingPostData.isSuccess) {
|
||||
context.push('/post/view/${existingPostData.value.id}');
|
||||
return;
|
||||
}
|
||||
final loadedPost = await manager.refreshStatusChain(notification.iid);
|
||||
if (loadedPost.isSuccess) {
|
||||
context.push('/post/view/${loadedPost.value.id}');
|
||||
return;
|
||||
}
|
||||
buildSnackbar(
|
||||
context, 'Error getting data for notification: ${loadedPost.error}');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final manager = context.watch<NotificationsManager>();
|
||||
|
@ -33,26 +49,33 @@ class NotificationControl extends StatelessWidget {
|
|||
),
|
||||
title: GestureDetector(
|
||||
onTap: () async {
|
||||
print('Open reference status: ${notification.iid}');
|
||||
final manager = getIt<TimelineManager>();
|
||||
final existingPostData = manager.getPostTreeEntryBy(notification.iid);
|
||||
if (existingPostData.isSuccess) {
|
||||
context.push('/post/view/${existingPostData.value.id}');
|
||||
return;
|
||||
switch (notification.type) {
|
||||
case NotificationType.follow:
|
||||
buildSnackbar(
|
||||
context, 'Want to follow ${notification.fromName}?');
|
||||
break;
|
||||
case NotificationType.follow_request:
|
||||
buildSnackbar(
|
||||
context, 'Want to accept follow ${notification.fromName}?');
|
||||
break;
|
||||
case NotificationType.unknown:
|
||||
buildSnackbar(context, 'Unknown message type, nothing to do');
|
||||
break;
|
||||
case NotificationType.favorite:
|
||||
case NotificationType.mention:
|
||||
case NotificationType.reshare:
|
||||
case NotificationType.status:
|
||||
_goToStatus(context);
|
||||
break;
|
||||
}
|
||||
final loadedPost = await manager.refreshStatusChain(notification.iid);
|
||||
if (loadedPost.isSuccess) {
|
||||
context.push('/post/view/${loadedPost.value.id}');
|
||||
return;
|
||||
}
|
||||
buildSnackbar(context,
|
||||
'Error getting data for notification: ${loadedPost.error}');
|
||||
},
|
||||
child: HtmlWidget(notification.content),
|
||||
),
|
||||
subtitle:
|
||||
Text(ElapsedDateUtils.epochSecondsToString(notification.timestamp)),
|
||||
trailing: notification.dismissed
|
||||
trailing: notification.dismissed ||
|
||||
(notification.type == NotificationType.follow ||
|
||||
notification.type == NotificationType.follow_request)
|
||||
? null
|
||||
: IconButton(
|
||||
onPressed: () async {
|
||||
|
|
|
@ -4,12 +4,24 @@ enum NotificationType {
|
|||
follow_request,
|
||||
mention,
|
||||
reshare,
|
||||
status
|
||||
status,
|
||||
unknown;
|
||||
|
||||
static NotificationType parse(String? text) {
|
||||
if (text == null) {
|
||||
return unknown;
|
||||
}
|
||||
|
||||
return NotificationType.values.firstWhere(
|
||||
(e) => e.name == text,
|
||||
orElse: () => unknown,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class UserNotification {
|
||||
final String id;
|
||||
final String type;
|
||||
final NotificationType type;
|
||||
final String fromId;
|
||||
final String fromName;
|
||||
final String fromUrl;
|
||||
|
|
|
@ -4,7 +4,7 @@ extension NotificationFriendicaExtension on UserNotification {
|
|||
static UserNotification fromJson(Map<String, dynamic> json) =>
|
||||
UserNotification(
|
||||
id: json['id'].toString(),
|
||||
type: json['type'].toString(),
|
||||
type: NotificationType.parse(json['type']),
|
||||
fromId: json['uid'],
|
||||
fromName: json['name'],
|
||||
fromUrl: json['url'],
|
||||
|
|
|
@ -22,13 +22,35 @@ extension NotificationMastodonExtension on UserNotification {
|
|||
})
|
||||
: 0;
|
||||
|
||||
final type = json['type'];
|
||||
final type = NotificationType.parse(json['type']);
|
||||
final from = ConnectionMastodonExtensions.fromJson(json['account']);
|
||||
getIt<ConnectionsManager>().addConnection(from);
|
||||
final status = TimelineEntryMastodonExtensions.fromJson(json['status']);
|
||||
final referenceType = status.parentId == null ? 'post' : 'comment';
|
||||
final content =
|
||||
"${from.name} $type on ${status.author}'s $referenceType: ${status.body.truncate()}";
|
||||
var statusId = '';
|
||||
var statusLink = '';
|
||||
var content = '';
|
||||
switch (type) {
|
||||
case NotificationType.follow:
|
||||
content = '${from.name} wants to follow you';
|
||||
break;
|
||||
case NotificationType.follow_request:
|
||||
content = '${from.name} submitted a follow request ';
|
||||
break;
|
||||
case NotificationType.unknown:
|
||||
content = '${from.name} has unknown interaction notification';
|
||||
break;
|
||||
case NotificationType.favorite:
|
||||
case NotificationType.mention:
|
||||
case NotificationType.reshare:
|
||||
case NotificationType.status:
|
||||
final status = TimelineEntryMastodonExtensions.fromJson(json['status']);
|
||||
statusId = status.id;
|
||||
statusLink = status.externalLink;
|
||||
final referenceType = status.parentId.isEmpty ? 'post' : 'comment';
|
||||
content =
|
||||
"${from.name} $type on ${status.author}'s $referenceType: ${status.body.truncate()}";
|
||||
break;
|
||||
}
|
||||
|
||||
return UserNotification(
|
||||
id: json['id'].toString(),
|
||||
type: type,
|
||||
|
@ -36,10 +58,10 @@ extension NotificationMastodonExtension on UserNotification {
|
|||
fromName: from.name,
|
||||
fromUrl: from.profileUrl.toString(),
|
||||
timestamp: timestamp,
|
||||
iid: status.id,
|
||||
iid: statusId,
|
||||
dismissed: json['dismissed'] ?? false,
|
||||
content: content,
|
||||
link: status.externalLink,
|
||||
link: statusLink,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue