make gotify api return values uniform
This commit is contained in:
@@ -110,8 +110,9 @@ class GotifyClient(GotifySession):
|
||||
else GotifyErrorModel(response)
|
||||
)
|
||||
|
||||
def delete_application(self, application_id: int) -> bool:
|
||||
return self._delete(f"/application/{application_id}").ok
|
||||
def delete_application(self, application_id: int) -> None | GotifyErrorModel:
|
||||
response = self._delete(f"/application/{application_id}")
|
||||
return None if response.ok else GotifyErrorModel(response)
|
||||
|
||||
def upload_application_image(
|
||||
self, application_id: int, img_path: str
|
||||
@@ -132,6 +133,10 @@ class GotifyClient(GotifySession):
|
||||
)
|
||||
return None
|
||||
|
||||
def delete_application_image(self, application_id: int) -> None | GotifyErrorModel:
|
||||
response = self._delete(f"/application/{application_id}/image")
|
||||
return None if response.ok else GotifyErrorModel(response)
|
||||
|
||||
"""
|
||||
Message
|
||||
"""
|
||||
@@ -151,8 +156,9 @@ class GotifyClient(GotifySession):
|
||||
paging=GotifyPagingModel(j["paging"]),
|
||||
)
|
||||
|
||||
def delete_application_messages(self, application_id: int) -> bool:
|
||||
return self._delete(f"/application/{application_id}/message").ok
|
||||
def delete_application_messages(self, application_id: int) -> None | GotifyErrorModel:
|
||||
response = self._delete(f"/application/{application_id}/message")
|
||||
return None if response.ok else GotifyErrorModel(response)
|
||||
|
||||
def get_messages(
|
||||
self, limit: int = 100, since: int | None = None
|
||||
@@ -166,11 +172,13 @@ class GotifyClient(GotifySession):
|
||||
paging=GotifyPagingModel(j["paging"]),
|
||||
)
|
||||
|
||||
def delete_messages(self) -> bool:
|
||||
return self._delete("/message").ok
|
||||
def delete_messages(self) -> None | GotifyErrorModel:
|
||||
response = self._delete("/message")
|
||||
return None if response.ok else GotifyErrorModel(response)
|
||||
|
||||
def delete_message(self, message_id: int) -> bool:
|
||||
return self._delete(f"/message/{message_id}").ok
|
||||
def delete_message(self, message_id: int) -> None | GotifyErrorModel:
|
||||
response = self._delete(f"/message/{message_id}")
|
||||
return None if response.ok else GotifyErrorModel(response)
|
||||
|
||||
def listen(
|
||||
self,
|
||||
|
||||
@@ -9,7 +9,6 @@ from PyQt6 import QtCore
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
|
||||
from gotify_tray.database import Cache, Settings
|
||||
from gotify_tray.gotify.api import GotifyClient
|
||||
from gotify_tray.gotify.models import GotifyVersionModel
|
||||
from gotify_tray.utils import process_messages
|
||||
|
||||
@@ -50,7 +49,8 @@ class BaseTask(QtCore.QThread):
|
||||
|
||||
|
||||
class DeleteMessageTask(BaseTask):
|
||||
deleted = pyqtSignal(bool)
|
||||
success = pyqtSignal()
|
||||
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||
|
||||
def __init__(self, message_id: int, gotify_client: gotify.GotifyClient):
|
||||
super(DeleteMessageTask, self).__init__()
|
||||
@@ -58,12 +58,16 @@ class DeleteMessageTask(BaseTask):
|
||||
self.gotify_client = gotify_client
|
||||
|
||||
def task(self):
|
||||
success = self.gotify_client.delete_message(self.message_id)
|
||||
self.deleted.emit(success)
|
||||
result = self.gotify_client.delete_message(self.message_id)
|
||||
if isinstance(result, gotify.GotifyErrorModel):
|
||||
self.error.emit(result)
|
||||
else:
|
||||
self.success.emit()
|
||||
|
||||
|
||||
class DeleteApplicationMessagesTask(BaseTask):
|
||||
deleted = pyqtSignal(bool)
|
||||
success = pyqtSignal()
|
||||
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||
|
||||
def __init__(self, appid: int, gotify_client: gotify.GotifyClient):
|
||||
super(DeleteApplicationMessagesTask, self).__init__()
|
||||
@@ -71,20 +75,27 @@ class DeleteApplicationMessagesTask(BaseTask):
|
||||
self.gotify_client = gotify_client
|
||||
|
||||
def task(self):
|
||||
success = self.gotify_client.delete_application_messages(self.appid)
|
||||
self.deleted.emit(success)
|
||||
result = self.gotify_client.delete_application_messages(self.appid)
|
||||
if isinstance(result, gotify.GotifyErrorModel):
|
||||
self.error.emit(result)
|
||||
else:
|
||||
self.success.emit()
|
||||
|
||||
|
||||
class DeleteAllMessagesTask(BaseTask):
|
||||
deleted = pyqtSignal(bool)
|
||||
success = pyqtSignal()
|
||||
error = pyqtSignal(gotify.GotifyErrorModel)
|
||||
|
||||
def __init__(self, gotify_client: gotify.GotifyClient):
|
||||
super(DeleteAllMessagesTask, self).__init__()
|
||||
self.gotify_client = gotify_client
|
||||
|
||||
def task(self):
|
||||
success = self.gotify_client.delete_messages()
|
||||
self.deleted.emit(success)
|
||||
result = self.gotify_client.delete_messages()
|
||||
if isinstance(result, gotify.GotifyErrorModel):
|
||||
self.error.emit(result)
|
||||
else:
|
||||
self.success.emit()
|
||||
|
||||
|
||||
class GetApplicationsTask(BaseTask):
|
||||
@@ -197,7 +208,7 @@ class VerifyServerInfoTask(BaseTask):
|
||||
class ServerConnectionWatchdogTask(BaseTask):
|
||||
closed = pyqtSignal()
|
||||
|
||||
def __init__(self, gotify_client: GotifyClient):
|
||||
def __init__(self, gotify_client: gotify.GotifyClient):
|
||||
super(ServerConnectionWatchdogTask, self).__init__()
|
||||
self.gotify_client = gotify_client
|
||||
|
||||
|
||||
Reference in New Issue
Block a user