# getLatestMetadata method

Future <Result<AvatarError, List <UserAvatarMetadata>>> getLatestMetadata(

1. JID jid

)

Attempts to fetch the latest item from the User Avatar metadata node. Returns the list of metadata contained within it. The list may be empty.

If an error occured, returns an AvatarError.

## Implementation

    Future<Result<AvatarError, List<UserAvatarMetadata>>> getLatestMetadata(
      JID jid,
    ) async {
      final resultsRaw = await _getPubSubManager()
          .getItems(jid, userAvatarMetadataXmlns, maxItems: 1);
      if (resultsRaw.isType<PubSubError>()) return Result(UnknownAvatarError());

      final results = resultsRaw.get<List<PubSubItem>>();
      if (results.isEmpty) {
        return Result(UnknownAvatarError());
      }

      return Result(
        results.first.payload
            .findTags('info')
            .map(UserAvatarMetadata.fromXML)
            .toList(),
      );
    }