From 5ce6543275ccd83e9ed322eeeec618cb45a421d1 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 10 May 2024 23:42:59 +0800 Subject: [PATCH] :sparkles: Message view source --- lib/i18n/app_en.arb | 3 +- lib/i18n/app_zh.arb | 3 +- lib/widgets/chat/message_action.dart | 110 +++++++++++++++++++++++++-- lib/widgets/posts/post_action.dart | 17 ++++- pubspec.lock | 10 ++- pubspec.yaml | 1 + 6 files changed, 132 insertions(+), 12 deletions(-) diff --git a/lib/i18n/app_en.arb b/lib/i18n/app_en.arb index f1bc19f..b11af59 100644 --- a/lib/i18n/app_en.arb +++ b/lib/i18n/app_en.arb @@ -127,5 +127,6 @@ "chatMessageSending": "Now delivering your messages...", "chatMessageEditNotify": "You are about editing a message.", "chatMessageReplyNotify": "You are about replying a message.", - "chatMessageDeleteConfirm": "Are you sure you want to delete this message? This operation cannot be revert and no local history is saved!" + "chatMessageDeleteConfirm": "Are you sure you want to delete this message? This operation cannot be revert and no local history is saved!", + "chatMessageViewSource": "View source" } diff --git a/lib/i18n/app_zh.arb b/lib/i18n/app_zh.arb index cecf2c6..f77035e 100644 --- a/lib/i18n/app_zh.arb +++ b/lib/i18n/app_zh.arb @@ -127,5 +127,6 @@ "chatMessageSending": "正在送出你的信息……", "chatMessageEditNotify": "你正在编辑信息中……", "chatMessageReplyNotify": "你正在回复消息中……", - "chatMessageDeleteConfirm": "你确定要删除这条消息吗?这条消息将永远的从所有人的视图中消失,并且不会有本地消息记录保存!" + "chatMessageDeleteConfirm": "你确定要删除这条消息吗?这条消息将永远的从所有人的视图中消失,并且不会有本地消息记录保存!", + "chatMessageViewSource": "查看原始信息" } diff --git a/lib/widgets/chat/message_action.dart b/lib/widgets/chat/message_action.dart index e1fae80..b219732 100644 --- a/lib/widgets/chat/message_action.dart +++ b/lib/widgets/chat/message_action.dart @@ -1,4 +1,8 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; +import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import 'package:solian/models/message.dart'; import 'package:solian/providers/auth.dart'; @@ -26,7 +30,7 @@ class ChatMessageAction extends StatelessWidget { final auth = context.read(); return SizedBox( - height: 320, + height: 400, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -40,7 +44,7 @@ class ChatMessageAction extends StatelessWidget { style: Theme.of(context).textTheme.headlineSmall, ), Text( - 'Message ID #${item.id.toString().padLeft(8, '0')}', + '#${item.id.toString().padLeft(8, '0')}', style: Theme.of(context).textTheme.bodySmall, ), ], @@ -82,9 +86,7 @@ class ChatMessageAction extends StatelessWidget { return ListView( children: [ - ...(snapshot.data['id'] == item.sender.account.externalId - ? authorizedItems - : List.empty()), + ...(snapshot.data['id'] == item.sender.account.externalId ? authorizedItems : List.empty()), ListTile( leading: const Icon(Icons.reply), title: Text(AppLocalizations.of(context)!.reply), @@ -92,6 +94,17 @@ class ChatMessageAction extends StatelessWidget { if (onReply != null) onReply!(); if (Navigator.canPop(context)) Navigator.pop(context); }, + ), + ListTile( + leading: const Icon(Icons.code), + title: Text(AppLocalizations.of(context)!.chatMessageViewSource), + onTap: () { + if (Navigator.canPop(context)) Navigator.pop(context); + showModalBottomSheet( + context: context, + builder: (context) => ChatMessageSourceWidget(item: item), + ); + }, ) ], ); @@ -108,3 +121,90 @@ class ChatMessageAction extends StatelessWidget { ); } } + +class ChatMessageSourceWidget extends StatelessWidget { + final Message item; + + const ChatMessageSourceWidget({super.key, required this.item}); + + @override + Widget build(BuildContext context) { + return ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(32)), + child: SizedBox( + width: double.infinity, + height: 640, + child: ListView( + children: [ + Container( + padding: const EdgeInsets.only(left: 20, top: 20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context)!.chatMessageViewSource, + style: Theme.of(context).textTheme.headlineSmall, + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8), + child: Text( + 'Raw content', + style: Theme.of(context).textTheme.titleMedium, + ), + ), + Markdown( + selectable: true, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + data: '```\n${item.rawContent}\n```', + padding: const EdgeInsets.all(0), + ), + Padding( + padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8), + child: Text( + 'Decoded content', + style: Theme.of(context).textTheme.titleMedium, + ), + ), + Markdown( + selectable: true, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + data: '```\n${const JsonEncoder.withIndent(' ').convert(item.decodedContent)}\n```', + padding: const EdgeInsets.all(0), + styleSheet: MarkdownStyleSheet( + code: GoogleFonts.robotoMono( + backgroundColor: Theme.of(context).cardTheme.color ?? Theme.of(context).cardColor, + fontSize: Theme.of(context).textTheme.bodyMedium!.fontSize! * 0.85, + ), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8), + child: Text( + 'Entire message', + style: Theme.of(context).textTheme.titleMedium, + ), + ), + Markdown( + selectable: true, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + data: '```\n${const JsonEncoder.withIndent(' ').convert(item)}\n```', + padding: const EdgeInsets.all(0), + styleSheet: MarkdownStyleSheet( + code: GoogleFonts.robotoMono( + backgroundColor: Theme.of(context).cardTheme.color ?? Theme.of(context).cardColor, + fontSize: Theme.of(context).textTheme.bodyMedium!.fontSize! * 0.85, + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index 386c095..d076231 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -54,10 +54,19 @@ class PostItemAction extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - padding: const EdgeInsets.only(left: 20, top: 20, bottom: 12), - child: Text( - AppLocalizations.of(context)!.action, - style: Theme.of(context).textTheme.headlineSmall, + padding: const EdgeInsets.only(left: 20, top: 20, bottom: 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + AppLocalizations.of(context)!.action, + style: Theme.of(context).textTheme.headlineSmall, + ), + Text( + '#${item.id.toString().padLeft(8, '0')}', + style: Theme.of(context).textTheme.bodySmall, + ), + ], ), ), Expanded( diff --git a/pubspec.lock b/pubspec.lock index 1421bcd..ab4ea8a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -493,6 +493,14 @@ packages: url: "https://pub.dev" source: hosted version: "13.2.4" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + sha256: b1ac0fe2832c9cc95e5e88b57d627c5e68c223b9657f4b96e1487aa9098c7b82 + url: "https://pub.dev" + source: hosted + version: "6.2.1" hive: dependency: transitive description: @@ -1420,4 +1428,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.3.3 <4.0.0" - flutter: ">=3.19.0" + flutter: ">=3.19.2" diff --git a/pubspec.yaml b/pubspec.yaml index 2977ed9..52cdf7d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -73,6 +73,7 @@ dependencies: desktop_drop: ^0.4.4 easy_debounce: ^2.0.3 encrypt: ^5.0.3 + google_fonts: ^6.2.1 dev_dependencies: flutter_test: