Skip to content

Commit

Permalink
Fix the inserted_at field on listens
Browse files Browse the repository at this point in the history
This resolves a deserialization error. Not that this also changes
`IListen.InsertedAt` from a `string` to a `DateTimeOffset`.
  • Loading branch information
Zastai committed Dec 22, 2023
1 parent a130dd7 commit 814d43c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions MetaBrainz.ListenBrainz/Interfaces/IListen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace MetaBrainz.ListenBrainz.Interfaces;
[PublicAPI]
public interface IListen : IJsonBasedObject {

/// <summary>The timestamp at which the listen information was inserted in the database, in human-readable format.</summary>
string InsertedAt { get; }
/// <summary>The timestamp at which the listen information was inserted in the database.</summary>
DateTimeOffset InsertedAt { get; }

/// <summary>The MessyBrainz ID for the recording that was listened to.</summary>
Guid MessyRecordingId { get; }
Expand Down
6 changes: 3 additions & 3 deletions MetaBrainz.ListenBrainz/Json/Readers/ListenReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class ListenReader : ObjectReader<Listen> {
public static readonly ListenReader Instance = new();

protected override Listen ReadObjectContents(ref Utf8JsonReader reader, JsonSerializerOptions options) {
string? inserted = null;
long? inserted = null;
Guid? msid = null;
ITrackInfo? track = null;
string? user = null;
Expand All @@ -26,7 +26,7 @@ protected override Listen ReadObjectContents(ref Utf8JsonReader reader, JsonSeri
reader.Read();
switch (prop) {
case "inserted_at":
inserted = reader.GetString();
inserted = reader.GetInt64();
break;
case "listened_at":
ts = reader.GetInt64();
Expand Down Expand Up @@ -66,7 +66,7 @@ protected override Listen ReadObjectContents(ref Utf8JsonReader reader, JsonSeri
if (ts is null) {
throw new JsonException("Expected listened-at timestamp not found or null.");
}
return new Listen(inserted, msid.Value, ts.Value, track, user) {
return new Listen(inserted.Value, msid.Value, ts.Value, track, user) {
UnhandledProperties = rest
};
}
Expand Down
6 changes: 3 additions & 3 deletions MetaBrainz.ListenBrainz/Objects/Listen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace MetaBrainz.ListenBrainz.Objects;
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
internal sealed class Listen : JsonBasedObject, IListen {

public Listen(string inserted, Guid msid, long timestamp, ITrackInfo track, string user) {
this.InsertedAt = inserted;
public Listen(long inserted, Guid msid, long timestamp, ITrackInfo track, string user) {
this.InsertedAt = DateTimeOffset.FromUnixTimeSeconds(inserted);
this.MessyRecordingId = msid;
this.Timestamp = DateTimeOffset.FromUnixTimeSeconds(timestamp);
this.Track = track;
this.UnixTimestamp = timestamp;
this.User = user;
}

public string InsertedAt { get; }
public DateTimeOffset InsertedAt { get; }

public Guid MessyRecordingId { get; }

Expand Down
2 changes: 1 addition & 1 deletion public-api/MetaBrainz.ListenBrainz.net6.0.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public interface ILatestImport : MetaBrainz.Common.Json.IJsonBasedObject {
```cs
public interface IListen : MetaBrainz.Common.Json.IJsonBasedObject {

string InsertedAt {
System.DateTimeOffset InsertedAt {
public abstract get;
}

Expand Down
2 changes: 1 addition & 1 deletion public-api/MetaBrainz.ListenBrainz.net8.0.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ public interface ILatestImport : MetaBrainz.Common.Json.IJsonBasedObject {
```cs
public interface IListen : MetaBrainz.Common.Json.IJsonBasedObject {

string InsertedAt {
System.DateTimeOffset InsertedAt {
public abstract get;
}

Expand Down

0 comments on commit 814d43c

Please sign in to comment.