git ssb

7+

dinoworm 🐛 / patchcore



Commit fa010d0d169bf175ec229c7939cf4b2f25f0d442

feed.obs.thread: resolve blog body

Matt McKegg committed on 4/10/2018, 9:16:57 AM
Parent: 9b421343eb76d9c775a0f125bdc96770f966c4ea

Files changed

feed/obs/thread.jschanged
package.jsonchanged
feed/obs/thread.jsView
@@ -1,15 +1,19 @@
11 var nest = require('depnest')
22 var sort = require('ssb-sort')
33 var ref = require('ssb-ref')
4 +var isBlog = require('scuttle-blog/isBlog')
5 +var Blog = require('scuttle-blog')
6 +
47 var { Array: MutantArray, Value, map, computed, concat } = require('mutant')
58
69 exports.needs = nest({
710 'backlinks.obs.for': 'first',
811 'sbot.async.get': 'first',
912 'message.sync.unbox': 'first',
1013 'message.sync.root': 'first',
11- 'message.sync.isBlocked': 'first'
14 + 'message.sync.isBlocked': 'first',
15 + 'sbot.obs.connection': 'first'
1216 })
1317
1418 exports.gives = nest('feed.obs.thread')
1519
@@ -22,13 +26,27 @@
2226 var { isBlocked, root } = api.message.sync
2327
2428 var prepend = MutantArray()
2529 api.sbot.async.get(rootId, (err, value) => {
26- sync.set(true)
2730 if (!err) {
2831 var msg = unboxIfNeeded({key: rootId, value})
2932 if (isBlocked(msg)) msg.isBlocked = true
30- prepend.push(Value(msg))
33 +
34 + if (isBlog(msg)) {
35 + // resolve the blog body before returning
36 + Blog(api.sbot.obs.connection).async.get(msg, (err, result) => {
37 + if (!err) {
38 + msg.body = result.body
39 + prepend.push(Value(msg))
40 + sync.set(true)
41 + }
42 + })
43 + } else {
44 + sync.set(true)
45 + prepend.push(Value(msg))
46 + }
47 + } else {
48 + sync.set(true)
3149 }
3250 })
3351
3452 var backlinks = api.backlinks.obs.for(rootId)
@@ -45,9 +63,9 @@
4563 })
4664
4765 // append the root message to the sorted replies list
4866 // -------------------------
49- // concat preserves the individual observable messages so that clients don't need to
67 + // concat preserves the individual observable messages so that clients don't need to
5068 // rerender the entire list when an item is added (map will only be called for new items)
5169 // (we can't use a computed here as it would squash the individual observables into a single one)
5270 var messages = concat([prepend, replies])
5371
package.jsonView
@@ -46,8 +46,9 @@
4646 "pull-abortable": "^4.1.0",
4747 "pull-cat": "^1.1.11",
4848 "pull-reconnect": "0.0.3",
4949 "pull-stream": "^3.5.0",
50 + "scuttle-blog": "^1.0.0",
5051 "simple-mime": "^0.1.0",
5152 "sorted-array-functions": "^1.0.0",
5253 "split-buffer": "^1.0.0",
5354 "ssb-client": "^4.5.2",

Built with git-ssb-web