git ssb

3+

arj / patchbook



Tree: c6808ebda95764b1cdd2b287584c051d8901fb42

Files: c6808ebda95764b1cdd2b287584c051d8901fb42 / book / obs / book.js

1135 bytesRaw
1const nest = require('depnest')
2const ref = require('ssb-ref')
3const { Value, Struct } = require('mutant')
4
5exports.needs = nest({
6 'book.pull.get': 'first',
7 'book.obs.struct': 'first',
8 'sbot.async.publish': 'first'
9})
10
11exports.gives = nest('book.obs.book')
12
13exports.create = function (api) {
14 return nest('book.obs.book', function (id) {
15 if (!ref.isLink(id)) throw new Error('a valid id must be specified')
16
17 let book = api.book.obs.struct({ key: id })
18 api.book.pull.get(id, dbBook => {
19 // FIXME: subjective
20 Object.keys(dbBook.common).forEach((k) => {
21 if (dbBook.common[k]) {
22 book[k].set(dbBook.common[k])
23 }
24 })
25 })
26
27 book.amend = function(cb)
28 {
29 let msg = { type: 'bookclub-update', root: id }
30
31 let s = book()
32
33 msg.common = {
34 title: s.title,
35 authors: s.authors,
36 description: s.description,
37 images: s.images
38 }
39
40 console.log(msg)
41 return
42
43 /* FIXME
44 if (book.subjective)
45 msg.subjective = subjectiveObj
46 */
47
48 api.sbot.async.publish(msg, cb)
49 }
50
51 return book
52 })
53}
54

Built with git-ssb-web