mirror of
https://github.com/pdxlocations/contact.git
synced 2026-03-28 17:12:35 +01:00
Add display of message ack/nak
Note that this is not (yet) saved in the DB so won't persist
This commit is contained in:
@@ -76,7 +76,7 @@ def load_messages_from_db():
|
||||
# Add messages to globals.all_messages in tuple format
|
||||
for user_id, message in db_messages:
|
||||
if user_id == str(get_nodeNum()):
|
||||
formatted_message = (f"{globals.message_prefix} Sent: ", message)
|
||||
formatted_message = (f"{globals.sent_message_prefix}: ", message)
|
||||
else:
|
||||
formatted_message = (f"{globals.message_prefix} {get_name_from_number(int(user_id), 'short')}: ", message)
|
||||
|
||||
|
||||
@@ -11,5 +11,5 @@ interface = None
|
||||
display_log = False
|
||||
db_file_path = "client.db"
|
||||
message_prefix = ">>"
|
||||
sent_message_prefix =">> Sent:"
|
||||
notification_symbol = "*"
|
||||
sent_message_prefix = message_prefix + " Sent"
|
||||
notification_symbol = "*"
|
||||
|
||||
@@ -5,7 +5,7 @@ from ui.curses_ui import draw_packetlog_win, draw_node_list, draw_messages_windo
|
||||
from db_handler import save_message_to_db, maybe_store_nodeinfo_in_db
|
||||
|
||||
|
||||
def on_receive(packet):
|
||||
def on_receive(packet, interface):
|
||||
global nodes_win
|
||||
|
||||
# update packet log
|
||||
|
||||
@@ -3,30 +3,59 @@ from db_handler import save_message_to_db
|
||||
from utilities.utils import get_nodeNum
|
||||
import globals
|
||||
|
||||
ack_naks = {}
|
||||
|
||||
# Note "onAckNak" has special meaning to the API, thus the nonstandard naming convention
|
||||
# See https://github.com/meshtastic/python/blob/master/meshtastic/mesh_interface.py#L462
|
||||
def onAckNak(packet):
|
||||
from ui.curses_ui import draw_messages_window
|
||||
request = packet['decoded']['requestId']
|
||||
if(request not in ack_naks):
|
||||
return
|
||||
|
||||
acknak = ack_naks.pop(request)
|
||||
message = globals.all_messages[acknak['channel']][acknak['messageIndex']][1]
|
||||
|
||||
confirm_string = " "
|
||||
if(packet['decoded']['routing']['errorReason'] == "NONE"):
|
||||
if(packet['from'] == get_nodeNum()): # Ack "from" ourself means implicit ACK
|
||||
confirm_string = "[◌]"
|
||||
else:
|
||||
confirm_string = "[✓]"
|
||||
else:
|
||||
confirm_string = "[x]"
|
||||
|
||||
globals.all_messages[acknak['channel']][acknak['messageIndex']] = (globals.sent_message_prefix + confirm_string + ": ", message)
|
||||
|
||||
draw_messages_window()
|
||||
|
||||
def send_message(message, destination=BROADCAST_NUM, channel=0):
|
||||
|
||||
myid = get_nodeNum()
|
||||
send_on_channel = 0
|
||||
if isinstance(globals.channel_list[channel], int):
|
||||
channel_id = globals.channel_list[channel]
|
||||
if isinstance(channel_id, int):
|
||||
send_on_channel = 0
|
||||
destination = globals.channel_list[channel]
|
||||
elif isinstance(globals.channel_list[channel], str):
|
||||
destination = channel_id
|
||||
elif isinstance(channel_id, str):
|
||||
send_on_channel = channel
|
||||
|
||||
globals.interface.sendText(
|
||||
sent_message_data = globals.interface.sendText(
|
||||
text=message,
|
||||
destinationId=destination,
|
||||
wantAck=False,
|
||||
wantAck=True,
|
||||
wantResponse=False,
|
||||
onResponse=None,
|
||||
onResponse=onAckNak,
|
||||
channelIndex=send_on_channel,
|
||||
)
|
||||
|
||||
# Add sent message to the messages dictionary
|
||||
if globals.channel_list[channel] in globals.all_messages:
|
||||
globals.all_messages[globals.channel_list[channel]].append((globals.sent_message_prefix + " ", message))
|
||||
if channel_id in globals.all_messages:
|
||||
globals.all_messages[channel_id].append((globals.sent_message_prefix + "[…]: ", message))
|
||||
else:
|
||||
globals.all_messages[globals.channel_list[channel]] = [(globals.sent_message_prefix + " ", message)]
|
||||
globals.all_messages[channel_id] = [(globals.sent_message_prefix + "[…]: ", message)]
|
||||
|
||||
save_message_to_db(globals.channel_list[channel], myid, message)
|
||||
ack_naks[sent_message_data.id] = {'channel' : channel_id, 'messageIndex' : len(globals.all_messages[channel_id]) - 1 }
|
||||
|
||||
|
||||
save_message_to_db(channel_id, myid, message)
|
||||
|
||||
Reference in New Issue
Block a user