clear app db of channel messages on delete

we were only deleting channels and messages on device and the in app db would persist
this caused weird messages to later show up in other channels as they were deleted and
added due to the fact we store messages by channel index(slot #)
This commit is contained in:
446564
2026-02-19 11:46:57 -08:00
parent 9437846127
commit 4bf2519559
2 changed files with 30 additions and 12 deletions
+20 -2
View File
@@ -3,6 +3,7 @@ import 'dart:math';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:meshcore_open/storage/channel_message_store.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
@@ -104,6 +105,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final connector = context.watch<MeshCoreConnector>(); final connector = context.watch<MeshCoreConnector>();
final channelMessageStore = ChannelMessageStore();
// Auto-navigate back to scanner if disconnected // Auto-navigate back to scanner if disconnected
if (!checkConnectionAndNavigate(connector)) { if (!checkConnectionAndNavigate(connector)) {
@@ -304,6 +306,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
return _buildChannelTile( return _buildChannelTile(
context, context,
connector, connector,
channelMessageStore,
channel, channel,
showDragHandle: true, showDragHandle: true,
dragIndex: index, dragIndex: index,
@@ -323,6 +326,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
return _buildChannelTile( return _buildChannelTile(
context, context,
connector, connector,
channelMessageStore,
channel, channel,
); );
}, },
@@ -352,6 +356,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
Widget _buildChannelTile( Widget _buildChannelTile(
BuildContext context, BuildContext context,
MeshCoreConnector connector, MeshCoreConnector connector,
ChannelMessageStore channelMessageStore,
Channel channel, { Channel channel, {
bool showDragHandle = false, bool showDragHandle = false,
int? dragIndex, int? dragIndex,
@@ -468,7 +473,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
); );
} }
}, },
onLongPress: () => _showChannelActions(context, connector, channel), onLongPress: () => _showChannelActions(
context,
connector,
channelMessageStore,
channel,
),
), ),
); );
} }
@@ -476,6 +486,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
void _showChannelActions( void _showChannelActions(
BuildContext context, BuildContext context,
MeshCoreConnector connector, MeshCoreConnector connector,
ChannelMessageStore channelMessageStore,
Channel channel, Channel channel,
) { ) {
showModalBottomSheet( showModalBottomSheet(
@@ -505,7 +516,12 @@ class _ChannelsScreenState extends State<ChannelsScreen>
Navigator.pop(context); Navigator.pop(context);
await Future.delayed(const Duration(milliseconds: 100)); await Future.delayed(const Duration(milliseconds: 100));
if (context.mounted) { if (context.mounted) {
_confirmDeleteChannel(context, connector, channel); _confirmDeleteChannel(
context,
connector,
channelMessageStore,
channel,
);
} }
}, },
), ),
@@ -1451,6 +1467,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
void _confirmDeleteChannel( void _confirmDeleteChannel(
BuildContext context, BuildContext context,
MeshCoreConnector connector, MeshCoreConnector connector,
ChannelMessageStore channelMessageStore,
Channel channel, Channel channel,
) { ) {
showDialog( showDialog(
@@ -1469,6 +1486,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
onPressed: () { onPressed: () {
Navigator.pop(dialogContext); Navigator.pop(dialogContext);
connector.deleteChannel(channel.index); connector.deleteChannel(channel.index);
channelMessageStore.clearChannelMessages(channel.index);
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(
+10 -10
View File
@@ -69,10 +69,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: characters name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.4.0" version: "1.4.1"
checked_yaml: checked_yaml:
dependency: transitive dependency: transitive
description: description:
@@ -497,26 +497,26 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: matcher name: matcher
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.12.17" version: "0.12.18"
material_color_utilities: material_color_utilities:
dependency: transitive dependency: transitive
description: description:
name: material_color_utilities name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.11.1" version: "0.13.0"
meta: meta:
dependency: transitive dependency: transitive
description: description:
name: meta name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.17.0" version: "1.18.0"
mgrs_dart: mgrs_dart:
dependency: transitive dependency: transitive
description: description:
@@ -910,10 +910,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: test_api name: test_api
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.7" version: "0.7.9"
timezone: timezone:
dependency: transitive dependency: transitive
description: description: