hide URL previews if generating them throws an error
This commit is contained in:
parent
b727d0342d
commit
3c7c74f745
2 changed files with 27 additions and 25 deletions
|
|
@ -12,33 +12,36 @@ class UrlPreviewController extends AsyncNotifier<OpenGraphData?> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<OpenGraphData?> build() async {
|
Future<OpenGraphData?> build() async {
|
||||||
final homeserver = ref.watch(
|
try {
|
||||||
ClientStateController.provider.select((value) => value?.homeserverUrl),
|
final homeserver = ref.watch(
|
||||||
);
|
ClientStateController.provider.select((value) => value?.homeserverUrl),
|
||||||
|
);
|
||||||
|
|
||||||
if (homeserver != null && !link.contains("matrix.to")) {
|
if (homeserver != null && !link.contains("matrix.to")) {
|
||||||
{
|
{
|
||||||
final response = await get(
|
final response = await get(
|
||||||
.parse(homeserver)
|
.parse(homeserver)
|
||||||
.resolve("/_matrix/client/v1/media/preview_url")
|
.resolve("/_matrix/client/v1/media/preview_url")
|
||||||
.replace(queryParameters: {"url": link}),
|
.replace(queryParameters: {"url": link}),
|
||||||
headers: await ref.watch(HeaderController.provider.future),
|
headers: await ref.watch(HeaderController.provider.future),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final decodedValue = json.decode(response.body);
|
final decodedValue = json.decode(response.body);
|
||||||
if (decodedValue is! Map<String, dynamic>) 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 .fromJson(decodedValue).copyWith(imageUrl: image);
|
return .fromJson(decodedValue).copyWith(imageUrl: image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (_) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -508,7 +508,6 @@ class RoomChat extends HookConsumerWidget {
|
||||||
MemberList(roomId),
|
MemberList(roomId),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
endDrawer: showMembersByDefault ? null : MemberList(roomId),
|
endDrawer: showMembersByDefault ? null : MemberList(roomId),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue