Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ abstract class UrlPreviewComponent<T extends Client> implements Component<T> {
Future<UrlPreviewData?> getPreviewForUrl(Room room, Uri url);

UrlPreviewData? getCachedPreview(Timeline timeline, TimelineEvent event);

// This is a dummy value that we can store in the cache when we fail to get the url preview.
// Instead of storing null, which is a bit confusing as if the cache returns null, does that mean we have
// nothing cached, or the result was invalid? maybe this is dumb but it was the simplest way
// to prevent weird ui glitches when failed fetches kept getting retried.
static UrlPreviewData invalidPreviewData =
UrlPreviewData(Uri.new(), title: "Unable to get url preview ");
}

class UrlPreviewData {
Uri uri;
String? siteName;
String? title;
String? description;
ImageProvider? image;
final Uri uri;
final String? siteName;
final String? title;
final String? description;
final ImageProvider? image;

UrlPreviewData(
const UrlPreviewData(
this.uri, {
this.siteName,
this.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class MatrixUrlPreviewComponent implements UrlPreviewComponent<MatrixClient> {

if (data != null) {
cache[uri.toString()] = data;
} else {
cache[uri.toString()] = UrlPreviewComponent.invalidPreviewData;
}

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class _TimelineEventViewUrlPreviewsState
@override
Widget build(BuildContext context) {
BenchmarkValues.numTimelineUrlPreviewBuilt += 1;

if (data == UrlPreviewComponent.invalidPreviewData) return Container();

return Padding(
padding: const EdgeInsets.fromLTRB(0, 2, 40, 2),
child: (loading || data != null)
Expand Down