mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-12-03 05:10:02 -05:00
Merge new feature branch into master
This commit is contained in:
commit
0d3b519a07
21 changed files with 7290 additions and 604 deletions
|
|
@ -72,6 +72,24 @@ class Conversation:
|
|||
|
||||
ingested_path = lxmessage.write_to_directory(conversation_path)
|
||||
|
||||
if not originator and ingested_path is not None:
|
||||
try:
|
||||
rssi = getattr(lxmessage, "rssi", None)
|
||||
snr = getattr(lxmessage, "snr", None)
|
||||
q = getattr(lxmessage, "q", None)
|
||||
if rssi is not None or snr is not None or q is not None:
|
||||
index = ConversationMessage.read_index(conversation_path)
|
||||
filename = os.path.basename(ingested_path)
|
||||
entry = index.get(filename) or {}
|
||||
if rssi is not None: entry["rssi"] = rssi
|
||||
if snr is not None: entry["snr"] = snr
|
||||
if q is not None: entry["q"] = q
|
||||
index[filename] = entry
|
||||
with open(os.path.join(conversation_path, ".index"), "wb") as index_file:
|
||||
index_file.write(msgpack.packb(index))
|
||||
except Exception as e:
|
||||
RNS.log("Error while storing reception stats for message: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
try:
|
||||
ConversationMessage.extract_attachments_from_lxm(lxmessage, app)
|
||||
except Exception as e:
|
||||
|
|
@ -204,7 +222,7 @@ class Conversation:
|
|||
|
||||
self.__changed_callback = None
|
||||
|
||||
if not self.__resolve_send_destination():
|
||||
if not self.ensure_send_destination():
|
||||
RNS.Transport.request_path(bytes.fromhex(source_hash))
|
||||
|
||||
if initiator:
|
||||
|
|
@ -289,7 +307,7 @@ class Conversation:
|
|||
def register_changed_callback(self, callback):
|
||||
self.__changed_callback = callback
|
||||
|
||||
def __resolve_send_destination(self):
|
||||
def ensure_send_destination(self):
|
||||
if self.send_destination == None:
|
||||
self.source_identity = RNS.Identity.recall(bytes.fromhex(self.source_hash))
|
||||
|
||||
|
|
@ -300,13 +318,16 @@ class Conversation:
|
|||
return self.send_destination != None
|
||||
|
||||
def send(self, content="", title="", fields=None):
|
||||
if self.__resolve_send_destination():
|
||||
if self.ensure_send_destination():
|
||||
dest = self.send_destination
|
||||
source = self.app.lxmf_destination
|
||||
desired_method = LXMF.LXMessage.DIRECT
|
||||
if self.app.directory.preferred_delivery(dest.hash) == DirectoryEntry.PROPAGATED:
|
||||
preferred = self.app.directory.preferred_delivery(dest.hash)
|
||||
if preferred == DirectoryEntry.PROPAGATED:
|
||||
if self.app.message_router.get_outbound_propagation_node() != None:
|
||||
desired_method = LXMF.LXMessage.PROPAGATED
|
||||
elif preferred == DirectoryEntry.OPPORTUNISTIC:
|
||||
desired_method = LXMF.LXMessage.OPPORTUNISTIC
|
||||
else:
|
||||
if not self.app.message_router.delivery_link_available(dest.hash) and RNS.Identity.current_ratchet_id(dest.hash) != None:
|
||||
RNS.log(f"Have ratchet for {RNS.prettyhexrep(dest.hash)}, requesting opportunistic delivery of message", RNS.LOG_DEBUG)
|
||||
|
|
@ -335,7 +356,7 @@ class Conversation:
|
|||
return False
|
||||
|
||||
def paper_output(self, content="", title="", mode="print_qr"):
|
||||
if self.__resolve_send_destination():
|
||||
if self.ensure_send_destination():
|
||||
try:
|
||||
dest = self.send_destination
|
||||
source = self.app.lxmf_destination
|
||||
|
|
@ -440,6 +461,9 @@ class ConversationMessage:
|
|||
self._cached_method = None
|
||||
self._cached_has_attachments = None
|
||||
self._cached_attachment_names = None
|
||||
self._cached_rssi = None
|
||||
self._cached_snr = None
|
||||
self._cached_q = None
|
||||
|
||||
self.sort_timestamp = os.path.getmtime(file_path) if os.path.isfile(file_path) else 0
|
||||
|
||||
|
|
@ -483,6 +507,12 @@ class ConversationMessage:
|
|||
if self._cached_signature_validated is None:
|
||||
self._cached_signature_validated = self.lxm.signature_validated
|
||||
self._cached_method = self.lxm.method
|
||||
if self._cached_rssi is None:
|
||||
self._cached_rssi = getattr(self.lxm, "rssi", None)
|
||||
if self._cached_snr is None:
|
||||
self._cached_snr = getattr(self.lxm, "snr", None)
|
||||
if self._cached_q is None:
|
||||
self._cached_q = getattr(self.lxm, "q", None)
|
||||
if hasattr(self.lxm, "get_fields"):
|
||||
_fields = self.lxm.get_fields()
|
||||
if _fields and isinstance(_fields, dict) and LXMF.FIELD_RENDERER in _fields:
|
||||
|
|
@ -603,6 +633,22 @@ class ConversationMessage:
|
|||
self.load()
|
||||
return self._cached_state
|
||||
|
||||
def get_method(self):
|
||||
if self._cached_method is not None:
|
||||
return self._cached_method
|
||||
if not self.loaded:
|
||||
self.load()
|
||||
return self._cached_method
|
||||
|
||||
def get_rssi(self):
|
||||
return self._cached_rssi
|
||||
|
||||
def get_snr(self):
|
||||
return self._cached_snr
|
||||
|
||||
def get_q(self):
|
||||
return self._cached_q
|
||||
|
||||
def get_transport_encryption(self):
|
||||
if self._cached_transport_encryption is not None:
|
||||
return self._cached_transport_encryption
|
||||
|
|
@ -964,6 +1010,9 @@ class ConversationMessage:
|
|||
"renderer": None if self._cached_renderer is ConversationMessage._RENDERER_UNSET else self._cached_renderer,
|
||||
"has_attachments": self._cached_has_attachments,
|
||||
"attachment_names": self._cached_attachment_names,
|
||||
"rssi": self._cached_rssi,
|
||||
"snr": self._cached_snr,
|
||||
"q": self._cached_q,
|
||||
}
|
||||
|
||||
def restore_from_index(self, entry):
|
||||
|
|
@ -981,6 +1030,9 @@ class ConversationMessage:
|
|||
self._cached_renderer = entry.get("renderer", ConversationMessage._RENDERER_UNSET)
|
||||
self._cached_has_attachments = entry.get("has_attachments")
|
||||
self._cached_attachment_names = entry.get("attachment_names")
|
||||
self._cached_rssi = entry.get("rssi")
|
||||
self._cached_snr = entry.get("snr")
|
||||
self._cached_q = entry.get("q")
|
||||
|
||||
@staticmethod
|
||||
def read_index(conversation_path):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue