From 7edf84564b5605af7d404749d079788345ef02ed Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 28 Apr 2020 14:11:56 +0200 Subject: [PATCH] Update sdk --- lib/components/avatar.dart | 8 ++++---- lib/components/content_banner.dart | 6 +++--- lib/components/image_bubble.dart | 12 ++++++++++-- lib/components/list_items/presence_list_item.dart | 2 +- lib/components/list_items/public_room_list_item.dart | 7 +++++-- lib/components/matrix.dart | 7 ++++--- lib/components/message_content.dart | 12 ------------ lib/utils/famedlysdk_store.dart | 3 +++ lib/views/invitation_selection.dart | 4 +++- lib/views/new_private_chat.dart | 8 ++++++-- lib/views/settings.dart | 2 +- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 13 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/components/avatar.dart b/lib/components/avatar.dart index 3f49e89..1c7af47 100644 --- a/lib/components/avatar.dart +++ b/lib/components/avatar.dart @@ -7,7 +7,7 @@ import 'package:flutter_advanced_networkimage/provider.dart'; import 'matrix.dart'; class Avatar extends StatelessWidget { - final MxContent mxContent; + final Uri mxContent; final String name; final double size; final Function onTap; @@ -39,16 +39,16 @@ class Avatar extends StatelessWidget { onTap: onTap, child: CircleAvatar( radius: size / 2, - backgroundImage: mxContent.mxc?.isNotEmpty ?? false + backgroundImage: mxContent != null ? AdvancedNetworkImage( src, useDiskCache: !kIsWeb, ) : null, - backgroundColor: mxContent.mxc.isEmpty + backgroundColor: mxContent == null ? name?.color ?? Theme.of(context).secondaryHeaderColor : Theme.of(context).secondaryHeaderColor, - child: mxContent.mxc.isEmpty + child: mxContent == null ? Text(fallbackLetters, style: TextStyle(color: Colors.white)) : null, ), diff --git a/lib/components/content_banner.dart b/lib/components/content_banner.dart index e77176b..55453db 100644 --- a/lib/components/content_banner.dart +++ b/lib/components/content_banner.dart @@ -6,7 +6,7 @@ import 'package:flutter_advanced_networkimage/provider.dart'; import 'matrix.dart'; class ContentBanner extends StatelessWidget { - final MxContent mxContent; + final Uri mxContent; final double height; final IconData defaultIcon; final bool loading; @@ -25,7 +25,7 @@ class ContentBanner extends StatelessWidget { final mediaQuery = MediaQuery.of(context); final int bannerSize = (mediaQuery.size.width * mediaQuery.devicePixelRatio).toInt(); - final String src = mxContent.getThumbnail( + final String src = mxContent?.getThumbnail( Matrix.of(context).client, width: bannerSize, height: bannerSize, @@ -47,7 +47,7 @@ class ContentBanner extends StatelessWidget { child: Opacity( opacity: 0.75, child: !loading - ? mxContent.mxc?.isNotEmpty ?? false + ? mxContent != null ? Image( height: 300, fit: BoxFit.cover, diff --git a/lib/components/image_bubble.dart b/lib/components/image_bubble.dart index 339dfc1..dacb6f4 100644 --- a/lib/components/image_bubble.dart +++ b/lib/components/image_bubble.dart @@ -3,6 +3,8 @@ import 'package:famedlysdk/famedlysdk.dart'; import 'package:flutter/material.dart'; import 'package:fluffychat/utils/matrix_file_extension.dart'; +import 'dialogs/simple_dialogs.dart'; + class ImageBubble extends StatefulWidget { final Event event; @@ -23,7 +25,7 @@ class _ImageBubbleState extends State { Future _getFile() async { if (_file != null) return _file; - return widget.event.downloadAndDecryptAttachment(); + return widget.event.downloadAndDecryptAttachment(getThumbnail: true); } @override @@ -47,7 +49,13 @@ class _ImageBubbleState extends State { } if (_file != null) { return InkWell( - onTap: () => _file.open(), + onTap: () async { + final MatrixFile matrixFile = + await SimpleDialogs(context).tryRequestWithLoadingDialog( + widget.event.downloadAndDecryptAttachment(), + ); + matrixFile.open(); + }, child: Image.memory( _file.bytes, fit: BoxFit.cover, diff --git a/lib/components/list_items/presence_list_item.dart b/lib/components/list_items/presence_list_item.dart index efec546..d36dcf2 100644 --- a/lib/components/list_items/presence_list_item.dart +++ b/lib/components/list_items/presence_list_item.dart @@ -19,7 +19,7 @@ class PresenceListItem extends StatelessWidget { return FutureBuilder( future: Matrix.of(context).client.getProfileFromUserId(presence.sender), builder: (context, snapshot) { - MxContent avatarUrl = MxContent(''); + Uri avatarUrl; String displayname = presence.sender.localpart; if (snapshot.hasData) { avatarUrl = snapshot.data.avatarUrl; diff --git a/lib/components/list_items/public_room_list_item.dart b/lib/components/list_items/public_room_list_item.dart index 263baf0..030f4cd 100644 --- a/lib/components/list_items/public_room_list_item.dart +++ b/lib/components/list_items/public_room_list_item.dart @@ -30,8 +30,11 @@ class PublicRoomListItem extends StatelessWidget { final bool hasTopic = publicRoomEntry.topic != null && publicRoomEntry.topic.isNotEmpty; return ListTile( - leading: - Avatar(MxContent(publicRoomEntry.avatarUrl), publicRoomEntry.name), + leading: Avatar( + publicRoomEntry.avatarUrl == null + ? null + : Uri.parse(publicRoomEntry.avatarUrl), + publicRoomEntry.name), title: Text(hasTopic ? "${publicRoomEntry.name} (${publicRoomEntry.numJoinedMembers})" : publicRoomEntry.name), diff --git a/lib/components/matrix.dart b/lib/components/matrix.dart index 44968c6..e588eee 100644 --- a/lib/components/matrix.dart +++ b/lib/components/matrix.dart @@ -77,12 +77,13 @@ class MatrixState extends State { await storage.deleteItem(widget.clientName); } - Future downloadAndSaveContent(MxContent content, + Future downloadAndSaveContent(Uri content, {int width, int height, ThumbnailMethod method}) async { final bool thumbnail = width == null && height == null ? false : true; final String tempDirectory = (await getTemporaryDirectory()).path; final String prefix = thumbnail ? "thumbnail" : ""; - File file = File('$tempDirectory/${prefix}_${content.mxc.split("/").last}'); + File file = + File('$tempDirectory/${prefix}_${content.toString().split("/").last}'); if (!file.existsSync()) { final url = thumbnail @@ -214,7 +215,7 @@ class MatrixState extends State { // The person object for the android message style notification final person = Person( name: room.getLocalizedDisplayname(context), - icon: room.avatar.mxc.isEmpty + icon: room.avatar == null ? null : await downloadAndSaveContent( room.avatar, diff --git a/lib/components/message_content.dart b/lib/components/message_content.dart index c9fd832..0b5cc02 100644 --- a/lib/components/message_content.dart +++ b/lib/components/message_content.dart @@ -3,9 +3,7 @@ import 'package:fluffychat/components/audio_player.dart'; import 'package:fluffychat/components/image_bubble.dart'; import 'package:fluffychat/i18n/i18n.dart'; import 'package:fluffychat/utils/event_extension.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_styled_toast/flutter_styled_toast.dart'; import 'package:link_text/link_text.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:fluffychat/utils/matrix_file_extension.dart'; @@ -51,16 +49,6 @@ class MessageContent extends StatelessWidget { style: TextStyle(color: Colors.white), ), onPressed: () async { - if (kIsWeb) { - if (event.room.encrypted) { - showToast(I18n.of(context).notSupportedInWeb); - } - await launch( - MxContent(event.content["url"]) - .getDownloadLink(event.room.client), - ); - return; - } final MatrixFile matrixFile = await SimpleDialogs(context) .tryRequestWithLoadingDialog( diff --git a/lib/utils/famedlysdk_store.dart b/lib/utils/famedlysdk_store.dart index a78d233..c3f8d2a 100644 --- a/lib/utils/famedlysdk_store.dart +++ b/lib/utils/famedlysdk_store.dart @@ -623,4 +623,7 @@ class ExtendedStore extends Store implements ExtendedStoreAPI { 'saved_at INTEGER, ' + 'UNIQUE(mxc_uri))', }; + + @override + int get maxFileSize => 1 * 1024 * 1024; } diff --git a/lib/views/invitation_selection.dart b/lib/views/invitation_selection.dart index 7e85a1c..a34eb52 100644 --- a/lib/views/invitation_selection.dart +++ b/lib/views/invitation_selection.dart @@ -159,7 +159,9 @@ class _InvitationSelectionState extends State { itemCount: foundProfiles.length, itemBuilder: (BuildContext context, int i) => ListTile( leading: Avatar( - MxContent(foundProfiles[i]["avatar_url"] ?? ""), + foundProfiles[i]["avatar_url"] == null + ? null + : Uri.parse(foundProfiles[i]["avatar_url"]), foundProfiles[i]["display_name"] ?? foundProfiles[i]["user_id"], ), diff --git a/lib/views/new_private_chat.dart b/lib/views/new_private_chat.dart index 819055e..ddf34fe 100644 --- a/lib/views/new_private_chat.dart +++ b/lib/views/new_private_chat.dart @@ -158,7 +158,9 @@ class _NewPrivateChatState extends State<_NewPrivateChat> { ? Padding( padding: const EdgeInsets.all(8.0), child: Avatar( - MxContent(foundProfile["avatar_url"] ?? ""), + foundProfile["avatar_url"] == null + ? null + : Uri.parse(foundProfile["avatar_url"]), foundProfile["display_name"] ?? foundProfile["user_id"], size: 12, @@ -186,7 +188,9 @@ class _NewPrivateChatState extends State<_NewPrivateChat> { }); }, leading: Avatar( - MxContent(foundProfile["avatar_url"] ?? ""), + foundProfile["avatar_url"] == null + ? null + : Uri.parse(foundProfile["avatar_url"]), foundProfile["display_name"] ?? foundProfile["user_id"], //size: 24, ), diff --git a/lib/views/settings.dart b/lib/views/settings.dart index a7a1e5b..44f1277 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -152,7 +152,7 @@ class _SettingsState extends State { color: Theme.of(context).appBarTheme.textTheme.title.color), ), background: ContentBanner( - profile?.avatarUrl ?? MxContent(""), + profile?.avatarUrl, height: 300, defaultIcon: Icons.account_circle, loading: profile == null, diff --git a/pubspec.lock b/pubspec.lock index 8b327a2..d941fe7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -117,8 +117,8 @@ packages: dependency: "direct main" description: path: "." - ref: "28dee0e2e3dc2fdde64b29d0a65028b49b4c4dc7" - resolved-ref: "28dee0e2e3dc2fdde64b29d0a65028b49b4c4dc7" + ref: "1265ebf7da56440ead152bbf44502b941436dc1b" + resolved-ref: "1265ebf7da56440ead152bbf44502b941436dc1b" url: "https://gitlab.com/famedly/famedlysdk.git" source: git version: "0.0.1" diff --git a/pubspec.yaml b/pubspec.yaml index 30072cd..da85597 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: famedlysdk: git: url: https://gitlab.com/famedly/famedlysdk.git - ref: 28dee0e2e3dc2fdde64b29d0a65028b49b4c4dc7 + ref: 1265ebf7da56440ead152bbf44502b941436dc1b localstorage: ^3.0.1+4 bubble: ^1.1.9+1