Skip to content

Commit 54799ef

Browse files
committed
Deserialized notification schedule type
1 parent 37b18f9 commit 54799ef

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationCustomDeserializers.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ class NotConditionDeserializer : JsonDeserializer<NotificationExpression.NotCond
114114
}
115115
}
116116

117+
// Create a custom deserializer if needed
118+
class NotificationTypeDeserializer : JsonDeserializer<NotificationScheduleType>() {
119+
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): NotificationScheduleType {
120+
return NotificationScheduleType.fromString(p.valueAsString)
121+
}
122+
}
123+
117124
private fun JsonNode.toNotificationExpressions(p: JsonParser): List<NotificationExpression> = this.map { element ->
118125
val parser = element.traverse(p.codec)
119126
parser.nextToken()

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationFormatUtils.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,32 @@ data class NotificationData(
2727
)
2828

2929
data class NotificationSchedule(
30-
val type: String,
31-
)
30+
@JsonDeserialize(using = NotificationTypeDeserializer::class)
31+
val type: NotificationScheduleType,
32+
) {
33+
constructor(type: String) : this(NotificationScheduleType.fromString(type))
34+
}
3235

3336
enum class NotificationSeverity {
3437
INFO,
3538
WARNING,
3639
CRITICAL,
3740
}
3841

42+
enum class NotificationScheduleType {
43+
STARTUP,
44+
EMERGENCY;
45+
46+
companion object {
47+
fun fromString(value: String): NotificationScheduleType {
48+
return when (value.lowercase()) {
49+
"startup" -> STARTUP
50+
else -> EMERGENCY
51+
}
52+
}
53+
}
54+
}
55+
3956
data class NotificationContentDescriptionLocale(
4057
@JsonProperty("en-US")
4158
val locale: NotificationContentDescription,

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/ProcessNotificationsBase.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,20 @@ class ProcessNotificationsBase(
4444
}
4545

4646
fun retrieveStartupAndEmergencyNotifications() {
47+
val isStartupPoll = isStartup.compareAndSet(true,false)
4748
val notifications = getNotificationsFromFile()
48-
4949
notifications?.let { notificationsList ->
50-
val (startupNotifications, emergencyNotifications) = notificationsList.notifications
51-
?.partition { notification ->
52-
notification.schedule.type.equals("StartUp", ignoreCase = true)
50+
val activeNotifications = notificationsList.notifications
51+
?.filter { notification ->
52+
// Keep notification if:
53+
// - it's not a startup notification, OR
54+
// - it is a startup notification AND this is the first poll
55+
notification.schedule.type != NotificationScheduleType.STARTUP || isStartupPoll
5356
}
54-
?: Pair(emptyList(), emptyList())
55-
56-
val dismissalState = NotificationDismissalState.getInstance()
57-
val startupList = if (isStartup.compareAndSet(true, false)) {
58-
startupNotifications
59-
} else {
60-
emptyList()
61-
}
62-
63-
val combinedNotifications = startupList.plus(emergencyNotifications)
64-
val activeNotifications = combinedNotifications.filter { !dismissalState.isDismissed(it.id) }
57+
?.filter { notification ->
58+
!NotificationDismissalState.getInstance().isDismissed(notification.id)
59+
}
60+
?: emptyList()
6561

6662
activeNotifications.forEach { processNotification(project, it) }
6763
}

0 commit comments

Comments
 (0)