8111b3e693f584dd9aa9e9c6f7517ad1f47670c9
[mygpo.git] / couchdb / general / _design / history / views / by_user / map.js
blob8111b3e693f584dd9aa9e9c6f7517ad1f47670c9
1 function(doc)
3     function processEpisodeAction(action)
4     {
5         action_obj = {
6                 type:          "Episode",
7                 podcast_url:   doc.podcast_ref_url,
8                 episode_url:   doc.ref_url,
9                 podcast_id:    doc.podcast,
10                 episode_id:    doc.episode,
11                 action:        action.action,
12                 timestamp:     action.timestamp.slice(0, action.timestamp.length-1),
13             }
15         if(action.device != null)
16         {
17             action_obj["device_id"] = action.device;
18         }
19         if(action.started != null)
20         {
21             action_obj["started"] = action.started;
22         }
23         if(action.playmark != null)
24         {
25             action_obj["position"] = action.playmark;
26         }
27         if(action.total != null)
28         {
29             action_obj["total"] = action.total;
30         }
32         emit([doc.user, action_obj.timestamp], action_obj);
33     }
35     function processSubscriptionAction(action)
36     {
37         action_obj = {
38                 type:          "Subscription",
39                 podcast_url:   doc.ref_url,
40                 podcast_id:    doc.podcast,
41                 action:        action.action,
42                 timestamp:     action.timestamp.slice(0, action.timestamp.length-1),
43                 device_id:     action.device,
44             }
46         emit([doc.user, action_obj.timestamp], action_obj);
47     }
50     if(doc.doc_type == "EpisodeUserState")
51     {
52         for(var n in doc.actions)
53         {
54             processEpisodeAction(doc.actions[n]);
55         }
56     }
57     if(doc.doc_type == "PodcastUserState")
58     {
59         for(var n in doc.actions)
60         {
61             processSubscriptionAction(doc.actions[n]);
62         }
63     }