2019-05-29 17:40:16 +02:00
|
|
|
import SHA1 from 'strophe.js/src/sha1';
|
2021-05-11 16:09:36 +02:00
|
|
|
import { _converse, converse } from '@converse/headless/core';
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2020-03-06 15:19:48 +01:00
|
|
|
const { Strophe, $build } = converse.env;
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
function propertySort (array, property) {
|
|
|
|
return array.sort((a, b) => { return a[property] > b[property] ? -1 : 1 });
|
|
|
|
}
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2021-05-11 16:09:36 +02:00
|
|
|
function generateVerificationString () {
|
2019-10-24 14:29:15 +02:00
|
|
|
const identities = _converse.api.disco.own.identities.get();
|
|
|
|
const features = _converse.api.disco.own.features.get();
|
2018-05-11 13:31:48 +02:00
|
|
|
|
2018-10-23 03:41:38 +02:00
|
|
|
if (identities.length > 1) {
|
|
|
|
propertySort(identities, "category");
|
|
|
|
propertySort(identities, "type");
|
|
|
|
propertySort(identities, "lang");
|
2018-05-11 13:31:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 11:13:13 +02:00
|
|
|
let S = identities.reduce((result, id) => `${result}${id.category}/${id.type}/${id?.lang ?? ''}/${id.name}<`, "");
|
2018-10-23 03:41:38 +02:00
|
|
|
features.sort();
|
2020-03-06 15:19:48 +01:00
|
|
|
S = features.reduce((result, feature) => `${result}${feature}<`, S);
|
2019-05-29 17:40:16 +02:00
|
|
|
return SHA1.b64_sha1(S);
|
2018-10-23 03:41:38 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:09:36 +02:00
|
|
|
export function createCapsNode () {
|
2018-10-23 03:41:38 +02:00
|
|
|
return $build("c", {
|
|
|
|
'xmlns': Strophe.NS.CAPS,
|
|
|
|
'hash': "sha-1",
|
|
|
|
'node': "https://conversejs.org",
|
2021-05-11 16:09:36 +02:00
|
|
|
'ver': generateVerificationString()
|
2018-10-23 03:41:38 +02:00
|
|
|
}).nodeTree;
|
|
|
|
}
|