Skip to content

Commit

Permalink
Fix removing youtube channels from being monitored
Browse files Browse the repository at this point in the history
  • Loading branch information
laurencee committed Jun 25, 2016
1 parent 016ccb5 commit c86cdbc
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions Livestream.Monitor/Model/ApiClients/YoutubeApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,10 @@ public void AddChannelWithoutQuerying(ChannelIdentifier newChannel)
moniteredChannels.Add(newChannel);
}

public async Task RemoveChannel(ChannelIdentifier channelIdentifier)
public Task RemoveChannel(ChannelIdentifier channelIdentifier)
{
ChannelIdentifier actualChannel = null;
foreach (var moniteredChannel in moniteredChannels)
{
// map back to the originally added channel (by channel name)
try
{
var actualChannelId = await GetChannelIdByChannelName(moniteredChannel.ChannelId, CancellationToken.None);
var existingChannelIdentifier = moniteredChannels.FirstOrDefault(x => x.ChannelId.IsEqualTo(actualChannelId));
if (existingChannelIdentifier != null && Equals(existingChannelIdentifier, channelIdentifier))
{
actualChannel = moniteredChannel;
break;
}
}
// we're being careful to just address this specific error to avoid removing the wrong channel due some network/api error
catch (Exception e) when(e.Message.StartsWith("Channel name not found"))
{
actualChannel = moniteredChannel;
}
}

if (actualChannel != null) moniteredChannels.Remove(actualChannel);
moniteredChannels.Remove(channelIdentifier);
return Task.CompletedTask;
}

public Task<List<LivestreamQueryResult>> QueryChannels(CancellationToken cancellationToken)
Expand Down

0 comments on commit c86cdbc

Please sign in to comment.