Skip to content

Commit 267cdc2

Browse files
authored
Add Live Activity topics (#1773)
When a user is subscribed to a team, we will offer them a live activity whenever that team is playing a match, as an alternative to push notifications throughout the match. This live activity will be provided via a single notification when the match starts, and users with app versions that can support live activities will receive it by subscribing to topics of type `FootballTeamLiveActivity`. Users with app versions that do not support live activities will instead be subscribing to topics of type `FootballTeam`, which will deliver notifications throughout the match. A user may visit a match info page before a live activity for that match is available, as we only create it a couple of hours before the match starts. We still want them to be able to subscribe and get that live activity when it's ready, so we'll allow them to sign up to this notification topic instead. The live activity will then be provided via a single notification when the match starts. Users with app versions that do not support live activities will instead be subscribing to topics of type `FootballMatch`, which will deliver notifications throughout the match. This change adds two new `TopicType`s, `FootballTeamLiveActivity` and `FootballMatchLiveActivity`, and includes them in the notification payload for kick-off events only.
1 parent 10aee02 commit 267cdc2

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

api-models/src/main/scala/com/gu/mobile.notifications.client/models/Topic.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,30 @@ object TopicTypes {
2020
case object TagSeries extends TopicType { override val toString = "tag-series" }
2121
case object TagBlog extends TopicType { override val toString = "tag-blog" }
2222
case object FootballTeam extends TopicType { override val toString = "football-team" }
23+
/**
24+
* When a user is subscribed to a team, we will offer them a live activity
25+
* whenever that team is playing a match, as an alternative to push
26+
* notifications throughout the match. This live activity will be provided
27+
* via a single notification when the match starts, and users with app
28+
* versions that can support live activities will receive it by subscribing
29+
* to topics of type `FootballTeamLiveActivity`. Users with app versions that
30+
* do not support live activities will instead be subscribing to topics of
31+
* type `FootballTeam`, which will deliver notifications throughout the
32+
* match.
33+
*/
34+
case object FootballTeamLiveActivity extends TopicType { override val toString = "football-team-live-activity" }
2335
case object FootballMatch extends TopicType { override val toString = "football-match" }
36+
/**
37+
* A user may visit a match info page before a live activity for that match
38+
* is available, as we only create it a couple of hours before the match
39+
* starts. We still want them to be able to subscribe and get that live
40+
* activity when it's ready, so we'll allow them to sign up to this
41+
* notification topic instead. The live activity will then be provided via a
42+
* single notification when the match starts. Users with app versions that do
43+
* not support live activities will instead be subscribing to topics of type
44+
* `FootballMatch`, which will deliver notifications throughout the match.
45+
*/
46+
case object FootballMatchLiveActivity extends TopicType { override val toString = "football-match-live-activity" }
2447
case object User extends TopicType { override val toString = "user-type" }
2548
case object Newsstand extends TopicType { override val toString = "newsstand" }
2649
}

football/src/main/scala/com/gu/mobile/notifications/football/notificationbuilders/MatchStatusNotificationBuilder.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@ class MatchStatusNotificationBuilder(mapiHost: String) {
1717
previousEvents: List[FootballMatchEvent],
1818
articleId: Option[String]
1919
): FootballMatchStatusPayload = {
20+
val liveActivityTopics =
21+
if (triggeringEvent.isInstanceOf[KickOff])
22+
List(
23+
Topic(TopicTypes.FootballTeamLiveActivity, matchInfo.homeTeam.id),
24+
Topic(TopicTypes.FootballTeamLiveActivity, matchInfo.awayTeam.id),
25+
Topic(TopicTypes.FootballMatchLiveActivity, matchInfo.id)
26+
)
27+
else Nil
28+
2029
val topics = List(
2130
Topic(TopicTypes.FootballTeam, matchInfo.homeTeam.id),
2231
Topic(TopicTypes.FootballTeam, matchInfo.awayTeam.id),
2332
Topic(TopicTypes.FootballMatch, matchInfo.id)
24-
)
33+
) ++ liveActivityTopics
2534

2635
val allEvents = triggeringEvent :: previousEvents
2736
val goals = allEvents.collect { case g: Goal => g }

football/src/test/scala/com/gu/mobile/notifications/football/lib/EventConsumerSpec.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.gu.mobile.notifications.football.lib
33
import java.net.URI
44
import com.gu.mobile.notifications.client.models._
55
import com.gu.mobile.notifications.client.models.Importance.{Major, Minor}
6-
import com.gu.mobile.notifications.client.models.TopicTypes.{FootballMatch, FootballTeam}
6+
import com.gu.mobile.notifications.client.models.TopicTypes.{FootballMatch, FootballTeam, FootballTeamLiveActivity, FootballMatchLiveActivity}
77
import com.gu.mobile.notifications.client.models.liveActitivites.{CreateChannelEvent, EndLiveActivityEvent, LiveActivityPayload, StartLiveActivityEvent}
88
import com.gu.mobile.notifications.football.models.{MatchDataWithArticle, PenaltyShootoutKick}
99
import com.gu.mobile.notifications.football.notificationbuilders.{MatchStatusLiveActivityPayloadBuilder, MatchStatusNotificationBuilder}
@@ -47,7 +47,10 @@ class EventConsumerSpec(implicit ev: ExecutionEnv)
4747
topic = List(
4848
Topic(FootballTeam, "1006"),
4949
Topic(FootballTeam, "29"),
50-
Topic(FootballMatch, "4011135")
50+
Topic(FootballMatch, "4011135"),
51+
Topic(FootballTeamLiveActivity, "1006"),
52+
Topic(FootballTeamLiveActivity, "29"),
53+
Topic(FootballMatchLiveActivity, "4011135"),
5154
),
5255
matchStatus = "1st",
5356
eventId = "7e730fbe-b013-3a0e-89cb-12b46260d7be",

0 commit comments

Comments
 (0)