diff --git a/.gitignore b/.gitignore index ec7276f..a6c45d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv/ __pycache__/ client.db +.DS_Store diff --git a/database.py b/database.py index 4a9e053..d7f3d0c 100644 --- a/database.py +++ b/database.py @@ -53,7 +53,7 @@ def save_message_to_db(channel, user_id, message_text): # Construct the table name table_name = f"{str(get_nodeNum())}_{channel}_messages" - quoted_table_name = f'"{table_name}"' # Quote the table name becuase we might begin with numerics + quoted_table_name = f'"{table_name}"' # Quote the table name becuase we begin with numerics # Ensure the table exists create_table_query = f''' diff --git a/message_handlers/rx_handler.py b/message_handlers/rx_handler.py index 2ec02f4..c235baa 100644 --- a/message_handlers/rx_handler.py +++ b/message_handlers/rx_handler.py @@ -60,7 +60,7 @@ def on_receive(packet): draw_channel_list() update_messages_window() - save_message_to_db(globals.channel_list[channel_number], message_from_id, message_string) + save_message_to_db(node['num'], message_from_id, message_string) except KeyError as e: print(f"Error processing packet: {e}") diff --git a/utilities/utils.py b/utilities/utils.py index 8feb73a..7389a51 100644 --- a/utilities/utils.py +++ b/utilities/utils.py @@ -3,14 +3,17 @@ from meshtastic.protobuf import config_pb2 import re def get_channels(): + """Retrieve channels from the node and update globals.channel_list and globals.all_messages.""" node = globals.interface.getNode('^local') device_channels = node.channels - channel_output = [] + # Clear and rebuild channel list + globals.channel_list = [] + for device_channel in device_channels: if device_channel.role: + # Use the channel name if available, otherwise use the modem preset if device_channel.settings.name: - # Use the channel name channel_name = device_channel.settings.name else: # If channel name is blank, use the modem preset @@ -19,14 +22,16 @@ def get_channels(): modem_preset_string = config_pb2._CONFIG_LORACONFIG_MODEMPRESET.values_by_number[modem_preset_enum].name channel_name = convert_to_camel_case(modem_preset_string) - # Add channel to output - channel_output.append(channel_name) + # Add channel to globals.channel_list if not already present + if channel_name not in globals.channel_list: + globals.channel_list.append(channel_name) - # Only initialize globals.all_messages[channel_name] if it doesn't already exist + # Initialize globals.all_messages[channel_name] if it doesn't exist if channel_name not in globals.all_messages: globals.all_messages[channel_name] = [] - return list(globals.all_messages.keys()) + + return globals.channel_list def get_node_list(): node_list = []