git ssb

2+

mixmix / ticktack



Commit 804b24d8cddfc3e10bfebea176fdb4109178fcd6

working next-stepper on blogIndex with latest ssb-query

mix irving committed on 5/28/2018, 4:21:50 AM
Parent: 17df3c936c4c4573ec97072a96be633ed3ae1c2b

Files changed

app/page/blogIndex.jschanged
blog/sync/isBlog.jschanged
package-lock.jsonchanged
package.jsonchanged
app/page/blogIndex.jsView
@@ -1,20 +1,22 @@
11 const nest = require('depnest')
2-const { h, Value, Array: MutantArray, resolve } = require('mutant')
2 +const { h, Array: MutantArray, resolve } = require('mutant')
33 const Scroller = require('mutant-scroll')
44 const pull = require('pull-stream')
5 +
56 const Next = require('pull-next')
7 +const get = require('lodash/get')
8 +const clone = require('lodash/cloneDeep')
69
710 exports.gives = nest('app.page.blogIndex')
811
912 exports.needs = nest({
1013 'app.html.blogCard': 'first',
1114 'app.html.topNav': 'first',
12- // 'app.html.scroller': 'first',
1315 'app.html.sideNav': 'first',
1416 'blog.sync.isBlog': 'first',
15- 'feed.pull.public': 'first',
16- 'feed.pull.type': 'first',
17 + 'sbot.pull.stream': 'first',
18 + 'sbot.obs.connection': 'first',
1719 'history.sync.push': 'first',
1820 'keys.sync.id': 'first',
1921 'message.sync.isBlocked': 'first',
2022 'translations.sync.strings': 'first',
@@ -28,35 +30,13 @@
2830 // location here can expected to be: { page: 'blogIndex'}
2931
3032 var strings = api.translations.sync.strings()
3133
32- // const filter = () => pull(
33- // pull.filter(api.blog.sync.isBlog), // isBlog or Plog?
34- // pull.filter(msg => !msg.value.content.root), // show only root messages
35- // pull.filter(msg => !api.message.sync.isBlocked(msg)) // this is already in feed.pull.type
36- // )
37-
38- // stream: api.feed.pull.public, // for post + blog type
39-
40- const streamToTop = pull(
41- // next(stream, { live: true, reverse: false, old: false, limit: 100, property: indexProperty }),
42- api.feed.pull.type('blog')({ live: true, reverse: false, old: false }),
43- // filter()
44- )
45-
46-
47- const streamToBottom = pull(
48- Next
49- api.feed.pull.type('blog')({ live: false, reverse: true }),
50- // filter()
51-
52- )
53-
5434 var blogs = Scroller({
5535 classList: ['content'],
5636 prepend: api.app.html.topNav(location),
57- streamToTop,
58- streamToBottom,
37 + streamToTop: Source({ reverse: false, live: true, old: false, limit: 20 }),
38 + streamToBottom: Source({ reverse: true, live: false, limit: 20 }),
5939 updateTop: update,
6040 updateBottom: update,
6141 store: blogsCache,
6242 render
@@ -67,23 +47,43 @@
6747 blogs
6848 ])
6949 })
7050
51 + function Source (opts) {
52 + const commonOpts = {
53 + query: [{
54 + $filter: {
55 + value: {
56 + content: {
57 + type: 'blog'
58 + },
59 + timestamp: { $gt: 0, $lt: undefined }
60 + }
61 + }
62 + }]
63 + }
64 +
65 + return pull(
66 + StepperStream(
67 + (options) => api.sbot.pull.stream(sbot => sbot.query.read(options)),
68 + Object.assign(commonOpts, opts)
69 + ),
70 + pull.filter(api.blog.sync.isBlog), // isBlog or Plog?
71 + // pull.filter(msg => !msg.value.content.root), // show only root messages
72 + pull.filter(msg => !api.message.sync.isBlocked(msg)) // this is already in feed.pull.type
73 + )
74 + }
75 +
7176 function update (soFar, newBlog) {
7277 soFar.transaction(() => {
7378 var object = newBlog // Value(newBlog)
7479
7580 const index = indexOf(soFar, (blog) => newBlog.key === resolve(blog).key)
7681 // if blog already in cache, not needed again
7782 if (index >= 0) return
7883
79- // Orders by: time received
80- const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp)
84 + const justOlderPosition = indexOf(soFar, (msg) => newBlog.value.timestamp > resolve(msg).value.timestamp)
8185
82- // Orders by: time published BUT the messagesByType stream streams _by time received_
83- // TODO - we need an index of all blogs otherwise the scroller doesn't work...
84- // const justOlderPosition = indexOf(soFar, (msg) => newBlog.value.timestamp > resolve(msg).value.timestamp)
85-
8686 if (justOlderPosition > -1) {
8787 soFar.insert(object, justOlderPosition)
8888 } else {
8989 soFar.push(object)
@@ -106,4 +106,51 @@
106106 }
107107 }
108108 return -1
109109 }
110 +
111 +// this is needed because muxrpc doesn't do back-pressure yet
112 +// this is a modified pull-next-step for ssb-query
113 +function StepperStream (createStream, _opts) {
114 + var opts = clone(_opts)
115 + var last = null
116 + var count = -1
117 +
118 + return Next(() => {
119 + if (last) {
120 + if (count === 0) return
121 + // mix: not sure which case this ends stream for
122 + //
123 +
124 + var value = get(last, ['value', 'timestamp'])
125 + if (value == null) return
126 +
127 + if (opts.reverse) {
128 + opts.query[0].$filter.value.timestamp.$lt = value
129 + } else {
130 + opts.query[0].$filter.value.timestamp.$gt = value
131 + }
132 + last = null
133 + }
134 +
135 + return pull(
136 + createStream(clone(opts)),
137 + pull.through(
138 + (msg) => {
139 + count++
140 + if (!msg.sync) {
141 + last = msg
142 + }
143 + },
144 + (err) => {
145 + // retry on errors...
146 + if (err) {
147 + count = -1
148 + return count
149 + }
150 + // end stream if there were no results
151 + if (last == null) last = {}
152 + }
153 + )
154 + )
155 + })
156 +}
blog/sync/isBlog.jsView
@@ -2,9 +2,9 @@
22 const get = require('lodash/get')
33 const isBlog = require('scuttle-blog/isBlog')
44
55 exports.gives = nest({
6- 'blog.sync.isBlog': true,
6 + 'blog.sync.isBlog': true
77 })
88
99 const MIN_LENGTH_FOR_BLOG_POST = 800
1010
@@ -13,12 +13,16 @@
1313 'blog.sync.isBlog': isBloggy
1414 })
1515
1616 function isBloggy (msg) {
17 + // if (!isBlog(msg)) {
18 + // console.log(isBlog.errors)
19 + // console.log(JSON.stringify(msg.value.content, null, 2))
20 + // console.log('')
21 + // }
1722 if (isBlog(msg)) return true
1823
1924 const type = msg.value.content.type
2025 if (type === 'post' && get(msg, 'value.content.text', '').length > MIN_LENGTH_FOR_BLOG_POST) return true
2126 return false
2227 }
2328 }
24-
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 289783 bytes
New file size: 282870 bytes
package.jsonView
@@ -47,9 +47,9 @@
4747 "patch-history": "^1.0.0",
4848 "patch-profile": "^1.0.4",
4949 "patch-settings": "^1.1.2",
5050 "patch-suggest": "^1.1.0",
51- "patchcore": "^1.23.3",
51 + "patchcore": "^1.26.1",
5252 "pull-defer": "^0.2.2",
5353 "pull-next": "^1.0.1",
5454 "pull-next-step": "^1.0.0",
5555 "pull-obv": "^1.3.0",
@@ -70,9 +70,9 @@
7070 "ssb-keys": "^7.0.10",
7171 "ssb-markdown": "^3.3.0",
7272 "ssb-mentions": "^0.4.0",
7373 "ssb-private": "^0.1.2",
74- "ssb-query": "^0.1.2",
74 + "ssb-query": "^2.1.0",
7575 "ssb-reduce-stream": "^1.0.2",
7676 "ssb-ref": "^2.7.1",
7777 "ssb-server-channel": "^1.1.1",
7878 "ssb-ws": "^1.0.3",

Built with git-ssb-web