git ssb

0+

Piet / ssb-loomio



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 AM
Parent: 34b19bd57eb496c6327fb91324191692206ce85a

Files changed

methods.jschanged
poll/pull/all.jsadded
poll/pull/closed.jsadded
poll/pull/open.jsadded
methods.jsView
@@ -10,8 +10,13 @@
1010 sync: {
1111 isPoll: () => isPoll,
1212 isChooseOnePoll: () => isChooseOnePoll
1313 // 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')
1419 }
1520 },
1621 position: {
1722 async: {
poll/pull/all.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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