diff --git a/meshchat.py b/meshchat.py index bebdc92..f62641a 100644 --- a/meshchat.py +++ b/meshchat.py @@ -20,6 +20,7 @@ from peewee import SqliteDatabase from serial.tools import list_ports import database +from src.backend.announce_handler import AnnounceHandler from src.backend.lxmf_message_fields import LxmfImageField, LxmfFileAttachmentsField, LxmfFileAttachment, LxmfAudioField from src.backend.audio_call_manager import AudioCall, AudioCallManager @@ -2044,24 +2045,6 @@ class Config: lxmf_delivery_transfer_limit_in_bytes = IntConfig("lxmf_delivery_transfer_limit_in_bytes", 1000 * 1000 * 10) # 10MB -# an announce handler that forwards announces to a provided callback for the provided aspect filter -# this handler exists so we can have access to the original aspect, as this is not provided in the announce itself -class AnnounceHandler: - - def __init__(self, aspect_filter, received_announce_callback): - self.aspect_filter = aspect_filter - self.received_announce_callback = received_announce_callback - - # we will just pass the received announce back to the provided callback - def received_announce(self, destination_hash, announced_identity, app_data): - try: - # handle received announce - self.received_announce_callback(self.aspect_filter, destination_hash, announced_identity, app_data) - except: - # ignore failure to handle received announce - pass - - class NomadnetDownloader: def __init__(self, destination_hash: bytes, path: str, on_download_success: Callable[[bytes], None], on_download_failure: Callable[[str], None], on_progress_update: Callable[[float], None], timeout: int|None = None): diff --git a/src/backend/announce_handler.py b/src/backend/announce_handler.py new file mode 100644 index 0000000..5d2cd3a --- /dev/null +++ b/src/backend/announce_handler.py @@ -0,0 +1,16 @@ +# an announce handler that forwards announces to a provided callback for the provided aspect filter +# this handler exists so we can have access to the original aspect, as this is not provided in the announce itself +class AnnounceHandler: + + def __init__(self, aspect_filter: str, received_announce_callback): + self.aspect_filter = aspect_filter + self.received_announce_callback = received_announce_callback + + # we will just pass the received announce back to the provided callback + def received_announce(self, destination_hash, announced_identity, app_data): + try: + # handle received announce + self.received_announce_callback(self.aspect_filter, destination_hash, announced_identity, app_data) + except: + # ignore failure to handle received announce + pass