Skip to content

Commit

Permalink
feat: Add AdditionalInformation property where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Aug 15, 2023
1 parent 82bacc9 commit f6a9631
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System.Collections.Immutable;
using System.Threading.Tasks;
using Lavalink4NET.Protocol.Models;
using Lavalink4NET.Protocol.Responses;
using Lavalink4NET.Rest;
using Lavalink4NET.Rest.Entities.Tracks;
using Lavalink4NET.Tracks;
Expand Down Expand Up @@ -33,10 +33,14 @@ public static class TrackManagerExtensions
return null;
}

static PlaylistInformation CreatePlaylist(PlaylistInformationModel playlistInformationModel)
static PlaylistInformation CreatePlaylist(PlaylistLoadResultData data)
{
var playlistName = playlistInformationModel.Name;
return new PlaylistInformation(playlistName, null);
var playlistName = data.PlaylistInformation.Name;

return new PlaylistInformation(
Name: playlistName,
SelectedTrack: null,
AdditionalInformation: data.AdditionalInformation);
}

var tracks = searchResult.Tracks is null
Expand All @@ -57,8 +61,14 @@ static PlaylistInformation CreatePlaylist(PlaylistInformationModel playlistInfor

var texts = searchResult.Texts is null
? ImmutableArray<TextResult>.Empty
: searchResult.Texts.Value.Select(x => new TextResult(x.Text)).ToImmutableArray();
: searchResult.Texts.Value.Select(x => new TextResult(x.Text, x.AdditionalInformation)).ToImmutableArray();

return new SearchResult(tracks, albums, artists, playlists, texts);
return new SearchResult(
Tracks: tracks,
Albums: albums,
Artists: artists,
Playlists: playlists,
Texts: texts,
AdditionalInformation: searchResult.AdditionalInformation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Lavalink4NET.Protocol.Models;
using Lavalink4NET.Protocol.Responses;

public sealed record class SearchResultModel
{
Expand All @@ -13,21 +14,21 @@ public sealed record class SearchResultModel

[JsonPropertyName("albums")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableArray<PlaylistInformationModel>? Albums { get; set; }
public ImmutableArray<PlaylistLoadResultData>? Albums { get; set; }

[JsonPropertyName("artists")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableArray<PlaylistInformationModel>? Artists { get; set; }
public ImmutableArray<PlaylistLoadResultData>? Artists { get; set; }

[JsonPropertyName("playlists")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableArray<PlaylistInformationModel>? Playlists { get; set; }
public ImmutableArray<PlaylistLoadResultData>? Playlists { get; set; }

[JsonPropertyName("texts")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public ImmutableArray<TextResultModel>? Texts { get; set; }

[JsonRequired]
[JsonPropertyName("plugin")]
public IDictionary<string, JsonNode> AdditionalData { get; set; } = null!;
public IImmutableDictionary<string, JsonNode> AdditionalInformation { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Lavalink4NET.Integrations.Lavasearch.Models;

using System.Collections.Immutable;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

Expand All @@ -11,5 +12,5 @@ public sealed record class TextResultModel

[JsonRequired]
[JsonPropertyName("plugin")]
public IDictionary<string, JsonNode> AdditionalData { get; set; } = null!;
public IImmutableDictionary<string, JsonNode> AdditionalInformation { get; set; } = null!;
}
4 changes: 3 additions & 1 deletion src/Lavalink4NET.Integrations.Lavasearch/SearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Lavalink4NET.Integrations.Lavasearch;

using System.Collections.Immutable;
using System.Text.Json.Nodes;
using Lavalink4NET.Rest.Entities.Tracks;
using Lavalink4NET.Tracks;

Expand All @@ -9,4 +10,5 @@ public sealed record class SearchResult(
ImmutableArray<PlaylistInformation> Albums,
ImmutableArray<PlaylistInformation> Artists,
ImmutableArray<PlaylistInformation> Playlists,
ImmutableArray<TextResult> Texts);
ImmutableArray<TextResult> Texts,
IImmutableDictionary<string, JsonNode> AdditionalInformation);
7 changes: 6 additions & 1 deletion src/Lavalink4NET.Integrations.Lavasearch/TextResult.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
namespace Lavalink4NET.Integrations.Lavasearch;

public readonly record struct TextResult(string Text);
using System.Collections.Immutable;
using System.Text.Json.Nodes;

public readonly record struct TextResult(
string Text,
IImmutableDictionary<string, JsonNode> AdditionalInformation);
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace Lavalink4NET.Protocol.Models;

using System.Text.Json.Serialization;
using Lavalink4NET.Protocol.Converters;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Lavalink4NET.Protocol.Responses;

using System.Collections.Immutable;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Lavalink4NET.Protocol.Models;

Expand All @@ -9,9 +10,9 @@ public sealed record class PlaylistLoadResultData(
[property: JsonPropertyName("info")]
PlaylistInformationModel PlaylistInformation,

[property: JsonRequired]
[property: JsonPropertyName("pluginInfo")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
IImmutableDictionary<string, object?>? PluginInformation,
IImmutableDictionary<string, JsonNode> AdditionalInformation,

[property: JsonRequired]
[property: JsonPropertyName("tracks")]
Expand Down
7 changes: 6 additions & 1 deletion src/Lavalink4NET.Rest/Entities/Tracks/PlaylistInformation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace Lavalink4NET.Rest.Entities.Tracks;

using System.Collections.Immutable;
using System.Text.Json.Nodes;
using Lavalink4NET.Tracks;

public readonly record struct PlaylistInformation(string Name, LavalinkTrack? SelectedTrack);
public readonly record struct PlaylistInformation(
string Name,
LavalinkTrack? SelectedTrack,
IImmutableDictionary<string, JsonNode> AdditionalInformation);
3 changes: 2 additions & 1 deletion src/Lavalink4NET.Rest/LavalinkApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ internal static (PlaylistInformation Playlist, ImmutableArray<LavalinkTrack> Tra

var playlistInformation = new PlaylistInformation(
Name: loadResult.PlaylistInformation.Name,
SelectedTrack: selectedTrack);
SelectedTrack: selectedTrack,
AdditionalInformation: loadResult.AdditionalInformation);

return (playlistInformation, tracks);
}
Expand Down

0 comments on commit f6a9631

Please sign in to comment.