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,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final manager = context.watch<NotificationsManager>();
|
final manager = context.watch<NotificationsManager>();
|
||||||
|
@ -33,26 +49,33 @@ class NotificationControl extends StatelessWidget {
|
||||||
),
|
),
|
||||||
title: GestureDetector(
|
title: GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
print('Open reference status: ${notification.iid}');
|
switch (notification.type) {
|
||||||
final manager = getIt<TimelineManager>();
|
case NotificationType.follow:
|
||||||
final existingPostData = manager.getPostTreeEntryBy(notification.iid);
|
buildSnackbar(
|
||||||
if (existingPostData.isSuccess) {
|
context, 'Want to follow ${notification.fromName}?');
|
||||||
context.push('/post/view/${existingPostData.value.id}');
|
break;
|
||||||
return;
|
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),
|
child: HtmlWidget(notification.content),
|
||||||
),
|
),
|
||||||
subtitle:
|
subtitle:
|
||||||
Text(ElapsedDateUtils.epochSecondsToString(notification.timestamp)),
|
Text(ElapsedDateUtils.epochSecondsToString(notification.timestamp)),
|
||||||
trailing: notification.dismissed
|
trailing: notification.dismissed ||
|
||||||
|
(notification.type == NotificationType.follow ||
|
||||||
|
notification.type == NotificationType.follow_request)
|
||||||
? null
|
? null
|
||||||
: IconButton(
|
: IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
|
|
@ -4,12 +4,24 @@ enum NotificationType {
|
||||||
follow_request,
|
follow_request,
|
||||||
mention,
|
mention,
|
||||||
reshare,
|
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 {
|
class UserNotification {
|
||||||
final String id;
|
final String id;
|
||||||
final String type;
|
final NotificationType type;
|
||||||
final String fromId;
|
final String fromId;
|
||||||
final String fromName;
|
final String fromName;
|
||||||
final String fromUrl;
|
final String fromUrl;
|
||||||
|
|
|
@ -4,7 +4,7 @@ extension NotificationFriendicaExtension on UserNotification {
|
||||||
static UserNotification fromJson(Map<String, dynamic> json) =>
|
static UserNotification fromJson(Map<String, dynamic> json) =>
|
||||||
UserNotification(
|
UserNotification(
|
||||||
id: json['id'].toString(),
|
id: json['id'].toString(),
|
||||||
type: json['type'].toString(),
|
type: NotificationType.parse(json['type']),
|
||||||
fromId: json['uid'],
|
fromId: json['uid'],
|
||||||
fromName: json['name'],
|
fromName: json['name'],
|
||||||
fromUrl: json['url'],
|
fromUrl: json['url'],
|
||||||
|
|
|
@ -22,13 +22,35 @@ extension NotificationMastodonExtension on UserNotification {
|
||||||
})
|
})
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
final type = json['type'];
|
final type = NotificationType.parse(json['type']);
|
||||||
final from = ConnectionMastodonExtensions.fromJson(json['account']);
|
final from = ConnectionMastodonExtensions.fromJson(json['account']);
|
||||||
getIt<ConnectionsManager>().addConnection(from);
|
getIt<ConnectionsManager>().addConnection(from);
|
||||||
|
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']);
|
final status = TimelineEntryMastodonExtensions.fromJson(json['status']);
|
||||||
final referenceType = status.parentId == null ? 'post' : 'comment';
|
statusId = status.id;
|
||||||
final content =
|
statusLink = status.externalLink;
|
||||||
|
final referenceType = status.parentId.isEmpty ? 'post' : 'comment';
|
||||||
|
content =
|
||||||
"${from.name} $type on ${status.author}'s $referenceType: ${status.body.truncate()}";
|
"${from.name} $type on ${status.author}'s $referenceType: ${status.body.truncate()}";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return UserNotification(
|
return UserNotification(
|
||||||
id: json['id'].toString(),
|
id: json['id'].toString(),
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -36,10 +58,10 @@ extension NotificationMastodonExtension on UserNotification {
|
||||||
fromName: from.name,
|
fromName: from.name,
|
||||||
fromUrl: from.profileUrl.toString(),
|
fromUrl: from.profileUrl.toString(),
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
iid: status.id,
|
iid: statusId,
|
||||||
dismissed: json['dismissed'] ?? false,
|
dismissed: json['dismissed'] ?? false,
|
||||||
content: content,
|
content: content,
|
||||||
link: status.externalLink,
|
link: statusLink,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue