mostly working now?

This commit is contained in:
pdxlocations
2025-01-11 21:24:00 -08:00
parent 037877180e
commit 30eb1b3e2a
5 changed files with 25 additions and 32 deletions
+15 -24
View File
@@ -43,8 +43,6 @@ def init_nodedb():
print(f"Unexpected error in init_and_update_nodedb: {e}")
def save_message_to_db(channel, user_id, message_text):
"""Save messages to the database, ensuring the table exists."""
try:
@@ -91,9 +89,6 @@ def load_messages_from_db():
db_cursor.execute(query, (f"{str(get_nodeNum())}_%_messages",))
tables = [row[0] for row in db_cursor.fetchall()]
# Reset the channel list before populating
globals.channel_list = []
# Iterate through each table and fetch its messages
for table_name in tables:
query = f'SELECT user_id, message_text FROM "{table_name}"'
@@ -105,39 +100,35 @@ def load_messages_from_db():
# Extract the channel name from the table name
channel = table_name.split("_")[1]
# Determine the correct channel name
if channel.isdigit():
friendly_channel_name = get_name_from_number(int(channel))
else:
friendly_channel_name = channel
# Convert the channel to an integer if it's numeric, otherwise keep it as a string
channel = int(channel) if channel.isdigit() else channel
# Add the channel to globals.channel_list if not already present
if friendly_channel_name not in globals.channel_list:
globals.channel_list.append(friendly_channel_name)
if channel not in globals.channel_list:
globals.channel_list.append(channel)
# Ensure the channel exists in globals.all_messages
if friendly_channel_name not in globals.all_messages:
globals.all_messages[friendly_channel_name] = []
if channel not in globals.all_messages:
globals.all_messages[channel] = []
# Add messages to globals.all_messages in tuple format
for user_id, message in db_messages:
formatted_message = (f"{globals.message_prefix} {get_name_from_number(int(user_id), 'short')}: ", message)
if formatted_message not in globals.all_messages[friendly_channel_name]:
globals.all_messages[friendly_channel_name].append(formatted_message)
if user_id == str(get_nodeNum()):
formatted_message = (f"{globals.message_prefix} Sent: ", message)
else:
formatted_message = (f"{globals.message_prefix} {get_name_from_number(int(user_id), 'long')}: ", message)
if formatted_message not in globals.all_messages[channel]:
globals.all_messages[channel].append(formatted_message)
except sqlite3.Error as e:
print(f"SQLite error while loading messages from table '{table_name}': {e}")
except sqlite3.Error as e:
print(f"SQLite error in load_messages_from_db: {e}")
def maybe_store_nodeinfo_in_db(packet):
"""Save nodeinfo unless that record is already there."""
try:
+1 -1
View File
@@ -8,4 +8,4 @@ direct_message = False
interface = None
display_log = False
db_file_path = "client.db"
message_prefix = ">> "
message_prefix = ">>"
+5 -5
View File
@@ -2,11 +2,11 @@ from meshtastic import BROADCAST_NUM
from utilities.utils import get_node_list, decimal_to_hex, get_nodeNum
import globals
from ui.curses_ui import update_packetlog_win, draw_node_list, update_messages_window, draw_channel_list, add_notification
from database import init_nodedb, save_message_to_db, maybe_store_nodeinfo_in_db
from database import save_message_to_db, maybe_store_nodeinfo_in_db
def on_receive(packet):
global nodes_win
# update packet log
globals.packet_buffer.append(packet)
@@ -57,10 +57,10 @@ def on_receive(packet):
globals.all_messages[globals.channel_list[channel_number]].append((f"{globals.message_prefix} {message_from_string} ", message_string))
else:
globals.all_messages[globals.channel_list[channel_number]] = [(f"{globals.message_prefix} {message_from_string} ", message_string)]
draw_channel_list()
update_messages_window()
save_message_to_db(node['num'], message_from_id, message_string)
draw_channel_list()
update_messages_window()
save_message_to_db(globals.channel_list[channel_number], message_from_id, message_string)
except KeyError as e:
print(f"Error processing packet: {e}")
+3 -1
View File
@@ -139,6 +139,7 @@ def draw_splash(stdscr):
stdscr.box()
stdscr.refresh()
def draw_channel_list():
# Get the dimensions of the channel window
_, win_width = channel_win.getmaxyx()
@@ -159,7 +160,9 @@ def draw_channel_list():
channel_win.refresh()
def draw_node_list():
global nodes_win
nodes_win.clear()
height, width = nodes_win.getmaxyx()
start_index = max(0, globals.selected_node - (height - 3)) # Calculate starting index based on selected node and window height
@@ -355,4 +358,3 @@ def main_ui(stdscr):
else:
# Append typed character to input text
input_text += chr(char)
+1 -1
View File
@@ -8,7 +8,7 @@ def get_channels():
device_channels = node.channels
# Clear and rebuild channel list
globals.channel_list = []
# globals.channel_list = []
for device_channel in device_channels:
if device_channel.role: