From c67bd6b464f9779fbeb38f96e2c25143256aa5aa Mon Sep 17 00:00:00 2001 From: otsmr Date: Sun, 26 Oct 2025 23:06:49 +0100 Subject: [PATCH] fixing multiple bugs --- README.md | 6 +- lib/src/views/camera/share_image_view.dart | 2 - .../chat_media_entry.dart | 27 +++++++- .../response_container.dart | 62 +++++++++++-------- 4 files changed, 63 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 33187be..09663de 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ This repository contains the complete source code of the [twonly](https://twonly - End-to-End encryption using the [Signal Protocol](https://de.wikipedia.org/wiki/Signal-Protokoll) - No email or phone number required to register - Privacy friendly - Everything is stored on the device +- Open-Source ## In work - For Android: Using [UnifiedPush](https://unifiedpush.org/) instead of FCM -- For Android: Reproducible Builds + Publishing on Github/F-Droid +- For Android: Reproducible Builds + Publishing F-Droid - Implementing [Sealed Sender](https://signal.org/blog/sealed-sender/) to minimize metadata -- Maybe: Switching from the Signal Protocol to [MLS](https://openmls.tech/). ## Security Issues If you discover a security issue in twonly, please adhere to the coordinated vulnerability disclosure model. Please send @@ -33,8 +33,6 @@ guarantee a bounty currently :/ Some dependencies are downloaded directly from the source as there are some new changes which are not yet published on pub.dev or because they require some special installation. -- `flutter_secure_storage`: We need the 10.0.0-beta version, but this version has some issues which are fixed but [not yet published](https://github.com/juliansteenbakker/flutter_secure_storage/issues/866): - ```bash git submodule update --init --recursive diff --git a/lib/src/views/camera/share_image_view.dart b/lib/src/views/camera/share_image_view.dart index 92cb735..1db8c71 100644 --- a/lib/src/views/camera/share_image_view.dart +++ b/lib/src/views/camera/share_image_view.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:twonly/globals.dart'; import 'package:twonly/src/database/daos/groups.dao.dart'; -import 'package:twonly/src/database/tables/mediafiles.table.dart'; import 'package:twonly/src/database/twonly.db.dart'; import 'package:twonly/src/services/api/mediafiles/upload.service.dart'; import 'package:twonly/src/services/mediafiles/mediafile.service.dart'; @@ -65,7 +64,6 @@ class _ShareImageView extends State { await widget.mediaStoreFuture; } mediaStoreFutureReady = true; - await widget.mediaFileService.setUploadState(UploadState.preprocessing); unawaited(startBackgroundMediaUpload(widget.mediaFileService)); if (!mounted) return; setState(() {}); diff --git a/lib/src/views/chats/chat_messages_components/chat_media_entry.dart b/lib/src/views/chats/chat_messages_components/chat_media_entry.dart index 8afe01a..0337ba2 100644 --- a/lib/src/views/chats/chat_messages_components/chat_media_entry.dart +++ b/lib/src/views/chats/chat_messages_components/chat_media_entry.dart @@ -36,7 +36,30 @@ class ChatMediaEntry extends StatefulWidget { class _ChatMediaEntryState extends State { GlobalKey reopenMediaFile = GlobalKey(); - bool canBeReopened = false; + bool _canBeReopened = false; + + @override + void initState() { + super.initState(); + unawaited(initAsync()); + } + + Future initAsync() async { + if (widget.message.senderId == null || widget.message.mediaStored) { + return; + } + if (widget.mediaService.mediaFile.requiresAuthentication || + widget.mediaService.mediaFile.displayLimitInMilliseconds != null) { + return; + } + if (widget.mediaService.tempPath.existsSync()) { + if (mounted) { + setState(() { + _canBeReopened = true; + }); + } + } + } Future onDoubleTap() async { if (widget.message.openedAt == null || widget.message.mediaStored) { @@ -109,7 +132,7 @@ class _ChatMediaEntryState extends State { mediaService: widget.mediaService, color: color, galleryItems: widget.galleryItems, - canBeReopened: canBeReopened, + canBeReopened: _canBeReopened, ), ), ), diff --git a/lib/src/views/chats/chat_messages_components/response_container.dart b/lib/src/views/chats/chat_messages_components/response_container.dart index 4752b89..3db2601 100644 --- a/lib/src/views/chats/chat_messages_components/response_container.dart +++ b/lib/src/views/chats/chat_messages_components/response_container.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:twonly/globals.dart'; +import 'package:twonly/src/database/daos/contacts.dao.dart'; import 'package:twonly/src/database/tables/mediafiles.table.dart'; import 'package:twonly/src/database/tables/messages.table.dart'; import 'package:twonly/src/database/twonly.db.dart'; @@ -128,22 +129,34 @@ class ResponsePreview extends StatefulWidget { } class _ResponsePreviewState extends State { - Message? message; - MediaFileService? mediaService; + Message? _message; + MediaFileService? _mediaService; + String _username = ''; @override void initState() { - message = widget.message; + _message = widget.message; initAsync(); super.initState(); } Future initAsync() async { - message ??= await twonlyDB.messagesDao + _message ??= await twonlyDB.messagesDao .getMessageById(widget.messageId!) .getSingleOrNull(); - if (message?.mediaId != null) { - mediaService = await MediaFileService.fromMediaId(message!.mediaId!); + if (_message?.mediaId != null) { + _mediaService = await MediaFileService.fromMediaId(_message!.mediaId!); + } + if (_message?.senderId != null) { + final contact = await twonlyDB.contactsDao + .getContactByUserId(_message!.senderId!) + .getSingleOrNull(); + if (contact != null) { + _username = getContactDisplayName(contact); + } + } + if (_message == null && mounted) { + _username = context.lang.quotedMessageWasDeleted; } if (mounted) setState(() {}); } @@ -152,28 +165,27 @@ class _ResponsePreviewState extends State { Widget build(BuildContext context) { String? subtitle; var color = const Color.fromARGB(233, 68, 137, 255); - var username = ''; - if (message != null) { - if (message!.type == MessageType.text) { - if (message!.content != null) { - subtitle = truncateString(message!.content!); + if (_message != null) { + if (_message!.type == MessageType.text) { + if (_message!.content != null) { + subtitle = truncateString(_message!.content!); } } - if (message!.type == MessageType.media && mediaService != null) { - subtitle = mediaService!.mediaFile.type == MediaType.video + if (_message!.type == MessageType.media && _mediaService != null) { + subtitle = _mediaService!.mediaFile.type == MediaType.video ? context.lang.video : context.lang.image; } - username = context.lang.you; - if (message!.senderId != null) { - username = message!.senderId.toString(); + if (_message!.senderId == null) { + _username = context.lang.you; + // _username = _message!.senderId.toString(); } - color = getMessageColor(message!); + color = getMessageColor(_message!); - if (!message!.mediaStored) { + if (!_message!.mediaStored) { return Container( padding: widget.showBorder ? const EdgeInsets.only(left: 10, right: 10) @@ -192,7 +204,7 @@ class _ResponsePreviewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - username, + _username, style: const TextStyle(fontWeight: FontWeight.bold), ), if (subtitle != null) Text(subtitle), @@ -200,8 +212,6 @@ class _ResponsePreviewState extends State { ), ); } - } else { - username = context.lang.quotedMessageWasDeleted; } return Container( @@ -222,20 +232,20 @@ class _ResponsePreviewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - username, + _username, style: const TextStyle(fontWeight: FontWeight.bold), ), if (subtitle != null) Text(subtitle), ], ), ), - if (mediaService != null) + if (_mediaService != null) SizedBox( height: widget.showBorder ? 100 : 210, child: Image.file( - mediaService!.mediaFile.type == MediaType.video - ? mediaService!.thumbnailPath - : mediaService!.storedPath, + _mediaService!.mediaFile.type == MediaType.video + ? _mediaService!.thumbnailPath + : _mediaService!.storedPath, ), ), ],