Skip to content

Commit

Permalink
feat(notifications): Add more curly variables for partially available…
Browse files Browse the repository at this point in the history
… notification

* feat: Add more curly variables for partially available notification

* test: Fix newly added test
  • Loading branch information
sephrat committed Sep 7, 2022
1 parent 29fb614 commit 66aa101
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
Expand Up @@ -292,6 +292,8 @@ public void TvNotificationPartialAvailablilityTests()

notificationOptions.Substitutes.Add("Season", "1");
notificationOptions.Substitutes.Add("Episodes", "1, 2");
notificationOptions.Substitutes.Add("EpisodesCount", "2");
notificationOptions.Substitutes.Add("SeasonEpisodes", "1x1, 1x2");
var req = F.Build<ChildRequests>()
.With(x => x.RequestType, RequestType.TvShow)
.With(x => x.Available, true)
Expand Down Expand Up @@ -324,6 +326,8 @@ public void TvNotificationPartialAvailablilityTests()
Assert.That("name", Is.EqualTo(sut.ApplicationName));
Assert.That(sut.PartiallyAvailableEpisodeNumbers, Is.EqualTo("1, 2"));
Assert.That(sut.PartiallyAvailableSeasonNumber, Is.EqualTo("1"));
Assert.That(sut.PartiallyAvailableEpisodeCount, Is.EqualTo("2"));
Assert.That(sut.PartiallyAvailableEpisodesList, Is.EqualTo("1x1, 1x2"));
}

[Test]
Expand Down
12 changes: 12 additions & 0 deletions src/Ombi.Notifications/NotificationMessageCurlys.cs
Expand Up @@ -186,6 +186,14 @@ private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificati
{
PartiallyAvailableEpisodeNumbers = epNumber;
}
if (opts.Substitutes.TryGetValue("EpisodesCount", out var epCount))
{
PartiallyAvailableEpisodeCount = epCount;
}
if (opts.Substitutes.TryGetValue("SeasonEpisodes", out var sEpisodes))
{
PartiallyAvailableEpisodesList = sEpisodes;
}
}
}

Expand Down Expand Up @@ -295,6 +303,8 @@ private void CalculateRequestStatus(BaseRequest req)
public string ProviderId { get; set; }
public string PartiallyAvailableEpisodeNumbers { get; set; }
public string PartiallyAvailableSeasonNumber { get; set; }
public string PartiallyAvailableEpisodeCount { get; set; }
public string PartiallyAvailableEpisodesList { get; set; }

// System Defined
private string LongDate => DateTime.Now.ToString("D");
Expand Down Expand Up @@ -336,6 +346,8 @@ private void CalculateRequestStatus(BaseRequest req)
{ nameof(ProviderId), ProviderId },
{ nameof(PartiallyAvailableEpisodeNumbers), PartiallyAvailableEpisodeNumbers },
{ nameof(PartiallyAvailableSeasonNumber), PartiallyAvailableSeasonNumber },
{ nameof(PartiallyAvailableEpisodesList), PartiallyAvailableEpisodesList },
{ nameof(PartiallyAvailableEpisodeCount), PartiallyAvailableEpisodeCount },
};
}
}
2 changes: 2 additions & 0 deletions src/Ombi.Schedule/Jobs/ArrAvailabilityChecker.cs
Expand Up @@ -212,6 +212,8 @@ await _hub.Clients.Clients(NotificationHub.AdminConnectionIds)
};
notification.Substitutes.Add("Season", availableEpisode.First().SeasonNumber.ToString());
notification.Substitutes.Add("Episodes", string.Join(", ", availableEpisode.Select(x => x.EpisodeNumber)));
notification.Substitutes.Add("EpisodesCount", $"{availableEpisode.Count}");
notification.Substitutes.Add("SeasonEpisodes", string.Join(", ", availableEpisode.Select(x => $"{x.SeasonNumber}x{x.EpisodeNumber}" )));
await _notification.Notify(notification);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs
Expand Up @@ -227,6 +227,8 @@ private async Task ProcessTv()
};
notification.Substitutes.Add("Season", availableEpisode.First().SeasonNumber.ToString());
notification.Substitutes.Add("Episodes", string.Join(", ", availableEpisode.Select(x => x.EpisodeNumber)));
notification.Substitutes.Add("EpisodesCount", $"{availableEpisode.Count}");
notification.Substitutes.Add("SeasonEpisodes", string.Join(", ", availableEpisode.Select(x => $"{x.SeasonNumber}x{x.EpisodeNumber}" )));
await _notificationService.Notify(notification);
}
}
Expand Down
Expand Up @@ -253,6 +253,8 @@ private async Task ProcessTv()
};
notification.Substitutes.Add("Season", availableEpisode.First().SeasonNumber.ToString());
notification.Substitutes.Add("Episodes", string.Join(", ", availableEpisode.Select(x => x.EpisodeNumber)));
notification.Substitutes.Add("EpisodesCount", $"{availableEpisode.Count}");
notification.Substitutes.Add("SeasonEpisodes", string.Join(", ", availableEpisode.Select(x => $"{x.SeasonNumber}x{x.EpisodeNumber}" )));
await _notificationService.Notify(notification);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs
Expand Up @@ -174,6 +174,8 @@ private async Task ProcessTv(List<ChildRequests> tv)
};
notification.Substitutes.Add("Season", availableEpisode.First().SeasonNumber.ToString());
notification.Substitutes.Add("Episodes", string.Join(", " ,availableEpisode.Select(x => x.EpisodeNumber)));
notification.Substitutes.Add("EpisodesCount", $"{availableEpisode.Count}");
notification.Substitutes.Add("SeasonEpisodes", string.Join(", ", availableEpisode.Select(x => $"{x.SeasonNumber}x{x.EpisodeNumber}" )));
await _notificationService.Notify(notification);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Store/Context/OmbiContext.cs
Expand Up @@ -213,7 +213,7 @@ public void Seed()
notificationToAdd = new NotificationTemplates
{
NotificationType = notificationType,
Message = "Your TV request for {Title} is now partially available! Season {PartiallyAvailableSeasonNumber} Episodes {PartiallyAvailableEpisodeNumbers}!",
Message = "Your TV request for {Title} is now partially available! Episodes {PartiallyAvailableEpisodesList}!",
Subject = "{ApplicationName}: Partially Available Request!",
Agent = agent,
Enabled = true,
Expand Down

0 comments on commit 66aa101

Please sign in to comment.