git ssb

0+

Josiah / ssb-tags



Commit 9fc97c76b6c3a194ee7d1ccab6a3fe398866e4b4

First pass at tags

Josiah Witt committed on 1/15/2018, 1:23:06 AM
Parent: 0a61f73856a935cde1353f9eed9dc9f27928802f

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -1,8 +1,8 @@
11 var FlumeReduce = require('flumeview-reduce')
22 var ref = require('ssb-ref')
33
4-exports.name = 'sbot-tags'
4 +exports.name = 'tags'
55 exports.version = require('./package.json').version
66 exports.manifest = {
77 stream: 'source',
88 get: 'async'
@@ -13,23 +13,47 @@
1313
1414 function reduce (result, item) {
1515 if (!result) result = {}
1616 if (!result.tags) result.tags = {}
17 + if (!result.messages) result.messages = {}
1718 var tags = result.tags
19 + var messages = result.messages
1820
1921 if (item) {
20- var { author, tag, message, tagged, timestamp } = item
22 + var { tag, author, message, tagged, timestamp } = item
23 +
2124 if (!tags[author]) tags[author] = {}
2225 if (!tags[author][tag]) tags[author][tag] = {}
23- if (!tags[author][tag][message] || timestamp > tags[author][tag][message].timestamp) {
26 + if (
27 + tagged &&
28 + (!tags[author][tag][message] ||
29 + timestamp > tags[author][tag][message].timestamp)
30 + ) {
2431 tags[author][tag][message] = { timestamp, tagged }
32 + } else if (!tagged && tags[author][tag][message]) {
33 + delete tags[author][tag][message]
2534 }
35 +
36 + if (!messages[message]) messages[message] = {}
37 + if (!messages[message][tag]) messages[message][tag] = {}
38 + if (
39 + tagged &&
40 + (!messages[message][tag][author] ||
41 + timestamp > messages[message][tag][author].timestamp)
42 + ) {
43 + messages[message][tag][author] = { timestamp, tagged }
44 + } else if (!tagged && messages[message][tag][author]) {
45 + delete messages[message][tag][authpr]
46 + }
2647 }
2748
2849 return result
2950 }
3051
3152 function map (msg) {
53 + // only include your own tags (for now)
54 + if (msg.value.author !== ssb.id) return
55 +
3256 // unbox private message
3357 if (msg.value.content === 'string') {
3458 // unbox private message (requires ssb-private plugin)
3559 msg = ssb.private.unbox(msg)
package.jsonView
@@ -1,12 +1,12 @@
11 {
2- "name": "sbot-tags",
2 + "name": "ssb-tags",
33 "description": "scuttlebot plugin for getting reduced 'tags' state",
44 "version": "0.1.0",
5- "homepage": "https://github.com/wittjosiah/sbot-tags",
5 + "homepage": "https://github.com/wittjosiah/ssb-tags",
66 "repository": {
77 "type": "git",
8- "url": "git://github.com/wittjosiah/sbot-tags.git"
8 + "url": "git://github.com/wittjosiah/ssb-tags.git"
99 },
1010 "dependencies": {
1111 "flumeview-reduce": "^1.3.9",
1212 "ssb-ref": "^2.7.1"

Built with git-ssb-web