UNPKG

629 BJavaScriptView Raw
1const pull = require('pull-stream');
2
3module.exports = (sbot, gameDb, gameSsbCtrl) => {
4 function endedGamesPagesSource(playerId) {
5 return gameDb.getGamesFinished(playerId);
6 }
7
8 function getGameSummaryCb(gameId, cb) {
9 gameSsbCtrl.getSmallGameSummary(gameId)
10 .then(res => cb(null, res))
11 .catch(e => cb(e, null));
12 }
13
14 function endedGamesSummariesSource(playerId) {
15 const endedGamesSrc = endedGamesPagesSource(playerId);
16
17 const flatStream = pull(endedGamesSrc, pull.flatten());
18
19 return pull(flatStream, pull.asyncMap(getGameSummaryCb));
20 }
21
22
23 return {
24 endedGamesSummariesSource,
25 };
26};