ReadElementsFromXml method

  1. @override
Future<void> ReadElementsFromXml(
  1. EwsServiceXmlReader reader
)
override
Read Photo results from XML. The reader.

Implementation

@override
Future<void> ReadElementsFromXml(EwsServiceXmlReader reader) async {
  bool hasChanged =
      await reader.ReadElementValueWithNamespace<bool>(
        XmlNamespace.Messages,
        XmlElementNames.HasChanged,
      ) ??
      false;

  await reader.ReadStartElementWithNamespace(
    XmlNamespace.Messages,
    XmlElementNames.PictureData,
  );
  Uint8List photoData = reader.IsEmptyElement
      ? Uint8List(0)
      : await reader.ReadBase64ElementValue();

  // We only get a content type if we get a photo
  if (photoData.isNotEmpty) {
    Results.Photo = photoData;
    Results.ContentType = await reader.ReadElementValueWithNamespace<String>(
      XmlNamespace.Messages,
      XmlElementNames.ContentType,
    );
  }

  if (hasChanged) {
    if (Results.Photo == null || Results.Photo!.isEmpty) {
      Results.Status = GetUserPhotoStatus.PhotoOrUserNotFound;
    } else {
      Results.Status = GetUserPhotoStatus.PhotoReturned;
    }
  } else {
    Results.Status = GetUserPhotoStatus.PhotoUnchanged;
  }
}