Skip to content

Commit

Permalink
make function more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverabrahams committed Oct 14, 2024
1 parent 94e6b3e commit 762bbdc
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions common/app/model/dotcomrendering/pageElements/PageElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1817,55 +1817,54 @@ object PageElement {
}

private def audioToPageElement(element: ApiBlockElement) = {
for {
d <- element.audioTypeData
html = d.html.getOrElse("")
mandatory = true
thirdPartyTracking = containsThirdPartyTracking(element.tracking)
} yield {
if (html.isEmpty) {
AudioBlockElement(element.assets.toList.map(asset => AudioAsset.make(asset, Some(d))))
} else {
/*
comment id: 2e5ac4fd-e7f1-4c04-bdcd-ceadd2dc5d4c

element.audioTypeData.map { d =>
val mandatory = true
val thirdPartyTracking = containsThirdPartyTracking(element.tracking)
/*
comment id: 2e5ac4fd-e7f1-4c04-bdcd-ceadd2dc5d4c
Audio is a versatile carrier. It carries both audio and, incorrectly, non audio (in legacy content).
The audioToPageElement function performs the transformation of an Audio element to the appropriate
PageElement.
The function returns either:
1. SoundcloudBlockElement
2. SpotifyBlockElement
3. EmbedBlockElement
4. AudioBlockElement (currently: an error message)
1. SoundcloudBlockElement
2. SpotifyBlockElement
3. EmbedBlockElement
4. AudioBlockElement
Note: EmbedBlockElement is returned by both extractChartDatawrapperEmbedBlockElement and extractGenericEmbedBlockElement
The former catches charts from charts-datawrapper.s3.amazonaws.com while the latter captures any iframe.
Note: AudioBlockElement is currently a catch all element which helps identify when Audio is carrying an incorrect
payload. It was decided that handling those as they come up will be an ongoing health task of the dotcom team,
and not part of the original DCR migration.
*/
extractSoundcloudBlockElement(html, mandatory, thirdPartyTracking, d.source, d.sourceDomain)
.getOrElse {
extractSpotifyBlockElement(element, thirdPartyTracking).getOrElse {
*/
d.html
.flatMap { html =>
extractSoundcloudBlockElement(html, mandatory, thirdPartyTracking, d.source, d.sourceDomain)
.orElse {
extractSpotifyBlockElement(element, thirdPartyTracking)
}
.orElse {
extractChartDatawrapperEmbedBlockElement(
html,
d.role,
thirdPartyTracking,
d.source,
d.sourceDomain,
d.caption,
).getOrElse {
extractGenericEmbedBlockElement(html, d.role, thirdPartyTracking, d.source, d.sourceDomain, d.caption)
.getOrElse {
AudioBlockElement(element.assets.toList.map(asset => AudioAsset.make(asset, Some(d))))
}
}
)
}
}
}
.orElse {
extractGenericEmbedBlockElement(
html,
d.role,
thirdPartyTracking,
d.source,
d.sourceDomain,
d.caption,
)
}
}
.getOrElse {
AudioBlockElement(element.assets.toList.map(asset => AudioAsset.make(asset, Some(d))))
}
}
}

Expand Down

0 comments on commit 762bbdc

Please sign in to comment.