Commit 3ab10d83371e7fb6a97e4b0a23ded460ab8e01de
Adds pull-next-query stuff so we can stream open / closed / all polls.
Piet Geursen committed on 6/6/2018, 4:18:53 AMParent: 34b19bd57eb496c6327fb91324191692206ce85a
Files changed
methods.js | changed |
poll/pull/all.js | added |
poll/pull/closed.js | added |
poll/pull/open.js | added |
methods.js | ||
---|---|---|
@@ -10,8 +10,13 @@ | ||
10 | 10 … | sync: { |
11 | 11 … | isPoll: () => isPoll, |
12 | 12 … | isChooseOnePoll: () => isChooseOnePoll |
13 | 13 … | // Poll: // this is not exported - doesn't follow the inject pattern atm |
14 … | + }, | |
15 … | + pull: { | |
16 … | + closed: require('./poll/pull/closed'), | |
17 … | + open: require('./poll/pull/open'), | |
18 … | + all: require('./poll/pull/all') | |
14 | 19 … | } |
15 | 20 … | }, |
16 | 21 … | position: { |
17 | 22 … | async: { |
poll/pull/all.js | ||
---|---|---|
@@ -1,0 +1,23 @@ | ||
1 … | +var next = require('pull-next-query') | |
2 … | + | |
3 … | +module.exports = function (server) { | |
4 … | + return function ClosedPollsStream (opts) { | |
5 … | + const defaultOpts = { | |
6 … | + limit: 100, | |
7 … | + query: [{ | |
8 … | + $filter: { | |
9 … | + value: { | |
10 … | + timestamp: { $gt: 0 }, | |
11 … | + content: { | |
12 … | + type: 'poll', | |
13 … | + closesAt: { $lt: new Date().toISOString() } | |
14 … | + } | |
15 … | + } | |
16 … | + } | |
17 … | + }] | |
18 … | + } | |
19 … | + const _opts = Object.assign({}, defaultOpts, opts) | |
20 … | + | |
21 … | + return next(server.query.read, _opts) | |
22 … | + } | |
23 … | +} |
poll/pull/closed.js | ||
---|---|---|
@@ -1,0 +1,23 @@ | ||
1 … | +var next = require('pull-next-query') | |
2 … | + | |
3 … | +module.exports = function (server) { | |
4 … | + return function ClosedPollsStream (opts) { | |
5 … | + const defaultOpts = { | |
6 … | + limit: 100, | |
7 … | + query: [{ | |
8 … | + $filter: { | |
9 … | + value: { | |
10 … | + timestamp: { $gt: 0 }, // this forces ssb query to stream in order of message published timestamp. | |
11 … | + content: { | |
12 … | + type: 'poll', | |
13 … | + closesAt: { $lt: new Date().toISOString() } | |
14 … | + } | |
15 … | + } | |
16 … | + } | |
17 … | + }] | |
18 … | + } | |
19 … | + const _opts = Object.assign({}, defaultOpts, opts) | |
20 … | + | |
21 … | + return next(server.query.read, _opts) | |
22 … | + } | |
23 … | +} |
poll/pull/open.js | |||
---|---|---|---|
@@ -1,0 +1,22 @@ | |||
1 … | +var next = require('pull-next-query') | ||
2 … | + | ||
3 … | +module.exports = function (server) { | ||
4 … | + return function AllPollsStream (opts) { | ||
5 … | + const defaultOpts = { | ||
6 … | + limit: 100, | ||
7 … | + query: [{ | ||
8 … | + $filter: { | ||
9 … | + value: { | ||
10 … | + timestamp: { $gt: 0 }, // this forces ssb query to stream in order of message published timestamp. | ||
11 … | + content: { | ||
12 … | + type: 'poll' | ||
13 … | + } | ||
14 … | + } | ||
15 … | + } | ||
16 … | + }] | ||
17 … | + } | ||
18 … | + const _opts = Object.assign({}, defaultOpts, opts) | ||
19 … | + | ||
20 … | + return next(server.query.read, _opts) | ||
21 … | + } | ||
22 … | +} |
Built with git-ssb-web