xmpp.chapril.org-conversejs/src/plugins/omemo/index.js

111 lines
3.9 KiB
JavaScript
Raw Normal View History

/**
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)
*/
import './fingerprints.js';
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';
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';
import { _converse, api, converse } from '@converse/headless/core';
import {
encryptFile,
getOMEMOToolbarButton,
handleEncryptedFiles,
initOMEMO,
2021-04-12 04:29:00 +02:00
omemo,
onChatBoxesInitialized,
onChatInitialized,
parseEncryptedMessage,
setEncryptedFileURL,
registerPEPPushHandler,
} from './utils.js';
2021-04-12 04:29:00 +02:00
const { Strophe } = converse.env;
converse.env.omemo = omemo;
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
2018-10-23 03:41:38 +02:00
converse.plugins.add('converse-omemo', {
enabled (_converse) {
return (
window.libsignal &&
_converse.config.get('trusted') &&
!api.settings.get('clear_cache_on_logout') &&
!_converse.api.settings.get('blacklisted_plugins').includes('converse-omemo')
);
2018-10-23 03:41:38 +02:00
},
dependencies: ['converse-chatview', 'converse-pubsub'],
2018-10-23 03:41:38 +02:00
overrides: { ChatBox },
2019-05-24 13:52:15 +02:00
initialize () {
api.settings.extend({ 'omemo_default': false });
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);
2021-04-12 04:29:00 +02:00
_converse.OMEMOStore = OMEMOStore;
_converse.Device = Device;
_converse.Devices = Devices;
_converse.DeviceList = DeviceList;
_converse.DeviceLists = DeviceLists;
/******************** Event Handlers ********************/
api.waitUntil('chatBoxesInitialized').then(onChatBoxesInitialized);
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);
api.listen.on('parseMessage', parseEncryptedMessage);
api.listen.on('parseMUCMessage', parseEncryptedMessage);
api.listen.on('chatBoxViewInitialized', onChatInitialized);
api.listen.on('chatRoomViewInitialized', onChatInitialized);
api.listen.on('connected', registerPEPPushHandler);
api.listen.on('getToolbarButtons', getOMEMOToolbarButton);
api.listen.on('statusInitialized', initOMEMO);
api.listen.on('addClientFeatures', () => api.disco.own.features.add(`${Strophe.NS.OMEMO_DEVICELIST}+notify`));
2018-10-23 03:41:38 +02:00
api.listen.on('afterMessageBodyTransformed', handleEncryptedFiles);
api.listen.on('userDetailsModalInitialized', contact => {
2018-10-23 03:41:38 +02:00
const jid = contact.get('jid');
_converse.generateFingerprints(jid).catch(e => log.error(e));
2018-10-23 03:41:38 +02:00
});
api.listen.on('profileModalInitialized', () => {
_converse.generateFingerprints(_converse.bare_jid).catch(e => log.error(e));
2018-10-23 03:41:38 +02:00
});
api.listen.on('clearSession', () => {
delete _converse.omemo_store
if (_converse.shouldClearCache() && _converse.devicelists) {
2019-09-19 16:54:55 +02:00
_converse.devicelists.clearStore();
delete _converse.devicelists;
}
});
2018-10-23 03:41:38 +02:00
}
});