feat: show relay NOTICE
This commit is contained in:
parent
f244f60c56
commit
1601f71b03
6 changed files with 44 additions and 10 deletions
|
|
@ -128,11 +128,13 @@ class Relay:
|
|||
],
|
||||
}
|
||||
|
||||
def add_notice(self, notice: str):
|
||||
self.notice_list = ([notice] + self.notice_list)[:20]
|
||||
|
||||
def _on_open(self, _):
|
||||
logger.info(f"Connected to relay: '{self.url}'.")
|
||||
self.connected = True
|
||||
|
||||
|
||||
def _on_close(self, _, status_code, message):
|
||||
logger.warning(f"Connection to relay {self.url} closed. Status: '{status_code}'. Message: '{message}'.")
|
||||
self.close()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import time
|
|||
from loguru import logger
|
||||
|
||||
from .filter import Filters
|
||||
from .message_pool import MessagePool
|
||||
from .message_pool import MessagePool, NoticeMessage
|
||||
from .relay import Relay, RelayPolicy
|
||||
from .subscription import Subscription
|
||||
|
||||
|
|
@ -80,6 +80,11 @@ class RelayManager:
|
|||
if relay.policy.should_write:
|
||||
relay.publish(message)
|
||||
|
||||
def handle_notice(self, notice: NoticeMessage):
|
||||
relay = next((r for r in self.relays.values() if r.url == notice.url))
|
||||
if relay:
|
||||
relay.add_notice(notice.content)
|
||||
|
||||
def _open_connection(self, relay: Relay, ssl_options: dict = None, proxy: dict = None):
|
||||
self.threads[relay.url] = threading.Thread(
|
||||
target=relay.connect,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue