Skip to content

Commit 8e85548

Browse files
committed
initial commit
1 parent 8b76791 commit 8e85548

File tree

7 files changed

+3278
-0
lines changed

7 files changed

+3278
-0
lines changed

.eslintrc

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"extends": "airbnb-base",
3+
"parserOptions": {
4+
"sourceType": "script"
5+
},
6+
7+
"rules": {
8+
// Customized
9+
"handle-callback-err": [ "error","^(e$|(e|(.*(_e|E)))rr)" ],
10+
"comma-dangle": ["error", {
11+
"arrays": "always-multiline",
12+
"objects": "always-multiline",
13+
"imports": "always-multiline",
14+
"exports": "always-multiline",
15+
"functions": "never"
16+
}],
17+
"no-empty": ["error", { "allowEmptyCatch": true }],
18+
"no-underscore-dangle": "off",
19+
"no-console": "off",
20+
"no-mixed-operators": ["error", { "allowSamePrecedence": true }],
21+
"strict": ["error", "global"],
22+
"consistent-return": "off",
23+
"func-names": "off",
24+
"no-tabs": "off",
25+
"indent": ["error", "tab"],
26+
"no-eq-null": "off",
27+
"camelcase": "off",
28+
"no-new": "off",
29+
"no-shadow": "off",
30+
"no-use-before-define": ["error", "nofunc"],
31+
"no-prototype-builtins": "off",
32+
"new-cap": "off",
33+
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
34+
"object-curly-newline": "off",
35+
"no-restricted-globals": "off",
36+
"function-paren-newline": "off",
37+
"import/no-unresolved": "error",
38+
"quotes": ["error", "single", {
39+
"avoidEscape": true,
40+
"allowTemplateLiterals": true
41+
}],
42+
"no-else-return": [ "error", { "allowElseIf": true } ],
43+
"operator-linebreak": [ "error", "after" ],
44+
45+
// ES6
46+
"prefer-rest-params": "off",
47+
"prefer-spread": "off",
48+
"prefer-arrow-callback": "off",
49+
"prefer-template": "off",
50+
"no-var": "off",
51+
"object-shorthand": "off",
52+
"vars-on-top": "off",
53+
"prefer-destructuring": "off",
54+
55+
// TODO
56+
"import/no-extraneous-dependencies": "off",
57+
"import/no-dynamic-require": "off",
58+
"import/newline-after-import": "off",
59+
"no-bitwise": "off",
60+
"global-require": "off",
61+
"max-len": "off",
62+
"no-param-reassign": "off",
63+
"no-restricted-syntax": "off",
64+
"no-script-url": "off",
65+
"default-case": "off",
66+
"linebreak-style": "off",
67+
68+
// "no-multi-assign": "off",
69+
// "one-var": "off",
70+
// "no-undef": "off",
71+
// "max-nested-callbacks": "off",
72+
// "no-mixed-requires": "off",
73+
// "brace-style": "off",
74+
// "max-statements-per-line": "off",
75+
// "no-unused-vars": "off",
76+
// "no-mixed-spaces-and-tabs": "off",
77+
// "no-useless-concat": "off",
78+
// "require-jsdoc": "off",
79+
// "eqeqeq": "off",
80+
// "no-negated-condition": "off",
81+
// "one-var-declaration-per-line": "off",
82+
// "no-lonely-if": "off",
83+
// "radix": "off",
84+
// "no-else-return": "off",
85+
// "no-useless-escape": "off",
86+
// "block-scoped-var": "off",
87+
// "operator-assignment": "off",
88+
// "yoda": "off",
89+
// "no-loop-func": "off",
90+
// "no-void": "off",
91+
// "valid-jsdoc": "off",
92+
// "no-cond-assign": "off",
93+
// "no-redeclare": "off",
94+
// "no-unreachable": "off",
95+
// "no-nested-ternary": "off",
96+
// "operator-linebreak": "off",
97+
// "guard-for-in": "off",
98+
// "no-unneeded-ternary": "off",
99+
// "no-sequences": "off",
100+
// "no-extend-native": "off",
101+
// "no-shadow-restricted-names": "off",
102+
// "no-extra-boolean-cast": "off",
103+
// "no-path-concat": "off",
104+
// "no-unused-expressions": "off",
105+
// "no-return-assign": "off",
106+
// "no-restricted-modules": "off",
107+
// "object-curly-spacing": "off",
108+
// "indent": "off",
109+
// "padded-blocks": "off",
110+
// "eol-last": "off",
111+
// "lines-around-directive": "off",
112+
// "strict": "off",
113+
// "comma-dangle": "off",
114+
// "no-multi-spaces": "off",
115+
// "quotes": "off",
116+
// "keyword-spacing": "off",
117+
// "no-mixed-operators": "off",
118+
// "comma-spacing": "off",
119+
// "no-trailing-spaces": "off",
120+
// "key-spacing": "off",
121+
// "no-multiple-empty-lines": "off",
122+
// "spaced-comment": "off",
123+
// "space-in-parens": "off",
124+
// "block-spacing": "off",
125+
// "quote-props": "off",
126+
// "space-unary-ops": "off",
127+
// "no-empty": "off",
128+
// "dot-notation": "off",
129+
// "func-call-spacing": "off",
130+
// "array-bracket-spacing": "off",
131+
// "object-property-newline": "off",
132+
// "no-continue": "off",
133+
// "no-extra-semi": "off",
134+
// "no-spaced-func": "off",
135+
// "no-useless-return": "off"
136+
}
137+
}
138+

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sftp-config.json
2+
node_modules/

