Merged RRC support from Zenith and neutral

This commit is contained in:
Mark Qvist 2026-05-17 02:04:37 +02:00
commit bffb9e47dc
12 changed files with 3628 additions and 58 deletions

View file

@ -59,6 +59,13 @@ THEMES = {
("placeholder", "dark gray", "default", "default", "dark gray", "default"),
("placeholder_text", "dark gray", "default", "default", "dark gray", "default"),
("error", "light red,blink", "default", "blink", "#f44,blink", "default"),
("irc_ts", "dark gray", "default", "default", "#888", "default"),
("irc_nick_self", "light green", "default", "default", "#6c5", "default"),
("irc_nick_peer", "light cyan", "default", "default", "#3cd", "default"),
("irc_notice", "yellow", "default", "default", "#fd3", "default"),
("irc_error", "light red", "default", "default", "#f55", "default"),
("irc_system", "dark gray", "default", "default", "#888", "default"),
("irc_mention", "light red,bold", "default", "bold", "#fb4,bold", "default"),
],
},
@ -103,7 +110,14 @@ THEMES = {
("placeholder", "light gray", "default", "default", "#999", "default"),
("placeholder_text", "light gray", "default", "default", "#999", "default"),
("error", "dark red,blink", "default", "blink", "#a22,blink", "default"),
],
("irc_ts", "dark gray", "default", "default", "#888", "default"),
("irc_nick_self", "dark green", "default", "default", "#3a0", "default"),
("irc_nick_peer", "dark cyan", "default", "default", "#077", "default"),
("irc_notice", "brown", "default", "default", "#a70", "default"),
("irc_error", "dark red", "default", "default", "#a22", "default"),
("irc_system", "dark gray", "default", "default", "#888", "default"),
("irc_mention", "dark red,bold", "default", "bold", "#c50,bold", "default"),
],
}
}

View file

