UNPKG

1.48 kBJavaScriptView Raw
1const mutantPullReduce = require('mutant-pull-reduce');
2const computed = require('mutant/computed');
3const GameComparer = require('./gameComparer')();
4const Value = require('mutant/value');
5
6/**
7 * A controller for managing invites
8 *
9 * @param {*} myIdent - The user's identity.
10 * @param {*} gameChallenger The ssb game challenger (at the lower layer).
11 * @param {*} gameDb The ssb game db (at the lower layer).
12 * @param {*} myGameUpdates An observable with the latest game update for the current player
13 */
14module.exports = (myIdent, gameChallenger, gameDb, myGameUpdates) => {
15
16 function inviteToPlay(playerKey, asWhite, rematchFromGameId) {
17 return gameChallenger.inviteToPlay(playerKey, asWhite, rematchFromGameId);
18 }
19
20 function acceptChallenge(rootGameMessage) {
21 return gameChallenger.acceptChallenge(rootGameMessage);
22 }
23
24 function pendingChallengesSent() {
25 const pendingChallengesSource = gameDb.pendingChallengesSent(myIdent);
26
27 return mutantPullReduce(pendingChallengesSource, (state, next) => next, {
28 nextTick: true,
29 sync: true,
30 });
31 }
32
33 function pendingChallengesReceived() {
34 const challengesReceivedSource = gameDb.pendingChallengesReceived(myIdent);
35
36 return mutantPullReduce(challengesReceivedSource, (state, next) => next, {
37 nextTick: true,
38 sync: true,
39 });
40 }
41
42 return {
43 inviteToPlay,
44 acceptChallenge,
45 pendingChallengesSent,
46 pendingChallengesReceived,
47 }
48}
\No newline at end of file