xmpp: Implement retrieving the device bundle
This commit is contained in:
@@ -216,7 +216,9 @@ class PubSubManager extends XmppManagerBase {
|
||||
XMLNode.xmlns(
|
||||
tag: 'pubsub',
|
||||
xmlns: pubsubXmlns,
|
||||
children: [ XMLNode(tag: 'items', attributes: <String, String>{ 'node': node }) ],
|
||||
children: [
|
||||
XMLNode(tag: 'items', attributes: <String, String>{ 'node': node }),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
@@ -238,4 +240,43 @@ class PubSubManager extends XmppManagerBase {
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<PubSubItem?> getItem(String jid, String node, String id) async {
|
||||
final result = await getAttributes().sendStanza(
|
||||
Stanza.iq(
|
||||
type: 'get',
|
||||
to: jid,
|
||||
children: [
|
||||
XMLNode.xmlns(
|
||||
tag: 'pubsub',
|
||||
xmlns: pubsubXmlns,
|
||||
children: [
|
||||
XMLNode(
|
||||
tag: 'items',
|
||||
attributes: <String, String>{ 'node': node },
|
||||
children: [
|
||||
XMLNode(
|
||||
tag: 'item',
|
||||
attributes: <String, String>{ 'id': id },
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (result.attributes['type'] != 'result') return null;
|
||||
|
||||
final pubsub = result.firstTag('pubsub', xmlns: pubsubXmlns);
|
||||
if (pubsub == null) return null;
|
||||
|
||||
final item = pubsub.firstTag('items')!.firstTag('item')!;
|
||||
return PubSubItem(
|
||||
id: item.attributes['id']! as String,
|
||||
payload: item.children[0],
|
||||
node: node,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,16 +44,40 @@ class OmemoManager extends XmppManagerBase {
|
||||
Future<void> commitState() async {}
|
||||
|
||||
/// Retrieves the OMEMO device list from [jid].
|
||||
Future<List<int>?> getDeviceList(JID jid) async {
|
||||
Future<List<int>?> retrieveDeviceList(JID jid) async {
|
||||
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
|
||||
final items = await pm.getItems(jid.toBare().toString(), omemoDevicesXmlns);
|
||||
if (items == null) return null;
|
||||
|
||||
final item = items.first.payload;
|
||||
final devicesElement = item.firstTag('devices', xmlns: omemoXmlns)!;
|
||||
|
||||
return devicesElement.children
|
||||
return items.first.payload.children
|
||||
.map((child) => int.parse(child.attributes['id']! as String))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Retrieves a bundle from entity [jid] with the device id [deviceId].
|
||||
Future<OmemoBundle?> retrieveDeviceBundle(JID jid, int deviceId) async {
|
||||
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
|
||||
final bareJid = jid.toBare().toString();
|
||||
final item = await pm.getItem(bareJid, omemoBundlesXmlns, '$deviceId');
|
||||
if (item == null) return null;
|
||||
|
||||
final spk = item.payload.firstTag('spk')!;
|
||||
final spks = item.payload.firstTag('spks')!;
|
||||
final ik = item.payload.firstTag('ik')!;
|
||||
final prekeysElement = item.payload.firstTag('prekeys')!;
|
||||
final prekeys = <int, String>{};
|
||||
for (final prekey in prekeysElement.children) {
|
||||
prekeys[int.parse(prekey.attributes['id']! as String)] = prekey.innerText();
|
||||
}
|
||||
|
||||
return OmemoBundle(
|
||||
bareJid,
|
||||
deviceId,
|
||||
spk.innerText(),
|
||||
int.parse(spk.attributes['id']! as String),
|
||||
spks.innerText(),
|
||||
ik.innerText(),
|
||||
prekeys,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user