git ssb

0+

Josiah / ssb-tags



Commit 1f77997f086f31ce27aa9d3d2401244657e728f6

Use root tag id as the indexing key

The root key is the key that actually matters since that is what
ties different instances of tag messages together.
Josiah Witt committed on 2/13/2018, 10:27:36 PM
Parent: 0e8fddd65bb3d05fbcafb9c66ceea4ea5d9648e5

Files changed

index.jschanged
index.jsView
@@ -17,28 +17,35 @@
1717
1818 function reduce(result, item) {
1919 if (!item) return result
2020
21- var { tag, author, message, tagged, timestamp } = item
22- var storedTimestamp = get(result, [author, tag, message])
21 + var { root, tagKey, author, message, tagged, timestamp } = item
22 + var storedTimestamp = get(result, [author, tagKey, message])
2323
24- if (shouldAddTag()) {
24 + if (root) {
25 + var rootTag = {
26 + [author]: {
27 + [tagKey]: {}
28 + }
29 + }
30 + result = merge(result, rootTag)
31 + } else if (shouldAddTag()) {
2532 var newTag = {
2633 [author]: {
27- [tag]: {
34 + [tagKey]: {
2835 [message]: timestamp
2936 }
3037 }
3138 }
3239 result = merge(result, newTag)
3340 } else if (shouldRemoveTag()) {
34- delete result[author][tag][message]
41 + delete result[author][tagKey][message]
3542 }
3643
3744 return result
3845
3946 function shouldAddTag() {
40- if (tagged !== true) return false
47 + if (!tagged) return false
4148 return !storedTimestamp || timestamp > storedTimestamp
4249 }
4350
4451 function shouldRemoveTag() {
@@ -54,21 +61,32 @@
5461 if (msg.value.content === 'string') {
5562 // unbox private message (requires ssb-private plugin)
5663 msg = ssb.private.unbox(msg)
5764 }
58-
65 +
5966 if (isTag(msg)) {
6067 return {
61- tag: msg.key,
68 + tagKey: msg.value.content.root,
6269 author: msg.value.author,
6370 message: msg.value.content.message,
6471 tagged: msg.value.content.tagged,
6572 timestamp: msg.value.timestamp
6673 }
67- }
74 + } else if (isRootTag(msg)) {
75 + return {
76 + tagKey: msg.key,
77 + author: msg.value.author,
78 + timestamp: msg.value.timestamp,
79 + root: true
80 + }
81 + }
6882 }
6983 }
7084
85 +function isRootTag(msg) {
86 + return get(msg, 'value.content.type') === 'tag'
87 +}
88 +
7189 function isTag(msg) {
7290 return get(msg, 'value.content.type') === 'tag'
7391 && ref.isLink(get(msg, 'value.content.message'))
7492 }

Built with git-ssb-web