From 9eb94e5f488f795e74f46ceb3ec62fc355f2e1d4 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 19 Oct 2024 21:45:18 +0200 Subject: [PATCH] fix(xep): Fix crash when the device list node is empty --- packages/moxxmpp/lib/src/xeps/xep_0384/errors.dart | 4 ++++ packages/moxxmpp/lib/src/xeps/xep_0384/xep_0384.dart | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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].