Upgrade masto.js to V5

- Fix all breaking changes
- Have to manual remove null/undefined values before creating statuses
- Have to recreate iterator instance if start from scratch because can't pass args in next()
pull/31/head
Lim Chee Aun 2022-12-25 23:28:55 +08:00
rodzic cf4fbc8553
commit 318c2aeffc
9 zmienionych plików z 267 dodań i 174 usunięć

287
package-lock.json wygenerowano
Wyświetl plik

@ -14,7 +14,7 @@
"history": "~5.3.0",
"iconify-icon": "~1.0.2",
"just-debounce-it": "~3.2.0",
"masto": "~4.11.1",
"masto": "~5.0.4",
"mem": "~9.0.2",
"preact": "~10.11.3",
"preact-router": "~4.1.0",
@ -2150,6 +2150,18 @@
"resolved": "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz",
"integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA=="
},
"node_modules/@mastojs/ponyfills": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@mastojs/ponyfills/-/ponyfills-1.0.4.tgz",
"integrity": "sha512-1NaIGmcU7OmyNzx0fk+cYeGTkdXlOJOSdetaC4pStVWsrhht2cdlYSAfe5NDW3FcUmcEm2vVceB9lcClN1RCxw==",
"dependencies": {
"@types/node": "^18.11.17",
"@types/node-fetch": "^2.6.2",
"abort-controller": "^3.0.0",
"form-data": "^4.0.0",
"node-fetch": "^2.6.7"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -2450,8 +2462,29 @@
"node_modules/@types/node": {
"version": "18.11.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.17.tgz",
"integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==",
"dev": true
"integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng=="
},
"node_modules/@types/node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==",
"dependencies": {
"@types/node": "*",
"form-data": "^3.0.0"
}
},
"node_modules/@types/node-fetch/node_modules/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/@types/resolve": {
"version": "1.17.1",
@ -2543,6 +2576,17 @@
"dev": true,
"peer": true
},
"node_modules/abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"dependencies": {
"event-target-shim": "^5.0.0"
},
"engines": {
"node": ">=6.5"
}
},
"node_modules/acorn": {
"version": "8.8.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",
@ -2647,16 +2691,6 @@
"postcss": "^8.1.0"
}
},
"node_modules/axios": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz",
"integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==",
"dependencies": {
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/babel-plugin-polyfill-corejs2": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.3.3.tgz",
@ -3167,6 +3201,14 @@
"node": ">=0.10.0"
}
},
"node_modules/event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
"engines": {
"node": ">=6"
}
},
"node_modules/eventemitter3": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.0.tgz",
@ -3256,25 +3298,6 @@
"node": ">=8"
}
},
"node_modules/follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@ -3836,27 +3859,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/isomorphic-form-data": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-form-data/-/isomorphic-form-data-2.0.0.tgz",
"integrity": "sha512-TYgVnXWeESVmQSg4GLVbalmQ+B4NPi/H4eWxqALKj63KsUrcu301YDjBqaOw3h+cbak7Na4Xyps3BiptHtxTfg==",
"dependencies": {
"form-data": "^2.3.2"
}
},
"node_modules/isomorphic-form-data/node_modules/form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 0.12"
}
},
"node_modules/isomorphic-ws": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz",
@ -4146,14 +4148,13 @@
}
},
"node_modules/masto": {
"version": "4.11.1",
"resolved": "https://registry.npmjs.org/masto/-/masto-4.11.1.tgz",
"integrity": "sha512-siTQNhfLV1JjOERCGgjagMvD6q0K0hLuhOXrbXNcYzHAwpbPeSeAM6CSpIRrZ8zFDepOR62Djs/GtJdTR21Rfw==",
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/masto/-/masto-5.0.4.tgz",
"integrity": "sha512-oMveJRoq/VdkgMXZNoZ6CvFyr5WdzH2zNIcK3QdHNlAOt1HkoqyHjPVicgjxq/lnwv6grqLB/XvlYA2N6ltVyA==",
"dependencies": {
"axios": "1.1.3",
"@mastojs/ponyfills": "^1.0.4",
"change-case": "^4.1.2",
"eventemitter3": "^5.0.0",
"isomorphic-form-data": "^2.0.0",
"isomorphic-ws": "^5.0.0",
"semver": "^7.3.7",
"ws": "^8.8.0"
@ -4285,6 +4286,44 @@
"tslib": "^2.0.3"
}
},
"node_modules/node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/node-fetch/node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"node_modules/node-fetch/node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"node_modules/node-fetch/node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/node-releases": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz",
@ -4509,11 +4548,6 @@
"resolved": "https://registry.npmjs.org/proxy-compare/-/proxy-compare-2.3.0.tgz",
"integrity": "sha512-c3L2CcAi7f7pvlD0D7xsF+2CQIW8C3HaYx2Pfgq8eA4HAl3GAH6/dVYsyBbYF/0XJs2ziGLrzmz5fmzPm6A0pQ=="
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
@ -7178,6 +7212,18 @@
"resolved": "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz",
"integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA=="
},
"@mastojs/ponyfills": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@mastojs/ponyfills/-/ponyfills-1.0.4.tgz",
"integrity": "sha512-1NaIGmcU7OmyNzx0fk+cYeGTkdXlOJOSdetaC4pStVWsrhht2cdlYSAfe5NDW3FcUmcEm2vVceB9lcClN1RCxw==",
"requires": {
"@types/node": "^18.11.17",
"@types/node-fetch": "^2.6.2",
"abort-controller": "^3.0.0",
"form-data": "^4.0.0",
"node-fetch": "^2.6.7"
}
},
"@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -7406,8 +7452,28 @@
"@types/node": {
"version": "18.11.17",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.17.tgz",
"integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==",
"dev": true
"integrity": "sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng=="
},
"@types/node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==",
"requires": {
"@types/node": "*",
"form-data": "^3.0.0"
},
"dependencies": {
"form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
}
}
},
"@types/resolve": {
"version": "1.17.1",
@ -7499,6 +7565,14 @@
"dev": true,
"peer": true
},
"abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"requires": {
"event-target-shim": "^5.0.0"
}
},
"acorn": {
"version": "8.8.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz",
@ -7562,16 +7636,6 @@
"postcss-value-parser": "^4.2.0"
}
},
"axios": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz",
"integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==",
"requires": {
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"babel-plugin-polyfill-corejs2": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.3.3.tgz",
@ -7958,6 +8022,11 @@
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true
},
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"eventemitter3": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.0.tgz",
@ -8040,11 +8109,6 @@
"to-regex-range": "^5.0.1"
}
},
"follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
},
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@ -8439,26 +8503,6 @@
"call-bind": "^1.0.2"
}
},
"isomorphic-form-data": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-form-data/-/isomorphic-form-data-2.0.0.tgz",
"integrity": "sha512-TYgVnXWeESVmQSg4GLVbalmQ+B4NPi/H4eWxqALKj63KsUrcu301YDjBqaOw3h+cbak7Na4Xyps3BiptHtxTfg==",
"requires": {
"form-data": "^2.3.2"
},
"dependencies": {
"form-data": {
"version": "2.5.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz",
"integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
}
}
},
"isomorphic-ws": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz",
@ -8685,14 +8729,13 @@
}
},
"masto": {
"version": "4.11.1",
"resolved": "https://registry.npmjs.org/masto/-/masto-4.11.1.tgz",
"integrity": "sha512-siTQNhfLV1JjOERCGgjagMvD6q0K0hLuhOXrbXNcYzHAwpbPeSeAM6CSpIRrZ8zFDepOR62Djs/GtJdTR21Rfw==",
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/masto/-/masto-5.0.4.tgz",
"integrity": "sha512-oMveJRoq/VdkgMXZNoZ6CvFyr5WdzH2zNIcK3QdHNlAOt1HkoqyHjPVicgjxq/lnwv6grqLB/XvlYA2N6ltVyA==",
"requires": {
"axios": "1.1.3",
"@mastojs/ponyfills": "^1.0.4",
"change-case": "^4.1.2",
"eventemitter3": "^5.0.0",
"isomorphic-form-data": "^2.0.0",
"isomorphic-ws": "^5.0.0",
"semver": "^7.3.7",
"ws": "^8.8.0"
@ -8787,6 +8830,35 @@
"tslib": "^2.0.3"
}
},
"node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
"integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==",
"requires": {
"whatwg-url": "^5.0.0"
},
"dependencies": {
"tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"requires": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
}
}
},
"node-releases": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz",
@ -8941,11 +9013,6 @@
"resolved": "https://registry.npmjs.org/proxy-compare/-/proxy-compare-2.3.0.tgz",
"integrity": "sha512-c3L2CcAi7f7pvlD0D7xsF+2CQIW8C3HaYx2Pfgq8eA4HAl3GAH6/dVYsyBbYF/0XJs2ziGLrzmz5fmzPm6A0pQ=="
},
"proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",

