fix(xep): Fix crash when the device list node is empty

This commit is contained in:
PapaTutuWawa 2024-10-19 21:45:18 +02:00
parent db77790bf4
commit 9eb94e5f48
2 changed files with 8 additions and 1 deletions

View File

@ -4,6 +4,10 @@ class UnknownOmemoError extends OmemoError {}
class InvalidAffixElementsException implements Exception {} class InvalidAffixElementsException implements Exception {}
/// Internal exception that is returned when the device list cannot be
/// fetched because the returned list is empty.
class EmptyDeviceListException implements OmemoError {}
class OmemoNotSupportedForContactException extends OmemoError {} class OmemoNotSupportedForContactException extends OmemoError {}
class EncryptionFailedException implements Exception {} class EncryptionFailedException implements Exception {}

View File

@ -535,7 +535,10 @@ class OmemoManager extends XmppManagerBase {
final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!; final pm = getAttributes().getManagerById<PubSubManager>(pubsubManager)!;
final result = await pm.getItems(jid.toBare(), omemoDevicesXmlns); final result = await pm.getItems(jid.toBare(), omemoDevicesXmlns);
if (result.isType<PubSubError>()) return Result(UnknownOmemoError()); if (result.isType<PubSubError>()) return Result(UnknownOmemoError());
return Result(result.get<List<PubSubItem>>().first.payload);
final itemList = result.get<List<PubSubItem>>();
if (itemList.isEmpty) return Result(EmptyDeviceListException());
return Result(itemList.first.payload);
} }
/// Retrieves the OMEMO device list from [jid]. /// Retrieves the OMEMO device list from [jid].