Commit 45fa9dbe authored by Tijmen de Mes's avatar Tijmen de Mes

Moved message code

parent adb683e8
...@@ -2272,15 +2272,15 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2272,15 +2272,15 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
def _NH_ChatSessionItemDidChange(self, notification): def _NH_ChatSessionItemDidChange(self, notification):
self._update_widgets_for_session() self._update_widgets_for_session()
def _NH_ChatStreamGotMessage(self, notification): def _NH_GotMessage(self, notification):
blink_session = notification.sender.blink_session blink_session = notification.sender
session = blink_session.items.chat session = blink_session.items.chat
message = notification.data
if session is None: if session is None:
return return
message = notification.data.message
if message.content_type.startswith('image/'): if message.content_type.startswith('image/'):
content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip()) content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip())
elif message.content_type.startswith('text/'): elif message.content_type.startswith('text/'):
...@@ -2289,7 +2289,11 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2289,7 +2289,11 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
else: else:
return return
uri = '%s@%s' % (message.sender.uri.user.decode(), message.sender.uri.host.decode()) try:
uri = '%s@%s' % (message.sender.uri.user.decode(), message.sender.uri.host.decode())
except AttributeError:
uri = '%s@%s' % (message.sender.uri.user, message.sender.uri.host)
account_manager = AccountManager() account_manager = AccountManager()
if account_manager.has_account(uri): if account_manager.has_account(uri):
account = account_manager.get_account(uri) account = account_manager.get_account(uri)
...@@ -2300,11 +2304,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2300,11 +2304,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
else: else:
sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename) sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename)
is_status_message = any(h.name == 'Message-Type' and h.value == 'status' and h.namespace == 'urn:ag-projects:xml:ns:cpim' for h in message.additional_headers) session.chat_widget.add_message(ChatMessage(content, sender, 'incoming', id=message.id))
if is_status_message:
session.chat_widget.add_message(ChatStatus(content))
else:
session.chat_widget.add_message(ChatMessage(content, sender, 'incoming'))
session.remote_composing = False session.remote_composing = False
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
...@@ -2313,15 +2313,37 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2313,15 +2313,37 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
SIPApplication.alert_audio_bridge.add(player) SIPApplication.alert_audio_bridge.add(player)
player.start() player.start()
def _NH_GotMessage(self, notification): def _NH_DidAcceptMessage(self, notification):
blink_session = notification.sender blink_session = notification.sender
session = blink_session.items.chat session = blink_session.items.chat
if session is None:
return
session.chat_widget.update_message_status(id=notification.data.id, status='accepted')
message = notification.data
def _NH_DidNotDeliverMessage(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
if session is None:
return
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_GotComposingIndication(self, notification):
session = notification.sender.items.chat
if session is None:
return
session.update_composing_indication(notification.data)
def _NH_ChatStreamGotMessage(self, notification):
blink_session = notification.sender.blink_session
session = blink_session.items.chat
if session is None: if session is None:
return return
message = notification.data.message
if message.content_type.startswith('image/'): if message.content_type.startswith('image/'):
content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip()) content = '''<img src="data:{};base64,{}" class="scaled-to-fit" />'''.format(message.content_type, message.content.decode('base64').rstrip())
elif message.content_type.startswith('text/'): elif message.content_type.startswith('text/'):
...@@ -2330,11 +2352,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2330,11 +2352,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
else: else:
return return
try: uri = '%s@%s' % (message.sender.uri.user.decode(), message.sender.uri.host.decode())
uri = '%s@%s' % (message.sender.uri.user.decode(), message.sender.uri.host.decode())
except AttributeError:
uri = '%s@%s' % (message.sender.uri.user, message.sender.uri.host)
account_manager = AccountManager() account_manager = AccountManager()
if account_manager.has_account(uri): if account_manager.has_account(uri):
account = account_manager.get_account(uri) account = account_manager.get_account(uri)
...@@ -2345,7 +2363,11 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2345,7 +2363,11 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
else: else:
sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename) sender = ChatSender(message.sender.display_name or session.name, uri, session.icon.filename)
session.chat_widget.add_message(ChatMessage(content, sender, 'incoming', id=message.id)) is_status_message = any(h.name == 'Message-Type' and h.value == 'status' and h.namespace == 'urn:ag-projects:xml:ns:cpim' for h in message.additional_headers)
if is_status_message:
session.chat_widget.add_message(ChatStatus(content))
else:
session.chat_widget.add_message(ChatMessage(content, sender, 'incoming'))
session.remote_composing = False session.remote_composing = False
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
...@@ -2354,28 +2376,6 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2354,28 +2376,6 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
SIPApplication.alert_audio_bridge.add(player) SIPApplication.alert_audio_bridge.add(player)
player.start() player.start()
def _NH_DidAcceptMessage(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
if session is None:
return
session.chat_widget.update_message_status(id=notification.data.id, status='accepted')
def _NH_DidNotDeliverMessage(self, notification):
blink_session = notification.sender
session = blink_session.items.chat
if session is None:
return
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_GotComposingIndication(self, notification):
session = notification.sender.items.chat
if session is None:
return
session.update_composing_indication(notification.data)
def _NH_ChatStreamGotComposingIndication(self, notification): def _NH_ChatStreamGotComposingIndication(self, notification):
session = notification.sender.blink_session.items.chat session = notification.sender.blink_session.items.chat
if session is None: if session is None:
......
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