2019-07-11 10:48:52 +02:00
|
|
|
/**
|
2020-01-26 16:21:20 +01:00
|
|
|
* @copyright The Converse.js contributors
|
2019-09-19 16:54:55 +02:00
|
|
|
* @license Mozilla Public License (MPLv2)
|
2019-07-11 10:48:52 +02:00
|
|
|
*/
|
2021-11-24 00:25:07 +01:00
|
|
|
import './fingerprints.js';
|
2021-11-24 20:38:13 +01:00
|
|
|
import './profile.js';
|
2021-04-12 04:29:00 +02:00
|
|
|
import 'modals/user-details.js';
|
|
|
|
import 'plugins/profile/index.js';
|
|
|
|
import ChatBox from './overrides/chatbox.js';
|
|
|
|
import ConverseMixins from './mixins/converse.js';
|
|
|
|
import Device from './device.js';
|
|
|
|
import DeviceList from './devicelist.js';
|
|
|
|
import DeviceLists from './devicelists.js';
|
|
|
|
import Devices from './devices.js';
|
|
|
|
import OMEMOStore from './store.js';
|
2021-04-11 19:51:58 +02:00
|
|
|
import log from '@converse/headless/log';
|
2021-04-12 04:29:00 +02:00
|
|
|
import omemo_api from './api.js';
|
|
|
|
import { OMEMOEnabledChatBox } from './mixins/chatbox.js';
|
2021-04-11 19:51:58 +02:00
|
|
|
import { _converse, api, converse } from '@converse/headless/core';
|
|
|
|
import {
|
2021-07-01 12:57:28 +02:00
|
|
|
encryptFile,
|
2021-04-11 19:51:58 +02:00
|
|
|
getOMEMOToolbarButton,
|
2021-06-24 20:20:02 +02:00
|
|
|
handleEncryptedFiles,
|
2021-04-11 19:51:58 +02:00
|
|
|
initOMEMO,
|
2021-04-12 04:29:00 +02:00
|
|
|
omemo,
|
2021-04-11 19:51:58 +02:00
|
|
|
onChatBoxesInitialized,
|
|
|
|
onChatInitialized,
|
|
|
|
parseEncryptedMessage,
|
2021-07-01 12:57:28 +02:00
|
|
|
setEncryptedFileURL,
|
2021-04-11 19:51:58 +02:00
|
|
|
registerPEPPushHandler,
|
|
|
|
} from './utils.js';
|
|
|
|
|
2021-04-12 04:29:00 +02:00
|
|
|
const { Strophe } = converse.env;
|
|
|
|
|
|
|
|
converse.env.omemo = omemo;
|
2021-04-11 19:51:58 +02:00
|
|
|
|
|
|
|
Strophe.addNamespace('OMEMO_DEVICELIST', Strophe.NS.OMEMO + '.devicelist');
|
|
|
|
Strophe.addNamespace('OMEMO_VERIFICATION', Strophe.NS.OMEMO + '.verification');
|
|
|
|
Strophe.addNamespace('OMEMO_WHITELISTED', Strophe.NS.OMEMO + '.whitelisted');
|
|
|
|
Strophe.addNamespace('OMEMO_BUNDLES', Strophe.NS.OMEMO + '.bundles');
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2020-11-18 10:49:31 +01:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
converse.plugins.add('converse-omemo', {
|
|
|
|
enabled (_converse) {
|
2021-04-11 19:51:58 +02:00
|
|
|
return (
|
|
|
|
window.libsignal &&
|
2020-11-02 13:22:00 +01:00
|
|
|
_converse.config.get('trusted') &&
|
|
|
|
!api.settings.get('clear_cache_on_logout') &&
|
2021-04-11 19:51:58 +02:00
|
|
|
!_converse.api.settings.get('blacklisted_plugins').includes('converse-omemo')
|
|
|
|
);
|
2018-10-23 03:41:38 +02:00
|
|
|
},
|
|
|
|
|
2021-11-24 20:38:13 +01:00
|
|
|
dependencies: ['converse-chatview', 'converse-pubsub'],
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2021-11-24 20:38:13 +01:00
|
|
|
overrides: { ChatBox },
|
2019-05-24 13:52:15 +02:00
|
|
|
|
|
|
|
initialize () {
|
2021-04-11 19:51:58 +02:00
|
|
|
api.settings.extend({ 'omemo_default': false });
|
2020-03-31 13:15:57 +02:00
|
|
|
api.promises.add(['OMEMOInitialized']);
|
2019-05-24 13:52:15 +02:00
|
|
|
|
|
|
|
_converse.NUM_PREKEYS = 100; // Set here so that tests can override
|
|
|
|
|
|
|
|
Object.assign(_converse.ChatBox.prototype, OMEMOEnabledChatBox);
|
2021-04-12 04:29:00 +02:00
|
|
|
Object.assign(_converse, ConverseMixins);
|
|
|
|
Object.assign(_converse.api, omemo_api);
|
2018-05-11 17:31:49 +02:00
|
|
|
|
2021-04-12 04:29:00 +02:00
|
|
|
_converse.OMEMOStore = OMEMOStore;
|
|
|
|
_converse.Device = Device;
|
|
|
|
_converse.Devices = Devices;
|
|
|
|
_converse.DeviceList = DeviceList;
|
|
|
|
_converse.DeviceLists = DeviceLists;
|
2018-05-11 17:31:49 +02:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
/******************** Event Handlers ********************/
|
2020-11-18 10:49:31 +01:00
|
|
|
api.waitUntil('chatBoxesInitialized').then(onChatBoxesInitialized);
|
|
|
|
|
2021-07-01 12:57:28 +02:00
|
|
|
api.listen.on('afterFileUploaded', (msg, attrs) => msg.file.xep454_ivkey ? setEncryptedFileURL(msg, attrs) : attrs);
|
|
|
|
api.listen.on('beforeFileUpload', (chat, file) => chat.get('omemo_active') ? encryptFile(file) : file);
|
|
|
|
|
2020-09-06 12:30:30 +02:00
|
|
|
api.listen.on('parseMessage', parseEncryptedMessage);
|
|
|
|
api.listen.on('parseMUCMessage', parseEncryptedMessage);
|
2019-08-01 10:26:35 +02:00
|
|
|
|
2020-06-08 12:12:49 +02:00
|
|
|
api.listen.on('chatBoxViewInitialized', onChatInitialized);
|
|
|
|
api.listen.on('chatRoomViewInitialized', onChatInitialized);
|
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('connected', registerPEPPushHandler);
|
2020-06-08 12:12:49 +02:00
|
|
|
api.listen.on('getToolbarButtons', getOMEMOToolbarButton);
|
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('statusInitialized', initOMEMO);
|
2021-04-11 19:51:58 +02:00
|
|
|
api.listen.on('addClientFeatures', () => api.disco.own.features.add(`${Strophe.NS.OMEMO_DEVICELIST}+notify`));
|
2018-10-23 03:41:38 +02:00
|
|
|
|
2021-06-24 20:20:02 +02:00
|
|
|
api.listen.on('afterMessageBodyTransformed', handleEncryptedFiles);
|
|
|
|
|
2020-11-18 10:49:31 +01:00
|
|
|
api.listen.on('userDetailsModalInitialized', contact => {
|
2018-10-23 03:41:38 +02:00
|
|
|
const jid = contact.get('jid');
|
2019-11-06 11:01:34 +01:00
|
|
|
_converse.generateFingerprints(jid).catch(e => log.error(e));
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('profileModalInitialized', () => {
|
2019-11-06 11:01:34 +01:00
|
|
|
_converse.generateFingerprints(_converse.bare_jid).catch(e => log.error(e));
|
2018-10-23 03:41:38 +02:00
|
|
|
});
|
2018-11-12 15:12:33 +01:00
|
|
|
|
2020-03-31 13:15:57 +02:00
|
|
|
api.listen.on('clearSession', () => {
|
2022-02-02 14:10:19 +01:00
|
|
|
delete _converse.omemo_store
|
2019-08-01 10:26:35 +02:00
|
|
|
if (_converse.shouldClearCache() && _converse.devicelists) {
|
2019-09-19 16:54:55 +02:00
|
|
|
_converse.devicelists.clearStore();
|
2019-08-01 10:26:35 +02:00
|
|
|
delete _converse.devicelists;
|
|
|
|
}
|
|
|
|
});
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
});
|