@ -192,6 +192,8 @@ class Browser:
return "nomadnetwork.node"
elif destination_type == "lxmf":
return "lxmf.delivery"
elif destination_type == "rrc":
return "rrc.hub.session"
else:
return destination_type
@ -250,6 +252,11 @@ class Browser:
recurse_down(self.attr_maps)
RNS.log("Including request data: "+str(request_data), RNS.LOG_DEBUG)
# rrc://<hex>[:<dest_name>]/<room> URL form
if link_target.startswith("rrc://"):
self.handle_rrc_link(link_target[6:])
return
components = link_target.split("@")
destination_type = None
@ -280,6 +287,10 @@ class Browser:
RNS.log("Passing LXMF link to handler", RNS.LOG_DEBUG)
self.handle_lxmf_link(link_target)
elif destination_type == "rrc.hub.session":
RNS.log("Passing RRC link to handler", RNS.LOG_DEBUG)
self.handle_rrc_link(link_target)
elif destination_type == "partial":
if partial_ids != None and len(partial_ids) > 0: self.handle_partial_updates(partial_ids)
@ -331,6 +342,49 @@ class Browser:
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
def handle_rrc_link(self, link_target):
try:
if not isinstance(link_target, str):
raise ValueError("invalid RRC link payload")
rest = link_target.strip()
if rest.startswith("/"):
rest = rest[1:]
hub_part, _, room = rest.partition("/")
hex_part, _, dest = hub_part.partition(":")
hex_part = hex_part.strip()
dest = dest.strip() or None
try:
hub_hash = bytes.fromhex(hex_part)
except Exception:
raise ValueError("invalid hub hash")
expected_len = RNS.Reticulum.TRUNCATED_HASHLENGTH // 8
if len(hub_hash) != expected_len:
raise ValueError("hub hash must be "+str(expected_len)+" bytes")
room = room.strip().lstrip("#").strip()
room_norm = room.lower() if room else None
existing = self.app.rrc.find_hub(hub_hash, dest_name=dest)
self.app.ui.main_display.show_channels(None)
channels = self.app.ui.main_display.sub_displays.channels_display
if existing is not None:
channels.update_list()
if room_norm:
channels._select_room(None, (existing, room_norm))
else:
channels._select_hub(None, existing)
return
channels.confirm_new_hub_dialog(hub_hash, dest, room_norm)
except Exception as e:
RNS.log("Could not open RRC link: "+str(e), RNS.LOG_ERROR)
self.browser_footer = urwid.Text("Could not open RRC link: "+str(e))
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
def micron_released_focus(self):
if self.delegate != None:
self.delegate.focus_lists()

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
import RNS
import collections
import os
import shutil
import time
@ -133,7 +134,40 @@ class ConversationsDisplay():
self.shortcuts_display = self.list_shortcuts
self.widget = self.columns_widget
nomadnet.Conversation.created_callback = self.update_conversation_list
self._pending_actions = collections.deque()
self._wake_fd = None
try:
self._wake_fd = self.app.ui.loop.watch_pipe(self._process_pending)
except Exception:
pass
nomadnet.Conversation.created_callback = lambda: self._wake(self.update_conversation_list)
def _process_pending(self, data):
while True:
try:
action = self._pending_actions.popleft()
except IndexError:
break
try:
action()
except Exception as e:
RNS.log("Conversations UI action failed: "+str(e), RNS.LOG_ERROR)
return True
def _wake(self, action):
self._pending_actions.append(action)
if self._wake_fd is not None:
try:
os.write(self._wake_fd, b".")
return
except Exception:
pass
try:
self.app.ui.loop.set_alarm_in(0.0, lambda l, d: self._process_pending(None))
except Exception:
pass
def focus_change_event(self):
if not self.dialog_open:
@ -1024,7 +1058,7 @@ class ConversationWidget(urwid.WidgetWrap):
self.update_message_widgets()
self.conversation.register_changed_callback(self.conversation_changed)
self.conversation.register_changed_callback(self._on_conversation_changed_from_callback)
#title_editor = MessageEdit(caption="\u270E", edit_text="", multiline=False)
title_editor = MessageEdit(caption="", edit_text="", multiline=False)
@ -1243,6 +1277,13 @@ class ConversationWidget(urwid.WidgetWrap):
else:
return super(ConversationWidget, self).keypress(size, key)
def _on_conversation_changed_from_callback(self, conversation):
delegate = getattr(self, "delegate", None)
if delegate is not None and hasattr(delegate, "_wake"):
delegate._wake(lambda: self.conversation_changed(conversation))
else:
self.conversation_changed(conversation)
def conversation_changed(self, conversation):
if hasattr(self, "peer_info_widget"):
self._update_peer_info()
@ -1798,32 +1839,34 @@ class ClickableAttachment(urwid.Text):
self.set_text(" "+g["cross"]+" Save failed: "+str(e))
def _copy_attachment_to_dest(filename, src_path):
def _resolve_attachment_save_path(filename):
app = nomadnet.NomadNetworkApp.get_shared_instance()
save_dir = app.attachment_save_path if app.attachment_save_path else app.downloads_path
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
save_path = os.path.join(save_dir, filename)
safe_name = ConversationMessage.safe_attachment_name(filename)
base_dir = os.path.realpath(save_dir) + os.sep
candidate = os.path.realpath(os.path.join(save_dir, safe_name))
if not (candidate + os.sep).startswith(base_dir):
raise OSError(13, os.strerror(13))
counter = 0
base, ext = os.path.splitext(filename)
while os.path.isfile(save_path):
base, ext = os.path.splitext(safe_name)
while os.path.isfile(candidate):
counter += 1
save_path = os.path.join(save_dir, base+"_"+str(counter)+ext)
candidate = os.path.realpath(os.path.join(save_dir, base+"_"+str(counter)+ext))
if not (candidate + os.sep).startswith(base_dir):
raise OSError(13, os.strerror(13))
return candidate
def _copy_attachment_to_dest(filename, src_path):
save_path = _resolve_attachment_save_path(filename)
shutil.copy2(src_path, save_path)
return save_path
def _save_attachment_to_disk(filename, data):
app = nomadnet.NomadNetworkApp.get_shared_instance()
save_dir = app.attachment_save_path if app.attachment_save_path else app.downloads_path
if not os.path.isdir(save_dir):
os.makedirs(save_dir)
save_path = os.path.join(save_dir, filename)
counter = 0
base, ext = os.path.splitext(filename)
while os.path.isfile(save_path):
counter += 1
save_path = os.path.join(save_dir, base+"_"+str(counter)+ext)
save_path = _resolve_attachment_save_path(filename)
with open(save_path, "wb") as f:
f.write(data)
return save_path

