From 04cd9d7502551e0618e62e6bc84bc2adb0df26a5 Mon Sep 17 00:00:00 2001 From: Micah Morrison Date: Fri, 22 Dec 2023 08:38:23 -0500 Subject: [PATCH] Do not show unformatted markdown --- lib/utils/notifications.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/utils/notifications.dart b/lib/utils/notifications.dart index dee29f95b..0fb1bc61f 100644 --- a/lib/utils/notifications.dart +++ b/lib/utils/notifications.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:html/parser.dart'; import 'package:lemmy_api_client/v3.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:thunder/account/models/account.dart'; @@ -58,10 +59,14 @@ Future pollRepliesAndShowNotifications() async { // For each message, generate a notification. // On Android, put them in the same group. for (final CommentReplyView commentReplyView in newReplies) { + // Format the comment body in a couple ways + final String htmlComment = markdownToHtml(commentReplyView.comment.content); + final String plaintextComment = parse(parse(htmlComment).body?.text).documentElement?.text ?? commentReplyView.comment.content; + final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // Configure Android-specific settings final BigTextStyleInformation bigTextStyleInformation = BigTextStyleInformation( - '${commentReplyView.post.name} · ${generateCommunityFullName(null, commentReplyView.community.name, fetchInstanceNameFromUrl(commentReplyView.community.actorId), communitySeparator: communitySeparator)}\n${markdownToHtml(commentReplyView.comment.content)}', + '${commentReplyView.post.name} · ${generateCommunityFullName(null, commentReplyView.community.name, fetchInstanceNameFromUrl(commentReplyView.community.actorId), communitySeparator: communitySeparator)}\n$htmlComment', contentTitle: generateUserFullName(null, commentReplyView.creator.name, fetchInstanceNameFromUrl(commentReplyView.creator.actorId), userSeparator: userSeparator), summaryText: generateUserFullName(null, account.username, account.instance, userSeparator: userSeparator), htmlFormatBigText: true, @@ -83,7 +88,7 @@ Future pollRepliesAndShowNotifications() async { // Title (username of sender) generateUserFullName(null, commentReplyView.creator.name, fetchInstanceNameFromUrl(commentReplyView.creator.actorId), userSeparator: userSeparator), // Body (body of comment) - commentReplyView.comment.content, + plaintextComment, notificationDetails, payload: repliesGroupKey, // In the future, this could be a specific message ID for deep navigation );