diff --git a/package-lock.json b/package-lock.json index 1810f9d9..2c8ad199 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "string-length": "~5.0.1", "swiped-events": "~1.1.7", "toastify-js": "~1.12.0", + "uid": "~2.0.1", "use-resize-observer": "~9.1.0", "valtio": "~1.8.2" }, @@ -2160,6 +2161,14 @@ "resolved": "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz", "integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==" }, + "node_modules/@lukeed/csprng": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.0.1.tgz", + "integrity": "sha512-uSvJdwQU5nK+Vdf6zxcWAY2A8r7uqe+gePwLWzJ+fsQehq18pc0I2hJKwypZ2aLM90+Er9u1xn4iLJPZ+xlL4g==", + "engines": { + "node": ">=8" + } + }, "node_modules/@mastojs/ponyfills": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@mastojs/ponyfills/-/ponyfills-1.0.4.tgz", @@ -5190,6 +5199,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/uid": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.1.tgz", + "integrity": "sha512-PF+1AnZgycpAIEmNtjxGBVmKbZAQguaa4pBUq6KNaGEcpzZ2klCNZLM34tsjp76maN00TttiiUf6zkIBpJQm2A==", + "dependencies": { + "@lukeed/csprng": "^1.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -7261,6 +7281,11 @@ "resolved": "https://registry.npmjs.org/@juggle/resize-observer/-/resize-observer-3.4.0.tgz", "integrity": "sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==" }, + "@lukeed/csprng": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@lukeed/csprng/-/csprng-1.0.1.tgz", + "integrity": "sha512-uSvJdwQU5nK+Vdf6zxcWAY2A8r7uqe+gePwLWzJ+fsQehq18pc0I2hJKwypZ2aLM90+Er9u1xn4iLJPZ+xlL4g==" + }, "@mastojs/ponyfills": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@mastojs/ponyfills/-/ponyfills-1.0.4.tgz", @@ -9529,6 +9554,14 @@ "integrity": "sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg==", "dev": true }, + "uid": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/uid/-/uid-2.0.1.tgz", + "integrity": "sha512-PF+1AnZgycpAIEmNtjxGBVmKbZAQguaa4pBUq6KNaGEcpzZ2klCNZLM34tsjp76maN00TttiiUf6zkIBpJQm2A==", + "requires": { + "@lukeed/csprng": "^1.0.0" + } + }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", diff --git a/package.json b/package.json index 54b4ffb9..59cd64ab 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "string-length": "~5.0.1", "swiped-events": "~1.1.7", "toastify-js": "~1.12.0", + "uid": "~2.0.1", "use-resize-observer": "~9.1.0", "valtio": "~1.8.2" }, diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 71e5b3ac..6dd0026d 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -5,6 +5,7 @@ import { forwardRef } from 'preact/compat'; import { useEffect, useMemo, useRef, useState } from 'preact/hooks'; import { useHotkeys } from 'react-hotkeys-hook'; import stringLength from 'string-length'; +import { uid } from 'uid/single'; import { useSnapshot } from 'valtio'; import supportedLanguages from '../data/status-supported-languages'; @@ -80,6 +81,8 @@ function Compose({ }) { console.warn('RENDER COMPOSER'); const [uiState, setUIState] = useState('default'); + const UID = useMemo(() => uid(), []); + console.log('Compose UID', UID); const currentAccount = getCurrentAccount(); const currentAccountInfo = currentAccount.info; @@ -626,7 +629,9 @@ function Compose({ params, ); } else { - newStatus = await masto.v1.statuses.create(params); + newStatus = await masto.v1.statuses.create(params, { + idempotencyKey: UID, + }); } setUIState('default');