Skip to content

Commit

Permalink
Merge pull request #27560 from guardian/e2e/audio-in-dcr-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs authored Oct 28, 2024
2 parents ba57677 + d3ac9d0 commit c1f98b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 6 additions & 12 deletions applications/app/services/dotcomrendering/MediaPicker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@ import model.Cors.RichRequestHeader
import model.{MediaPage, Video, Audio}
import play.api.mvc.RequestHeader
import utils.DotcomponentsLogger
import navigation.NavLinks.media
import experiments.ActiveExperiments
import conf.switches.Switches.DCRVideoPages
import conf.switches.Switches.{DCRAudioPages, DCRVideoPages}

object MediaPicker extends GuLogging {

/** Add to this function any logic for including/excluding an audio/video article from being rendered with DCR
*
* Currently defaulting to false until we implement in DCR
*/
private def dcrCouldRender(mediaPage: MediaPage): Boolean = {
private def dcrShouldRender(mediaPage: MediaPage): Boolean = {
mediaPage.media match {
case Video(content, source, mediaAtom) => true
case Audio(content) => false
case Audio(content) => DCRAudioPages.isSwitchedOn
case Video(content, source, mediaAtom) => DCRVideoPages.isSwitchedOn
case _ => false
}
}

private def dcrLogFlags(mediaPage: MediaPage): Map[String, String] = {
Map(
("isVideo", mediaPage.media.isInstanceOf[Video].toString()),
("isAudio", mediaPage.media.isInstanceOf[Audio].toString()),
("isVideo", mediaPage.media.isInstanceOf[Video].toString()),
)
}

Expand All @@ -35,14 +31,12 @@ object MediaPicker extends GuLogging {
)(implicit
request: RequestHeader,
): RenderType = {

val dcrCanRender = dcrCouldRender(mediaPage)
val flags = dcrLogFlags(mediaPage)

val tier = {
if (request.forceDCROff) LocalRender
else if (request.forceDCR) RemoteRender
else if (dcrCanRender && DCRVideoPages.isSwitchedOn) RemoteRender
else if (dcrShouldRender(mediaPage)) RemoteRender
else LocalRender
}

Expand Down
10 changes: 10 additions & 0 deletions common/app/conf/switches/FeatureSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ trait FeatureSwitches {
exposeClientSide = true,
)

val DCRAudioPages = Switch(
SwitchGroup.Feature,
"dcr-audio-pages",
"If this switch is on, we will render audio pages with DCR",
owners = Seq(Owner.withEmail("[email protected]"), Owner.withEmail("[email protected]")),
safeState = Off,
sellByDate = never,
exposeClientSide = false,
)

val DCRVideoPages = Switch(
SwitchGroup.Feature,
"dcr-video-pages",
Expand Down

0 comments on commit c1f98b2

Please sign in to comment.