Add duplicate profile merge and share deep-link routing
This commit is contained in:
@@ -48,26 +48,33 @@ class _WhatsAppShareListenerState extends ConsumerState<WhatsAppShareListener> {
|
||||
try {
|
||||
_mediaSubscription = ReceiveSharingIntent.instance
|
||||
.getMediaStream()
|
||||
.listen(_handleMediaList, onError: (_) {});
|
||||
.listen(
|
||||
(List<SharedMediaFile> files) =>
|
||||
_handleMediaList(files, autoOpenDestination: false),
|
||||
onError: (_) {},
|
||||
);
|
||||
|
||||
final List<SharedMediaFile> initialMedia = await ReceiveSharingIntent
|
||||
.instance
|
||||
.getInitialMedia();
|
||||
if (initialMedia.isNotEmpty) {
|
||||
await _handleMediaList(initialMedia);
|
||||
await _handleMediaList(initialMedia, autoOpenDestination: true);
|
||||
}
|
||||
} catch (_) {
|
||||
// Unsupported platform/plugin state should not break app usage.
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleMediaList(List<SharedMediaFile> files) async {
|
||||
Future<void> _handleMediaList(
|
||||
List<SharedMediaFile> files, {
|
||||
required bool autoOpenDestination,
|
||||
}) async {
|
||||
for (final SharedMediaFile file in files) {
|
||||
final String? rawText = _extractText(file);
|
||||
if (rawText == null) {
|
||||
continue;
|
||||
}
|
||||
await _handleRawText(rawText);
|
||||
await _handleRawText(rawText, autoOpenDestination: autoOpenDestination);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +102,10 @@ class _WhatsAppShareListenerState extends ConsumerState<WhatsAppShareListener> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _handleRawText(String rawText) async {
|
||||
Future<void> _handleRawText(
|
||||
String rawText, {
|
||||
required bool autoOpenDestination,
|
||||
}) async {
|
||||
final String trimmed = rawText.trim();
|
||||
if (trimmed.isEmpty) {
|
||||
return;
|
||||
@@ -130,6 +140,10 @@ class _WhatsAppShareListenerState extends ConsumerState<WhatsAppShareListener> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (autoOpenDestination) {
|
||||
_openShareDestination(result);
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -140,16 +154,8 @@ class _WhatsAppShareListenerState extends ConsumerState<WhatsAppShareListener> {
|
||||
: 'Imported from WhatsApp to ${result.profileName}.',
|
||||
),
|
||||
action: SnackBarAction(
|
||||
label: result.isQueuedForResolution ? 'Open Inbox' : 'Open People',
|
||||
onPressed: () {
|
||||
Navigator.of(context).push<void>(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => result.isQueuedForResolution
|
||||
? const ShareInboxView()
|
||||
: const PeopleView(),
|
||||
),
|
||||
);
|
||||
},
|
||||
label: result.isQueuedForResolution ? 'Open Inbox' : 'Open Profile',
|
||||
onPressed: () => _openShareDestination(result),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -160,4 +166,27 @@ class _WhatsAppShareListenerState extends ConsumerState<WhatsAppShareListener> {
|
||||
// Best effort.
|
||||
}
|
||||
}
|
||||
|
||||
void _openShareDestination(SharedMessageIngestResult result) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
if (result.isQueuedForResolution) {
|
||||
Navigator.of(context).push<void>(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => const ShareInboxView(),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.profileId != null) {
|
||||
ref.read(selectedPersonIdProvider.notifier).select(result.profileId!);
|
||||
}
|
||||
Navigator.of(context).push<void>(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) => const PeopleView(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user