View file

@ -717,6 +717,12 @@ Sets whether to output a notification character (bell or flash) to the terminal
Determines whether your LXMF address is automatically announced when the program starts. Must be a boolean value.
<
>>>
`!announce_interval = 360`!
>>>>
Determines how often, in minutes, your LXMF address is announced on the network. Defaults to 6 hours.
<
>>>
`!try_propagation_on_send_fail = yes`!
>>>>
@ -765,6 +771,16 @@ The maximum accepted unpacked size for messages received directly from other pee
With this option enabled, Nomad Network will only display one entry in the announce stream per destination. Older announces are culled when a new one arrives.
<
>> RRC Section
This section hold configuration directives related to the RRC client behaviour. It is delimited by the `![rrc]`! header in the configuration file. Available directives, along with their default values, are as follows:
>>>
`!history_per_room_cap = 500`!
>>>>
Maximum number of messages retained per room in the in-memory scrollback buffer, and the number of messages restored from on-disk history at startup. The on-disk log itself is appended to indefinitely; this cap only controls how much backlog is visible. Set to 0 to keep every message in memory.
<
>> Text UI Section
This section hold configuration directives related to the look and feel of the text-based user interface of the program. It is delimited by the `![textui]`! header in the configuration file. Available directives, along with their default values, are as follows:

View file

@ -2,6 +2,7 @@ import RNS
from .Network import *
from .Conversations import *
from .Channels import *
from .Directory import *
from .Config import *
from .Interfaces import *
@ -15,6 +16,7 @@ class SubDisplays():
self.app = app
self.network_display = NetworkDisplay(self.app)
self.conversations_display = ConversationsDisplay(self.app)
self.channels_display = ChannelsDisplay(self.app)
self.directory_display = DirectoryDisplay(self.app)
self.config_display = ConfigDisplay(self.app)
self.interface_display = InterfaceDisplay(self.app)
@ -103,6 +105,11 @@ class MainDisplay():
self.sub_displays.active_display = self.sub_displays.conversations_display
self.update_active_sub_display()
def show_channels(self, user_data):
self.sub_displays.active_display = self.sub_displays.channels_display
self.update_active_sub_display()
self.sub_displays.channels_display.start()
def show_directory(self, user_data):
self.sub_displays.active_display = self.sub_displays.directory_display
self.update_active_sub_display()
@ -181,6 +188,7 @@ class MenuDisplay():
menu_text = (urwid.PACK, self.menu_indicator)
button_network = (11, MenuButton("Network", on_press=handler.show_network))
button_conversations = (17, MenuButton("Conversations", on_press=handler.show_conversations))
button_channels = (12, MenuButton("Channels", on_press=handler.show_channels))
button_directory = (13, MenuButton("Directory", on_press=handler.show_directory))
button_map = (7, MenuButton("Map", on_press=handler.show_map))
button_log = (7, MenuButton("Log", on_press=handler.show_log))
@ -191,9 +199,9 @@ class MenuDisplay():
# buttons = [menu_text, button_conversations, button_node, button_directory, button_map]
if self.app.config["textui"]["hide_guide"]:
buttons = [menu_text, button_conversations, button_network, button_log, button_interfaces, button_config, button_quit]
buttons = [menu_text, button_conversations, button_network, button_channels, button_log, button_interfaces, button_config, button_quit]
else:
buttons = [menu_text, button_conversations, button_network, button_log, button_interfaces, button_config, button_guide, button_quit]
buttons = [menu_text, button_conversations, button_network, button_channels, button_log, button_interfaces, button_config, button_guide, button_quit]
columns = MenuColumns(buttons, dividechars=1)
columns.handler = handler