refactor: share handler
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
<integer>10</integer>
|
<integer>10</integer>
|
||||||
<key>NSExtensionActivationSupportsText</key>
|
<key>NSExtensionActivationSupportsText</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
|
||||||
|
<integer>20</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>PHSupportedMediaTypes</key>
|
<key>PHSupportedMediaTypes</key>
|
||||||
<array>
|
<array>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import '../../features/auth/providers/unified_auth_providers.dart';
|
|||||||
import '../../features/chat/providers/chat_providers.dart';
|
import '../../features/chat/providers/chat_providers.dart';
|
||||||
import '../../features/chat/services/file_attachment_service.dart';
|
import '../../features/chat/services/file_attachment_service.dart';
|
||||||
import '../../core/providers/app_providers.dart';
|
import '../../core/providers/app_providers.dart';
|
||||||
|
// No server chat creation here; follow chat flow on first send
|
||||||
|
|
||||||
/// Lightweight payload for a share event
|
/// Lightweight payload for a share event
|
||||||
class SharedPayload {
|
class SharedPayload {
|
||||||
@@ -160,11 +161,16 @@ Future<void> _processPayload(Ref ref, SharedPayload payload) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefill text in the composer (do not auto-send)
|
// Prefill text in the composer (do not auto-send) and request focus
|
||||||
final text = payload.text?.trim();
|
final text = payload.text?.trim();
|
||||||
if (text != null && text.isNotEmpty) {
|
if (text != null && text.isNotEmpty) {
|
||||||
ref.read(prefilledInputTextProvider.notifier).state = text;
|
ref.read(prefilledInputTextProvider.notifier).state = text;
|
||||||
|
// Bump focus trigger to ensure input focuses after navigation/build
|
||||||
|
final current = ref.read(inputFocusTriggerProvider);
|
||||||
|
ref.read(inputFocusTriggerProvider.notifier).state = current + 1;
|
||||||
}
|
}
|
||||||
|
// Do NOT create a placeholder server chat here. The drawer will refresh
|
||||||
|
// when the user sends their first message, matching in-app behavior.
|
||||||
// This allows the user to add a caption before sending
|
// This allows the user to add a caption before sending
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('ShareReceiver: failed to process payload: $e');
|
debugPrint('ShareReceiver: failed to process payload: $e');
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ final isLoadingConversationProvider = StateProvider<bool>((ref) => false);
|
|||||||
// Prefilled input text (e.g., when sharing text from other apps)
|
// Prefilled input text (e.g., when sharing text from other apps)
|
||||||
final prefilledInputTextProvider = StateProvider<String?>((ref) => null);
|
final prefilledInputTextProvider = StateProvider<String?>((ref) => null);
|
||||||
|
|
||||||
|
// Trigger to request focus on the chat input (increment to signal)
|
||||||
|
final inputFocusTriggerProvider = StateProvider<int>((ref) => 0);
|
||||||
|
|
||||||
class ChatMessagesNotifier extends StateNotifier<List<ChatMessage>> {
|
class ChatMessagesNotifier extends StateNotifier<List<ChatMessage>> {
|
||||||
final Ref _ref;
|
final Ref _ref;
|
||||||
StreamSubscription? _messageStream;
|
StreamSubscription? _messageStream;
|
||||||
@@ -533,7 +536,14 @@ Future<void> _sendMessageInternal(
|
|||||||
// Invalidate conversations provider to refresh the list
|
// Invalidate conversations provider to refresh the list
|
||||||
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
||||||
Future.delayed(const Duration(milliseconds: 100), () {
|
Future.delayed(const Duration(milliseconds: 100), () {
|
||||||
ref.invalidate(conversationsProvider);
|
try {
|
||||||
|
// Guard against using ref after widget disposal
|
||||||
|
if (ref.mounted == true) {
|
||||||
|
ref.invalidate(conversationsProvider);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// If ref doesn't support mounted or is disposed, skip
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Still add the message locally
|
// Still add the message locally
|
||||||
@@ -1742,7 +1752,11 @@ Future<void> _saveConversationToServer(dynamic ref) async {
|
|||||||
// Refresh conversations list to show the updated conversation
|
// Refresh conversations list to show the updated conversation
|
||||||
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
// Adding a small delay to prevent rapid invalidations that could cause duplicates
|
||||||
Future.delayed(const Duration(milliseconds: 100), () {
|
Future.delayed(const Duration(milliseconds: 100), () {
|
||||||
ref.invalidate(conversationsProvider);
|
try {
|
||||||
|
if (ref.mounted == true) {
|
||||||
|
ref.invalidate(conversationsProvider);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fallback to local storage
|
// Fallback to local storage
|
||||||
|
|||||||
@@ -204,6 +204,18 @@ class _EnhancedAttachmentState extends ConsumerState<EnhancedAttachment> {
|
|||||||
.toString();
|
.toString();
|
||||||
final size = _fileInfo?['size'];
|
final size = _fileInfo?['size'];
|
||||||
final sizeLabel = size is num ? _formatSize(size.toInt()) : null;
|
final sizeLabel = size is num ? _formatSize(size.toInt()) : null;
|
||||||
|
final lowerName = filename.toLowerCase();
|
||||||
|
final fileExtension = lowerName.contains('.')
|
||||||
|
? lowerName.split('.').last
|
||||||
|
: '';
|
||||||
|
final List<String> metaParts = [];
|
||||||
|
if (fileExtension.isNotEmpty) {
|
||||||
|
metaParts.add('.${fileExtension.toUpperCase()}');
|
||||||
|
}
|
||||||
|
if (sizeLabel != null) {
|
||||||
|
metaParts.add(sizeLabel);
|
||||||
|
}
|
||||||
|
final metaLabel = metaParts.join(' • ');
|
||||||
|
|
||||||
final card = Container(
|
final card = Container(
|
||||||
constraints: widget.constraints,
|
constraints: widget.constraints,
|
||||||
@@ -217,15 +229,14 @@ class _EnhancedAttachmentState extends ConsumerState<EnhancedAttachment> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
_fileIconFor(filename),
|
_fileIconFor(filename),
|
||||||
style: const TextStyle(fontSize: AppTypography.headlineLarge),
|
style: const TextStyle(fontSize: AppTypography.headlineLarge),
|
||||||
),
|
),
|
||||||
const SizedBox(width: Spacing.sm),
|
const SizedBox(width: Spacing.sm),
|
||||||
ConstrainedBox(
|
Expanded(
|
||||||
constraints: const BoxConstraints(maxWidth: 220),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -240,9 +251,9 @@ class _EnhancedAttachmentState extends ConsumerState<EnhancedAttachment> {
|
|||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (sizeLabel != null)
|
if (metaLabel.isNotEmpty)
|
||||||
Text(
|
Text(
|
||||||
sizeLabel,
|
metaLabel,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: context.conduitTheme.textSecondary.withValues(
|
color: context.conduitTheme.textSecondary.withValues(
|
||||||
alpha: 0.7,
|
alpha: 0.7,
|
||||||
|
|||||||
@@ -342,6 +342,16 @@ class _ModernChatInputState extends ConsumerState<ModernChatInput>
|
|||||||
orElse: () => false,
|
orElse: () => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// React to external focus requests (e.g., from share prefill)
|
||||||
|
final focusTick = ref.watch(inputFocusTriggerProvider);
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (!mounted) return;
|
||||||
|
if (focusTick > 0) {
|
||||||
|
_ensureFocusedIfEnabled();
|
||||||
|
if (!_isExpanded) _setExpanded(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
// Transparent wrapper so rounded corners are visible against page background
|
// Transparent wrapper so rounded corners are visible against page background
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
|
|||||||
Reference in New Issue
Block a user