Skip to content

Commit

Permalink
Fixes post announcement issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JudahGabriel committed Aug 16, 2024
1 parent 3c75408 commit ea47645
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
36 changes: 23 additions & 13 deletions Chavah.NetCore/Common/Extensions/RavenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,35 @@ public static Operation PatchAll(this IDocumentStore db, string collectionName,
rqlPatch.AppendLine("update {");

// For each variable in the dictionary, declare the variable in the RQL script.
if (variables != null)
{
variables
.Select(kv =>
{
var variableValue = kv.Value?.ToString();
var escapedVariableValue = variableValue?.Replace("\"", "\\\""); // replace any quotes with escaped quotes. 'Hi I am a "JS" string' -> 'Hi I am a \"JS\" string'
var escapedWithQuotes = kv.Value is string ? "\"" + escapedVariableValue + "\"" : escapedVariableValue; // string? Surround the value with quotes. foo -> "foo"
return $"var {kv.Key} = {escapedWithQuotes};"; // The actual variable declaration, e.g. var foo = "123";
})
.ForEach(v => rqlPatch.AppendLine(v));
}
//if (variables != null)
//{
// variables
// .Select(kv =>
// {
// var variableValue = kv.Value?.ToString();
// var escapedVariableValue = variableValue?.Replace("\"", "\\\""); // replace any quotes with escaped quotes. 'Hi I am a "JS" string' -> 'Hi I am a \"JS\" string'
// var escapedWithQuotes = kv.Value is string ? "\"" + escapedVariableValue + "\"" : escapedVariableValue; // string? Surround the value with quotes. foo -> "foo"
// return $"var {kv.Key} = {escapedWithQuotes};"; // The actual variable declaration, e.g. var foo = "123";
// })
// .ForEach(v => rqlPatch.AppendLine(v));
//}

rqlPatch.AppendLine(jsPatchScript);
rqlPatch.Append('}');

var queryParams = new Raven.Client.Parameters();
if (variables != null)
{
foreach (var queryVariable in variables)
{
queryParams.Add(queryVariable.Key, queryVariable.Value);
}
}

var patch = new PatchByQueryOperation(new Raven.Client.Documents.Queries.IndexQuery
{
Query = rqlPatch.ToString()
Query = rqlPatch.ToString(),
QueryParameters = queryParams
});

return db.Operations.Send(patch);
Expand Down
4 changes: 2 additions & 2 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.parse(post));
this.Notifications.unshift(JSON.parse($post));
if (this.Notifications.length > 10) {
this.Notifications.length = 10;
}
Expand Down
6 changes: 3 additions & 3 deletions Chavah.NetCore/Controllers/TagsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ public async Task<string> Rename(string oldTag, string newTag)
// Fix up the tag name in each song.
const string patchScript = @"
if (this.Tags && this.Tags.length) {
var oldTagIndex = this.Tags.indexOf(oldTag);
var oldTagIndex = this.Tags.indexOf($oldTag);
if (oldTagIndex >= 0)
{
this.Tags.splice(oldTagIndex, 1);
var newTagIndex = this.Tags.indexOf(newTag);
var newTagIndex = this.Tags.indexOf($newTag);
if (newTagIndex === -1) {
this.Tags.splice(oldTagIndex, 0, newTag);
this.Tags.splice(oldTagIndex, 0, $newTag);
}
}
}";
Expand Down
6 changes: 3 additions & 3 deletions Chavah.NetCore/Services/BlogPostNotificationCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BlogPostNotificationCreator(
IPushNotificationSender pushNotifications,
IHttpClientFactory httpClientFactory,
ILogger<BlogPostNotificationCreator> logger)
: base(TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(30), logger)
: base(TimeSpan.FromSeconds(5), 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.parse(post));
this.Notifications.unshift(JSON.parse($post));
if (this.Notifications.length > 10) {
this.Notifications.length = 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// Clone the song so that we assign a new clientId for tracking separately in ng repeaters.
const clone = new Song(song);
clone.setSolePickReason(SongPick.YouRequestedSong);
this.audioPlayer.playNewSong(clone);
this.audioPlayer.playSongById(clone.id); // We play song by ID so that we fetch the user's like status for it.
}

private fetchSongs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace BitShuva.Chavah {
constructor(
private readonly audioPlayer: AudioPlayerService,
private readonly songApi: SongApiService) {

// Move the last new music announcement to yesterday.
// That way we'll get a new music announcement on our desired timeframe, even if we just started listening.
this.lastNewMusicAnnouncement.setDate(this.lastNewMusicAnnouncement.getDate() - 1);
}

getPendingNewMusicAnnouncement(): NewMusicAnnoucement | null {
Expand Down

0 comments on commit ea47645

Please sign in to comment.