Remove flutter chat #26
8 changed files with 293 additions and 275 deletions
fix up url embeds
commit
fee12cb94d
|
|
@ -26,15 +26,15 @@ class UrlPreviewController extends AsyncNotifier<OpenGraphData?> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final decodedValue = json.decode(response.body) as Map?;
|
final decodedValue = json.decode(response.body);
|
||||||
if (decodedValue?.isNotEmpty == true) return null;
|
if (decodedValue is! Map<String, dynamic>) return null;
|
||||||
|
|
||||||
final mxc = decodedValue!["og:image"];
|
final mxc = decodedValue["og:image"];
|
||||||
final image = mxc == null
|
final image = mxc == null
|
||||||
? null
|
? null
|
||||||
: Uri.tryParse(mxc)?.mxcToHttps(homeserver);
|
: Uri.tryParse(mxc)?.mxcToHttps(homeserver);
|
||||||
|
|
||||||
return OpenGraphData.fromJson({...decodedValue, "og:image": image});
|
return OpenGraphData.fromJson(decodedValue).copyWith(imageUrl: image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ abstract class OpenGraphData with _$OpenGraphData {
|
||||||
const factory OpenGraphData({
|
const factory OpenGraphData({
|
||||||
@JsonKey(name: "og:title") required String? title,
|
@JsonKey(name: "og:title") required String? title,
|
||||||
@JsonKey(name: "og:description") required String? description,
|
@JsonKey(name: "og:description") required String? description,
|
||||||
@JsonKey(name: "og:image") required String? imageUrl,
|
@JsonKey(name: "og:image") required Uri? imageUrl,
|
||||||
@JsonKey(name: "og:image:width") required double? width,
|
@JsonKey(name: "og:image:width") required double? width,
|
||||||
@JsonKey(name: "og:image:height") required double? height,
|
@JsonKey(name: "og:image:height") required double? height,
|
||||||
}) = _OpenGraphData;
|
}) = _OpenGraphData;
|
||||||
|
|
||||||
factory OpenGraphData.fromJson(Map<String, Object?> json) =>
|
factory OpenGraphData.fromJson(Map<String, dynamic> json) =>
|
||||||
_$OpenGraphDataFromJson(json);
|
_$OpenGraphDataFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ class Html extends ConsumerWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) => HtmlWidget(
|
Widget build(BuildContext context, WidgetRef ref) => HtmlWidget(
|
||||||
html,
|
html,
|
||||||
|
buildAsync: false,
|
||||||
textStyle: textStyle,
|
textStyle: textStyle,
|
||||||
customWidgetBuilder: (element) {
|
customWidgetBuilder: (element) {
|
||||||
if (element.attributes.keys.contains("data-mx-profile-fallback")) {
|
if (element.attributes.keys.contains("data-mx-profile-fallback")) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
|
import "package:collection/collection.dart";
|
||||||
import "package:cross_cache/cross_cache.dart";
|
import "package:cross_cache/cross_cache.dart";
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
import "package:flutter_blurhash/flutter_blurhash.dart";
|
import "package:flutter_blurhash/flutter_blurhash.dart";
|
||||||
import "package:flutter_riverpod/flutter_riverpod.dart";
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
|
import "package:linkify/linkify.dart";
|
||||||
import "package:nexus/controllers/client_state_controller.dart";
|
import "package:nexus/controllers/client_state_controller.dart";
|
||||||
import "package:nexus/controllers/cross_cache_controller.dart";
|
import "package:nexus/controllers/cross_cache_controller.dart";
|
||||||
import "package:nexus/helpers/extensions/get_headers.dart";
|
import "package:nexus/helpers/extensions/get_headers.dart";
|
||||||
|
|
@ -59,17 +61,16 @@ class RenderEvent extends ConsumerWidget {
|
||||||
children: getEventOptions!(event).toList(),
|
children: getEventOptions!(event).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return GestureDetector(
|
final child = switch (event.content) {
|
||||||
onSecondaryTapUp: contextMenuCallback,
|
|
||||||
onLongPressStart: contextMenuCallback,
|
|
||||||
child: switch (event.content) {
|
|
||||||
MessageContent() => Row(
|
MessageContent() => Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
children: [
|
children: [
|
||||||
isGrouped || textOnly
|
if (!textOnly)
|
||||||
? SizedBox(width: 40)
|
if (isGrouped)
|
||||||
: MessageAvatar(event, height: 40),
|
SizedBox(width: 40)
|
||||||
|
else
|
||||||
|
MessageAvatar(event, height: 40),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
|
|
@ -79,21 +80,26 @@ class RenderEvent extends ConsumerWidget {
|
||||||
Row(
|
Row(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
MessageDisplayname(
|
Flexible(
|
||||||
|
child: MessageDisplayname(
|
||||||
event,
|
event,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
Flexible(child: timestamp),
|
Flexible(child: timestamp),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ClipRRect(
|
ClipRRect(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
borderRadius: textOnly
|
||||||
|
? BorderRadius.zero
|
||||||
|
: BorderRadius.all(Radius.circular(8)),
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: textOnly
|
||||||
vertical: 8,
|
? EdgeInsets.zero
|
||||||
horizontal: 12,
|
: EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
||||||
),
|
decoration: textOnly
|
||||||
decoration: BoxDecoration(
|
? null
|
||||||
|
: BoxDecoration(
|
||||||
color:
|
color:
|
||||||
ref.watch(
|
ref.watch(
|
||||||
ClientStateController.provider.select(
|
ClientStateController.provider.select(
|
||||||
|
|
@ -122,6 +128,11 @@ class RenderEvent extends ConsumerWidget {
|
||||||
:final formattedBody,
|
:final formattedBody,
|
||||||
:final format,
|
:final format,
|
||||||
) ||
|
) ||
|
||||||
|
NoticeMessageContent(
|
||||||
|
:final body,
|
||||||
|
:final formattedBody,
|
||||||
|
:final format,
|
||||||
|
) ||
|
||||||
ImageMessageContent(
|
ImageMessageContent(
|
||||||
:final body,
|
:final body,
|
||||||
:final formattedBody,
|
:final formattedBody,
|
||||||
|
|
@ -156,9 +167,8 @@ class RenderEvent extends ConsumerWidget {
|
||||||
: Linkify(
|
: Linkify(
|
||||||
text: body,
|
text: body,
|
||||||
maxLines: maxLines,
|
maxLines: maxLines,
|
||||||
options: LinkifyOptions(
|
overflow: TextOverflow.ellipsis,
|
||||||
humanize: false,
|
options: LinkifyOptions(humanize: false),
|
||||||
),
|
|
||||||
onOpen: (link) => ref
|
onOpen: (link) => ref
|
||||||
.watch(LaunchHelper.provider)
|
.watch(LaunchHelper.provider)
|
||||||
.launchUrl(Uri.parse(link.url)),
|
.launchUrl(Uri.parse(link.url)),
|
||||||
|
|
@ -200,8 +210,7 @@ class RenderEvent extends ConsumerWidget {
|
||||||
loadingProgress == null
|
loadingProgress == null
|
||||||
? child
|
? child
|
||||||
: switch (info?.blurHash) {
|
: switch (info?.blurHash) {
|
||||||
final blurHash? =>
|
final blurHash? => SizedBox(
|
||||||
SizedBox(
|
|
||||||
width:
|
width:
|
||||||
info?.width ??
|
info?.width ??
|
||||||
info?.height ??
|
info?.height ??
|
||||||
|
|
@ -236,25 +245,19 @@ class RenderEvent extends ConsumerWidget {
|
||||||
style: errorStyle,
|
style: errorStyle,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
if (event.lastEditRowId != null)
|
if (event.lastEditRowId != null && !textOnly)
|
||||||
Text(
|
Text(
|
||||||
"(edited)",
|
"(edited)",
|
||||||
style: theme.textTheme.labelSmall,
|
style: theme.textTheme.labelSmall,
|
||||||
),
|
),
|
||||||
if (RegExp(
|
if (linkify(body).firstWhereOrNull(
|
||||||
r'''https?://[^\s"'<>]+''',
|
(element) => element is UrlElement,
|
||||||
).allMatches(body).firstOrNull?.group(0)
|
)
|
||||||
case final link?)
|
case final UrlElement link?)
|
||||||
LinkPreview(link),
|
LinkPreview(link.url),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
_ =>
|
_ => Text("Unknown message type", style: errorStyle),
|
||||||
textOnly
|
|
||||||
? Text(
|
|
||||||
"Unknown message type",
|
|
||||||
style: errorStyle,
|
|
||||||
)
|
|
||||||
: SizedBox.shrink(),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -280,11 +283,17 @@ class RenderEvent extends ConsumerWidget {
|
||||||
Text("changed the room avatar"),
|
Text("changed the room avatar"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
_ =>
|
_ => null,
|
||||||
textOnly
|
};
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onSecondaryTapUp: contextMenuCallback,
|
||||||
|
onLongPressStart: contextMenuCallback,
|
||||||
|
child: child == null
|
||||||
|
? textOnly
|
||||||
? Text("Unknown event type", style: errorStyle)
|
? Text("Unknown event type", style: errorStyle)
|
||||||
: SizedBox.shrink(),
|
: SizedBox.shrink()
|
||||||
},
|
: Padding(padding: EdgeInsets.symmetric(vertical: 8), child: child),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -325,9 +325,7 @@ class RoomChat extends HookConsumerWidget {
|
||||||
SuperSliverList.builder(
|
SuperSliverList.builder(
|
||||||
listController: listController.value,
|
listController: listController.value,
|
||||||
itemCount: value.length,
|
itemCount: value.length,
|
||||||
itemBuilder: (_, index) => Padding(
|
itemBuilder: (_, index) => EventWrapper(
|
||||||
padding: EdgeInsets.symmetric(vertical: 8),
|
|
||||||
child: EventWrapper(
|
|
||||||
value[index],
|
value[index],
|
||||||
RenderEvent(
|
RenderEvent(
|
||||||
value[index],
|
value[index],
|
||||||
|
|
@ -348,7 +346,6 @@ class RoomChat extends HookConsumerWidget {
|
||||||
isFlashing: false,
|
isFlashing: false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
AsyncLoading() => Loading(),
|
AsyncLoading() => Loading(),
|
||||||
|
|
|
||||||
|
|
@ -17,44 +17,48 @@ class LinkPreview extends ConsumerWidget {
|
||||||
.betterWhen(
|
.betterWhen(
|
||||||
data: (preview) => preview == null
|
data: (preview) => preview == null
|
||||||
? SizedBox.shrink()
|
? SizedBox.shrink()
|
||||||
: InkWell(
|
: ConstrainedBox(
|
||||||
onTap: () =>
|
constraints: BoxConstraints.loose(Size.fromWidth(400)),
|
||||||
ref.watch(LaunchHelper.provider).launchUrl(Uri.parse(link)),
|
child: InkWell(
|
||||||
|
onTap: () => ref
|
||||||
|
.watch(LaunchHelper.provider)
|
||||||
|
.launchUrl(Uri.parse(link)),
|
||||||
child: Card(
|
child: Card(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsetsGeometry.all(8),
|
||||||
child: Column(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
if (preview.title != null)
|
if (preview.title != null)
|
||||||
Text(
|
Text(
|
||||||
preview.title!,
|
preview.title!,
|
||||||
style: Theme.of(context).textTheme.labelLarge,
|
style: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
),
|
||||||
if (preview.description != null)
|
if (preview.description != null) ...[
|
||||||
Text(preview.description!),
|
Text(preview.description!),
|
||||||
|
SizedBox(height: 4),
|
||||||
|
],
|
||||||
if (preview.imageUrl != null)
|
if (preview.imageUrl != null)
|
||||||
Image(
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(8),
|
||||||
|
),
|
||||||
|
child: Image(
|
||||||
errorBuilder: (_, _, _) => SizedBox.shrink(),
|
errorBuilder: (_, _, _) => SizedBox.shrink(),
|
||||||
width: preview.width,
|
width: preview.width,
|
||||||
height: preview.height,
|
|
||||||
image: CachedNetworkImage(
|
image: CachedNetworkImage(
|
||||||
preview.imageUrl!,
|
preview.imageUrl.toString(),
|
||||||
ref.watch(CrossCacheController.provider),
|
ref.watch(CrossCacheController.provider),
|
||||||
headers: ref.headers,
|
headers: ref.headers,
|
||||||
),
|
),
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.fitWidth,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
// text: link,
|
),
|
||||||
// backgroundColor: isSentByMe
|
),
|
||||||
// ? colorScheme.inversePrimary
|
|
||||||
// : colorScheme.surfaceContainerLow,
|
|
||||||
// outsidePadding: EdgeInsets.only(top: 4),
|
|
||||||
// insidePadding: EdgeInsets.symmetric(
|
|
||||||
// vertical: 8,
|
|
||||||
// horizontal: 16,
|
|
||||||
// ),
|
|
||||||
// linkPreviewData: preview,
|
|
||||||
// onLinkPreviewDataFetched: (_) => null,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
11
pubspec.lock
11
pubspec.lock
|
|
@ -720,12 +720,13 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.2"
|
version: "3.0.2"
|
||||||
linkify:
|
linkify:
|
||||||
dependency: transitive
|
dependency: "direct overridden"
|
||||||
description:
|
description:
|
||||||
name: linkify
|
path: "."
|
||||||
sha256: "4139ea77f4651ab9c315b577da2dd108d9aa0bd84b5d03d33323f1970c645832"
|
ref: "fix/consecutive-periods-loose-url"
|
||||||
url: "https://pub.dev"
|
resolved-ref: e990021f30b8535b462d41a39f37019045ae55f4
|
||||||
source: hosted
|
url: "https://github.com/appelladev/linkify"
|
||||||
|
source: git
|
||||||
version: "5.0.0"
|
version: "5.0.0"
|
||||||
lints:
|
lints:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ flutter:
|
||||||
environment:
|
environment:
|
||||||
sdk: "3.11.4"
|
sdk: "3.11.4"
|
||||||
|
|
||||||
|
dependency_overrides:
|
||||||
|
linkify:
|
||||||
|
git:
|
||||||
|
url: https://github.com/appelladev/linkify
|
||||||
|
ref: fix/consecutive-periods-loose-url
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue