xmpp.chapril.org-conversejs/src/plugins/omemo/fingerprints.js
JC Brand bad2577e5e OMEMO Refactoring
When calling `getDeviceList`, wait for the devices to be fetched

Otherwise a race condition might occur, whereby a new device gets
created in the collection, and then removed again as the collection is
replaced with the values fetched from the browser-storage cache.

Also created `converse-omemo-fingerprints` component to asynchronously
render fingerprints in the user details modal. Was done as part of this
commit because due to `getDeviceList` being async, the relevant test for
the modal were also failing
2021-11-24 21:14:11 +01:00

35 lines
1.2 KiB
JavaScript

import tpl_fingerprints from './templates/fingerprints.js';
import { CustomElement } from 'shared/components/element.js';
import { _converse, api } from "@converse/headless/core";
export class Fingerprints extends CustomElement {
static get properties () {
return {
'jid': { type: String }
}
}
async initialize () {
this.devicelist = await _converse.devicelists.getDeviceList(this.jid);
this.listenTo(this.devicelist.devices, 'change:bundle', this.requestUpdate);
this.listenTo(this.devicelist.devices, 'change:trusted', this.requestUpdate);
this.listenTo(this.devicelist.devices, 'remove', this.requestUpdate);
this.listenTo(this.devicelist.devices, 'add', this.requestUpdate);
this.listenTo(this.devicelist.devices, 'reset', this.requestUpdate);
this.requestUpdate();
}
render () {
return this.devicelist ? tpl_fingerprints(this) : '';
}
toggleDeviceTrust (ev) {
const radio = ev.target;
const device = this.devicelist.devices.get(radio.getAttribute('name'));
device.save('trusted', parseInt(radio.value, 10));
}
}
api.elements.define('converse-omemo-fingerprints', Fingerprints);