aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 3d0f89ff80dce27f7a913bd119aa62824b0804a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# logbook-channels

logbook-channels is a utility to unify the two ways of adding messages to channels in Scuttlebutt: hashtags and channel headers.

The files in the repo are as follows:
- **pull-many-v2.js** is a utility that must be in the same directory as either *channels-v2.js* or *channels-lib.js*.
- **channels-v2.js** is a standalone command line utility. To print all messages in the `logbook` channel, run `node channels-v2.js logbook`.
- **channels-lib.js** provides channel messages from a pull-stream. Example usage would be:

```
const pull = require("pull-stream");
const clientFactory = require("ssb-client");
const channels = require("./channels-lib");

clientFactory(function(err, client) {
  if(err) throw err;
  channel.getMessages(client, "logbook", null, function(messageStream) {
    pull(messageStream, pull.drain(function(msg, _) {
      console.log(JSON.stringify(msg));
    })
  });
});
```

To integrate into Patchfoo:
```
Serve.prototype.logbook = function (ext) {
  var q = this.query
  var opts = {
    reverse: !q.forwards,
    //sortByTimestamp: q.sort === 'claimed',
    sortByTimestamp: q.sort || 'claimed',
    lt: Number(q.lt) || Date.now(),
    gt: Number(q.gt) || -Infinity,
    filter: q.filter,
  }

  logbook.getMessages(this.app.sbot, "logbook", this, function(messageStream, serve) {
    pull(messageStream,
	    serve.renderThreadPaginated(opts, null, q),
	    serve.wrapMessages(),
	    serve.wrapPublic(),
	    serve.wrapPage('logbook'),
	    serve.respondSink(200, {
		    'Content-Type': ctype(ext)
	    })
	    //pull.drain(function(msg) {
		    //console.log(JSON.stringify(msg));
	    //})
    )
  }
  , hops=3)

	    //this.renderThreadPaginated(opts, null, q),
	    //this.wrapMessages(),
	    //this.wrapPublic(),
	    //this.wrapPage('public'),
	    //this.respondSink(200, {
		    //'Content-Type': ctype(ext)
	    //})
    //)
    //});

  //pull(
    //this.app.createLogStream(opts),
    //pull.filter(msg => {
      //return !msg.value.content.vote
    //}),
    //this.renderThreadPaginated(opts, null, q),
    //this.wrapMessages(),
    //this.wrapPublic(),
    //this.wrapPage('public'),
    //this.respondSink(200, {
      //'Content-Type': ctype(ext)
    //})
  //)
}
```Serve.prototype.logbook = function (ext) {
  var q = this.query
  var opts = {
    reverse: !q.forwards,
    //sortByTimestamp: q.sort === 'claimed',
    sortByTimestamp: q.sort || 'claimed',
    lt: Number(q.lt) || Date.now(),
    gt: Number(q.gt) || -Infinity,
    filter: q.filter,
  }

  logbook.getMessages(this.app.sbot, "logbook", this, function(messageStream, serve) {
    pull(messageStream,
	    serve.renderThreadPaginated(opts, null, q),
	    serve.wrapMessages(),
	    serve.wrapPublic(),
	    serve.wrapPage('logbook'),
	    serve.respondSink(200, {
		    'Content-Type': ctype(ext)
	    })
	    //pull.drain(function(msg) {
		    //console.log(JSON.stringify(msg));
	    //})
    )
  }
  , hops=3)

	    //this.renderThreadPaginated(opts, null, q),
	    //this.wrapMessages(),
	    //this.wrapPublic(),
	    //this.wrapPage('public'),
	    //this.respondSink(200, {
		    //'Content-Type': ctype(ext)
	    //})
    //)
    //});

  //pull(
    //this.app.createLogStream(opts),
    //pull.filter(msg => {
      //return !msg.value.content.vote
    //}),
    //this.renderThreadPaginated(opts, null, q),
    //this.wrapMessages(),
    //this.wrapPublic(),
    //this.wrapPage('public'),
    //this.respondSink(200, {
      //'Content-Type': ctype(ext)
    //})
  //)
}