fix refresh halting when deleting a message

This commit is contained in:
dries.k
2023-04-08 09:48:54 +02:00
parent d71b053fdd
commit b3692a3bf9
2 changed files with 18 additions and 6 deletions

View File

@@ -190,9 +190,21 @@ class MainApplication(QtWidgets.QApplication):
message: gotify.GotifyMessageModel, message: gotify.GotifyMessageModel,
application: gotify.GotifyApplicationModel, application: gotify.GotifyApplicationModel,
): ):
"""Insert a message gotify message into the messages model. Also add the message widget to the listview
Args:
row (int): >=0: insert message at specified position, <0: append message to the end of the model
message (gotify.GotifyMessageModel): message
application (gotify.GotifyApplicationModel): application
"""
self.update_last_id(message.id) self.update_last_id(message.id)
message_item = MessagesModelItem(message) message_item = MessagesModelItem(message)
self.messages_model.insertRow(row, message_item)
if row >= 0:
self.messages_model.insertRow(row, message_item)
else:
self.messages_model.appendRow(message_item)
self.main_window.insert_message_widget( self.main_window.insert_message_widget(
message_item, message_item,
self.downloader.get_filename( self.downloader.get_filename(
@@ -204,10 +216,10 @@ class MainApplication(QtWidgets.QApplication):
"""Process messages before inserting them into the main window """Process messages before inserting them into the main window
""" """
def insert_helper(row: int, message: gotify.GotifyMessageModel): def insert_helper(message: gotify.GotifyMessageModel):
if item := self.application_model.itemFromId(message.appid): if item := self.application_model.itemFromId(message.appid):
self.insert_message( self.insert_message(
row, message, item.data(ApplicationItemDataRole.ApplicationRole), -1, message, item.data(ApplicationItemDataRole.ApplicationRole)
) )
self.processEvents() self.processEvents()

View File

@@ -217,7 +217,7 @@ class ProcessMessageTask(BaseTask):
class ProcessMessagesTask(BaseTask): class ProcessMessagesTask(BaseTask):
message_processed = pyqtSignal(int, gotify.GotifyMessageModel) message_processed = pyqtSignal(gotify.GotifyMessageModel)
def __init__(self, page: gotify.GotifyPagedMessagesModel): def __init__(self, page: gotify.GotifyPagedMessagesModel):
super(ProcessMessagesTask, self).__init__() super(ProcessMessagesTask, self).__init__()
@@ -225,10 +225,10 @@ class ProcessMessagesTask(BaseTask):
def task(self): def task(self):
downloader = Downloader() downloader = Downloader()
for i, message in enumerate(self.page.messages): for message in self.page.messages:
if image_url := get_image(message.message): if image_url := get_image(message.message):
downloader.get_filename(image_url) downloader.get_filename(image_url)
self.message_processed.emit(i, message) self.message_processed.emit(message)
# Prevent locking up the UI when there are a lot of messages with images ready at the same time # Prevent locking up the UI when there are a lot of messages with images ready at the same time
time.sleep(0.001) time.sleep(0.001)