multiple bugs

This commit is contained in:
otsmr 2026-05-13 00:07:08 +02:00
parent d7dffa82ff
commit 1e6ce639cf
6 changed files with 60 additions and 42 deletions

View file

@ -267,13 +267,13 @@ Future<void> requestMediaReupload(String mediaId) async {
final messages = await twonlyDB.messagesDao.getMessagesByMediaId(mediaId); final messages = await twonlyDB.messagesDao.getMessagesByMediaId(mediaId);
for (final message in messages) { for (final message in messages) {
if (message.openedAt != null) continue; if (message.openedAt != null || message.senderId == null) continue;
await sendCipherText( await sendCipherText(
messages.first.senderId!, message.senderId!,
EncryptedContent( EncryptedContent(
mediaUpdate: EncryptedContent_MediaUpdate( mediaUpdate: EncryptedContent_MediaUpdate(
type: EncryptedContent_MediaUpdate_Type.DECRYPTION_ERROR, type: EncryptedContent_MediaUpdate_Type.DECRYPTION_ERROR,
targetMessageId: messages.first.messageId, targetMessageId: message.messageId,
), ),
), ),
); );

View file

@ -40,6 +40,7 @@ void callbackDispatcher() {
// if (await initBackgroundExecution()) { // if (await initBackgroundExecution()) {
// await handlePeriodicTask(); // await handlePeriodicTask();
// } // }
break;
case 'eu.twonly.processing_task': case 'eu.twonly.processing_task':
if (await initBackgroundExecution()) { if (await initBackgroundExecution()) {
await handleProcessingTask(); await handleProcessingTask();
@ -130,6 +131,7 @@ Future<void> handlePeriodicTask({int lastExecutionInSecondsLimit = 120}) async {
return; return;
} }
try {
while (!AppState.gotMessageFromServer) { while (!AppState.gotMessageFromServer) {
if (stopwatch.elapsed.inSeconds >= 15) { if (stopwatch.elapsed.inSeconds >= 15) {
Log.info('No new message from the server after 15 seconds.'); Log.info('No new message from the server after 15 seconds.');
@ -145,9 +147,10 @@ Future<void> handlePeriodicTask({int lastExecutionInSecondsLimit = 120}) async {
await finishStartedPreprocessing(); await finishStartedPreprocessing();
await Future.delayed(const Duration(milliseconds: 2000)); await Future.delayed(const Duration(milliseconds: 2000));
} finally {
await apiService.close(() {}); await apiService.close(() {});
stopwatch.stop(); stopwatch.stop();
}
Log.info('eu.twonly.periodic_task finished after ${stopwatch.elapsed}.'); Log.info('eu.twonly.periodic_task finished after ${stopwatch.elapsed}.');
return; return;

View file

@ -11,6 +11,7 @@ import 'package:twonly/globals.dart';
import 'package:twonly/locator.dart'; import 'package:twonly/locator.dart';
import 'package:twonly/src/services/background/callback_dispatcher.background.dart'; import 'package:twonly/src/services/background/callback_dispatcher.background.dart';
import 'package:twonly/src/services/notifications/background.notifications.dart'; import 'package:twonly/src/services/notifications/background.notifications.dart';
import 'package:twonly/src/services/notifications/setup.notifications.dart';
import 'package:twonly/src/services/user.service.dart'; import 'package:twonly/src/services/user.service.dart';
import 'package:twonly/src/utils/log.dart'; import 'package:twonly/src/utils/log.dart';
@ -117,6 +118,7 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
SentryWidgetsFlutterBinding.ensureInitialized(); SentryWidgetsFlutterBinding.ensureInitialized();
await AppEnvironment.init(); await AppEnvironment.init();
final isInitialized = await initBackgroundExecution(); final isInitialized = await initBackgroundExecution();
await setupPushNotification();
Log.info('Handling a background message: ${message.messageId}'); Log.info('Handling a background message: ${message.messageId}');
await handleRemoteMessage(message); await handleRemoteMessage(message);

View file

@ -138,7 +138,12 @@ class MainCameraController {
? ImageFormatGroup.nv21 ? ImageFormatGroup.nv21
: ImageFormatGroup.bgra8888, : ImageFormatGroup.bgra8888,
); );
try {
await cameraController?.initialize(); await cameraController?.initialize();
} catch (e) {
Log.error(e);
return;
}
await cameraController?.startImageStream(_processCameraImage); await cameraController?.startImageStream(_processCameraImage);
await cameraController?.setZoomLevel(selectedCameraDetails.scaleFactor); await cameraController?.setZoomLevel(selectedCameraDetails.scaleFactor);
if (userService.currentUser.videoStabilizationEnabled && !kDebugMode) { if (userService.currentUser.videoStabilizationEnabled && !kDebugMode) {

View file

@ -61,7 +61,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
Message? currentMessage; Message? currentMessage;
DateTime? canBeSeenUntil; DateTime? canBeSeenUntil;
double progress = 0; final ValueNotifier<double> progress = ValueNotifier(0);
bool showSendTextMessageInput = false; bool showSendTextMessageInput = false;
final GlobalKey mediaWidgetKey = GlobalKey(); final GlobalKey mediaWidgetKey = GlobalKey();
@ -100,6 +100,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
progressTimer?.cancel(); progressTimer?.cancel();
_subscription?.cancel(); _subscription?.cancel();
downloadStateListener?.cancel(); downloadStateListener?.cancel();
progress.dispose();
ScreenProtector.preventScreenshotOff(); ScreenProtector.preventScreenshotOff();
@ -226,7 +227,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
canBeSeenUntil = null; canBeSeenUntil = null;
imageSaving = false; imageSaving = false;
imageSaved = false; imageSaved = false;
progress = 0; progress.value = 0;
showSendTextMessageInput = false; showSendTextMessageInput = false;
}); });
@ -388,9 +389,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
final duration = ctrl.value.duration.inSeconds; final duration = ctrl.value.duration.inSeconds;
if (duration > 0) { if (duration > 0) {
setState(() { progress.value = 1 - ctrl.value.position.inSeconds / duration;
progress = 1 - ctrl.value.position.inSeconds / duration;
});
} }
if (currentMediaLocal.mediaFile.displayLimitInMilliseconds != if (currentMediaLocal.mediaFile.displayLimitInMilliseconds !=
@ -450,9 +449,8 @@ class _MediaViewerViewState extends State<MediaViewerView> {
} }
final difference = canBeSeenUntil!.difference(clock.now()); final difference = canBeSeenUntil!.difference(clock.now());
// Calculate the progress as a value between 0.0 and 1.0 // Calculate the progress as a value between 0.0 and 1.0
progress = progress.value =
difference.inMilliseconds / (mediaFile.displayLimitInMilliseconds!); difference.inMilliseconds / (mediaFile.displayLimitInMilliseconds!);
setState(() {});
}); });
} }
} }
@ -647,7 +645,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
children: [ children: [
if (_showDownloadingLoader) _loader(), if (_showDownloadingLoader) _loader(),
if ((currentMedia != null || videoController != null) && if ((currentMedia != null || videoController != null) &&
(canBeSeenUntil == null || progress >= 0)) (canBeSeenUntil == null || progress.value >= 0))
GestureDetector( GestureDetector(
onTap: onTap, onTap: onTap,
onDoubleTap: (videoController == null) ? null : onTap, onDoubleTap: (videoController == null) ? null : onTap,
@ -717,7 +715,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
if (currentMedia != null && if (currentMedia != null &&
currentMedia?.mediaFile.downloadState != DownloadState.ready) currentMedia?.mediaFile.downloadState != DownloadState.ready)
Positioned.fill(child: _loader()), Positioned.fill(child: _loader()),
if (canBeSeenUntil != null || progress >= 0) if (canBeSeenUntil != null || progress.value >= 0)
Positioned( Positioned(
right: 20, right: 20,
top: 27, top: 27,
@ -726,9 +724,14 @@ class _MediaViewerViewState extends State<MediaViewerView> {
SizedBox( SizedBox(
width: 20, width: 20,
height: 20, height: 20,
child: CircularProgressIndicator( child: ValueListenableBuilder<double>(
value: progress, valueListenable: progress,
builder: (context, value, child) {
return CircularProgressIndicator(
value: value,
strokeWidth: 2, strokeWidth: 2,
);
},
), ),
), ),
], ],

View file

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:app_links/app_links.dart'; import 'package:app_links/app_links.dart';
import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_sharing_intent/model/sharing_file.dart'; import 'package:flutter_sharing_intent/model/sharing_file.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:twonly/locator.dart'; import 'package:twonly/locator.dart';
@ -40,9 +41,11 @@ class HomeViewState extends State<HomeView> {
final MainCameraController _mainCameraController = MainCameraController(); final MainCameraController _mainCameraController = MainCameraController();
final PageController _homeViewPageController = PageController(initialPage: 1); final PageController _homeViewPageController = PageController(initialPage: 1);
late StreamSubscription<List<SharedFile>> _intentStreamSub; StreamSubscription<List<SharedFile>>? _intentStreamSub;
late StreamSubscription<Uri> _deepLinkSub; StreamSubscription<Uri>? _deepLinkSub;
StreamSubscription<RemoteMessage>? _onMessageOpenedAppSub; StreamSubscription<RemoteMessage>? _onMessageOpenedAppSub;
StreamSubscription<int>? _homeViewPageIndexSub;
StreamSubscription<NotificationResponse>? _selectNotificationSub;
static final streamHomeViewPageIndex = StreamController<int>.broadcast(); static final streamHomeViewPageIndex = StreamController<int>.broadcast();
@ -53,14 +56,16 @@ class HomeViewState extends State<HomeView> {
if (mounted) setState(() {}); if (mounted) setState(() {});
}; };
streamHomeViewPageIndex.stream.listen((index) { _homeViewPageIndexSub = streamHomeViewPageIndex.stream.listen((index) {
_homeViewPageController.jumpToPage(index); _homeViewPageController.jumpToPage(index);
setState(() { setState(() {
_activePageIdx = index; _activePageIdx = index;
}); });
}); });
selectNotificationStream.stream.listen((response) async { _selectNotificationSub = selectNotificationStream.stream.listen((
response,
) async {
if (response.payload != null && if (response.payload != null &&
response.payload!.startsWith(Routes.chats) && response.payload!.startsWith(Routes.chats) &&
response.payload! != Routes.chats) { response.payload! != Routes.chats) {
@ -110,8 +115,8 @@ class HomeViewState extends State<HomeView> {
RemoteMessage? initialRemoteMessage; RemoteMessage? initialRemoteMessage;
try { try {
initialRemoteMessage = initialRemoteMessage = await FirebaseMessaging.instance
await FirebaseMessaging.instance.getInitialMessage(); .getInitialMessage();
} catch (e) { } catch (e) {
Log.error('Could not get initial Firebase message: $e'); Log.error('Could not get initial Firebase message: $e');
} }
@ -157,12 +162,12 @@ class HomeViewState extends State<HomeView> {
@override @override
void dispose() { void dispose() {
_onMessageOpenedAppSub?.cancel(); _onMessageOpenedAppSub?.cancel();
selectNotificationStream.close(); _homeViewPageIndexSub?.cancel();
streamHomeViewPageIndex.close(); _selectNotificationSub?.cancel();
_disableCameraTimer?.cancel(); _disableCameraTimer?.cancel();
_mainCameraController.closeCamera(); _mainCameraController.closeCamera();
_intentStreamSub.cancel(); _intentStreamSub?.cancel();
_deepLinkSub.cancel(); _deepLinkSub?.cancel();
super.dispose(); super.dispose();
} }