mirror of
https://github.com/pdxlocations/contact.git
synced 2026-08-10 02:42:46 +02:00
Sort nodes list by last heard
This commit is contained in:
+2
-1
@@ -16,4 +16,5 @@ interface = None
|
||||
display_log = False
|
||||
message_prefix = ">>"
|
||||
sent_message_prefix = message_prefix + " Sent"
|
||||
notification_symbol = "*"
|
||||
notification_symbol = "*"
|
||||
node_list = []
|
||||
|
||||
@@ -14,7 +14,7 @@ from utilities.arg_parser import setup_parser
|
||||
from utilities.interfaces import initialize_interface
|
||||
from message_handlers.rx_handler import on_receive
|
||||
from ui.curses_ui import main_ui, draw_splash
|
||||
from utilities.utils import get_channels
|
||||
from utilities.utils import get_channels, get_node_list
|
||||
from db_handler import init_nodedb, load_messages_from_db
|
||||
import globals
|
||||
|
||||
@@ -30,10 +30,11 @@ def main(stdscr):
|
||||
globals.interface = initialize_interface(args)
|
||||
globals.channel_list = get_channels()
|
||||
pub.subscribe(on_receive, 'meshtastic.receive')
|
||||
globals.node_list = get_node_list()
|
||||
init_nodedb()
|
||||
load_messages_from_db()
|
||||
main_ui(stdscr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
curses.wrapper(main)
|
||||
curses.wrapper(main)
|
||||
|
||||
@@ -17,13 +17,19 @@ def on_receive(packet, interface):
|
||||
if globals.display_log:
|
||||
draw_packetlog_win()
|
||||
try:
|
||||
if 'decoded' in packet and packet['decoded']['portnum'] == 'NODEINFO_APP':
|
||||
if 'decoded' not in packet:
|
||||
return
|
||||
|
||||
# Assume any incoming packet could update the last seen time for a node, so we
|
||||
# may need to reorder the list. This could probably be limited to specific packets.
|
||||
globals.node_list = get_node_list()
|
||||
draw_node_list()
|
||||
|
||||
if packet['decoded']['portnum'] == 'NODEINFO_APP':
|
||||
if "user" in packet['decoded'] and "longName" in packet['decoded']["user"]:
|
||||
get_node_list()
|
||||
draw_node_list()
|
||||
maybe_store_nodeinfo_in_db(packet)
|
||||
|
||||
elif 'decoded' in packet and packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
|
||||
elif packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
|
||||
message_bytes = packet['decoded']['payload']
|
||||
message_string = message_bytes.decode('utf-8')
|
||||
if packet.get('channel'):
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
import curses
|
||||
import textwrap
|
||||
import globals
|
||||
from utilities.utils import get_node_list, get_name_from_number, get_channels
|
||||
from utilities.utils import get_name_from_number, get_channels
|
||||
from settings import settings
|
||||
from message_handlers.tx_handler import send_message
|
||||
|
||||
@@ -133,7 +133,7 @@ def draw_node_list():
|
||||
win_height = nodes_win.getmaxyx()[0]
|
||||
start_index = max(0, globals.selected_node - (win_height - 3)) # Calculate starting index based on selected node and window height
|
||||
|
||||
for i, node in enumerate(get_node_list()[start_index:], start=1):
|
||||
for i, node in enumerate(globals.node_list[start_index:], start=1):
|
||||
if i < win_height - 1 : # Check if there is enough space in the window
|
||||
if globals.selected_node + 1 == start_index + i and globals.current_window == 2:
|
||||
nodes_win.addstr(i, 1, get_name_from_number(node, "long"), curses.color_pair(3))
|
||||
@@ -169,7 +169,7 @@ def select_messages(direction):
|
||||
draw_messages_window()
|
||||
|
||||
def select_nodes(direction):
|
||||
node_list_length = len(get_node_list())
|
||||
node_list_length = len(globals.node_list)
|
||||
globals.selected_node += direction
|
||||
|
||||
if globals.selected_node < 0:
|
||||
@@ -327,7 +327,7 @@ def main_ui(stdscr):
|
||||
|
||||
elif char == curses.KEY_ENTER or char == 10 or char == 13:
|
||||
if globals.current_window == 2:
|
||||
node_list = get_node_list()
|
||||
node_list = globals.node_list
|
||||
if node_list[globals.selected_node] not in globals.channel_list:
|
||||
globals.channel_list.append(node_list[globals.selected_node])
|
||||
globals.all_messages[node_list[globals.selected_node]] = []
|
||||
|
||||
+6
-4
@@ -34,11 +34,13 @@ def get_channels():
|
||||
return globals.channel_list
|
||||
|
||||
def get_node_list():
|
||||
node_list = []
|
||||
if globals.interface.nodes:
|
||||
for node in globals.interface.nodes.values():
|
||||
node_list.append(node['num'])
|
||||
return node_list
|
||||
sorted_nodes = sorted(
|
||||
globals.interface.nodes.values(),
|
||||
key = lambda node: (node['lastHeard'] if 'lastHeard' in node else 0),
|
||||
reverse = True)
|
||||
return [node['num'] for node in sorted_nodes]
|
||||
return []
|
||||
|
||||
def get_nodeNum():
|
||||
myinfo = globals.interface.getMyNodeInfo()
|
||||
|
||||
Reference in New Issue
Block a user