Wyświetl plik

@ -16,7 +16,7 @@
"history": "~5.3.0",
"iconify-icon": "~1.0.2",
"just-debounce-it": "~3.2.0",
"masto": "~4.11.1",
"masto": "~5.0.4",
"mem": "~9.0.2",
"preact": "~10.11.3",
"preact-router": "~4.1.0",

Wyświetl plik

@ -27,7 +27,7 @@ const { VITE_CLIENT_NAME: CLIENT_NAME } = import.meta.env;
window.__STATES__ = states;
async function startStream() {
const stream = await masto.stream.streamUser();
const stream = await masto.v1.stream.streamUser();
console.log('STREAM START', { stream });
stream.on('update', (status) => {
console.log('UPDATE', status);
@ -119,22 +119,20 @@ function startVisibility() {
// Buffer for WS reconnect
(async () => {
try {
const fetchHome = masto.timelines.fetchHome({
const fetchHome = masto.v1.timelines.listHome({
limit: 2,
// Need 2 because "new posts" only appear when there are 2 or more
});
const fetchNotifications = masto.notifications
.iterate({
limit: 1,
})
.next();
const fetchNotifications = masto.v1.notifications.list({
limit: 1,
});
const newStatuses = await fetchHome;
if (
newStatuses.value.length &&
newStatuses.value[0].id !== states.home[0].id
newStatuses.length &&
newStatuses[0].id !== states.home[0].id
) {
states.homeNew = newStatuses.value.map((status) => {
states.homeNew = newStatuses.map((status) => {
states.statuses.set(status.id, status);
if (status.reblog) {
states.statuses.set(status.reblog.id, status.reblog);
@ -148,8 +146,8 @@ function startVisibility() {
}
const newNotifications = await fetchNotifications;
if (newNotifications.value.length) {
const notification = newNotifications.value[0];
if (newNotifications.length) {
const notification = newNotifications[0];
const inNotificationsNew = states.notificationsNew.find(
(n) => n.id === notification.id,
);
@ -242,7 +240,7 @@ export function App() {
timeout: 30_000,
});
const mastoAccount = await masto.accounts.verifyCredentials();
const mastoAccount = await masto.v1.accounts.verifyCredentials();
console.log({ tokenJSON, mastoAccount });
@ -307,7 +305,7 @@ export function App() {
// Collect instance info
(async () => {
const info = await masto.instances.fetch();
const info = await masto.v2.instance.fetch();
console.log(info);
const { uri } = info;
const instances = store.local.getJSON('instances') || {};

Wyświetl plik

@ -20,7 +20,7 @@ function Account({ account }) {
setUIState('loading');
(async () => {
try {
const info = await masto.accounts.lookup({
const info = await masto.v1.accounts.lookup({
acct: account,
skip_webfinger: false,
});
@ -69,7 +69,9 @@ function Account({ account }) {
setRelationshipUIState('loading');
(async () => {
try {
const relationships = await masto.accounts.fetchRelationships([id]);
const relationships = await masto.v1.accounts.fetchRelationships([
id,
]);
console.log('fetched relationship', relationships);
if (relationships.length) {
setRelationship(relationships[0]);
@ -200,10 +202,12 @@ function Account({ account }) {
'Are you sure that you want to unfollow this account?',
);
if (yes) {
newRelationship = await masto.accounts.unfollow(id);
newRelationship = await masto.v1.accounts.unfollow(
id,
);
}
} else {
newRelationship = await masto.accounts.follow(id);
newRelationship = await masto.v1.accounts.follow(id);
}
if (newRelationship) setRelationship(newRelationship);
setRelationshipUIState('default');

Wyświetl plik

@ -90,7 +90,7 @@ function Compose({
const customEmojis = useRef();
useEffect(() => {
(async () => {
const emojis = await masto.customEmojis.fetchAll();
const emojis = await masto.v1.customEmojis.list();
console.log({ emojis });
customEmojis.current = emojis;
})();
@ -161,7 +161,9 @@ function Compose({
setUIState('loading');
(async () => {
try {
const statusSource = await masto.statuses.fetchSource(editStatus.id);
const statusSource = await masto.v1.statuses.fetchSource(
editStatus.id,
);
console.log({ statusSource });
const { text, spoilerText } = statusSource;
textareaRef.current.value = text;
@ -236,15 +238,16 @@ function Compose({
}[key];
provide(
new Promise((resolve) => {
const resultsIterator = masto.search({
const searchResults = masto.v2.search({
type,
q: text,
limit: 5,
});
resultsIterator.next().then(({ value }) => {
searchResults.then((value) => {
if (text !== textExpanderTextRef.current) {
return;
}
console.log({ value, type, v: value[type] });
const results = value[type];
console.log('RESULTS', value, results);
let html = '';
@ -614,16 +617,18 @@ function Compose({
// If already uploaded
return attachment;
} else {
const params = {
const params = removeNullUndefined({
file,
description,
};
return masto.mediaAttachments.create(params).then((res) => {
if (res.id) {
attachment.id = res.id;
}
return res;
});
return masto.v2.mediaAttachments
.create(params)
.then((res) => {
if (res.id) {
attachment.id = res.id;
}
return res;
});
}
});
const results = await Promise.allSettled(mediaPromises);
@ -648,7 +653,7 @@ function Compose({
console.log({ results, mediaAttachments });
}
const params = {
let params = {
status,
spoilerText,
sensitive,
@ -659,13 +664,17 @@ function Compose({
params.visibility = visibility;
params.inReplyToId = replyToStatus?.id || undefined;
}
params = removeNullUndefined(params);
console.log('POST', params);
let newStatus;
if (editStatus) {
newStatus = await masto.statuses.update(editStatus.id, params);
newStatus = await masto.v1.statuses.update(
editStatus.id,
params,
);
} else {
newStatus = await masto.statuses.create(params);
newStatus = await masto.v1.statuses.create(params);
}
setUIState('default');
@ -1129,4 +1138,13 @@ function countableText(inputText) {
.replace(usernameRegex, '$1@$3');
}
function removeNullUndefined(obj) {
for (let key in obj) {
if (obj[key] === null || obj[key] === undefined) {
delete obj[key];
}
}
return obj;
}
export default Compose;

Wyświetl plik

@ -28,7 +28,7 @@ import Avatar from './avatar';
import Icon from './icon';
function fetchAccount(id) {
return masto.accounts.fetch(id);
return masto.v1.accounts.fetch(id);
}
const memFetchAccount = mem(fetchAccount);
@ -521,10 +521,12 @@ function Status({
reblogsCount: reblogsCount + (reblogged ? -1 : 1),
});
if (reblogged) {
const newStatus = await masto.statuses.unreblog(id);
const newStatus = await masto.v1.statuses.unreblog(
id,
);
states.statuses.set(newStatus.id, newStatus);
} else {
const newStatus = await masto.statuses.reblog(id);
const newStatus = await masto.v1.statuses.reblog(id);
states.statuses.set(newStatus.id, newStatus);
states.statuses.set(
newStatus.reblog.id,
@ -558,10 +560,12 @@ function Status({
favouritesCount + (favourited ? -1 : 1),
});
if (favourited) {
const newStatus = await masto.statuses.unfavourite(id);
const newStatus = await masto.v1.statuses.unfavourite(
id,
);
states.statuses.set(newStatus.id, newStatus);
} else {
const newStatus = await masto.statuses.favourite(id);
const newStatus = await masto.v1.statuses.favourite(id);
states.statuses.set(newStatus.id, newStatus);
}
} catch (e) {
@ -587,10 +591,12 @@ function Status({
bookmarked: !bookmarked,
});
if (bookmarked) {
const newStatus = await masto.statuses.unbookmark(id);
const newStatus = await masto.v1.statuses.unbookmark(
id,
);
states.statuses.set(newStatus.id, newStatus);
} else {
const newStatus = await masto.statuses.bookmark(id);
const newStatus = await masto.v1.statuses.bookmark(id);
states.statuses.set(newStatus.id, newStatus);
}
} catch (e) {
@ -942,7 +948,7 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
setUIState('loading');
(async () => {
try {
const pollResponse = await masto.poll.fetch(id);
const pollResponse = await masto.v1.poll.fetch(id);
onUpdate(pollResponse);
} catch (e) {
// Silent fail
@ -1026,7 +1032,7 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
});
console.log(votes);
setUIState('loading');
const pollResponse = await masto.poll.vote(id, {
const pollResponse = await masto.v1.poll.vote(id, {
choices: votes,
});
console.log(pollResponse);
@ -1075,7 +1081,7 @@ function Poll({ poll, readOnly, onUpdate = () => {} }) {
setUIState('loading');
(async () => {
try {
const pollResponse = await masto.poll.fetch(id);
const pollResponse = await masto.v1.poll.fetch(id);
onUpdate(pollResponse);
} catch (e) {
// Silent fail
@ -1119,7 +1125,7 @@ function EditedAtModal({ statusID, onClose = () => {} }) {
setUIState('loading');
(async () => {
try {
const editHistory = await masto.statuses.fetchHistory(statusID);
const editHistory = await masto.v1.statuses.listHistory(statusID);
console.log(editHistory);
setEditHistory(editHistory);
setUIState('default');

Wyświetl plik

@ -16,18 +16,18 @@ function Home({ hidden }) {
const [showMore, setShowMore] = useState(false);
const homeIterator = useRef(
masto.timelines.iterateHome({
masto.v1.timelines.listHome({
limit: LIMIT,
}),
).current;
);
async function fetchStatuses(firstLoad) {
const allStatuses = await homeIterator.next(
firstLoad
? {
limit: LIMIT,
}
: undefined,
);
if (firstLoad) {
// Reset iterator
homeIterator.current = masto.v1.timelines.listHome({
limit: LIMIT,
});
}
const allStatuses = await homeIterator.current.next();
if (allStatuses.value <= 0) {
return { done: true };
}

Wyświetl plik

@ -212,18 +212,18 @@ function Notifications() {
const [onlyMentions, setOnlyMentions] = useState(false);
const notificationsIterator = useRef(
masto.notifications.iterate({
masto.v1.notifications.list({
limit: LIMIT,
}),
).current;
);
async function fetchNotifications(firstLoad) {
const allNotifications = await notificationsIterator.next(
firstLoad
? {
limit: LIMIT,
}
: undefined,
);
if (firstLoad) {
// Reset iterator
notificationsIterator.current = masto.v1.notifications.list({
limit: LIMIT,
});
}
const allNotifications = await notificationsIterator.current.next();
if (allNotifications.value <= 0) {
return { done: true };
}

Wyświetl plik

@ -72,8 +72,8 @@ function StatusPage({ id }) {
}
(async () => {
const heroFetch = masto.statuses.fetch(id);
const contextFetch = masto.statuses.fetchContext(id);
const heroFetch = masto.v1.statuses.fetch(id);
const contextFetch = masto.v1.statuses.fetchContext(id);
const hasStatus = snapStates.statuses.has(id);
let heroStatus = snapStates.statuses.get(id);