Commit c97bf36a82c6f82f3397cbf80d13e81822363318
dx: use ssb-db2 for votes and isPrivatelyBlocking
Andre Staltz committed on 12/28/2020, 4:42:52 PMParent: 1679c03c9b24dafb71f492aff7d40a5e2c326477
Files changed
src/backend/package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 331371 bytes New file size: 323273 bytes |
src/backend/package.json | ||
---|---|---|
@@ -16,9 +16,9 @@ | ||
16 | 16 | "cached-path-relative": ">=1.0.2", |
17 | 17 | "chloride": "2.2.14", |
18 | 18 | "estimate-progress": "1.0.0", |
19 | 19 | "ip": "1.1.5", |
20 | - "leveldown-nodejs-mobile": "5.1.1-3", | |
20 | + "leveldown-nodejs-mobile": "5.4.1-1", | |
21 | 21 | "multiserver-electron-ipc": "1.2.0", |
22 | 22 | "multiserver-rn-channel": "1.3.0", |
23 | 23 | "non-private-ip-android": "1.4.4-3", |
24 | 24 | "pull-cat": "1.1.11", |
@@ -38,9 +38,9 @@ | ||
38 | 38 | "ssb-bluetooth": "1.1.14", |
39 | 39 | "ssb-config": "3.4.5", |
40 | 40 | "ssb-conn": "0.19.1", |
41 | 41 | "ssb-db": "19.3.1", |
42 | - "ssb-db2": "0.4.0", | |
42 | + "ssb-db2": "0.12.0", | |
43 | 43 | "ssb-dht-invite": "1.11.0", |
44 | 44 | "ssb-ebt-fork-staltz": "5.6.7-1", |
45 | 45 | "ssb-friends": "4.1.4", |
46 | 46 | "ssb-invite-client": "1.1.0", |
src/backend/patches/ssb-db+19.3.1.patch | ||
---|---|---|
@@ -1,4 +1,26 @@ | ||
1 | +diff --git a/node_modules/ssb-db/create.js b/node_modules/ssb-db/create.js | |
2 | +index ec47ca5..da1ac54 100644 | |
3 | +--- a/node_modules/ssb-db/create.js | |
4 | ++++ b/node_modules/ssb-db/create.js | |
5 | +@@ -55,7 +55,7 @@ module.exports = function (path, opts, keys) { | |
6 | + } | |
7 | + | |
8 | + if (ref.isMsg(key)) { | |
9 | +- return db.keys.get(key, function (err, data) { | |
10 | ++ return db.keys.get(key, function (err, data, offset) { | |
11 | + if (err) return cb(err) | |
12 | + | |
13 | + if (isPrivate && unbox) { | |
14 | +@@ -70,7 +70,7 @@ module.exports = function (path, opts, keys) { | |
15 | + result = u.originalValue(data.value) | |
16 | + } | |
17 | + | |
18 | +- cb(null, !meta ? result : {key: data.key, value: result, timestamp: data.timestamp}) | |
19 | ++ cb(null, !meta ? result : {key: data.key, value: result, timestamp: data.timestamp}, offset) | |
20 | + }) | |
21 | + } else if (ref.isMsgLink(key)) { | |
22 | + var link = ref.parseLink(key) | |
1 | 23 | diff --git a/node_modules/ssb-db/extras.js b/node_modules/ssb-db/extras.js |
2 | 24 | index 78f6cda..9a6f9e7 100644 |
3 | 25 | --- a/node_modules/ssb-db/extras.js |
4 | 26 | +++ b/node_modules/ssb-db/extras.js |
src/backend/plugins/friendsUtils.ts | ||
---|---|---|
@@ -6,8 +6,16 @@ | ||
6 | 6 | |
7 | 7 | import {FeedId, Msg} from 'ssb-typescript'; |
8 | 8 | const pull = require('pull-stream'); |
9 | 9 | const cat = require('pull-cat'); |
10 | +const { | |
11 | + and, | |
12 | + author, | |
13 | + contact, | |
14 | + descending, | |
15 | + live, | |
16 | + toPullStream, | |
17 | +} = require('ssb-db2/operators'); | |
10 | 18 | |
11 | 19 | export = { |
12 | 20 | name: 'friendsUtils', |
13 | 21 | version: '1.0.0', |
@@ -24,29 +32,27 @@ | ||
24 | 32 | isPrivatelyBlockingStream(dest: FeedId) { |
25 | 33 | return pull( |
26 | 34 | cat([ |
27 | 35 | pull( |
28 | - ssb.links({ | |
29 | - source: ssb.id, | |
30 | - dest, | |
31 | - rel: 'contact', | |
32 | - live: false, | |
33 | - reverse: true, | |
34 | - }), | |
36 | + ssb.db.query( | |
37 | + and(author(ssb.id), contact(dest)), | |
38 | + descending(), | |
39 | + toPullStream(), | |
40 | + ), | |
35 | 41 | pull.take(1), |
36 | 42 | ), |
37 | - ssb.links({ | |
38 | - source: ssb.id, | |
39 | - dest, | |
40 | - rel: 'contact', | |
41 | - old: false, | |
42 | - live: true, | |
43 | - }), | |
43 | + ssb.db.query( | |
44 | + and(author(ssb.id), contact(dest)), | |
45 | + live(), | |
46 | + toPullStream(), | |
47 | + ), | |
44 | 48 | ]), |
45 | - pull.asyncMap((link: any, cb: any) => { | |
46 | - ssb.get(link.key, cb); | |
49 | + pull.map((msg: Msg) => { | |
50 | + if (!msg || !msg.value) return false; | |
51 | + if (typeof msg.value.content === 'string') return true; | |
52 | + if ((msg.value as any).meta?.private === true) return true; | |
53 | + return false; | |
47 | 54 | }), |
48 | - pull.map((val: Msg['value']) => typeof val.content === 'string'), | |
49 | 55 | ); |
50 | 56 | }, |
51 | 57 | }; |
52 | 58 | }, |
src/backend/plugins/votes.ts | ||
---|---|---|
@@ -6,10 +6,13 @@ | ||
6 | 6 | |
7 | 7 | import {Msg, FeedId} from 'ssb-typescript'; |
8 | 8 | const pull = require('pull-stream'); |
9 | 9 | const ref = require('ssb-ref'); |
10 | +const {and, votesFor, live, toPullStream} = require('ssb-db2/operators'); | |
10 | 11 | import {Readable} from './helpers/types'; |
11 | 12 | |
13 | +const THUMBS_UP_UNICODE = '\ud83d\udc4d'; | |
14 | + | |
12 | 15 | function collectUniqueAuthors() { |
13 | 16 | const theMap: Map<FeedId, string> = new Map(); |
14 | 17 | return function sink(read: Readable<Msg>) { |
15 | 18 | const outputSource: Readable<Array<[FeedId, string]>> = (abort, cb) => { |
@@ -30,9 +33,10 @@ | ||
30 | 33 | } |
31 | 34 | |
32 | 35 | const author = msg.value.author; |
33 | 36 | const voteValue = msg.value.content.vote.value; |
34 | - const voteExpression = msg.value.content.vote.expression ?? 'Like'; | |
37 | + const voteExpression = | |
38 | + msg.value.content.vote.expression ?? THUMBS_UP_UNICODE; | |
35 | 39 | if (voteValue < 1 && theMap.has(author)) { |
36 | 40 | theMap.delete(author); |
37 | 41 | } else if (voteValue >= 1) { |
38 | 42 | // this delete is used on purpose, to reset the insertion order |
@@ -60,22 +64,14 @@ | ||
60 | 64 | allow: ['voterStream'], |
61 | 65 | }, |
62 | 66 | }, |
63 | 67 | init: function init(ssb: any) { |
64 | - if (!ssb.backlinks || !ssb.backlinks.read) { | |
65 | - throw new Error('"votes" is missing required plugin "ssb-backlinks"'); | |
66 | - } | |
67 | - | |
68 | 68 | return { |
69 | 69 | voterStream: function voterStream(msgId: string) { |
70 | 70 | if (!ref.isLink(msgId)) |
71 | 71 | throw new Error('A message id must be specified'); |
72 | 72 | return pull( |
73 | - ssb.backlinks.read({ | |
74 | - query: [{$filter: {dest: msgId}}], | |
75 | - index: 'DTA', | |
76 | - live: true, | |
77 | - }), | |
73 | + ssb.db.query(and(votesFor(msgId)), live({old: true}), toPullStream()), | |
78 | 74 | collectUniqueAuthors(), |
79 | 75 | ); |
80 | 76 | }, |
81 | 77 | }; |
src/backend/ssb.ts | ||
---|---|---|
@@ -60,9 +60,9 @@ | ||
60 | 60 | SecretStack({appKey: require('ssb-caps').shs}) |
61 | 61 | // Core |
62 | 62 | .use(require('ssb-master')) |
63 | 63 | .use(require('ssb-db')) |
64 | - .use(require('ssb-db2/migrate')) | |
64 | + .use(require('ssb-db2')) | |
65 | 65 | // Replication |
66 | 66 | .use(require('ssb-replicate')) // needs: db |
67 | 67 | .use(require('ssb-friends')) // needs: db, replicate |
68 | 68 | // FIXME: see issue https://github.com/ssbc/ssb-ebt/issues/33 |
Built with git-ssb-web