Simplify the inserting and processing of messages.
Message widgets are now inserted into the listView through the `rowsInserted` callback of the messages model. Messages are processed in the GetMessagesTask and GetApplicationMessagesTask when fetching multiple new messages. Single new incoming messages are processed in ProcessMessageTask.
This commit is contained in:
@@ -4,7 +4,10 @@ import re
|
||||
import subprocess
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Iterator, List, Optional
|
||||
|
||||
from gotify_tray import gotify
|
||||
from gotify_tray.database import Downloader
|
||||
|
||||
|
||||
def verify_server(force_new: bool = False, enable_import: bool = True) -> bool:
|
||||
@@ -28,6 +31,14 @@ def verify_server(force_new: bool = False, enable_import: bool = True) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def process_messages(messages: List[gotify.GotifyMessageModel]) -> Iterator[gotify.GotifyMessageModel]:
|
||||
downloader = Downloader()
|
||||
for message in messages:
|
||||
if image_url := get_image(message.message):
|
||||
downloader.get_filename(image_url)
|
||||
yield message
|
||||
|
||||
|
||||
def convert_links(text):
|
||||
_link = re.compile(
|
||||
r'(?:(https://|http://)|(www\.))(\S+\b/?)([!"#$%&\'()*+,\-./:;<=>?@[\\\]^_`{|}~]*)(\s|$)',
|
||||
|
||||
Reference in New Issue
Block a user