Remove flutter chat #26
2 changed files with 11 additions and 164 deletions
add a placeholder EventText widget
commit
0be5336065
11
lib/widgets/chat_page/event_text.dart
Normal file
11
lib/widgets/chat_page/event_text.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import "package:flutter/material.dart";
|
||||
|
||||
class EventText extends StatelessWidget {
|
||||
final bool textOnly;
|
||||
const EventText({this.textOnly = false, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
throw UnimplementedError(); // NEXT TODO
|
||||
}
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
import "package:cross_cache/cross_cache.dart";
|
||||
import "package:flutter/material.dart";
|
||||
import "package:flutter_linkify/flutter_linkify.dart";
|
||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||
import "package:nexus/controllers/cross_cache_controller.dart";
|
||||
import "package:nexus/controllers/url_preview_controller.dart";
|
||||
import "package:nexus/helpers/extensions/better_when.dart";
|
||||
import "package:nexus/helpers/extensions/get_headers.dart";
|
||||
import "package:nexus/helpers/launch_helper.dart";
|
||||
import "package:nexus/widgets/chat_page/html/html.dart";
|
||||
import "package:nexus/widgets/chat_page/wrappers/message_wrapper.dart";
|
||||
import "package:nexus/widgets/chat_page/reply_widget.dart";
|
||||
|
||||
class TextMessageWrapper extends ConsumerWidget {
|
||||
final Message message;
|
||||
final String? content;
|
||||
final MessageGroupStatus? groupStatus;
|
||||
final Future<void> Function(Message oldMessage, Message newMessage)
|
||||
updateMessage;
|
||||
final bool isSentByMe;
|
||||
final Widget? extra;
|
||||
final OnTapReply onTapReply;
|
||||
|
||||
const TextMessageWrapper(
|
||||
this.message, {
|
||||
this.content,
|
||||
this.onTapReply,
|
||||
required this.updateMessage,
|
||||
required this.groupStatus,
|
||||
required this.isSentByMe,
|
||||
this.extra,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final textMessage = message is TextMessage ? message as TextMessage : null;
|
||||
|
||||
final link = textMessage == null
|
||||
? null
|
||||
: RegExp(
|
||||
r'''https?://[^\s"'<>]+''',
|
||||
).allMatches(textMessage.text).firstOrNull?.group(0);
|
||||
|
||||
return MessageWrapper(
|
||||
message,
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isSentByMe
|
||||
? (message.id.startsWith("~")
|
||||
? colorScheme.onPrimary
|
||||
: colorScheme.primaryContainer)
|
||||
: colorScheme.surfaceContainer,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ReplyWidget(
|
||||
message,
|
||||
groupStatus: groupStatus,
|
||||
onTapReply: onTapReply,
|
||||
),
|
||||
if (content != null)
|
||||
message.metadata?["format"] == "org.matrix.custom.html"
|
||||
? Html(
|
||||
textStyle: message.metadata?["big"] == true
|
||||
? TextStyle(fontSize: 32)
|
||||
: null,
|
||||
content!.replaceAllMapped(
|
||||
RegExp(
|
||||
"(<a\\b[^>]*>.*?<\\/a>)|(\\bhttps?:\\/\\/[^\\s<]+)",
|
||||
caseSensitive: false,
|
||||
dotAll: true,
|
||||
),
|
||||
(m) {
|
||||
// If it's already an <a> tag, leave it unchanged
|
||||
if (m.group(1) != null) {
|
||||
return m.group(1)!;
|
||||
}
|
||||
|
||||
// Otherwise, wrap the bare URL
|
||||
final url = m.group(2)!;
|
||||
return "<a href=\"$url\">$url</a>";
|
||||
},
|
||||
),
|
||||
)
|
||||
: Linkify(
|
||||
text: content!,
|
||||
options: LinkifyOptions(humanize: false),
|
||||
onOpen: (link) => ref
|
||||
.watch(LaunchHelper.provider)
|
||||
.launchUrl(Uri.parse(link.url)),
|
||||
linkStyle: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
),
|
||||
if (textMessage?.editedAt != null)
|
||||
Text("(edited)", style: theme.textTheme.labelSmall),
|
||||
if (link != null)
|
||||
ref
|
||||
.watch(UrlPreviewController.provider(link))
|
||||
.betterWhen(
|
||||
loading: SizedBox.shrink,
|
||||
data: (preview) => preview == null
|
||||
? SizedBox.shrink()
|
||||
: InkWell(
|
||||
onTap: () => ref
|
||||
.watch(LaunchHelper.provider)
|
||||
.launchUrl(Uri.parse(link)),
|
||||
child: Card(
|
||||
child: Column(
|
||||
children: [
|
||||
if (preview.title != null)
|
||||
Text(
|
||||
preview.title!,
|
||||
style: theme.textTheme.labelLarge,
|
||||
),
|
||||
if (preview.description != null)
|
||||
Text(preview.description!),
|
||||
if (preview.imageUrl != null)
|
||||
Image(
|
||||
errorBuilder: (_, _, _) =>
|
||||
SizedBox.shrink(),
|
||||
width: preview.width,
|
||||
height: preview.height,
|
||||
image: CachedNetworkImage(
|
||||
preview.imageUrl!,
|
||||
ref.watch(
|
||||
CrossCacheController.provider,
|
||||
),
|
||||
headers: ref.headers,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
],
|
||||
),
|
||||
// text: link,
|
||||
// backgroundColor: isSentByMe
|
||||
// ? colorScheme.inversePrimary
|
||||
// : colorScheme.surfaceContainerLow,
|
||||
// outsidePadding: EdgeInsets.only(top: 4),
|
||||
// insidePadding: EdgeInsets.symmetric(
|
||||
// vertical: 8,
|
||||
// horizontal: 16,
|
||||
// ),
|
||||
// linkPreviewData: preview,
|
||||
// onLinkPreviewDataFetched: (_) => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
?extra,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
groupStatus,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue