//
// Copyright (c) PlaceholderCompany. All rights reserved.
//
#nullable disable
#pragma warning disable CS1591
using System;
using System.Globalization;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using Jellyfin.Data;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Database.Implementations.Enums;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Querying;
namespace MediaBrowser.Controller.Channels
{
public class Channel : Folder
{
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
[JsonIgnore]
public override SourceType SourceType => SourceType.Channel;
///
/// Determines whether this channel is visible to the specified user.
///
/// The user.
/// Whether to skip the allowed tags check.
/// True if visible; otherwise, false.
public override bool IsVisible(User user, bool skipAllowedTagsCheck = false)
{
var blockedChannelsPreference = user.GetPreferenceValues(PreferenceKind.BlockedChannels);
if (blockedChannelsPreference.Length != 0)
{
if (blockedChannelsPreference.Contains(this.Id))
{
return false;
}
}
else
{
if (!user.HasPermission(PermissionKind.EnableAllChannels)
&& !user.GetPreferenceValues(PreferenceKind.EnabledChannels).Contains(this.Id))
{
return false;
}
}
return base.IsVisible(user, skipAllowedTagsCheck);
}
///
/// Gets items from the channel.
///
/// The items query.
/// The query result.
protected override QueryResult GetItemsInternal(InternalItemsQuery query)
{
try
{
query.Parent = this;
query.ChannelIds = new Guid[] { this.Id };
// Don't blow up here because it could cause parent screens with other content to fail
return ChannelManager.GetChannelItemsInternal(query, new Progress(), CancellationToken.None).GetAwaiter().GetResult();
}
catch
{
// Already logged at lower levels
return new QueryResult();
}
}
///
/// Gets the internal metadata path for this channel.
///
/// The base path.
/// The internal metadata path.
protected override string GetInternalMetadataPath(string basePath)
{
return GetInternalMetadataPath(basePath, this.Id);
}
///
/// Gets the internal metadata path for a channel with the specified ID.
///
/// The base path.
/// The channel ID.
/// The internal metadata path.
public static string GetInternalMetadataPath(string basePath, Guid id)
{
return System.IO.Path.Combine(basePath, "channels", id.ToString("N", CultureInfo.InvariantCulture), "metadata");
}
///
/// Determines whether this channel can be deleted.
///
/// True if deletable; otherwise, false.
public override bool CanDelete()
{
return false;
}
///
/// Determines whether the channel item is visible to the specified user.
///
/// The channel item.
/// The user.
/// True if visible; otherwise, false.
internal static bool IsChannelVisible(BaseItem channelItem, User user)
{
var channel = ChannelManager.GetChannel(channelItem.ChannelId.ToString(string.Empty));
return channel.IsVisible(user);
}
}
}