commitlint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = { extends: ['@commitlint/config-angular'] };

library.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
const LRU = require("lru-cache");
3+
4+
const controllers = require('./lib/controllers');
5+
const winston = require.main.require('winston');
6+
const meta = require.main.require('./src/meta');
7+
const db = require.main.require('./src/database');
8+
9+
const twoWayBlock = {};
10+
const cache = new LRU({
11+
max: 100,
12+
length: function () { return 1; },
13+
maxAge: 0,
14+
})
15+
twoWayBlock.addBlock = async function ({uid, targetUid}) {
16+
await db.sortedSetAdd(`uid:${targetUid}:blocked_by_uids`, Date.now(), uid);
17+
cache.del(parseInt(targetUid, 10));
18+
}
19+
twoWayBlock.removeBlock = async function({uid, targetUid}) {
20+
await db.sortedSetRemove(`uid:${targetUid}:blocked_by_uids`, uid);
21+
cache.del(parseInt(targetUid, 10));
22+
}
23+
twoWayBlock.filterBlocks = async function ({uid, posts}) {
24+
const blocked_uids = await twoWayBlock.list(uid);
25+
const blockedSet = new Set(blocked_uids);
26+
posts = posts.filter(function (item) {
27+
return !blockedSet.has(parseInt(isPlain ? item : item[property], 10));
28+
});
29+
return {uid, posts};
30+
}
31+
twoWayBlock.list = async function(uid) {
32+
if (cache.has(parseInt(uid, 10))) {
33+
return cache.get(parseInt(uid, 10));
34+
}
35+
let blocked_by = await db.getSortedSetRange('uid:' + uid + ':blocked_by_uids', 0, -1);
36+
blocked_by = blocked.map(uid => parseInt(uid, 10)).filter(Boolean);
37+
cache.set(parseInt(uid, 10), blocked_by);
38+
return blocked_by;
39+
}
40+
41+
module.exports = twoWayBlock;

package.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "nodebb-plugin-tow-way-block",
3+
"version": "1.0.5",
4+
"description": "Blocking a user hides your posts from them too",
5+
"main": "library.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/oplik0/nodebb-plugin-tow-way-block"
9+
},
10+
"keywords": [
11+
"nodebb",
12+
"plugin",
13+
"block"
14+
],
15+
"husky": {
16+
"hooks": {
17+
"pre-commit": "lint-staged",
18+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
19+
}
20+
},
21+
"lint-staged": {
22+
"*.js": [
23+
"eslint --fix",
24+
"git add"
25+
]
26+
},
27+
"author": {
28+
"name": "opliko",
29+
"email": "opliko.reg+npm@protonmail.com",
30+
"url": "https://wieloswiat.pl"
31+
},
32+
"license": "MIT",
33+
"bugs": {
34+
"url": "https://github.com/oplik0/nodebb-plugin-tow-way-block/issues"
35+
},
36+
"readmeFilename": "README.md",
37+
"nbbpm": {
38+
"compatibility": "^1.11.0"
39+
},
40+
"devDependencies": {
41+
"@commitlint/cli": "^7.3.2",
42+
"@commitlint/config-angular": "^7.3.1",
43+
"eslint": "^5.12.1",
44+
"eslint-config-airbnb-base": "^13.1.0",
45+
"eslint-plugin-import": "^2.15.0",
46+
"husky": "^1.3.1",
47+
"lint-staged": "^8.1.0"
48+
}
49+
}

plugin.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "nodebb-plugin-tow-way-block",
3+
"url": "https://github.com/oplik0/nodebb-plugin-tow-way-block",
4+
"library": "./library.js",
5+
"hooks": [
6+
{
7+
"hook":"filter:post.getPosts", "method": "filterBlocks"
8+
},
9+
{
10+
"hook":"action:user.block.add", "method": "addBlock"
11+
},
12+
{
13+
"hook":"action:user.block.remove", "method":"removeBlock"
14+
}
15+
16+
]
17+
}

0 commit comments

Comments
 (0)