Skip to content

An open-source cross-platform alternative to AirDrop

feat: save text messages to history (#1477)

Tien Do Nam357e9de1944b
diff --git a/app/assets/CHANGELOG.md b/app/assets/CHANGELOG.md
index 71dccdcd..4b34bc6a 100644
--- a/app/assets/CHANGELOG.md
+++ b/app/assets/CHANGELOG.md
@@ -1,6 +1,7 @@
## 1.15.0 (unreleased)
- feat: add clear button in the send tab (@Caesarovich)
+- feat: save text messages to history (@Tienisto)
- feat: confirm before adding or removing favorites in the nearby devices list (@Tienisto)
- feat: add URL view when sharing via link that shows the URL in bigger font (@harriseldon)
- feat(windows): add context menu integration ("Send to") (@Tienisto)
diff --git a/app/lib/model/persistence/receive_history_entry.dart b/app/lib/model/persistence/receive_history_entry.dart
index 9b082fc0..978dc428 100644
--- a/app/lib/model/persistence/receive_history_entry.dart
+++ b/app/lib/model/persistence/receive_history_entry.dart
@@ -8,10 +8,18 @@ part 'receive_history_entry.mapper.dart';
@MappableClass()
class ReceiveHistoryEntry with ReceiveHistoryEntryMappable {
final String id;
+
+ /// The name of the file.
+ /// If [isMessage] is true, this is the message content.
final String fileName;
+
final FileType fileType;
final String? path;
final bool savedToGallery;
+
+ @MappableField(hook: IsMessageHook())
+ final bool isMessage;
+
final int fileSize;
final String senderAlias;
final DateTime timestamp;
@@ -22,6 +30,7 @@ class ReceiveHistoryEntry with ReceiveHistoryEntryMappable {
required this.fileType,
required this.path,
required this.savedToGallery,
+ required this.isMessage,
required this.fileSize,
required this.senderAlias,
required this.timestamp,
@@ -31,8 +40,18 @@ class ReceiveHistoryEntry with ReceiveHistoryEntryMappable {
/// Because the raw timestamp is saved in UTC, we need to transform it to local time zone first.
String get timestampString {
final localTimestamp = timestamp.toLocal();
- return '${DateFormat.yMd(LocaleSettings.currentLocale.languageTag).format(localTimestamp)} ${DateFormat.jm(LocaleSettings.currentLocale.languageTag).format(localTimestamp)}';
+ final languageTag = LocaleSettings.currentLocale.languageTag;
+ return '${DateFormat.yMd(languageTag).format(localTimestamp)} ${DateFormat.jm(languageTag).format(localTimestamp)}';
}
static const fromJson = ReceiveHistoryEntryMapper.fromJson;
}
+
+class IsMessageHook extends MappingHook {
+ const IsMessageHook();
+
+ @override
+ Object? beforeDecode(Object? value) {
+ return value == true;
+ }
+}
diff --git a/app/lib/model/persistence/receive_history_entry.mapper.dart b/app/lib/model/persistence/receive_history_entry.mapper.dart
index ce6841af..00c47528 100644
--- a/app/lib/model/persistence/receive_history_entry.mapper.dart
+++ b/app/lib/model/persistence/receive_history_entry.mapper.dart
@@ -31,6 +31,8 @@ class ReceiveHistoryEntryMapper extends ClassMapperBase<ReceiveHistoryEntry> {
static const Field<ReceiveHistoryEntry, String> _f$path = Field('path', _$path);
static bool _$savedToGallery(ReceiveHistoryEntry v) => v.savedToGallery;
static const Field<ReceiveHistoryEntry, bool> _f$savedToGallery = Field('savedToGallery', _$savedToGallery);
+ static bool _$isMessage(ReceiveHistoryEntry v) => v.isMessage;
+ static const Field<ReceiveHistoryEntry, bool> _f$isMessage = Field('isMessage', _$isMessage, hook: IsMessageHook());
static int _$fileSize(ReceiveHistoryEntry v) => v.fileSize;
static const Field<ReceiveHistoryEntry, int> _f$fileSize = Field('fileSize', _$fileSize);
static String _$senderAlias(ReceiveHistoryEntry v) => v.senderAlias;
@@ -45,6 +47,7 @@ class ReceiveHistoryEntryMapper extends ClassMapperBase<ReceiveHistoryEntry> {
#fileType: _f$fileType,
#path: _f$path,
#savedToGallery: _f$savedToGallery,
+ #isMessage: _f$isMessage,
#fileSize: _f$fileSize,
#senderAlias: _f$senderAlias,
#timestamp: _f$timestamp,
@@ -57,6 +60,7 @@ class ReceiveHistoryEntryMapper extends ClassMapperBase<ReceiveHistoryEntry> {
fileType: data.dec(_f$fileType),
path: data.dec(_f$path),
savedToGallery: data.dec(_f$savedToGallery),
+ isMessage: data.dec(_f$isMessage),
fileSize: data.dec(_f$fileSize),
senderAlias: data.dec(_f$senderAlias),
timestamp: data.dec(_f$timestamp));
@@ -113,6 +117,7 @@ abstract class ReceiveHistoryEntryCopyWith<$R, $In extends ReceiveHistoryEntry,
FileType? fileType,
String? path,
bool? savedToGallery,
+ bool? isMessage,
int? fileSize,
String? senderAlias,
DateTime? timestamp});
@@ -132,6 +137,7 @@ class _ReceiveHistoryEntryCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, R
FileType? fileType,
Object? path = $none,
bool? savedToGallery,
+ bool? isMessage,
int? fileSize,
String? senderAlias,
DateTime? timestamp}) =>
@@ -141,6 +147,7 @@ class _ReceiveHistoryEntryCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, R
if (fileType != null) #fileType: fileType,
if (path != $none) #path: path,
if (savedToGallery != null) #savedToGallery: savedToGallery,
+ if (isMessage != null) #isMessage: isMessage,
if (fileSize != null) #fileSize: fileSize,
if (senderAlias != null) #senderAlias: senderAlias,
if (timestamp != null) #timestamp: timestamp
@@ -152,6 +159,7 @@ class _ReceiveHistoryEntryCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, R
fileType: data.get(#fileType, or: $value.fileType),
path: data.get(#path, or: $value.path),
savedToGallery: data.get(#savedToGallery, or: $value.savedToGallery),
+ isMessage: data.get(#isMessage, or: $value.isMessage),
fileSize: data.get(#fileSize, or: $value.fileSize),
senderAlias: data.get(#senderAlias, or: $value.senderAlias),
timestamp: data.get(#timestamp, or: $value.timestamp));
diff --git a/app/lib/pages/receive_history_page.dart b/app/lib/pages/receive_history_page.dart
index 7c3ba7b0..cd506e0d 100644
--- a/app/lib/pages/receive_history_page.dart
+++ b/app/lib/pages/receive_history_page.dart
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/persistence/receive_history_entry.dart';
+import 'package:localsend_app/pages/receive_page.dart';
+import 'package:localsend_app/pages/receive_page_controller.dart';
import 'package:localsend_app/provider/receive_history_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/theme.dart';
@@ -14,6 +16,7 @@ import 'package:localsend_app/widget/dialogs/history_clear_dialog.dart';
import 'package:localsend_app/widget/file_thumbnail.dart';
import 'package:localsend_app/widget/responsive_list_view.dart';
import 'package:refena_flutter/refena_flutter.dart';
+import 'package:routerino/routerino.dart';
enum _EntryOption {
open,
@@ -123,7 +126,18 @@ class ReceiveHistoryPage extends StatelessWidget {
splashFactory: NoSplash.splashFactory,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
- onTap: entry.path != null ? () async => _openFile(context, entry, context.redux(receiveHistoryProvider)) : null,
+ onTap: entry.path != null || entry.isMessage
+ ? () async {
+ if (entry.isMessage) {
+ context.redux(receivePageControllerProvider).dispatch(InitReceivePageFromHistoryMessageAction(entry: entry));
+ // ignore: unawaited_futures
+ context.push(() => const ReceivePage());
+ return;
+ }
+
+ await _openFile(context, entry, context.redux(receiveHistoryProvider));
+ }
+ : null,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
diff --git a/app/lib/pages/receive_page.dart b/app/lib/pages/receive_page.dart
index 1425c1d3..c9303c2e 100644
--- a/app/lib/pages/receive_page.dart
+++ b/app/lib/pages/receive_page.dart
@@ -5,10 +5,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:localsend_app/gen/strings.g.dart';
import 'package:localsend_app/model/persistence/color_mode.dart';
-import 'package:localsend_app/pages/progress_page.dart';
import 'package:localsend_app/pages/receive_options_page.dart';
+import 'package:localsend_app/pages/receive_page_controller.dart';
import 'package:localsend_app/provider/favorites_provider.dart';
-import 'package:localsend_app/provider/network/server/server_provider.dart';
import 'package:localsend_app/provider/selection/selected_receiving_files_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/theme.dart';
@@ -33,64 +32,17 @@ class ReceivePage extends StatefulWidget {
}
class _ReceivePageState extends State<ReceivePage> with Refena {
- String? _message;
- bool _isLink = false;
- bool _showFullIp = false;
-
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance.addPostFrameCallback((_) async => _init());
- }
-
@override
void dispose() {
super.dispose();
unawaited(TaskbarHelper.clearProgressBar());
}
- Future<void> _init() async {
- final receiveSession = ref.read(serverProvider)?.session;
- if (receiveSession == null) {
- return;
- }
-
- ref.notifier(selectedReceivingFilesProvider).setFiles(receiveSession.files.values.map((f) => f.file).toList());
- setState(() {
- // show message if there is only one text file
- _message = receiveSession.message;
- _isLink = _message != null && (_message!.startsWith('http://') || _message!.startsWith('https'));
- });
- }
-
- void _acceptNothing() {
- ref.notifier(serverProvider).acceptFileRequest({});
- }
-
- void _accept() {
- final selectedFiles = ref.read(selectedReceivingFilesProvider);
- ref.notifier(serverProvider).acceptFileRequest(selectedFiles);
- }
-
- void _decline() {
- ref.notifier(serverProvider).declineFileRequest();
- }
-
@override
Widget build(BuildContext context) {
- final receiveSession = ref.watch(serverProvider)?.session;
- if (receiveSession == null) {
- // when declining/accepting the request, there is a short frame where tempRequest is null
- return Scaffold(
- body: Container(),
- );
- }
- final selectedFiles = ref.watch(selectedReceivingFilesProvider);
- final colorMode = ref.watch(settingsProvider.select((state) => state.colorMode));
-
- final senderFavoriteEntry = ref.watch(favoritesProvider.select((state) => state.findDevice(receiveSession.sender)));
-
- if (receiveSession.status == SessionStatus.canceledBySender) {
+ final vm = context.watch(receivePageControllerProvider);
+ final senderFavoriteEntry = ref.watch(favoritesProvider.select((state) => state.findDevice(vm.sender)));
+ if (vm.status == SessionStatus.canceledBySender) {
unawaited(TaskbarHelper.setProgressBarMode(TaskbarProgressMode.error));
} else {
unawaited(TaskbarHelper.setProgressBarMode(TaskbarProgressMode.indeterminate));
@@ -98,7 +50,7 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
return WillPopScope(
onWillPop: () async {
- _decline();
+ vm.onDecline();
return true;
},
child: Scaffold(
@@ -109,7 +61,7 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
child: Builder(
builder: (context) {
final height = MediaQuery.of(context).size.height;
- final smallUi = _message != null && height < 600;
+ final smallUi = vm.message != null && height < 600;
return Padding(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: smallUi ? 20 : 30),
child: Column(
@@ -118,51 +70,53 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
- if (!smallUi)
+ if (vm.showSenderInfo && !smallUi)
Padding(
padding: const EdgeInsets.only(bottom: 10),
- child: Icon(receiveSession.sender.deviceType.icon, size: 64),
+ child: Icon(vm.sender.deviceType.icon, size: 64),
),
FittedBox(
child: Text(
- senderFavoriteEntry?.alias ?? receiveSession.sender.alias,
+ senderFavoriteEntry?.alias ?? vm.sender.alias,
style: TextStyle(fontSize: smallUi ? 32 : 48),
textAlign: TextAlign.center,
),
),
- const SizedBox(height: 10),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- InkWell(
- onTap: () {
- setState(() => _showFullIp = !_showFullIp);
- },
- child: DeviceBadge(
- backgroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
- foregroundColor: Theme.of(context).colorScheme.onInverseSurface,
- label: _showFullIp ? receiveSession.sender.ip : '#${receiveSession.sender.ip.visualId}',
- ),
- ),
- if (receiveSession.sender.deviceModel != null) ...[
- const SizedBox(width: 10),
- DeviceBadge(
- backgroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
- foregroundColor: Theme.of(context).colorScheme.onInverseSurface,
- label: receiveSession.sender.deviceModel!,
+ if (vm.showSenderInfo) ...[
+ const SizedBox(height: 10),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ InkWell(
+ onTap: () {
+ context.redux(receivePageControllerProvider).dispatch(SetShowFullIpAction(!vm.showFullIp));
+ },
+ child: DeviceBadge(
+ backgroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
+ foregroundColor: Theme.of(context).colorScheme.onInverseSurface,
+ label: vm.showFullIp ? vm.sender.ip : '#${vm.sender.ip.visualId}',
+ ),
),
+ if (vm.sender.deviceModel != null) ...[
+ const SizedBox(width: 10),
+ DeviceBadge(
+ backgroundColor: Theme.of(context).colorScheme.onSecondaryContainer,
+ foregroundColor: Theme.of(context).colorScheme.onInverseSurface,
+ label: vm.sender.deviceModel!,
+ ),
+ ],
],
- ],
- ),
+ ),
+ ],
const SizedBox(height: 40),
Text(
- _message != null
- ? (_isLink ? t.receivePage.subTitleLink : t.receivePage.subTitleMessage)
- : t.receivePage.subTitle(n: receiveSession.files.length),
+ vm.message != null
+ ? (vm.isLink ? t.receivePage.subTitleLink : t.receivePage.subTitleMessage)
+ : t.receivePage.subTitle(n: vm.fileCount),
style: smallUi ? null : Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
- if (_message != null)
+ if (vm.message != null)
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -175,7 +129,7 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
child: Padding(
padding: const EdgeInsets.all(10),
child: SelectableText(
- _message!,
+ vm.message!,
),
),
),
@@ -189,17 +143,17 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
ElevatedButton(
onPressed: () {
unawaited(
- Clipboard.setData(ClipboardData(text: _message!)),
+ Clipboard.setData(ClipboardData(text: vm.message!)),
);
if (checkPlatformIsDesktop()) {
context.showSnackBar(t.general.copiedToClipboard);
}
- _acceptNothing();
+ vm.onAccept();
context.pop();
},
child: Text(t.general.copy),
),
- if (_isLink)
+ if (vm.isLink)
Padding(
padding: const EdgeInsets.only(left: 20),
child: ElevatedButton(
@@ -209,8 +163,8 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
),
onPressed: () {
// ignore: discarded_futures
- launchUrl(Uri.parse(_message!), mode: LaunchMode.externalApplication);
- _acceptNothing();
+ launchUrl(Uri.parse(vm.message!), mode: LaunchMode.externalApplication);
+ vm.onAccept();
context.pop();
},
child: Text(t.general.open),
@@ -223,101 +177,7 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
],
),
),
- if (receiveSession.status == SessionStatus.waiting && _message == null)
- Padding(
- padding: const EdgeInsets.only(bottom: 20),
- child: TextButton.icon(
- style: TextButton.styleFrom(
- foregroundColor: Theme.of(context).colorScheme.onSurface,
- ),
- onPressed: () async {
- await context.push(() => const ReceiveOptionsPage());
- },
- icon: const Icon(Icons.settings),
- label: Text(t.receiveOptionsPage.title),
- ),
- ),
- if (receiveSession.status == SessionStatus.canceledBySender) ...[
- Padding(
- padding: const EdgeInsets.only(bottom: 20),
- child: Text(
- t.receivePage.canceled,
- style: TextStyle(color: Theme.of(context).colorScheme.warning),
- textAlign: TextAlign.center,
- ),
- ),
- Center(
- child: ElevatedButton.icon(
- onPressed: () {
- ref.notifier(serverProvider).closeSession();
- context.pop();
- },
- icon: const Icon(Icons.check_circle),
- label: Text(t.general.close),
- ),
- ),
- ] else if (_message != null)
- Center(
- child: TextButton.icon(
- style: TextButton.styleFrom(
- foregroundColor: Theme.of(context).colorScheme.onSurface,
- ),
- onPressed: () {
- _acceptNothing();
- context.pop();
- },
- icon: const Icon(Icons.close),
- label: Text(t.general.close),
- ),
- )
- else
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- ElevatedButton.icon(
- style: ElevatedButton.styleFrom(
- elevation: colorMode == ColorMode.yaru ? 0 : null,
- backgroundColor:
- colorMode == ColorMode.yaru ? Theme.of(context).colorScheme.background : Theme.of(context).colorScheme.error,
- foregroundColor: colorMode == ColorMode.yaru
- ? Theme.of(context).colorScheme.onBackground
- : Theme.of(context).colorScheme.onError,
- ),
- onPressed: () {
- _decline();
- context.pop();
- },
- icon: const Icon(Icons.close),
- label: Text(t.general.decline),
- ),
- const SizedBox(width: 20),
- ElevatedButton.icon(
- style: ElevatedButton.styleFrom(
- backgroundColor: Theme.of(context).colorScheme.primary,
- foregroundColor: Theme.of(context).colorScheme.onPrimary,
- ),
- onPressed: selectedFiles.isEmpty
- ? null
- : () async {
- final sessionId = ref.read(serverProvider)?.session?.sessionId;
- if (sessionId == null) {
- return;
- }
- _accept();
- await context.pushAndRemoveUntilImmediately(
- removeUntil: ReceivePage,
- builder: () => ProgressPage(
- showAppBar: false,
- closeSessionOnClose: true,
- sessionId: sessionId,
- ),
- );
- },
- icon: const Icon(Icons.check_circle),
- label: Text(t.general.accept),
- ),
- ],
- ),
+ _Actions(vm),
],
),
);
@@ -330,3 +190,102 @@ class _ReceivePageState extends State<ReceivePage> with Refena {
);
}
}
+
+class _Actions extends StatelessWidget {
+ final ReceivePageVm vm;
+
+ const _Actions(this.vm);
+
+ @override
+ Widget build(BuildContext context) {
+ final selectedFiles = context.watch(selectedReceivingFilesProvider);
+ final colorMode = context.watch(settingsProvider.select((state) => state.colorMode));
+
+ if (vm.message != null) {
+ return Center(
+ child: TextButton.icon(
+ style: TextButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onSurface,
+ ),
+ onPressed: () {
+ vm.onAccept();
+ context.pop();
+ },
+ icon: const Icon(Icons.close),
+ label: Text(t.general.close),
+ ),
+ );
+ }
+
+ if (vm.status == SessionStatus.canceledBySender) {
+ return Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(bottom: 20),
+ child: Text(
+ t.receivePage.canceled,
+ style: TextStyle(color: Theme.of(context).colorScheme.warning),
+ textAlign: TextAlign.center,
+ ),
+ ),
+ Center(
+ child: ElevatedButton.icon(
+ onPressed: () {
+ vm.onClose();
+ context.pop();
+ },
+ icon: const Icon(Icons.check_circle),
+ label: Text(t.general.close),
+ ),
+ ),
+ ],
+ );
+ }
+
+ return Column(
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(bottom: 20),
+ child: TextButton.icon(
+ style: TextButton.styleFrom(
+ foregroundColor: Theme.of(context).colorScheme.onSurface,
+ ),
+ onPressed: () async {
+ await context.push(() => const ReceiveOptionsPage());
+ },
+ icon: const Icon(Icons.settings),
+ label: Text(t.receiveOptionsPage.title),
+ ),
+ ),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ ElevatedButton.icon(
+ style: ElevatedButton.styleFrom(
+ elevation: colorMode == ColorMode.yaru ? 0 : null,
+ backgroundColor: colorMode == ColorMode.yaru ? Theme.of(context).colorScheme.background : Theme.of(context).colorScheme.error,
+ foregroundColor: colorMode == ColorMode.yaru ? Theme.of(context).colorScheme.onBackground : Theme.of(context).colorScheme.onError,
+ ),
+ onPressed: () {
+ vm.onDecline();
+ context.pop();
+ },
+ icon: const Icon(Icons.close),
+ label: Text(t.general.decline),
+ ),
+ const SizedBox(width: 20),
+ ElevatedButton.icon(
+ style: ElevatedButton.styleFrom(
+ backgroundColor: Theme.of(context).colorScheme.primary,
+ foregroundColor: Theme.of(context).colorScheme.onPrimary,
+ ),
+ onPressed: selectedFiles.isEmpty ? null : () => vm.onAccept(),
+ icon: const Icon(Icons.check_circle),
+ label: Text(t.general.accept),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+}
diff --git a/app/lib/pages/receive_page_controller.dart b/app/lib/pages/receive_page_controller.dart
new file mode 100644
index 00000000..f28f10a0
--- /dev/null
+++ b/app/lib/pages/receive_page_controller.dart
@@ -0,0 +1,189 @@
+import 'package:common/common.dart';
+import 'package:dart_mappable/dart_mappable.dart';
+import 'package:localsend_app/model/persistence/receive_history_entry.dart';
+import 'package:localsend_app/pages/progress_page.dart';
+import 'package:localsend_app/pages/receive_page.dart';
+import 'package:localsend_app/provider/network/server/server_provider.dart';
+import 'package:localsend_app/provider/selection/selected_receiving_files_provider.dart';
+import 'package:refena_flutter/refena_flutter.dart';
+import 'package:routerino/routerino.dart';
+
+part 'receive_page_controller.mapper.dart';
+
+@MappableClass()
+class ReceivePageVm with ReceivePageVmMappable {
+ final SessionStatus status;
+ final Device sender;
+
+ /// Show hashtag and device model.
+ final bool showSenderInfo;
+ final int fileCount;
+ final String? message;
+ final bool isLink;
+ final bool showFullIp;
+ final void Function() onAccept;
+ final void Function() onDecline;
+ final void Function() onClose;
+
+ ReceivePageVm({
+ required this.status,
+ required this.sender,
+ required this.showSenderInfo,
+ required this.fileCount,
+ required this.message,
+ required this.isLink,
+ required this.showFullIp,
+ required this.onAccept,
+ required this.onDecline,
+ required this.onClose,
+ });
+}
+
+final receivePageControllerProvider = ReduxProvider<ReceivePageController, ReceivePageVm>((ref) {
+ return ReceivePageController(
+ server: ref.notifier(serverProvider),
+ selectedReceivingFiles: ref.notifier(selectedReceivingFilesProvider),
+ );
+});
+
+class ReceivePageController extends ReduxNotifier<ReceivePageVm> {
+ final ServerService _server;
+ final SelectedReceivingFilesNotifier _selectedReceivingFiles;
+
+ ReceivePageController({
+ required ServerService server,
+ required SelectedReceivingFilesNotifier selectedReceivingFiles,
+ }) : _server = server,
+ _selectedReceivingFiles = selectedReceivingFiles;
+
+ @override
+ ReceivePageVm init() {
+ return ReceivePageVm(
+ status: SessionStatus.waiting,
+ sender: const Device(
+ ip: '0.0.0.0',
+ version: '1.0.0',
+ port: 8080,
+ https: false,
+ fingerprint: 'fingerprint',
+ alias: 'alias',
+ deviceModel: 'deviceModel',
+ deviceType: DeviceType.desktop,
+ download: true,
+ ),
+ showSenderInfo: true,
+ fileCount: 1,
+ message: 'message',
+ isLink: false,
+ showFullIp: false,
+ onAccept: () {},
+ onDecline: () {},
+ onClose: () {},
+ );
+ }
+
+ @override
+ get initialAction => _WatchStatusAction();
+}
+
+class _WatchStatusAction extends WatchAction<ReceivePageController, ReceivePageVm> {
+ @override
+ ReceivePageVm reduce() {
+ return state.copyWith(
+ status: ref.watch(serverProvider.select((state) => state?.session?.status ?? SessionStatus.waiting)),
+ );
+ }
+}
+
+class InitReceivePageAction extends ReduxAction<ReceivePageController, ReceivePageVm> {
+ @override
+ ReceivePageVm reduce() {
+ final receiveSession = notifier._server.state?.session;
+ if (receiveSession == null) {
+ return state;
+ }
+
+ return state.copyWith(
+ sender: receiveSession.sender,
+ showSenderInfo: true,
+ fileCount: receiveSession.files.length,
+ message: receiveSession.message,
+ isLink: receiveSession.message != null && (receiveSession.message!.startsWith('http://') || receiveSession.message!.startsWith('https')),
+ showFullIp: false,
+ onAccept: () async {
+ if (state.message != null) {
+ // accept nothing
+ notifier._server.acceptFileRequest({});
+ return;
+ }
+
+ final sessionId = notifier._server.state?.session?.sessionId;
+ if (sessionId == null) {
+ return;
+ }
+
+ final selectedFiles = notifier._selectedReceivingFiles.state;
+ notifier._server.acceptFileRequest(selectedFiles);
+
+ await Routerino.context.pushAndRemoveUntilImmediately(
+ removeUntil: ReceivePage,
+ builder: () => ProgressPage(
+ showAppBar: false,
+ closeSessionOnClose: true,
+ sessionId: sessionId,
+ ),
+ );
+ },
+ onDecline: () {
+ notifier._server.declineFileRequest();
+ },
+ onClose: () {
+ notifier._server.closeSession();
+ },
+ );
+ }
+}
+
+class InitReceivePageFromHistoryMessageAction extends ReduxAction<ReceivePageController, ReceivePageVm> {
+ final ReceiveHistoryEntry entry;
+
+ InitReceivePageFromHistoryMessageAction({required this.entry});
+
+ @override
+ ReceivePageVm reduce() {
+ return state.copyWith(
+ sender: Device(
+ ip: '0.0.0.0',
+ version: '1.0.0',
+ port: 8080,
+ https: false,
+ fingerprint: 'fingerprint',
+ alias: entry.senderAlias,
+ deviceModel: 'deviceModel',
+ deviceType: DeviceType.web,
+ download: true,
+ ),
+ showSenderInfo: false,
+ fileCount: 1,
+ message: entry.fileName,
+ isLink: entry.fileName.startsWith('http://') || entry.fileName.startsWith('https'),
+ showFullIp: false,
+ onAccept: () {},
+ onDecline: () {},
+ onClose: () {},
+ );
+ }
+}
+
+class SetShowFullIpAction extends ReduxAction<ReceivePageController, ReceivePageVm> {
+ final bool showFullIp;
+
+ SetShowFullIpAction(this.showFullIp);
+
+ @override
+ ReceivePageVm reduce() {
+ return state.copyWith(
+ showFullIp: showFullIp,
+ );
+ }
+}
diff --git a/app/lib/pages/receive_page_controller.mapper.dart b/app/lib/pages/receive_page_controller.mapper.dart
new file mode 100644
index 00000000..a82a2f78
--- /dev/null
+++ b/app/lib/pages/receive_page_controller.mapper.dart
@@ -0,0 +1,179 @@
+// coverage:ignore-file
+// GENERATED CODE - DO NOT MODIFY BY HAND
+// ignore_for_file: type=lint
+// ignore_for_file: unused_element, unnecessary_cast, override_on_non_overriding_member
+// ignore_for_file: strict_raw_type, inference_failure_on_untyped_parameter
+
+part of 'receive_page_controller.dart';
+
+class ReceivePageVmMapper extends ClassMapperBase<ReceivePageVm> {
+ ReceivePageVmMapper._();
+
+ static ReceivePageVmMapper? _instance;
+ static ReceivePageVmMapper ensureInitialized() {
+ if (_instance == null) {
+ MapperContainer.globals.use(_instance = ReceivePageVmMapper._());
+ DeviceMapper.ensureInitialized();
+ }
+ return _instance!;
+ }
+
+ @override
+ final String id = 'ReceivePageVm';
+
+ static SessionStatus _$status(ReceivePageVm v) => v.status;
+ static const Field<ReceivePageVm, SessionStatus> _f$status = Field('status', _$status);
+ static Device _$sender(ReceivePageVm v) => v.sender;
+ static const Field<ReceivePageVm, Device> _f$sender = Field('sender', _$sender);
+ static bool _$showSenderInfo(ReceivePageVm v) => v.showSenderInfo;
+ static const Field<ReceivePageVm, bool> _f$showSenderInfo = Field('showSenderInfo', _$showSenderInfo);
+ static int _$fileCount(ReceivePageVm v) => v.fileCount;
+ static const Field<ReceivePageVm, int> _f$fileCount = Field('fileCount', _$fileCount);
+ static String? _$message(ReceivePageVm v) => v.message;
+ static const Field<ReceivePageVm, String> _f$message = Field('message', _$message);
+ static bool _$isLink(ReceivePageVm v) => v.isLink;
+ static const Field<ReceivePageVm, bool> _f$isLink = Field('isLink', _$isLink);
+ static bool _$showFullIp(ReceivePageVm v) => v.showFullIp;
+ static const Field<ReceivePageVm, bool> _f$showFullIp = Field('showFullIp', _$showFullIp);
+ static void Function() _$onAccept(ReceivePageVm v) => v.onAccept;
+ static const Field<ReceivePageVm, void Function()> _f$onAccept = Field('onAccept', _$onAccept);
+ static void Function() _$onDecline(ReceivePageVm v) => v.onDecline;
+ static const Field<ReceivePageVm, void Function()> _f$onDecline = Field('onDecline', _$onDecline);
+ static void Function() _$onClose(ReceivePageVm v) => v.onClose;
+ static const Field<ReceivePageVm, void Function()> _f$onClose = Field('onClose', _$onClose);
+
+ @override
+ final MappableFields<ReceivePageVm> fields = const {
+ #status: _f$status,
+ #sender: _f$sender,
+ #showSenderInfo: _f$showSenderInfo,
+ #fileCount: _f$fileCount,
+ #message: _f$message,
+ #isLink: _f$isLink,
+ #showFullIp: _f$showFullIp,
+ #onAccept: _f$onAccept,
+ #onDecline: _f$onDecline,
+ #onClose: _f$onClose,
+ };
+
+ static ReceivePageVm _instantiate(DecodingData data) {
+ return ReceivePageVm(
+ status: data.dec(_f$status),
+ sender: data.dec(_f$sender),
+ showSenderInfo: data.dec(_f$showSenderInfo),
+ fileCount: data.dec(_f$fileCount),
+ message: data.dec(_f$message),
+ isLink: data.dec(_f$isLink),
+ showFullIp: data.dec(_f$showFullIp),
+ onAccept: data.dec(_f$onAccept),
+ onDecline: data.dec(_f$onDecline),
+ onClose: data.dec(_f$onClose));
+ }
+
+ @override
+ final Function instantiate = _instantiate;
+
+ static ReceivePageVm fromJson(Map<String, dynamic> map) {
+ return ensureInitialized().decodeMap<ReceivePageVm>(map);
+ }
+
+ static ReceivePageVm deserialize(String json) {
+ return ensureInitialized().decodeJson<ReceivePageVm>(json);
+ }
+}
+
+mixin ReceivePageVmMappable {
+ String serialize() {
+ return ReceivePageVmMapper.ensureInitialized().encodeJson<ReceivePageVm>(this as ReceivePageVm);
+ }
+
+ Map<String, dynamic> toJson() {
+ return ReceivePageVmMapper.ensureInitialized().encodeMap<ReceivePageVm>(this as ReceivePageVm);
+ }
+
+ ReceivePageVmCopyWith<ReceivePageVm, ReceivePageVm, ReceivePageVm> get copyWith =>
+ _ReceivePageVmCopyWithImpl(this as ReceivePageVm, $identity, $identity);
+ @override
+ String toString() {
+ return ReceivePageVmMapper.ensureInitialized().stringifyValue(this as ReceivePageVm);
+ }
+
+ @override
+ bool operator ==(Object other) {
+ return ReceivePageVmMapper.ensureInitialized().equalsValue(this as ReceivePageVm, other);
+ }
+
+ @override
+ int get hashCode {
+ return ReceivePageVmMapper.ensureInitialized().hashValue(this as ReceivePageVm);
+ }
+}
+
+extension ReceivePageVmValueCopy<$R, $Out> on ObjectCopyWith<$R, ReceivePageVm, $Out> {
+ ReceivePageVmCopyWith<$R, ReceivePageVm, $Out> get $asReceivePageVm => $base.as((v, t, t2) => _ReceivePageVmCopyWithImpl(v, t, t2));
+}
+
+abstract class ReceivePageVmCopyWith<$R, $In extends ReceivePageVm, $Out> implements ClassCopyWith<$R, $In, $Out> {
+ DeviceCopyWith<$R, Device, Device> get sender;
+ $R call(
+ {SessionStatus? status,
+ Device? sender,
+ bool? showSenderInfo,
+ int? fileCount,
+ String? message,
+ bool? isLink,
+ bool? showFullIp,
+ void Function()? onAccept,
+ void Function()? onDecline,
+ void Function()? onClose});
+ ReceivePageVmCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
+}
+
+class _ReceivePageVmCopyWithImpl<$R, $Out> extends ClassCopyWithBase<$R, ReceivePageVm, $Out>
+ implements ReceivePageVmCopyWith<$R, ReceivePageVm, $Out> {
+ _ReceivePageVmCopyWithImpl(super.value, super.then, super.then2);
+
+ @override
+ late final ClassMapperBase<ReceivePageVm> $mapper = ReceivePageVmMapper.ensureInitialized();
+ @override
+ DeviceCopyWith<$R, Device, Device> get sender => $value.sender.copyWith.$chain((v) => call(sender: v));
+ @override
+ $R call(
+ {SessionStatus? status,
+ Device? sender,
+ bool? showSenderInfo,
+ int? fileCount,
+ Object? message = $none,
+ bool? isLink,
+ bool? showFullIp,
+ void Function()? onAccept,
+ void Function()? onDecline,
+ void Function()? onClose}) =>
+ $apply(FieldCopyWithData({
+ if (status != null) #status: status,
+ if (sender != null) #sender: sender,
+ if (showSenderInfo != null) #showSenderInfo: showSenderInfo,
+ if (fileCount != null) #fileCount: fileCount,
+ if (message != $none) #message: message,
+ if (isLink != null) #isLink: isLink,
+ if (showFullIp != null) #showFullIp: showFullIp,
+ if (onAccept != null) #onAccept: onAccept,
+ if (onDecline != null) #onDecline: onDecline,
+ if (onClose != null) #onClose: onClose
+ }));
+ @override
+ ReceivePageVm $make(CopyWithData data) => ReceivePageVm(
+ status: data.get(#status, or: $value.status),
+ sender: data.get(#sender, or: $value.sender),
+ showSenderInfo: data.get(#showSenderInfo, or: $value.showSenderInfo),
+ fileCount: data.get(#fileCount, or: $value.fileCount),
+ message: data.get(#message, or: $value.message),
+ isLink: data.get(#isLink, or: $value.isLink),
+ showFullIp: data.get(#showFullIp, or: $value.showFullIp),
+ onAccept: data.get(#onAccept, or: $value.onAccept),
+ onDecline: data.get(#onDecline, or: $value.onDecline),
+ onClose: data.get(#onClose, or: $value.onClose));
+
+ @override
+ ReceivePageVmCopyWith<$R2, ReceivePageVm, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t) => _ReceivePageVmCopyWithImpl($value, $cast, t);
+}
diff --git a/app/lib/provider/network/server/controller/receive_controller.dart b/app/lib/provider/network/server/controller/receive_controller.dart
index df233905..d61a6db0 100644
--- a/app/lib/provider/network/server/controller/receive_controller.dart
+++ b/app/lib/provider/network/server/controller/receive_controller.dart
@@ -11,6 +11,7 @@ import 'package:localsend_app/pages/home_page.dart';
import 'package:localsend_app/pages/home_page_controller.dart';
import 'package:localsend_app/pages/progress_page.dart';
import 'package:localsend_app/pages/receive_page.dart';
+import 'package:localsend_app/pages/receive_page_controller.dart';
import 'package:localsend_app/provider/device_info_provider.dart';
import 'package:localsend_app/provider/dio_provider.dart';
import 'package:localsend_app/provider/favorites_provider.dart';
@@ -20,6 +21,7 @@ import 'package:localsend_app/provider/network/send_provider.dart';
import 'package:localsend_app/provider/network/server/server_utils.dart';
import 'package:localsend_app/provider/progress_provider.dart';
import 'package:localsend_app/provider/receive_history_provider.dart';
+import 'package:localsend_app/provider/selection/selected_receiving_files_provider.dart';
import 'package:localsend_app/provider/selection/selected_sending_files_provider.dart';
import 'package:localsend_app/provider/settings_provider.dart';
import 'package:localsend_app/util/api_route_builder.dart';
@@ -242,6 +244,26 @@ class ReceiveController {
await showFromTray();
}
+ final message = server.getState().session?.message;
+ if (message != null) {
+ // Message already received
+ await server.ref.redux(receiveHistoryProvider).dispatchAsync(AddHistoryEntryAction(
+ entryId: const Uuid().v4(),
+ fileName: message,
+ fileType: FileType.text,
+ path: null,
+ savedToGallery: false,
+ isMessage: true,
+ fileSize: message.length,
+ senderAlias: server.getState().session!.senderAlias,
+ timestamp: DateTime.now().toUtc(),
+ ));
+ } else {
+ server.ref.notifier(selectedReceivingFilesProvider).setFiles(server.getState().session!.files.values.map((f) => f.file).toList());
+ }
+
+ server.ref.redux(receivePageControllerProvider).dispatch(InitReceivePageAction());
+
// ignore: use_build_context_synchronously, unawaited_futures
Routerino.context.push(() => const ReceivePage());
@@ -444,6 +466,7 @@ class ReceiveController {
fileType: receivingFile.file.fileType,
path: saveToGallery ? null : destinationPath,
savedToGallery: saveToGallery,
+ isMessage: false,
fileSize: receivingFile.file.size,
senderAlias: receiveState.senderAlias,
timestamp: DateTime.now().toUtc(),
diff --git a/app/lib/provider/receive_history_provider.dart b/app/lib/provider/receive_history_provider.dart
index 796b01c1..cd9459f9 100644
--- a/app/lib/provider/receive_history_provider.dart
+++ b/app/lib/provider/receive_history_provider.dart
@@ -25,6 +25,7 @@ class AddHistoryEntryAction extends AsyncReduxAction<ReceiveHistoryService, List
final FileType fileType;
final String? path;
final bool savedToGallery;
+ final bool isMessage;
final int fileSize;
final String senderAlias;
final DateTime timestamp;
@@ -35,6 +36,7 @@ class AddHistoryEntryAction extends AsyncReduxAction<ReceiveHistoryService, List
required this.fileType,
required this.path,
required this.savedToGallery,
+ required this.isMessage,
required this.fileSize,
required this.senderAlias,
required this.timestamp,
@@ -53,6 +55,7 @@ class AddHistoryEntryAction extends AsyncReduxAction<ReceiveHistoryService, List
fileType: fileType,
path: path,
savedToGallery: savedToGallery,
+ isMessage: isMessage,
fileSize: fileSize,
senderAlias: senderAlias,
timestamp: timestamp,
diff --git a/app/test/unit/provider/receive_history_provider_test.dart b/app/test/unit/provider/receive_history_provider_test.dart
index 9a784b8d..41b6bcae 100644
--- a/app/test/unit/provider/receive_history_provider_test.dart
+++ b/app/test/unit/provider/receive_history_provider_test.dart
@@ -28,6 +28,7 @@ void main() {
fileType: entry.fileType,
path: entry.path,
savedToGallery: entry.savedToGallery,
+ isMessage: entry.isMessage,
fileSize: entry.fileSize,
senderAlias: entry.senderAlias,
timestamp: entry.timestamp,
@@ -52,6 +53,7 @@ void main() {
fileType: entry.fileType,
path: entry.path,
savedToGallery: entry.savedToGallery,
+ isMessage: entry.isMessage,
fileSize: entry.fileSize,
senderAlias: entry.senderAlias,
timestamp: entry.timestamp,
@@ -79,6 +81,7 @@ void main() {
fileType: entry.fileType,
path: entry.path,
savedToGallery: entry.savedToGallery,
+ isMessage: entry.isMessage,
fileSize: entry.fileSize,
senderAlias: entry.senderAlias,
timestamp: entry.timestamp,
@@ -164,6 +167,7 @@ ReceiveHistoryEntry _createEntry(String id) {
fileType: FileType.image,
path: 'path',
savedToGallery: true,
+ isMessage: false,
fileSize: 123,
senderAlias: 'senderAlias',
timestamp: DateTime(2021, 1, 1),