Commit 4b03268b authored by Tijmen de Mes's avatar Tijmen de Mes

Handle replicated SIP messages

parent b9b6e2df
...@@ -71,6 +71,10 @@ class SMSSettings(SettingsGroup): ...@@ -71,6 +71,10 @@ class SMSSettings(SettingsGroup):
private_key = Setting(type=ApplicationDataPath, default=None, nillable=True) private_key = Setting(type=ApplicationDataPath, default=None, nillable=True)
class SMSSettingsExtension(SMSSettings):
enable_message_replication = Setting(type=bool, default=True)
class SoundSettings(SettingsGroup): class SoundSettings(SettingsGroup):
inbound_ringtone = Setting(type=SoundFile, default=None, nillable=True) inbound_ringtone = Setting(type=SoundFile, default=None, nillable=True)
...@@ -89,7 +93,7 @@ class AccountExtension(SettingsObjectExtension): ...@@ -89,7 +93,7 @@ class AccountExtension(SettingsObjectExtension):
rtp = RTPSettingsExtension rtp = RTPSettingsExtension
server = ServerSettings server = ServerSettings
sip = SIPSettingsExtension sip = SIPSettingsExtension
sms = SMSSettings sms = SMSSettingsExtension
sounds = SoundSettings sounds = SoundSettings
xcap = XCAPSettingsExtension xcap = XCAPSettingsExtension
......
...@@ -671,6 +671,7 @@ class MessageManager(object, metaclass=Singleton): ...@@ -671,6 +671,7 @@ class MessageManager(object, metaclass=Singleton):
if account is None: if account is None:
return return
log.info(f'Received a message for {account.id}') log.info(f'Received a message for {account.id}')
data = notification.data data = notification.data
...@@ -679,7 +680,12 @@ class MessageManager(object, metaclass=Singleton): ...@@ -679,7 +680,12 @@ class MessageManager(object, metaclass=Singleton):
x_replicated_message = data.headers.get('X-Replicated-Message', Null) x_replicated_message = data.headers.get('X-Replicated-Message', Null)
to_header = data.headers.get('To', Null) to_header = data.headers.get('To', Null)
if x_replicated_message is Null: if x_replicated_message is not Null:
log.info('Message is a replicated message')
if not account.sms.enable_message_replication:
log.info('Skipping message, replicated message handling is disabled')
return
cpim_message = None cpim_message = None
if content_type == "message/cpim": if content_type == "message/cpim":
try: try:
...@@ -715,6 +721,8 @@ class MessageManager(object, metaclass=Singleton): ...@@ -715,6 +721,8 @@ class MessageManager(object, metaclass=Singleton):
elif not account.sms.enable_pgp: elif not account.sms.enable_pgp:
log.info(f"-- Skipping PGP encrypted message, PGP is disabled for {account.id}") log.info(f"-- Skipping PGP encrypted message, PGP is disabled for {account.id}")
return return
return
if content_type.lower() == 'text/pgp-private-key': if content_type.lower() == 'text/pgp-private-key':
log.info('Message is a private key') log.info('Message is a private key')
...@@ -745,12 +753,20 @@ class MessageManager(object, metaclass=Singleton): ...@@ -745,12 +753,20 @@ class MessageManager(object, metaclass=Singleton):
from blink.contacts import URIUtils from blink.contacts import URIUtils
contact, contact_uri = URIUtils.find_contact(sender.uri) contact, contact_uri = URIUtils.find_contact(sender.uri)
session_manager = SessionManager()
if x_replicated_message is not Null:
contact, contact_uri = URIUtils.find_contact(to_header.uri)
session_manager = SessionManager()
notification_center = NotificationCenter() notification_center = NotificationCenter()
timestamp = str(cpim_message.timestamp) if cpim_message is not None and cpim_message.timestamp is not None else str(ISOTimestamp.now()) timestamp = str(cpim_message.timestamp) if cpim_message is not None and cpim_message.timestamp is not None else str(ISOTimestamp.now())
message = BlinkMessage(body, content_type, sender, timestamp=timestamp, id=message_id, disposition=disposition, direction='incoming') message = BlinkMessage(body, content_type, sender, timestamp=timestamp, id=message_id, disposition=disposition, direction='incoming')
if x_replicated_message is not Null:
message.sender = account
message.direction = "outgoing"
try: try:
blink_session = next(session for session in self.sessions if session.contact.settings is contact.settings) blink_session = next(session for session in self.sessions if session.contact.settings is contact.settings)
except StopIteration: except StopIteration:
...@@ -759,6 +775,15 @@ class MessageManager(object, metaclass=Singleton): ...@@ -759,6 +775,15 @@ class MessageManager(object, metaclass=Singleton):
log.debug(f"Not creating session for incoming message for content type {content_type.lower()}") log.debug(f"Not creating session for incoming message for content type {content_type.lower()}")
if content_type.lower() != IMDNDocument.content_type: if content_type.lower() != IMDNDocument.content_type:
return return
elif x_replicated_message is not Null:
log.debug("Not creating session for incoming message, message is replicated")
notification_center.post_notification('BlinkGotHistoryMessage',
sender=account,
data=NotificationData(remote_uri=contact.uri.uri,
message=message,
encryption=encryption,
state='accepted'))
return
else: else:
log.debug("Starting new message session for incoming message") log.debug("Starting new message session for incoming message")
blink_session = session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False) blink_session = session_manager.create_session(contact, contact_uri, [StreamDescription('messages')], account=account, connect=False)
...@@ -772,6 +797,7 @@ class MessageManager(object, metaclass=Singleton): ...@@ -772,6 +797,7 @@ class MessageManager(object, metaclass=Singleton):
notification_center.post_notification('BlinkSessionWillAddStream', sender=blink_session, data=NotificationData(stream=stream)) notification_center.post_notification('BlinkSessionWillAddStream', sender=blink_session, data=NotificationData(stream=stream))
if account.sms.use_cpim and account.sms.enable_imdn and content_type.lower() == IMDNDocument.content_type: if account.sms.use_cpim and account.sms.enable_imdn and content_type.lower() == IMDNDocument.content_type:
# print("-- IMDN received")
document = IMDNDocument.parse(body) document = IMDNDocument.parse(body)
imdn_message_id = document.message_id.value imdn_message_id = document.message_id.value
imdn_status = document.notification.status.__str__() imdn_status = document.notification.status.__str__()
...@@ -779,7 +805,9 @@ class MessageManager(object, metaclass=Singleton): ...@@ -779,7 +805,9 @@ class MessageManager(object, metaclass=Singleton):
notification_center.post_notification('BlinkGotDispositionNotification', sender=blink_session, data=NotificationData(id=imdn_message_id, status=imdn_status)) notification_center.post_notification('BlinkGotDispositionNotification', sender=blink_session, data=NotificationData(id=imdn_message_id, status=imdn_status))
return return
elif content_type.lower() == IMDNDocument.content_type: elif content_type.lower() == IMDNDocument.content_type:
# print("-- IMDN received, ignored")
return return
if content_type.lower() in ['text/pgp-public-key', 'text/pgp-private-key']: if content_type.lower() in ['text/pgp-public-key', 'text/pgp-private-key']:
notification_center.post_notification('PGPKeysShouldReload', sender=blink_session) notification_center.post_notification('PGPKeysShouldReload', sender=blink_session)
return return
...@@ -801,7 +829,7 @@ class MessageManager(object, metaclass=Singleton): ...@@ -801,7 +829,7 @@ class MessageManager(object, metaclass=Singleton):
if not content_type.lower().startswith('text'): if not content_type.lower().startswith('text'):
return return
if account is not blink_session.account: if x_replicated_message or account is not blink_session.account:
history_message_data = NotificationData(remote_uri=contact.uri.uri, history_message_data = NotificationData(remote_uri=contact.uri.uri,
message=message, message=message,
encryption=encryption, encryption=encryption,
...@@ -816,13 +844,12 @@ class MessageManager(object, metaclass=Singleton): ...@@ -816,13 +844,12 @@ class MessageManager(object, metaclass=Singleton):
if account is blink_session.account: if account is blink_session.account:
notification_center.post_notification('BlinkMessageIsParsed', sender=blink_session, data=message) notification_center.post_notification('BlinkMessageIsParsed', sender=blink_session, data=message)
self._add_contact_to_messages_group(blink_session.account, blink_session.contact) self._add_contact_to_messages_group(blink_session.account, blink_session.contact)
notification_center.post_notification('BlinkGotMessage', sender=blink_session, data=message) notification_center.post_notification('BlinkGotMessage',
sender=blink_session,
data=message)
return return
self._handle_incoming_message(message, blink_session, account) self._handle_incoming_message(message, blink_session, account)
else:
# TODO handle replicated messages
pass
def _NH_BlinkSessionWasCreated(self, notification): def _NH_BlinkSessionWasCreated(self, notification):
session = notification.sender session = notification.sender
......
...@@ -262,6 +262,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -262,6 +262,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self.message_imdn_enabled_button.clicked.connect(self._SH_EnableMessageIMDNButtonClicked) self.message_imdn_enabled_button.clicked.connect(self._SH_EnableMessageIMDNButtonClicked)
self.message_add_unknown_contacts_button.clicked.connect(self._SH_AddUnknownContactsButtonClicked) self.message_add_unknown_contacts_button.clicked.connect(self._SH_AddUnknownContactsButtonClicked)
self.message_pgp_enabled_button.clicked.connect(self._SH_EnablePGPButtonClicked) self.message_pgp_enabled_button.clicked.connect(self._SH_EnablePGPButtonClicked)
self.message_replication_button.clicked.connect(self._SH_MessageReplicationButtonClicked)
# Audio devices # Audio devices
self.audio_alert_device_button.activated[int].connect(self._SH_AudioAlertDeviceButtonActivated) self.audio_alert_device_button.activated[int].connect(self._SH_AudioAlertDeviceButtonActivated)
...@@ -901,9 +902,15 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -901,9 +902,15 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
self.prefix_button.addItem(item_text) self.prefix_button.addItem(item_text)
self.prefix_button.setCurrentIndex(self.prefix_button.findText(item_text)) self.prefix_button.setCurrentIndex(self.prefix_button.findText(item_text))
self._update_pstn_example_label() self._update_pstn_example_label()
# Messages tab
self.message_replication_button.show()
self.message_replication_button.setChecked(account.sms.enable_message_replication)
else: else:
self.account_auto_answer.setText('Auto answer from all neighbours') self.account_auto_answer.setText('Auto answer from all neighbours')
self.message_replication_button.hide()
def update_chat_preview(self): def update_chat_preview(self):
blink_settings = BlinkSettings() blink_settings = BlinkSettings()
...@@ -1455,6 +1462,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -1455,6 +1462,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
account.sms.enable_pgp = checked account.sms.enable_pgp = checked
account.save() account.save()
def _SH_MessageReplicationButtonClicked(self, checked):
account = self.selected_account
account.sms.enable_message_replication = checked
account.save()
# Audio devices signal handlers # Audio devices signal handlers
def _SH_AudioAlertDeviceButtonActivated(self, index): def _SH_AudioAlertDeviceButtonActivated(self, index):
device = self.audio_alert_device_button.itemData(index) device = self.audio_alert_device_button.itemData(index)
......
...@@ -1279,44 +1279,52 @@ ...@@ -1279,44 +1279,52 @@
</size> </size>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin"> <item row="3" column="0" colspan="2">
<number>0</number> <widget class="QCheckBox" name="message_iscomposing_enabled_button">
</property> <property name="text">
<property name="topMargin"> <string>Enable Is-Composing</string>
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property> </property>
<item row="11" column="1"> </widget>
<widget class="QCheckBox" name="message_add_unknown_contacts_button"> </item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="message_cpim_enabled_button">
<property name="text"> <property name="text">
<string>Add unknown contacts to 'Messages' group in your contacts</string> <string>Use CPIM envelope</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="1"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="message_label">
<property name="enabled"> <property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>When sending messages</string>
</property>
<property name="scaledContents">
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget>
</item>
<item row="12" column="0" colspan="2">
<widget class="QCheckBox" name="message_replication_button">
<property name="text"> <property name="text">
<string>If you turn off IMDN you won't be able to see receipts from other people</string> <string>Handle server replicated messages</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1"> <item row="8" column="0" colspan="2">
<widget class="Line" name="line_4"> <widget class="QCheckBox" name="message_add_unknown_contacts_button">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Add unknown contacts to 'Messages' group in your contacts</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="10" column="0" colspan="2">
<widget class="QLabel" name="message_label"> <widget class="QLabel" name="history_label">
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
...@@ -1324,35 +1332,32 @@ ...@@ -1324,35 +1332,32 @@
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>When sending messages</string> <string>History and synchronization</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1"> <item row="9" column="0" colspan="2">
<widget class="QCheckBox" name="message_imdn_enabled_button"> <widget class="QCheckBox" name="message_pgp_enabled_button">
<property name="text"> <property name="text">
<string>Enable IMDN (Read receipts)</string> <string>Enable message encryption with OpenPGP (if supported by receiver)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="1" column="0" colspan="2">
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="message_iscomposing_enabled_button"> <widget class="QCheckBox" name="message_imdn_enabled_button">
<property name="text"> <property name="text">
<string>Enable Is-Composing</string> <string>Enable IMDN (Read receipts)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="4" column="0" colspan="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="font"> <property name="font">
<font> <font>
...@@ -1365,23 +1370,46 @@ ...@@ -1365,23 +1370,46 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="message_cpim_enabled_button"> <widget class="QLabel" name="label_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>Use CPIM envelope</string> <string>If you turn off IMDN you won't be able to see receipts from other people</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="1"> <item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="message_pgp_enabled_button"> <widget class="Line" name="line_4">
<property name="text"> <property name="orientation">
<string>Enable message encryption with OpenPGP (if supported by receiver)</string> <enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<widget class="Line" name="history_line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="advanced_tab"> <widget class="QWidget" name="advanced_tab">
...@@ -2973,14 +3001,14 @@ ...@@ -2973,14 +3001,14 @@
<string>File Logging Settings</string> <string>File Logging Settings</string>
</property> </property>
<layout class="QGridLayout" name="logging_group_box_layout"> <layout class="QGridLayout" name="logging_group_box_layout">
<item row="0" column="0" colspan="5"> <item row="0" column="0">
<widget class="QCheckBox" name="trace_sip_button"> <widget class="QCheckBox" name="trace_sip_button">
<property name="text"> <property name="text">
<string>Trace SIP</string> <string>Trace SIP</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="5">
<widget class="QCheckBox" name="trace_messaging_button"> <widget class="QCheckBox" name="trace_messaging_button">
<property name="text"> <property name="text">
<string>Trace SIP Messaging and PGP Encryption</string> <string>Trace SIP Messaging and PGP Encryption</string>
......
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