Skip to content

Commit

Permalink
Merge pull request #40 from calluswhatyouwant/v0.2.x
Browse files Browse the repository at this point in the history
Upgrade to v0.2.2
  • Loading branch information
JoseRenan committed Dec 26, 2018
2 parents 3243ecf + d3eec41 commit ce04c2e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/lib/models/player/play-history.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Context from './context';
import Track from '../track/track';
import { getAlbum, getArtist, getPlaylist } from '../..';

class PlayHistory {
track: Track;

playedAt: string; // Timestamp
playedAt: string;

context: Context | null;

Expand All @@ -13,6 +14,23 @@ class PlayHistory {
this.playedAt = json.played_at;
this.context = json.context ? new Context(json.context) : null;
}

getContextData(): Promise<any> {
if (this.context) {
const [, type, id] = this.context.uri.split(':');
switch (type) {
case 'album':
return getAlbum(id);
case 'artist':
return getArtist(id);
case 'playlist':
return getPlaylist(id);
default:
return getAlbum(this.track.album.id);
}
}
return getAlbum(this.track.album.id);
}
}

export default PlayHistory;

0 comments on commit ce04c2e

Please sign in to comment.