diff --git a/packages/moxxmpp/lib/src/xeps/xep_0384/errors.dart b/packages/moxxmpp/lib/src/xeps/xep_0384/errors.dart index 9a54334..7c5ae75 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0384/errors.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0384/errors.dart @@ -4,6 +4,10 @@ class UnknownOmemoError extends OmemoError {} 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 EncryptionFailedException implements Exception {} diff --git a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart index 2edbb54..5d24875 100644 --- a/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart +++ b/packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart @@ -535,7 +535,10 @@ class OmemoManager extends XmppManagerBase { final pm = getAttributes().getManagerById(pubsubManager)!; final result = await pm.getItems(jid.toBare(), omemoDevicesXmlns); if (result.isType()) return Result(UnknownOmemoError()); - return Result(result.get>().first.payload); + + final itemList = result.get>(); + if (itemList.isEmpty) return Result(EmptyDeviceListException()); + return Result(itemList.first.payload); } /// Retrieves the OMEMO device list from [jid].