3 if(doc.doc_type == "EpisodeUserState")
5 if(doc.actions == null || doc.actions.length == 0)
10 function sortByStarted(a, b)
14 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
17 function hasTimeValues(action)
19 return ((action != null) && (action.started != null) && (action.playmark != null));
22 var actions = doc.actions.slice(0); // creates a copy
23 actions = actions.filter(hasTimeValues);
24 actions.sort(sortByStarted);
26 var played_parts = [];
31 var action = actions[n];
35 flat_date = {start: action.started, end: action.playmark};
36 played_parts.push(flat_date);
40 if(action.started <= flat_date.end && action.playmark >= flat_date.end)
42 flat_date.end = action.playmark;
44 else if(action.started >= flat_date.start && action.playmark <= flat_date.end)
46 // part already contained
51 flat_date = {start: action.started, end: action.playmark};
52 played_parts.push(flat_date);
56 if (played_parts.length == 0)
62 for(var n in played_parts)
64 var part = played_parts[n];
65 sections.push(part.start);
66 sections.push(part.end);
69 emit([doc.podcast, doc.episode, doc.user], sections);