Skip to content
6 changes: 5 additions & 1 deletion assets/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3119,5 +3119,9 @@
"youAlreadySentAnInvitationToThisContact": "You already sent an invitation to this contact",
"selectedEmailWillReceiveAnInvitationLinkAndInstructions": "Selected email will receive an invitation link and instructions.",
"selectedNumberWillGetAnSMSWithAnInvitationLinkAndInstructions": "Selected number will get an SMS with an invitation link and instructions.",
"reaction": "Reaction"
"reaction": "Reaction",
"switchAccountConfirmation": "Switch Account Confirmation",
"youAreCurrentlyLoggedInWith": "You are currently logged in with",
"doYouWantToLogOutAndSwitchTo": "Do you want to log out and switch to",
"doYouWantToSwitchTo": "Do you want to switch to"
}
48 changes: 29 additions & 19 deletions lib/pages/chat_list/receive_sharing_intent_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:app_links/app_links.dart';
import 'package:collection/collection.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/event/twake_event_types.dart';
import 'package:fluffychat/pages/share/share.dart';
Expand Down Expand Up @@ -31,26 +32,35 @@ mixin ReceiveSharingIntentMixin<T extends StatefulWidget> on State<T> {
Future<void> _processIncomingSharedFiles(List<SharedMediaFile> files) async {
Logs().d('ReceiveSharingIntentMixin::_processIncomingSharedFiles: $files');
if (files.isEmpty) return;
if (files.length == 1 && files.first.type == SharedMediaType.text) {
Logs().d('Received text: ${files.first.path}');
_processIncomingSharedText(files.first.path);
return;
if (files.length == 1) {
final file = files.first;
Logs().d('Received text:path = ${file.path} | type = ${file.type}');
if (file.type == SharedMediaType.text ||
file.type == SharedMediaType.url ||
file.type == SharedMediaType.mailto) {
_processIncomingSharedText(files.first.path);
return;
}
}
matrixState.shareContentList = files.map(
(sharedMediaFile) {
final file = sharedMediaFile.toMatrixFile();
Logs().d(
'ReceiveSharingIntentMixin::_processIncomingSharedFiles: Path ${file.filePath}',
);
Logs().d(
'ReceiveSharingIntentMixin::_processIncomingSharedFiles: Size ${file.size}',
);
return {
'msgtype': TwakeEventTypes.shareFileEventType,
'file': file,
};
},
).toList();
matrixState.shareContentList = files
.map(
(sharedMediaFile) {
final file = sharedMediaFile.toMatrixFile();
if (file == null) return null;
Logs().d(
'ReceiveSharingIntentMixin::_processIncomingSharedFiles: Path ${file.filePath}',
);
Logs().d(
'ReceiveSharingIntentMixin::_processIncomingSharedFiles: Size ${file.size}',
);
return {
'msgtype': TwakeEventTypes.shareFileEventType,
'file': file,
};
},
)
.whereNotNull()
.toList();
openSharePage();
}

Expand Down
108 changes: 3 additions & 105 deletions lib/pages/settings_dashboard/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'dart:async';

import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/repository/federation_configurations_repository.dart';
import 'package:fluffychat/domain/repository/tom_configurations_repository.dart';
import 'package:fluffychat/event/twake_inapp_event_types.dart';
import 'package:fluffychat/pages/bootstrap/bootstrap_dialog.dart';
import 'package:fluffychat/pages/settings_dashboard/settings/settings_view_style.dart';
Expand Down Expand Up @@ -44,9 +42,6 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
final ValueNotifier<Uri?> avatarUriNotifier = ValueNotifier(Uri());
final ValueNotifier<String?> displayNameNotifier = ValueNotifier('');

final tomConfigurationRepository = getIt.get<ToMConfigurationsRepository>();
final federationConfigurationsRepository =
getIt.get<FederationConfigurationsRepository>();
final _responsiveUtils = getIt.get<ResponsiveUtils>();

static const String generateEmailSubject =
Expand Down Expand Up @@ -80,7 +75,7 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
bool optionSelected(SettingEnum settingEnum) =>
settingEnum == optionsSelectNotifier.value;

void logoutAction() async {
void handleLogoutAction() async {
final twakeContext = TwakeApp.routerKey.currentContext;
if (twakeContext == null) {
Logs().e(
Expand All @@ -100,68 +95,7 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
return;
}

await _tryToUploadKeyBackup();

if (PlatformInfos.isMobile) {
await _logoutActionsOnMobile();
} else {
await _logoutActions();
}
}

Future<void> _tryToUploadKeyBackup() async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
await matrix.client.encryption?.keyManager.uploadInboundGroupSessions();
},
);

return;
}

Future<void> _logoutActionsOnMobile() async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
try {
if (matrix.backgroundPush != null) {
await matrix.backgroundPush!.removeCurrentPusher();
}
await Future.wait([
matrix.client.logout(),
_deleteTomConfigurations(matrix.client),
_deleteFederationConfigurations(matrix.client),
]);
} catch (e) {
Logs().e('SettingsController()::_logoutActionsOnMobile - error: $e');
}
},
);
}

