mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
Add drawing sharing functionality and localization updates
- Implemented sharing options for drawings, including sharing to a public channel and specific rooms. - Added confirmation dialogs for deleting drawings and sharing drawings. - Enhanced the drawing toolbar to display a list of user's drawings with options to share or delete. - Updated localization files for English, Spanish, French, Croatian, Italian, German, Slovenian, and other languages to include new strings related to drawing sharing and management. - Introduced syncing of drawing messages with the DrawingProvider to restore missing drawings. - Improved the drawing minimap preview to display a small preview of drawings in the toolbar.
This commit is contained in:
@@ -322,6 +322,11 @@ class AppProvider with ChangeNotifier {
|
||||
debugPrint('📍 [AppProvider] Starting location tracking after successful initialization');
|
||||
await _startLocationTracking();
|
||||
|
||||
// Sync drawing messages with DrawingProvider
|
||||
// This restores any drawings that may be missing from storage
|
||||
debugPrint('🎨 [AppProvider] Syncing drawing messages with DrawingProvider...');
|
||||
messagesProvider.syncDrawingsWithProvider(drawingProvider);
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('Initialization error: $e');
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
||||
import '../models/message.dart';
|
||||
import '../models/contact.dart';
|
||||
import '../models/sar_marker.dart';
|
||||
import '../models/map_drawing.dart';
|
||||
import '../services/message_storage_service.dart';
|
||||
import '../services/notification_service.dart';
|
||||
import '../utils/sar_message_parser.dart';
|
||||
@@ -109,7 +110,32 @@ class MessagesProvider with ChangeNotifier {
|
||||
for (final message in storedMessages) {
|
||||
// Re-enhance each message to ensure SAR markers are properly detected
|
||||
// This handles cases where messages were stored before enhancement logic
|
||||
final enhancedMessage = SarMessageParser.enhanceMessage(message);
|
||||
var enhancedMessage = SarMessageParser.enhanceMessage(message);
|
||||
|
||||
// Check if it's a drawing message (D:...) and not already marked
|
||||
// This handles cases where messages were stored before drawing detection
|
||||
if (DrawingMessageParser.isDrawingMessage(enhancedMessage.text) &&
|
||||
!enhancedMessage.isDrawing) {
|
||||
debugPrint(
|
||||
'🎨 [MessagesProvider] Detected drawing message during initialization: ${enhancedMessage.id}',
|
||||
);
|
||||
// Parse the drawing to get its ID
|
||||
final drawing = DrawingMessageParser.parseDrawingMessage(
|
||||
enhancedMessage.text,
|
||||
senderName: enhancedMessage.senderName,
|
||||
messageId: enhancedMessage.id,
|
||||
);
|
||||
|
||||
// Mark message as drawing and link to drawing ID
|
||||
enhancedMessage = enhancedMessage.copyWith(
|
||||
isDrawing: true,
|
||||
drawingId: drawing?.id,
|
||||
);
|
||||
debugPrint(
|
||||
' Drawing ID: ${enhancedMessage.drawingId}, isDrawing: ${enhancedMessage.isDrawing}',
|
||||
);
|
||||
}
|
||||
|
||||
_messages.add(enhancedMessage);
|
||||
|
||||
// Extract SAR markers
|
||||
@@ -132,6 +158,78 @@ class MessagesProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sync drawing messages with DrawingProvider
|
||||
/// This restores drawings that may be missing from DrawingProvider storage
|
||||
/// Should be called after both providers are initialized
|
||||
void syncDrawingsWithProvider(dynamic drawingProvider) {
|
||||
debugPrint('🔄 [MessagesProvider] Syncing drawings with DrawingProvider...');
|
||||
int restoredCount = 0;
|
||||
|
||||
for (final message in _messages) {
|
||||
if (!message.isDrawing || message.drawingId == null) continue;
|
||||
|
||||
// Check if drawing exists in DrawingProvider
|
||||
final existingDrawing = drawingProvider.getDrawingById(message.drawingId!);
|
||||
if (existingDrawing != null) {
|
||||
continue; // Drawing already exists
|
||||
}
|
||||
|
||||
// Drawing is missing, reconstruct from message text
|
||||
debugPrint('🔧 [MessagesProvider] Restoring missing drawing: ${message.drawingId}');
|
||||
final drawing = DrawingMessageParser.parseDrawingMessage(
|
||||
message.text,
|
||||
senderName: message.senderName,
|
||||
messageId: message.id,
|
||||
);
|
||||
|
||||
if (drawing == null) {
|
||||
debugPrint('⚠️ [MessagesProvider] Failed to parse drawing from message ${message.id}');
|
||||
continue;
|
||||
}
|
||||
|
||||
// The parsed drawing has a new generated ID, but we need to use the original ID
|
||||
// Create a copy with the correct ID from the message
|
||||
final restoredDrawing = _createDrawingWithId(drawing, message.drawingId!);
|
||||
|
||||
if (restoredDrawing != null) {
|
||||
drawingProvider.addReceivedDrawing(restoredDrawing);
|
||||
restoredCount++;
|
||||
debugPrint('✅ [MessagesProvider] Restored drawing ${message.drawingId}');
|
||||
}
|
||||
}
|
||||
|
||||
debugPrint('✅ [MessagesProvider] Sync complete: restored $restoredCount drawings');
|
||||
}
|
||||
|
||||
/// Create a copy of a drawing with a specific ID
|
||||
dynamic _createDrawingWithId(dynamic drawing, String targetId) {
|
||||
if (drawing is LineDrawing) {
|
||||
return LineDrawing(
|
||||
id: targetId,
|
||||
color: drawing.color,
|
||||
createdAt: drawing.createdAt,
|
||||
points: drawing.points,
|
||||
senderName: drawing.senderName,
|
||||
isReceived: drawing.isReceived,
|
||||
messageId: drawing.messageId,
|
||||
isShared: drawing.isShared,
|
||||
);
|
||||
} else if (drawing is RectangleDrawing) {
|
||||
return RectangleDrawing(
|
||||
id: targetId,
|
||||
color: drawing.color,
|
||||
createdAt: drawing.createdAt,
|
||||
topLeft: drawing.topLeft,
|
||||
bottomRight: drawing.bottomRight,
|
||||
senderName: drawing.senderName,
|
||||
isReceived: drawing.isReceived,
|
||||
messageId: drawing.messageId,
|
||||
isShared: drawing.isShared,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Add a message
|
||||
/// If [contactLookup] function is provided, it will be used to match channel
|
||||
/// message senders with known contacts by name
|
||||
|
||||
Reference in New Issue
Block a user