Commit 1799e5f3 authored by Tijmen de Mes's avatar Tijmen de Mes

Added support for sylk history api

parent 94a8f926
......@@ -1644,6 +1644,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
notification_center.add_observer(self, name='BlinkGotDispositionNotification')
notification_center.add_observer(self, name='BlinkMessageDidSucceed')
notification_center.add_observer(self, name='BlinkMessageDidFail')
notification_center.add_observer(self, name='BlinkMessageWillRemove')
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidSucceed')
notification_center.add_observer(self, name='BlinkMessageHistoryLoadDidFail')
notification_center.add_observer(self, name='BlinkMessageHistoryLastContactsDidSucceed')
......@@ -2386,6 +2387,11 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
message = notification.data.message
direction = notification.data.message.direction
try:
history = notification.data.history
except AttributeError:
history = False
try:
received_account = notification.data.account
except AttributeError:
......@@ -2423,10 +2429,10 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
self.pending_decryption.remove(message)
session.chat_widget.update_message_text(message.id, content)
else:
session.chat_widget.add_message(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp))
session.chat_widget.add_message(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp, history=history))
session.chat_widget.update_message_encryption(message.id, message.is_secure)
else:
self.render_after_load.append(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp))
self.render_after_load.append(ChatMessage(content, sender, direction, id=message.id, timestamp=message.timestamp, history=history))
if direction != 'outgoing' and message.disposition is not None and 'display' in message.disposition and not encrypted:
if self.selected_session.blink_session is blink_session and not self.isMinimized() and self.isActiveWindow():
......@@ -2476,6 +2482,15 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
session.chat_widget.add_message(ChatStatus(f'Delivery failed: {notification.data.data.code} - {notification.data.data.reason}'))
session.chat_widget.update_message_status(id=notification.data.id, status='failed')
def _NH_BlinkMessageWillRemove(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
if session is None:
return
session.chat_widget.remove_message(notification.data)
def _NH_PGPMessageDidDecrypt(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
......@@ -2573,7 +2588,6 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
session.chat_widget.add_message(ChatMessage(content, sender, message.direction, id=message.message_id, timestamp=timestamp, history=True))
# session.chat_widget.add_message(ChatMessage(content, sender, message.direction, id=message.id, timestamp=timestamp))
if message.direction == "outgoing":
session.chat_widget.update_message_status(id=message.message_id, status=message.state)
elif message.state != 'displayed' and 'display' in message.disposition and not encrypted:
......
......@@ -61,6 +61,8 @@ class HistoryManager(object, metaclass=Singleton):
notification_center.add_observer(self, name='BlinkGotDispositionNotification')
notification_center.add_observer(self, name='BlinkDidSendDispositionNotification')
notification_center.add_observer(self, name='BlinkGotHistoryMessage')
notification_center.add_observer(self, name='BlinkGotHistoryMessageRemove')
notification_center.add_observer(self, name='BlinkGotHistoryConversationRemove')
@run_in_thread('file-io')
def save(self):
......@@ -157,6 +159,12 @@ class HistoryManager(object, metaclass=Singleton):
account = notification.sender
self.message_history.add_from_history(account, **notification.data.__dict__)
def _NH_BlinkGotHistoryMessageRemove(self, notification):
self.message_history.remove_message(notification.data)
def _NH_BlinkGotHistoryConversationRemove(self, notification):
self.message_history.remove_contact_messages(notification.sender, notification.data)
def _NH_BlinkMessageDidSucceed(self, notification):
data = notification.data
self.message_history.update(data.id, 'accepted')
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment