git ssb

1+

Daan Patchwork / manyverse



Commit c97bf36a82c6f82f3397cbf80d13e81822363318

dx: use ssb-db2 for votes and isPrivatelyBlocking

Andre Staltz committed on 12/28/2020, 4:42:52 PM
Parent: 1679c03c9b24dafb71f492aff7d40a5e2c326477

Files changed

src/backend/package-lock.jsonchanged
src/backend/package.jsonchanged
src/backend/patches/ssb-db+19.3.1.patchchanged
src/backend/plugins/friendsUtils.tschanged
src/backend/plugins/votes.tschanged
src/backend/ssb.tschanged
src/backend/package-lock.jsonView
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.jsonView
@@ -16,9 +16,9 @@
1616 "cached-path-relative": ">=1.0.2",
1717 "chloride": "2.2.14",
1818 "estimate-progress": "1.0.0",
1919 "ip": "1.1.5",
20- "leveldown-nodejs-mobile": "5.1.1-3",
20+ "leveldown-nodejs-mobile": "5.4.1-1",
2121 "multiserver-electron-ipc": "1.2.0",
2222 "multiserver-rn-channel": "1.3.0",
2323 "non-private-ip-android": "1.4.4-3",
2424 "pull-cat": "1.1.11",
@@ -38,9 +38,9 @@
3838 "ssb-bluetooth": "1.1.14",
3939 "ssb-config": "3.4.5",
4040 "ssb-conn": "0.19.1",
4141 "ssb-db": "19.3.1",
42- "ssb-db2": "0.4.0",
42+ "ssb-db2": "0.12.0",
4343 "ssb-dht-invite": "1.11.0",
4444 "ssb-ebt-fork-staltz": "5.6.7-1",
4545 "ssb-friends": "4.1.4",
4646 "ssb-invite-client": "1.1.0",
src/backend/patches/ssb-db+19.3.1.patchView
@@ -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)
123 diff --git a/node_modules/ssb-db/extras.js b/node_modules/ssb-db/extras.js
224 index 78f6cda..9a6f9e7 100644
325 --- a/node_modules/ssb-db/extras.js
426 +++ b/node_modules/ssb-db/extras.js
src/backend/plugins/friendsUtils.tsView
@@ -6,8 +6,16 @@
66
77 import {FeedId, Msg} from 'ssb-typescript';
88 const pull = require('pull-stream');
99 const cat = require('pull-cat');
10+const {
11+ and,
12+ author,
13+ contact,
14+ descending,
15+ live,
16+ toPullStream,
17+} = require('ssb-db2/operators');
1018
1119 export = {
1220 name: 'friendsUtils',
1321 version: '1.0.0',
@@ -24,29 +32,27 @@
2432 isPrivatelyBlockingStream(dest: FeedId) {
2533 return pull(
2634 cat([
2735 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+ ),
3541 pull.take(1),
3642 ),
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+ ),
4448 ]),
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;
4754 }),
48- pull.map((val: Msg['value']) => typeof val.content === 'string'),
4955 );
5056 },
5157 };
5258 },
src/backend/plugins/votes.tsView
@@ -6,10 +6,13 @@
66
77 import {Msg, FeedId} from 'ssb-typescript';
88 const pull = require('pull-stream');
99 const ref = require('ssb-ref');
10+const {and, votesFor, live, toPullStream} = require('ssb-db2/operators');
1011 import {Readable} from './helpers/types';
1112
13+const THUMBS_UP_UNICODE = '\ud83d\udc4d';
14+
1215 function collectUniqueAuthors() {
1316 const theMap: Map<FeedId, string> = new Map();
1417 return function sink(read: Readable<Msg>) {
1518 const outputSource: Readable<Array<[FeedId, string]>> = (abort, cb) => {
@@ -30,9 +33,10 @@
3033 }
3134
3235 const author = msg.value.author;
3336 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;
3539 if (voteValue < 1 && theMap.has(author)) {
3640 theMap.delete(author);
3741 } else if (voteValue >= 1) {
3842 // this delete is used on purpose, to reset the insertion order
@@ -60,22 +64,14 @@
6064 allow: ['voterStream'],
6165 },
6266 },
6367 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-
6868 return {
6969 voterStream: function voterStream(msgId: string) {
7070 if (!ref.isLink(msgId))
7171 throw new Error('A message id must be specified');
7272 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()),
7874 collectUniqueAuthors(),
7975 );
8076 },
8177 };
src/backend/ssb.tsView
@@ -60,9 +60,9 @@
6060 SecretStack({appKey: require('ssb-caps').shs})
6161 // Core
6262 .use(require('ssb-master'))
6363 .use(require('ssb-db'))
64- .use(require('ssb-db2/migrate'))
64+ .use(require('ssb-db2'))
6565 // Replication
6666 .use(require('ssb-replicate')) // needs: db
6767 .use(require('ssb-friends')) // needs: db, replicate
6868 // FIXME: see issue https://github.com/ssbc/ssb-ebt/issues/33

Built with git-ssb-web