Skip to content

Commit

Permalink
Added new song request announcements, station IDs. Fixed patch bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
JudahGabriel committed Jan 6, 2024
1 parent 82dba07 commit d3b2230
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Chavah.NetCore/Common/Extensions/RavenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ public static Operation PatchAll(this IDocumentStore db, string collectionName,
{
Query = rqlPatch.ToString()
});

return db.Operations.Send(patch);
}

Expand Down
2 changes: 1 addition & 1 deletion Chavah.NetCore/Controllers/CdnController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<List<string>> ValidateSongCdnLinks()
public RedirectResult GetStationId()
{
var directory = new Uri(cdnSettings.Value.HttpPath).Combine(cdnSettings.Value.SoundEffects);
var idAnnouncement = new Random().Next(1, 11);
var idAnnouncement = new Random().Next(1, 12);
return Redirect(directory.Combine($"StationId{idAnnouncement}.mp3").AbsoluteUri);
}

Expand Down
6 changes: 3 additions & 3 deletions Chavah.NetCore/Controllers/IftttController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ private Task AddNotificationToAllUsers(Notification notification)
{
var jsonNotification = JsonConvert.SerializeObject(notification);
var patchScript = @"
var existingNotification = this.Notifications.find(n => n.Url !== url);
var existingNotification = this.Notifications.find(n => n.Url === url);
if (!existingNotification) {
this.Notifications.unshift(json);
this.Notifications.unshift(JSON.parse(post));
if (this.Notifications.length > 10) {
this.Notifications.length = 10;
}
Expand All @@ -236,7 +236,7 @@ private Task AddNotificationToAllUsers(Notification notification)
var variables = new Dictionary<string, object>
{
{ "url", notification.Url },
{ "json", jsonNotification }
{ "post", jsonNotification }
};
var operation = DbSession.Advanced.DocumentStore.PatchAll<AppUser>(patchScript, variables);
return operation.WaitForCompletionAsync(TimeSpan.FromSeconds(60));
Expand Down
10 changes: 5 additions & 5 deletions Chavah.NetCore/Services/BlogPostNotificationCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.ServiceModel.Syndication;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Reactive.Linq;

using BitShuva.Chavah.Common;
using BitShuva.Chavah.Models;
Expand Down Expand Up @@ -36,7 +36,7 @@ public BlogPostNotificationCreator(
IPushNotificationSender pushNotifications,
IHttpClientFactory httpClientFactory,
ILogger<BlogPostNotificationCreator> logger)
: base(TimeSpan.FromSeconds(20), TimeSpan.FromMinutes(30), logger)
: base(TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(30), logger)
{
this.docStore = docStore;
this.pushNotifications = pushNotifications;
Expand Down Expand Up @@ -95,9 +95,9 @@ private async Task<Notification> TryAddNotificationAsync(RssFeedItem post)
// Serialize it
var jsonNotification = JsonConvert.SerializeObject(notification);
var patchScript = @"
var existingNotification = this.Notifications.find(n => n.Url !== url);
var existingNotification = this.Notifications.find(n => n.Url === url);
if (!existingNotification) {
this.Notifications.unshift(json);
this.Notifications.unshift(JSON.parse(post));
if (this.Notifications.length > 10) {
this.Notifications.length = 10;
}
Expand All @@ -106,7 +106,7 @@ private async Task<Notification> TryAddNotificationAsync(RssFeedItem post)
var variables = new Dictionary<string, object>
{
{ "url", notification.Url },
{ "json", jsonNotification }
{ "post", jsonNotification }
};
var patchOperation = docStore.PatchAll<AppUser>(patchScript, variables);
await patchOperation.WaitForCompletionAsync(TimeSpan.FromSeconds(30));
Expand Down
2 changes: 1 addition & 1 deletion Chavah.NetCore/wwwroot/js/Services/SongRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

if (!this.hasPlayedRequestAnnouncement) {
this.hasPlayedRequestAnnouncement = true;
const songRequestNumbers = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
const songRequestNumbers = [1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
// tslint:disable-next-line:max-line-length
const songRequestName = "SongRequest" + songRequestNumbers[Math.floor(Math.random() * songRequestNumbers.length)] + ".mp3";
const songRequestUrl = `${this.homeViewModel.soundEffects}/${songRequestName}`;
Expand Down

0 comments on commit d3b2230

Please sign in to comment.