forked from mudhorn/TC2-BBS-mesh
A number of fixes
- Added PyCharm .idea folder to gitignore - Made main menu banner alfa-numeric only to fix issue with iOS devices not being able to see the menu - Fixed delete-sync issue
This commit is contained in:
parent
a3e0b91995
commit
ab9449ad0b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ __pycache__/
|
||||||
bulletins.db
|
bulletins.db
|
||||||
venv/
|
venv/
|
||||||
.venv
|
.venv
|
||||||
|
.idea
|
||||||
|
|
|
@ -41,7 +41,7 @@ def handle_exit_command(sender_id, interface):
|
||||||
|
|
||||||
|
|
||||||
def handle_help_command(sender_id, interface, state=None):
|
def handle_help_command(sender_id, interface, state=None):
|
||||||
title = "█▓▒░ TC² BBS ░▒▓█\n"
|
title = "TC2 BBS\n"
|
||||||
commands = [
|
commands = [
|
||||||
"[M]ail Menu",
|
"[M]ail Menu",
|
||||||
"[B]ulletin Menu",
|
"[B]ulletin Menu",
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
[interface]
|
[interface]
|
||||||
type = serial
|
type = serial
|
||||||
# port = /dev/ttyUSB0
|
# port = /dev/ttyACM0
|
||||||
# hostname = 192.168.x.x
|
# hostname = 192.168.x.x
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -132,17 +132,16 @@ def get_mail_content(mail_id, recipient_id):
|
||||||
return c.fetchone()
|
return c.fetchone()
|
||||||
|
|
||||||
def delete_mail(unique_id, recipient_id, bbs_nodes, interface):
|
def delete_mail(unique_id, recipient_id, bbs_nodes, interface):
|
||||||
# TODO: ensure only recipient can delete mail
|
|
||||||
logging.info(f"Attempting to delete mail with unique_id: {unique_id} by {recipient_id}")
|
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
try:
|
try:
|
||||||
c.execute("SELECT unique_id FROM mail WHERE unique_id = ? and recipient = ?", (unique_id, recipient_id,))
|
c.execute("SELECT recipient FROM mail WHERE unique_id = ?", (unique_id,))
|
||||||
result = c.fetchone()
|
result = c.fetchone()
|
||||||
logging.debug(f"Fetch result for unique_id {unique_id}: {result}")
|
|
||||||
if result is None:
|
if result is None:
|
||||||
logging.error(f"No mail found with unique_id: {unique_id}")
|
logging.error(f"No mail found with unique_id: {unique_id}")
|
||||||
return # Early exit if no matching mail found
|
return # Early exit if no matching mail found
|
||||||
|
recipient_id = result[0]
|
||||||
|
logging.info(f"Attempting to delete mail with unique_id: {unique_id} by {recipient_id}")
|
||||||
c.execute("DELETE FROM mail WHERE unique_id = ? and recipient = ?", (unique_id, recipient_id,))
|
c.execute("DELETE FROM mail WHERE unique_id = ? and recipient = ?", (unique_id, recipient_id,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
send_delete_mail_to_bbs_nodes(unique_id, bbs_nodes, interface)
|
send_delete_mail_to_bbs_nodes(unique_id, bbs_nodes, interface)
|
||||||
|
@ -150,3 +149,5 @@ def delete_mail(unique_id, recipient_id, bbs_nodes, interface):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Error deleting mail with unique_id {unique_id}: {e}")
|
logging.error(f"Error deleting mail with unique_id {unique_id}: {e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ from command_handlers import (
|
||||||
handle_channel_directory_command, handle_channel_directory_steps
|
handle_channel_directory_command, handle_channel_directory_steps
|
||||||
)
|
)
|
||||||
|
|
||||||
from db_operations import add_bulletin, add_mail, delete_bulletin, delete_mail
|
from db_operations import add_bulletin, add_mail, delete_bulletin, delete_mail, get_db_connection
|
||||||
from utils import get_user_state, get_node_short_name, get_node_id_from_num, send_message
|
from utils import get_user_state, get_node_short_name, get_node_id_from_num, send_message
|
||||||
|
|
||||||
command_handlers = {
|
command_handlers = {
|
||||||
|
@ -47,7 +47,8 @@ def process_message(sender_id, message, interface, is_sync_message=False):
|
||||||
elif message.startswith("DELETE_MAIL|"):
|
elif message.startswith("DELETE_MAIL|"):
|
||||||
unique_id = message.split("|")[1]
|
unique_id = message.split("|")[1]
|
||||||
logging.info(f"Processing delete mail with unique_id: {unique_id}")
|
logging.info(f"Processing delete mail with unique_id: {unique_id}")
|
||||||
delete_mail(unique_id, [], interface)
|
recipient_id = get_recipient_id_by_mail(unique_id) # Fetch the recipient_id using this helper function
|
||||||
|
delete_mail(unique_id, recipient_id, [], interface)
|
||||||
else:
|
else:
|
||||||
if message_lower in command_handlers:
|
if message_lower in command_handlers:
|
||||||
command_handlers[message_lower](sender_id, interface)
|
command_handlers[message_lower](sender_id, interface)
|
||||||
|
@ -95,3 +96,13 @@ def on_receive(packet, interface):
|
||||||
logging.info("Ignoring message sent to group chat or from unknown node")
|
logging.info("Ignoring message sent to group chat or from unknown node")
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logging.error(f"Error processing packet: {e}")
|
logging.error(f"Error processing packet: {e}")
|
||||||
|
|
||||||
|
def get_recipient_id_by_mail(unique_id):
|
||||||
|
# Fix for Mail Delete sync issue
|
||||||
|
conn = get_db_connection()
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute("SELECT recipient FROM mail WHERE unique_id = ?", (unique_id,))
|
||||||
|
result = c.fetchone()
|
||||||
|
if result:
|
||||||
|
return result[0]
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in a new issue