better push notification stacking

This commit is contained in:
Thibault Duplessis 2016-12-05 16:53:37 +01:00
parent c58628b7a0
commit 3549738712
3 changed files with 22 additions and 9 deletions

View file

@ -25,8 +25,9 @@ private final class OneSignalPush(
"headings" -> Map("en" -> data.title),
"contents" -> Map("en" -> data.body),
"data" -> data.payload,
"android_group" -> data.group,
"collapse_id" -> data.group
"android_group" -> data.stacking.key,
"android_group_message" -> Map("en" -> data.stacking.message),
"collapse_id" -> data.stacking.key
)).flatMap {
case res if res.status == 200 =>
(res.json \ "errors").asOpt[List[String]] match {

View file

@ -31,7 +31,7 @@ private final class PushApi(
case _ => "It's a draw."
},
body = s"Your game with ${opponentName(pov)} is over.",
group = "gameStatus",
stacking = Stacking.GameFinish,
payload = Json.obj(
"userId" -> userId,
"userData" -> Json.obj(
@ -56,7 +56,7 @@ private final class PushApi(
pushToAll(userId, _.move, PushApi.Data(
title = "It's your turn!",
body = s"${opponentName(pov)} played $sanMove",
group = "yourTurn",
stacking = Stacking.GameMove,
payload = Json.obj(
"userId" -> userId,
"userData" -> Json.obj(
@ -82,7 +82,7 @@ private final class PushApi(
pushToAll(userId, _.corresAlarm, PushApi.Data(
title = "Time is almost up!",
body = s"You are about to lose on time against ${opponentName(pov)}",
group = "yourTurn",
stacking = Stacking.GameMove,
payload = Json.obj(
"userId" -> userId,
"userData" -> Json.obj(
@ -103,7 +103,7 @@ private final class PushApi(
pushToAll(t.receiverOf(p), _.message, PushApi.Data(
title = s"${sender.titleName}: ${t.name}",
body = p.text take 140,
group = "message",
stacking = Stacking.NewMessage,
payload = Json.obj(
"userId" -> t.receiverOf(p),
"userData" -> Json.obj(
@ -118,7 +118,7 @@ private final class PushApi(
pushToAll(dest.id, _.challenge.create, PushApi.Data(
title = s"${lightChallenger.titleName} (${challenger.rating.show}) challenges you!",
body = describeChallenge(c),
group = "challenge",
stacking = Stacking.ChallengeCreate,
payload = Json.obj(
"userId" -> dest.id,
"userData" -> Json.obj(
@ -134,7 +134,7 @@ private final class PushApi(
pushToAll(challenger.id, _.challenge.accept, PushApi.Data(
title = s"${lightJoiner.fold("Anonymous")(_.titleName)} accepts your challenge!",
body = describeChallenge(c),
group = "challenge",
stacking = Stacking.ChallengeAccept,
payload = Json.obj(
"userId" -> challenger.id,
"userData" -> Json.obj(
@ -192,6 +192,6 @@ private object PushApi {
case class Data(
title: String,
body: String,
group: String,
stacking: Stacking,
payload: JsObject)
}

View file

@ -0,0 +1,12 @@
package lila.push
private sealed abstract class Stacking(val key: String, val message: String)
private object Stacking {
case object GameFinish extends Stacking("gameFinish", "$[notif_count] games are over")
case object GameMove extends Stacking("gameMove", "It's your turn in $[notif_count] games")
case object NewMessage extends Stacking("newMessage", "You have $[notif_count] new messages")
case object ChallengeCreate extends Stacking("challengeCreate", "You have $[notif_count] new challenges")
case object ChallengeAccept extends Stacking("challengeAccept", "$[notif_count] players accepted your challenges")
}