git ssb

2+

mixmix / ticktack



Commit 2cf06eb4b4d0e4ac4b6f5dced90ef5da82a0a8fd

Merge pull request #147 from ticktackim/blogs_in_order

Blogs in order on blogIndex page
mix irving authored on 5/28/2018, 4:23:49 AM
GitHub committed on 5/28/2018, 4:23:49 AM
Parent: 67583b0e9605f9e2c2a95ff125a23e8a1cca8953
Parent: 804b24d8cddfc3e10bfebea176fdb4109178fcd6

Files changed

app/page/blogIndex.jschanged
blog/sync/isBlog.jschanged
package-lock.jsonchanged
package.jsonchanged
app/page/blogIndex.jsView
@@ -1,18 +1,22 @@
11 const nest = require('depnest')
2-const { h, Value, Array: MutantArray, resolve } = require('mutant')
2 +const { h, Array: MutantArray, resolve } = require('mutant')
3 +const Scroller = require('mutant-scroll')
34 const pull = require('pull-stream')
45
6 +const Next = require('pull-next')
7 +const get = require('lodash/get')
8 +const clone = require('lodash/cloneDeep')
9 +
510 exports.gives = nest('app.page.blogIndex')
611
712 exports.needs = nest({
813 'app.html.blogCard': 'first',
914 'app.html.topNav': 'first',
10- 'app.html.scroller': 'first',
1115 'app.html.sideNav': 'first',
1216 'blog.sync.isBlog': 'first',
13- 'feed.pull.public': 'first',
14- 'feed.pull.type': 'first',
17 + 'sbot.pull.stream': 'first',
18 + 'sbot.obs.connection': 'first',
1519 'history.sync.push': 'first',
1620 'keys.sync.id': 'first',
1721 'message.sync.isBlocked': 'first',
1822 'translations.sync.strings': 'first',
@@ -26,23 +30,16 @@
2630 // location here can expected to be: { page: 'blogIndex'}
2731
2832 var strings = api.translations.sync.strings()
2933
30- var blogs = api.app.html.scroller({
34 + var blogs = Scroller({
3135 classList: ['content'],
3236 prepend: api.app.html.topNav(location),
33- // stream: api.feed.pull.public,
34- stream: api.feed.pull.type('blog'),
35- filter: () => pull(
36- // pull.filter(api.blog.sync.isBlog),
37- pull.filter(msg => !msg.value.content.root), // show only root messages
38- pull.filter(msg => !api.message.sync.isBlocked(msg))
39- ),
40- // FUTURE : if we need better perf, we can add a persistent cache. At the moment this page is fast enough though.
41- // See implementation of app.html.sideNav for example
42- store: blogsCache,
37 + streamToTop: Source({ reverse: false, live: true, old: false, limit: 20 }),
38 + streamToBottom: Source({ reverse: true, live: false, limit: 20 }),
4339 updateTop: update,
4440 updateBottom: update,
41 + store: blogsCache,
4542 render
4643 })
4744
4845 return h('Page -blogIndex', {title: strings.home}, [
@@ -50,25 +47,43 @@
5047 blogs
5148 ])
5249 })
5350
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 +
5476 function update (soFar, newBlog) {
5577 soFar.transaction(() => {
56- const { timestamp } = newBlog.value
57-
5878 var object = newBlog // Value(newBlog)
5979
6080 const index = indexOf(soFar, (blog) => newBlog.key === resolve(blog).key)
6181 // if blog already in cache, not needed again
6282 if (index >= 0) return
6383
64- // Orders by: time received
65- const justOlderPosition = indexOf(soFar, (msg) => newBlog.timestamp > resolve(msg).timestamp)
84 + const justOlderPosition = indexOf(soFar, (msg) => newBlog.value.timestamp > resolve(msg).value.timestamp)
6685
67- // Orders by: time published BUT the messagesByType stream streams _by time received_
68- // TODO - we need an index of all blogs otherwise the scroller doesn't work...
69- // const justOlderPosition = indexOf(soFar, (msg) => timestamp > resolve(msg).value.timestamp)
70-
7186 if (justOlderPosition > -1) {
7287 soFar.insert(object, justOlderPosition)
7388 } else {
7489 soFar.push(object)
@@ -91,4 +106,51 @@
91106 }
92107 }
93108 return -1
94109 }
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