-
-
Notifications
You must be signed in to change notification settings - Fork 776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Split OMEMO plugin into view and headless components #3117
Draft
badrihippo
wants to merge
6
commits into
conversejs:master
Choose a base branch
from
badrihippo:headless-omemo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
151c698
Split omemo/utils.js into headless and UI versions
badrihippo dcbde1f
Split 'omemo-views/index.js' into headless and UI plugins
badrihippo daebbdf
Split 'handleEncryptedFiles' into headless and UI bits
badrihippo d0d5bfd
Remove extra "move to headless" TODOs
badrihippo 1a40ab5
Split omemo.util.onChatInitialized into headless/UI
badrihippo 9963d81
Remove extra import lines
badrihippo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* @copyright The Converse.js contributors | ||
* @license Mozilla Public License (MPLv2) | ||
*/ | ||
import ConverseMixins from './mixins/converse.js'; | ||
import omemo_api from './api.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 { _converse, api, converse } from '@converse/headless/core'; | ||
|
||
import { | ||
createOMEMOMessageStanza, | ||
encryptFile, | ||
getOutgoingMessageAttributes, | ||
handleEncryptedFiles, | ||
handleMessageSendError, | ||
initOMEMO, | ||
omemo, | ||
onChatBoxesInitialized, | ||
parseEncryptedMessage, | ||
registerPEPPushHandler | ||
setEncryptedFileURL, | ||
} from './utils.js' | ||
|
||
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'); | ||
|
||
|
||
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-views') | ||
); | ||
}, | ||
|
||
dependencies: ['converse-chat', 'converse-pubsub'], | ||
|
||
initialize() { | ||
api.settings.extend({ 'omemo-default': false }); | ||
api.promises.add(['OMEMOInitialized']); | ||
|
||
_converse.NUM_PREKEYS = 100; // Set here so that tests can override | ||
|
||
Object.assign(_converse, ConverseMixins); | ||
Object.assign(_converse.api, omemo_api); | ||
|
||
_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('getOutgoingMessageAttributes', getOutgoingMessageAttributes); | ||
|
||
api.listen.on('createMessageStanza', async (chat, data) => { | ||
try { | ||
data = await createOMEMOMessageStanza(chat, data); | ||
} catch (e) { | ||
handleMessageSendError(e, chat); | ||
} | ||
return data; | ||
}); | ||
|
||
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('connected', registerPEPPushHandler); | ||
|
||
api.listen.on('statusInitialized', initOMEMO); | ||
api.listen.on('addClientFeatures', () => api.disco.own.features.add(`${Strophe.NS.OMEMO_DEVICELIST}+notify`)); | ||
|
||
api.listen.on('afterMessageBodyTransformed', handleEncryptedFiles); | ||
|
||
api.listen.on('clearSession', () => { | ||
delete _converse.omemo_store | ||
if (_converse.shouldClearCache() && _converse.devicelists) { | ||
_converse.devicelists.clearStore(); | ||
delete _converse.devicelists; | ||
} | ||
}); | ||
} | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this file can also be moved to the headless plugin. Generally speaking, all models should go into headless, and
OMEMOStore
is a model.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, okay! All the tests passed but when I tried running in the browser it's not actually running. So let me debug that and then I'll get to this 🙂