Skip to content

Commit cba5e17

Browse files
committedOct 15, 2022
fixed issue with the priority queue #9
1 parent 2ae7bb0 commit cba5e17

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎Sparkfly.Main/Services/SparkflyManager.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ public void EnqueueVote(Track votedTrack, Client client)
160160
{
161161
int priority = 0; // lower number means higher priority
162162

163-
for (priority = 0; priority < Votes.Count; priority++)
163+
if (Votes.Any() && (CurrentlyPlayingVote.Client.Id == client.Id || PreviouslyPlayedVotes.Any(v => v.Client.Id == client.Id)))
164+
priority = 1;
165+
166+
for (; priority < Votes.Count; priority++)
164167
{
165168
if (Votes[priority].Any(v => v.Client.Id == client.Id))
166169
continue;
167170

168171
break;
169172
}
170173

171-
if (priority == 0 && PreviouslyPlayedVotes.Any(v => v.Client.Id == client.Id))
172-
priority = 1;
173-
174174
if (priority >= Votes.Count)
175175
Votes.Add(new Queue<Vote>());
176176

@@ -249,7 +249,10 @@ private async void OnTimerElapsedAsync(object source, EventArgs args)
249249
CurrentlyPlayingVote = nextVote;
250250
}
251251
else
252+
{
253+
PreviouslyPlayedVotes.Clear();
252254
CurrentlyPlayingVote = new Vote(newestTrack, new Client("0", "Spotify"));
255+
}
253256
}
254257

255258
if (nextVote is not null && !nextVote.IsOnSpotifyQueue && (newestTrack.DurationMs - newestTrack.ProgressMs) < _loopPeriodInMs * 2)

0 commit comments

Comments
 (0)
Please sign in to comment.