mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-02-05 10:05:26 -05:00
Added LXMF link support
This commit is contained in:
parent
d8a35be14d
commit
247db32033
@ -239,10 +239,11 @@ class Conversation:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
string = self.source_hash
|
string = self.source_hash
|
||||||
|
|
||||||
if self.source_identity:
|
# TODO: Remove this
|
||||||
if self.source_identity.app_data:
|
# if self.source_identity:
|
||||||
# TODO: Sanitise for viewing
|
# if self.source_identity.app_data:
|
||||||
string += " | "+self.source.source_identity.app_data.decode("utf-8")
|
# # TODO: Sanitise for viewing, or just clean this
|
||||||
|
# string += " | "+self.source_identity.app_data.decode("utf-8")
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
@ -60,8 +60,6 @@ class Directory:
|
|||||||
|
|
||||||
entries = {}
|
entries = {}
|
||||||
for e in unpacked_list:
|
for e in unpacked_list:
|
||||||
if e[1] == None:
|
|
||||||
e[1] = RNS.prettyhexrep(e[0])
|
|
||||||
|
|
||||||
if len(e) > 3:
|
if len(e) > 3:
|
||||||
hosts_node = e[3]
|
hosts_node = e[3]
|
||||||
@ -250,8 +248,9 @@ class DirectoryEntry:
|
|||||||
if len(source_hash) == RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
if len(source_hash) == RNS.Identity.TRUNCATED_HASHLENGTH//8:
|
||||||
self.source_hash = source_hash
|
self.source_hash = source_hash
|
||||||
|
|
||||||
if display_name == None:
|
# TODO: Clean
|
||||||
display_name = source_hash
|
# if display_name == None:
|
||||||
|
# display_name = source_hash
|
||||||
|
|
||||||
self.display_name = display_name
|
self.display_name = display_name
|
||||||
|
|
||||||
|
@ -133,7 +133,26 @@ class Browser:
|
|||||||
self.browser_footer = urwid.AttrMap(urwid.Pile([urwid.Divider(self.g["divider1"]), urwid.Text("Link to: "+str(link_target))]), "browser_controls")
|
self.browser_footer = urwid.AttrMap(urwid.Pile([urwid.Divider(self.g["divider1"]), urwid.Text("Link to: "+str(link_target))]), "browser_controls")
|
||||||
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
||||||
|
|
||||||
|
def expand_shorthands(self, destination_type):
|
||||||
|
if destination_type == "nnn":
|
||||||
|
return "nomadnetwork.node"
|
||||||
|
elif destination_type == "lxmf":
|
||||||
|
return "lxmf.delivery"
|
||||||
|
else:
|
||||||
|
return destination_type
|
||||||
|
|
||||||
def handle_link(self, link_target):
|
def handle_link(self, link_target):
|
||||||
|
components = link_target.split("@")
|
||||||
|
destination_type = None
|
||||||
|
|
||||||
|
if len(components) == 2:
|
||||||
|
destination_type = self.expand_shorthands(components[0])
|
||||||
|
link_target = components[1]
|
||||||
|
else:
|
||||||
|
destination_type = "nomadnetwork.node"
|
||||||
|
link_target = components[0]
|
||||||
|
|
||||||
|
if destination_type == "nomadnetwork.node":
|
||||||
if self.status >= Browser.DISCONECTED:
|
if self.status >= Browser.DISCONECTED:
|
||||||
RNS.log("Browser handling link to: "+str(link_target), RNS.LOG_DEBUG)
|
RNS.log("Browser handling link to: "+str(link_target), RNS.LOG_DEBUG)
|
||||||
try:
|
try:
|
||||||
@ -142,8 +161,54 @@ class Browser:
|
|||||||
self.browser_footer = urwid.Text("Could not open link: "+str(e))
|
self.browser_footer = urwid.Text("Could not open link: "+str(e))
|
||||||
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
||||||
else:
|
else:
|
||||||
RNS.log("Browser aleady hadling link, cannot handle link to: "+str(link_target), RNS.LOG_DEBUG)
|
RNS.log("Browser already handling link, cannot handle link to: "+str(link_target), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
|
elif destination_type == "lxmf.delivery":
|
||||||
|
RNS.log("Passing LXMF link to handler", RNS.LOG_DEBUG)
|
||||||
|
self.handle_lxmf_link(link_target)
|
||||||
|
|
||||||
|
else:
|
||||||
|
RNS.log("No known handler for destination type "+str(destination_type), RNS.LOG_DEBUG)
|
||||||
|
self.browser_footer = urwid.Text("Could not open link: "+"No known handler for destination type "+str(destination_type))
|
||||||
|
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
||||||
|
|
||||||
|
def handle_lxmf_link(self, link_target):
|
||||||
|
try:
|
||||||
|
if not type(link_target) is str:
|
||||||
|
raise ValueError("Invalid data type for LXMF link")
|
||||||
|
|
||||||
|
if len(link_target) != (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2:
|
||||||
|
raise ValueError("Invalid length for LXMF link")
|
||||||
|
|
||||||
|
try:
|
||||||
|
bytes.fromhex(link_target)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError("Could not decode destination hash from LXMF link")
|
||||||
|
|
||||||
|
existing_conversations = nomadnet.Conversation.conversation_list(self.app)
|
||||||
|
|
||||||
|
source_hash_text = link_target
|
||||||
|
display_name_data = RNS.Identity.recall_app_data(bytes.fromhex(source_hash_text))
|
||||||
|
|
||||||
|
display_name = None
|
||||||
|
if display_name_data != None:
|
||||||
|
display_name = display_name_data.decode("utf-8")
|
||||||
|
|
||||||
|
if not source_hash_text in [c[0] for c in existing_conversations]:
|
||||||
|
entry = DirectoryEntry(bytes.fromhex(source_hash_text), display_name=display_name)
|
||||||
|
self.app.directory.remember(entry)
|
||||||
|
|
||||||
|
new_conversation = nomadnet.Conversation(source_hash_text, nomadnet.NomadNetworkApp.get_shared_instance(), initiator=True)
|
||||||
|
self.app.ui.main_display.sub_displays.conversations_display.update_conversation_list()
|
||||||
|
|
||||||
|
self.app.ui.main_display.sub_displays.conversations_display.display_conversation(None, source_hash_text)
|
||||||
|
self.app.ui.main_display.show_conversations(None)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log("Error while starting conversation from link. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
self.browser_footer = urwid.Text("Could not open LXMF link: "+str(e))
|
||||||
|
self.frame.contents["footer"] = (self.browser_footer, self.frame.options())
|
||||||
|
|
||||||
|
|
||||||
def micron_released_focus(self):
|
def micron_released_focus(self):
|
||||||
|
@ -929,11 +929,11 @@ Here's a few examples:
|
|||||||
|
|
||||||
`Faaa
|
`Faaa
|
||||||
`=
|
`=
|
||||||
Here is a link without any label: `[1385edace36466a6b3dd:/page/index.mu]
|
Here is a link without any label: `[72914442a3689add83a09a767963f57c:/page/index.mu]
|
||||||
|
|
||||||
This is a `[labeled link`1385edace36466a6b3dd:/page/index.mu] to the same page, but it's hard to see if you don't know it
|
This is a `[labeled link`72914442a3689add83a09a767963f57c:/page/index.mu] to the same page, but it's hard to see if you don't know it
|
||||||
|
|
||||||
Here is `F00a`_`[a more visible link`1385edace36466a6b3dd:/page/index.mu]`_`f
|
Here is `F00a`_`[a more visible link`72914442a3689add83a09a767963f57c:/page/index.mu]`_`f
|
||||||
`=
|
`=
|
||||||
``
|
``
|
||||||
|
|
||||||
@ -941,11 +941,11 @@ The above markup produces the following output:
|
|||||||
|
|
||||||
`Faaa`B333
|
`Faaa`B333
|
||||||
|
|
||||||
Here is a link without any label: `[1385edace36466a6b3dd:/page/index.mu]
|
Here is a link without any label: `[72914442a3689add83a09a767963f57c:/page/index.mu]
|
||||||
|
|
||||||
This is a `[labeled link`1385edace36466a6b3dd:/page/index.mu] to the same page, but it's hard to see if you don't know it
|
This is a `[labeled link`72914442a3689add83a09a767963f57c:/page/index.mu] to the same page, but it's hard to see if you don't know it
|
||||||
|
|
||||||
Here is `F00f`_`[a more visible link`1385edace36466a6b3dd:/page/index.mu]`_`f
|
Here is `F00f`_`[a more visible link`72914442a3689add83a09a767963f57c:/page/index.mu]`_`f
|
||||||
|
|
||||||
``
|
``
|
||||||
|
|
||||||
|
@ -420,6 +420,9 @@ class KnownNodeInfo(urwid.WidgetWrap):
|
|||||||
|
|
||||||
addr_str = "<"+RNS.hexrep(source_hash, delimit=False)+">"
|
addr_str = "<"+RNS.hexrep(source_hash, delimit=False)+">"
|
||||||
|
|
||||||
|
if display_str == None:
|
||||||
|
display_str = addr_str
|
||||||
|
|
||||||
if node_ident != None:
|
if node_ident != None:
|
||||||
lxmf_addr_str = g["sent"]+" LXMF Propagation Node Address is "+RNS.prettyhexrep(RNS.Destination.hash_from_name_and_identity("lxmf.propagation", node_ident))
|
lxmf_addr_str = g["sent"]+" LXMF Propagation Node Address is "+RNS.prettyhexrep(RNS.Destination.hash_from_name_and_identity("lxmf.propagation", node_ident))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user