git ssb

7+

dinoworm 🐛 / patchcore



Commit 196bfa929c905a10e03900db3ff77a5f05c35300

Merge branch 'master' into backlinks-index

Matt McKegg committed on 6/12/2017, 5:05:45 AM
Parent: b57e44a4c2db39bc5672f61e5a4fdc3c9abccab7
Parent: d5f37c13cd95a2e321a1e51db1e64eef746ee0ea

Files changed

blob/obs/has.jsadded
message/html/markdown.jschanged
package.jsonchanged
blob/obs/has.jsView
@@ -1,0 +1,57 @@
1 +var nest = require('depnest')
2 +var pull = require('pull-stream')
3 +var Value = require('mutant/value')
4 +var onceTrue = require('mutant/once-true')
5 +var defer = require('pull-defer')
6 +
7 +exports.needs = nest({
8 + 'sbot.obs.connection': 'first'
9 +})
10 +
11 +exports.gives = nest('blob.obs.has', true)
12 +
13 +exports.create = function (api) {
14 + var cbs = null
15 +
16 + return nest('blob.obs.has', function (id) {
17 + var value = Value()
18 + onceTrue(api.sbot.obs.connection, sbot => {
19 + sbot.blobs.has(id, (_, has) => {
20 + if (has) {
21 + value.set(true)
22 + } else {
23 + value.set(false)
24 + waitFor(id, () => value.set(true))
25 + }
26 + })
27 + })
28 + return value
29 + })
30 +
31 + function waitFor (id, cb) {
32 + if (!cbs) {
33 + cbs = {}
34 + pull(
35 + StreamWhenConnected(api.sbot.obs.connection, sbot => sbot.blobs.ls({old: false})),
36 + pull.drain(blob => {
37 + if (cbs[blob]) {
38 + while (cbs[blob].length) {
39 + cbs[blob].pop()()
40 + }
41 + delete cbs[blob]
42 + }
43 + })
44 + )
45 + }
46 + if (!cbs[id]) cbs[id] = []
47 + cbs[id].push(cb)
48 + }
49 +}
50 +
51 +function StreamWhenConnected (connection, fn) {
52 + var stream = defer.source()
53 + onceTrue(connection, function (connection) {
54 + stream.resolve(fn(connection))
55 + })
56 + return stream
57 +}
message/html/markdown.jsView
@@ -2,11 +2,13 @@
22 const h = require('mutant/h')
33 const ref = require('ssb-ref')
44 const nest = require('depnest')
55 var htmlEscape = require('html-escape')
6 +var watch = require('mutant/watch')
67
78 exports.needs = nest({
89 'blob.sync.url': 'first',
10 + 'blob.obs.has': 'first',
911 'emoji.sync.url': 'first'
1012 })
1113
1214 exports.gives = nest('message.html.markdown')
@@ -27,24 +29,26 @@
2729 }
2830 })
2931 }
3032
31- var md = h('div', {className: 'Markdown'})
32- md.innerHTML = renderer.block(content.text, {
33- emoji: (emoji) => {
34- var url = emojiMentions[emoji]
35- ? api.blob.sync.url(emojiMentions[emoji])
36- : api.emoji.sync.url(emoji)
37- return renderEmoji(emoji, url)
38- },
39- toUrl: (id) => {
40- if (ref.isBlob(id)) return api.blob.sync.url(id)
41- return mentions[id] || id
42- },
43- imageLink: (id) => id
33 + return h('Markdown', {
34 + hooks: [
35 + LoadingBlobHook(api.blob.obs.has)
36 + ],
37 + innerHTML: renderer.block(content.text, {
38 + emoji: (emoji) => {
39 + var url = emojiMentions[emoji]
40 + ? api.blob.sync.url(emojiMentions[emoji])
41 + : api.emoji.sync.url(emoji)
42 + return renderEmoji(emoji, url)
43 + },
44 + toUrl: (id) => {
45 + if (ref.isBlob(id)) return api.blob.sync.url(id)
46 + return mentions[id] || id
47 + },
48 + imageLink: (id) => id
49 + })
4450 })
45-
46- return md
4751 }
4852
4953 function renderEmoji (emoji, url) {
5054 if (!url) return ':' + emoji + ':'
@@ -57,4 +61,27 @@
5761 >
5862 `
5963 }
6064 }
65 +
66 +function LoadingBlobHook (hasBlob) {
67 + return function (element) {
68 + var releases = []
69 + element.querySelectorAll('img').forEach(img => {
70 + var id = ref.extract(img.src)
71 + if (id) {
72 + releases.push(watch(hasBlob(id), has => {
73 + if (has === false) {
74 + img.classList.add('-pending')
75 + } else {
76 + img.classList.remove('-pending')
77 + }
78 + }))
79 + }
80 + })
81 + return function () {
82 + while (releases.length) {
83 + releases.pop()()
84 + }
85 + }
86 + }
87 +}
package.jsonView
@@ -1,7 +1,7 @@
11 {
22 "name": "patchcore",
3- "version": "0.7.0",
3 + "version": "0.8.0",
44 "description": "minimal core for ssb clients",
55 "main": "index.js",
66 "scripts": {
77 "start": "electro example",

Built with git-ssb-web