Future<void> _logoutActions() async {
await TwakeDialog.showFutureLoadingDialogFullScreen(
future: () async {
try {
if (matrix.backgroundPush != null) {
await matrix.backgroundPush!.removeCurrentPusher();
}
await Future.wait([
matrix.client.logout(),
_deleteTomConfigurations(matrix.client),
_deleteFederationConfigurations(matrix.client),
]);
} catch (e) {
Logs().e('SettingsController()::_logoutActions - error: $e');
} finally {
try {
await tryLogoutSso(context);
} catch (e) {
Logs().e('SettingsController()::_logoutActions - error: $e');
return;
}
}
},
);
await logoutAction(matrix: Matrix.of(context));
}

Client get client => Matrix.of(context).client;
Expand Down Expand Up @@ -275,7 +209,7 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
case SettingEnum.about:
PlatformInfos.showAboutDialogFullScreen();
case SettingEnum.logout:
logoutAction();
handleLogoutAction();
break;
case SettingEnum.deleteAccount:
if (await showConfirmAlertDialog(
Expand Down Expand Up @@ -324,42 +258,6 @@ class SettingsController extends State<Settings> with ConnectPageMixin {
});
}

Future<void> _deleteTomConfigurations(Client currentClient) async {
try {
Logs().d(
'SettingsController::_deleteTomConfigurations - Client ID: ${currentClient.userID}',
);
if (matrix.twakeSupported) {
await tomConfigurationRepository
.deleteTomConfigurations(currentClient.userID!);
}
Logs().d(
'SettingsController::_deleteTomConfigurations - Success',
);
} catch (e) {
Logs().e(
'SettingsController::_deleteTomConfigurations - error: $e',
);
}
}

Future<void> _deleteFederationConfigurations(Client currentClient) async {
try {
Logs().d(
'SettingsController::_deleteFederationConfigurations - Client ID: ${currentClient.userID}',
);
await federationConfigurationsRepository
.deleteFederationConfigurations(currentClient.userID!);
Logs().d(
'SettingsController::_deleteFederationConfigurations - Success',
);
} catch (e) {
Logs().e(
'SettingsController::_deleteFederationConfigurations - error: $e',
);
}
}

@override
void initState() {
_getCurrentProfile(client);
Expand Down
59 changes: 32 additions & 27 deletions lib/presentation/extensions/shared_media_file_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,39 @@ import 'package:matrix/matrix.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';

extension SharedMediaFileExtension on SharedMediaFile {
MatrixFile toMatrixFile() {
if (type == SharedMediaType.image) {
return MatrixImageFile(
bytes: null,
name: path.split("/").last,
filePath: path,
mimeType: mimeType,
);
MatrixFile? toMatrixFile() {
switch (type) {
case SharedMediaType.text:
case SharedMediaType.url:
case SharedMediaType.mailto:
return null;
case SharedMediaType.file:
return MatrixFile(
bytes: File(path).readAsBytesSync(),
name: path.split("/").last,
filePath: path,
mimeType: mimeType,
);
case SharedMediaType.image:
return MatrixImageFile(
bytes: null,
name: path.split("/").last,
filePath: path,
mimeType: mimeType,
);
case SharedMediaType.video:
Uint8List? thumbnailBytes;
if (thumbnail != null) {
thumbnailBytes = File(thumbnail!).readAsBytesSync();
}
return MatrixVideoFile(
bytes: thumbnailBytes,
name: path.split("/").last,
filePath: path,
duration: duration,
mimeType: mimeType,
);
}
if (type == SharedMediaType.video) {
Uint8List? thumbnailBytes;
if (thumbnail != null) {
thumbnailBytes = File(thumbnail!).readAsBytesSync();
}
return MatrixVideoFile(
bytes: thumbnailBytes,
name: path.split("/").last,
filePath: path,
duration: duration,
mimeType: mimeType,
);
}
return MatrixFile(
bytes: File(path).readAsBytesSync(),
name: path.split("/").last,
filePath: path,
mimeType: mimeType,
);
}

File toFile() {
Expand Down
Loading