Started work on channel-wide playlists.
This commit is contained in:
parent
59f097db39
commit
72a89ae5ff
5 changed files with 161 additions and 5 deletions
|
|
@ -103,7 +103,7 @@ const channelSchema = new mongoose.Schema({
|
|||
media: {
|
||||
nowPlaying: queuedMediaSchema,
|
||||
scheduled: [queuedMediaSchema],
|
||||
//We should consider moving archived media and channel playlists to their own collections/models for preformance sake
|
||||
//We should consider moving archived media and channel playlists to their own collections/models for preformances sake
|
||||
archived: [queuedMediaSchema],
|
||||
playlists: [playlistSchema]
|
||||
},
|
||||
|
|
@ -551,6 +551,73 @@ channelSchema.methods.getEmotes = function(){
|
|||
return emoteList;
|
||||
}
|
||||
|
||||
channelSchema.methods.getPlaylists = function(){
|
||||
//Create an empty array to hold our emote list
|
||||
const playlists = [];
|
||||
|
||||
//For each channel emote
|
||||
//this.media.playlists.forEach((playlist) => {
|
||||
for(let playlist of this.media.playlists){
|
||||
//Push an object with select information from the emote to the emote list
|
||||
playlists.push({
|
||||
name: playlist.name,
|
||||
count: playlist.media.length
|
||||
});
|
||||
}
|
||||
|
||||
//return the emote list
|
||||
return playlists;
|
||||
}
|
||||
|
||||
channelSchema.methods.playlistCrawl = function(cb){
|
||||
for(let listIndex in this.media.playlists){
|
||||
//Grab the associated playlist
|
||||
playlist = this.media.playlists[listIndex];
|
||||
|
||||
//Call the callback with the playlist and list index as arguments
|
||||
cb(playlist, listIndex);
|
||||
}
|
||||
}
|
||||
|
||||
channelSchema.methods.getPlaylistByName = function(name){
|
||||
//Create null value to hold our found playlist
|
||||
let foundPlaylist = null;
|
||||
|
||||
//Crawl through active playlists
|
||||
this.playlistCrawl((playlist) => {
|
||||
//If we found a match based on name
|
||||
if(playlist.name == name){
|
||||
//Keep it
|
||||
foundPlaylist = playlist;
|
||||
}
|
||||
});
|
||||
|
||||
//return the given playlist
|
||||
return foundPlaylist;
|
||||
}
|
||||
|
||||
channelSchema.methods.addToPlaylist = async function(name, media){
|
||||
//Create variable to hold found index
|
||||
let foundIndex = null
|
||||
|
||||
//Crawl through active playlists
|
||||
this.playlistCrawl((playlist, listIndex) => {
|
||||
//If the playlist name matches
|
||||
if(playlist.name == name){
|
||||
//Push the given media into the found playlist
|
||||
//this.media.playlists[listIndex].push(media);
|
||||
|
||||
//Make note of the found index
|
||||
foundIndex = listIndex
|
||||
}
|
||||
});
|
||||
|
||||
this.media.playlists[foundIndex].media.push(media);
|
||||
|
||||
//Save the changes made to the chan doc
|
||||
await this.save();
|
||||
}
|
||||
|
||||
channelSchema.methods.getChanBans = async function(){
|
||||
//Create an empty list to hold our found bans
|
||||
var banList = [];
|
||||
|
|
|
|||
|
|
@ -31,4 +31,4 @@ module.exports = new mongoose.Schema({
|
|||
required: true,
|
||||
default: []
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
|
@ -44,7 +44,7 @@ const queuedProperties = new mongoose.Schema({
|
|||
discriminatorKey: 'status'
|
||||
});
|
||||
|
||||
//methods
|
||||
//Methods
|
||||
//Rehydrate to a full phat queued media object
|
||||
queuedProperties.methods.rehydrate = function(){
|
||||
return new queuedMedia(
|
||||
|
|
@ -61,4 +61,5 @@ queuedProperties.methods.rehydrate = function(){
|
|||
);
|
||||
}
|
||||
|
||||
//Export schema under the 'queued' discriminator of mediaSchema
|
||||
module.exports = mediaSchema.discriminator('queued', queuedProperties);
|
||||
Loading…
Add table
Add a link
Reference in a new issue