[Refactoring] Fix TS and ESLint errors after updating packages (#1386)

This commit is contained in:
Alexander Zinchuk 2021-08-16 14:21:33 +03:00
parent 714148fdf4
commit d7ca790f0a
67 changed files with 130 additions and 154 deletions

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
dev

View File

@ -42,12 +42,15 @@
"import/no-webpack-loader-syntax": "off", "import/no-webpack-loader-syntax": "off",
"react/prop-types": "off", "react/prop-types": "off",
"react/jsx-one-expression-per-line": "off", "react/jsx-one-expression-per-line": "off",
"react/button-has-type": "off",
"react/require-default-props": "off",
// Teact feature // Teact feature
"react/style-prop-object": "off", "react/style-prop-object": "off",
"jsx-a11y/click-events-have-key-events": "off", "jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-static-element-interactions": "off", "jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/label-has-associated-control": "off", "jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/anchor-is-valid": "off", "jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/no-noninteractive-element-to-interactive-role": "off",
"no-async-without-await/no-async-without-await": 1, "no-async-without-await/no-async-without-await": 1,
"@typescript-eslint/no-use-before-define": [ "@typescript-eslint/no-use-before-define": [
"error", "error",
@ -57,9 +60,13 @@
], ],
"@typescript-eslint/camelcase": "off", "@typescript-eslint/camelcase": "off",
"@typescript-eslint/member-delimiter-style": "error", "@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/no-throw-literal": "off",
"teactn/prefer-separate-component-file": "off" "teactn/prefer-separate-component-file": "off"
}, },
"settings": { "settings": {
"import/resolver": "webpack" "import/resolver": "webpack"
},
"parserOptions": {
"project": "./tsconfig.json"
} }
} }

4
.husky/pre-commit Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx tsc && npx lint-staged

82
package-lock.json generated
View File

@ -4060,15 +4060,15 @@
} }
}, },
"@jest/types": { "@jest/types": {
"version": "26.6.2", "version": "27.0.6",
"resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.0.6.tgz",
"integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", "integrity": "sha512-aSquT1qa9Pik26JK5/3rvnYb4bGtm1VFNesHKmNTwmPIgOrixvhL2ghIvFRNEpzy3gU+rUgjIF/KodbkFAl++g==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-lib-coverage": "^2.0.0",
"@types/istanbul-reports": "^3.0.0", "@types/istanbul-reports": "^3.0.0",
"@types/node": "*", "@types/node": "*",
"@types/yargs": "^15.0.0", "@types/yargs": "^16.0.0",
"chalk": "^4.0.0" "chalk": "^4.0.0"
}, },
"dependencies": { "dependencies": {
@ -4478,13 +4478,13 @@
} }
}, },
"@types/jest": { "@types/jest": {
"version": "27.0.0", "version": "27.0.1",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.0.tgz", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.1.tgz",
"integrity": "sha512-IlpQZVpxufe+3qPaAqEoSPHVSxnJh1cf0BqqWHJeKiAUbwnHdmNzjP3ZCWSZSTbmAGXQPNk9QmM3Bif0pR54rg==", "integrity": "sha512-HTLpVXHrY69556ozYkcq47TtQJXpcWAWfkoqz+ZGz2JnmZhzlRjprCIyFnetSy8gpDWwTTGBcRVv1J1I1vBrHw==",
"dev": true, "dev": true,
"requires": { "requires": {
"jest-diff": "^26.0.0", "jest-diff": "^27.0.0",
"pretty-format": "^26.0.0" "pretty-format": "^27.0.0"
} }
}, },
"@types/json-schema": { "@types/json-schema": {
@ -4583,9 +4583,9 @@
} }
}, },
"@types/yargs": { "@types/yargs": {
"version": "15.0.14", "version": "16.0.4",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.14.tgz", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz",
"integrity": "sha512-yEJzHoxf6SyQGhBhIYGXQDSCkJjB6HohDShto7m8vaKg9Yp0Yn8+71J9eakh2bnPg6BfsH9PRMhiRTZnd4eXGQ==", "integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/yargs-parser": "*" "@types/yargs-parser": "*"
@ -7121,9 +7121,9 @@
"dev": true "dev": true
}, },
"diff-sequences": { "diff-sequences": {
"version": "26.6.2", "version": "27.0.6",
"resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-26.6.2.tgz", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.0.6.tgz",
"integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", "integrity": "sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==",
"dev": true "dev": true
}, },
"dir-glob": { "dir-glob": {
@ -11580,15 +11580,15 @@
} }
}, },
"jest-diff": { "jest-diff": {
"version": "26.6.2", "version": "27.0.6",
"resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.6.2.tgz", "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-27.0.6.tgz",
"integrity": "sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA==", "integrity": "sha512-Z1mqgkTCSYaFgwTlP/NUiRzdqgxmmhzHY1Tq17zL94morOHfHu3K4bgSgl+CR4GLhpV8VxkuOYuIWnQ9LnFqmg==",
"dev": true, "dev": true,
"requires": { "requires": {
"chalk": "^4.0.0", "chalk": "^4.0.0",
"diff-sequences": "^26.6.2", "diff-sequences": "^27.0.6",
"jest-get-type": "^26.3.0", "jest-get-type": "^27.0.6",
"pretty-format": "^26.6.2" "pretty-format": "^27.0.6"
}, },
"dependencies": { "dependencies": {
"ansi-styles": { "ansi-styles": {
@ -11951,9 +11951,9 @@
} }
}, },
"jest-get-type": { "jest-get-type": {
"version": "26.3.0", "version": "27.0.6",
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-26.3.0.tgz", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.0.6.tgz",
"integrity": "sha512-TpfaviN1R2pQWkIihlfEanwOXK0zcxrKEE4MlU6Tn7keoXdN6/3gK/xl0yEh8DOunn5pOVGKf8hB4R9gVh04ig==", "integrity": "sha512-XTkK5exIeUbbveehcSR8w0bhH+c0yloW/Wpl+9vZrjzztCPWrxhHwkIFpZzCt71oRBsgxmuUfxEqOYoZI2macg==",
"dev": true "dev": true
}, },
"jest-haste-map": { "jest-haste-map": {
@ -16230,14 +16230,14 @@
} }
}, },
"pretty-format": { "pretty-format": {
"version": "26.6.2", "version": "27.0.6",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.0.6.tgz",
"integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", "integrity": "sha512-8tGD7gBIENgzqA+UBzObyWqQ5B778VIFZA/S66cclyd5YkFLYs2Js7gxDKf0MXtTc9zcS7t1xhdfcElJ3YIvkQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@jest/types": "^26.6.2", "@jest/types": "^27.0.6",
"ansi-regex": "^5.0.0", "ansi-regex": "^5.0.0",
"ansi-styles": "^4.0.0", "ansi-styles": "^5.0.0",
"react-is": "^17.0.1" "react-is": "^17.0.1"
}, },
"dependencies": { "dependencies": {
@ -16248,27 +16248,9 @@
"dev": true "dev": true
}, },
"ansi-styles": { "ansi-styles": {
"version": "4.3.0", "version": "5.2.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
"dev": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true "dev": true
}, },
"react-is": { "react-is": {

View File

@ -44,7 +44,7 @@
"@types/croppie": "^2.6.1", "@types/croppie": "^2.6.1",
"@types/css-font-loading-module": "0.0.6", "@types/css-font-loading-module": "0.0.6",
"@types/dom-mediacapture-record": "^1.0.10", "@types/dom-mediacapture-record": "^1.0.10",
"@types/jest": "^27.0.0", "@types/jest": "^27.0.1",
"@types/react": "^17.0.17", "@types/react": "^17.0.17",
"@types/react-dom": "^17.0.9", "@types/react-dom": "^17.0.9",
"@types/resize-observer-browser": "^0.1.6", "@types/resize-observer-browser": "^0.1.6",

View File

@ -56,9 +56,15 @@ declare module 'pako/dist/pako_inflate' {
type WindowWithPerf = typeof window & { perf: AnyLiteral }; type WindowWithPerf = typeof window & { perf: AnyLiteral };
interface TEncodedImage {
result: Uint8ClampedArray;
width: number;
height: number;
}
interface IWebpWorker extends Worker { interface IWebpWorker extends Worker {
wasmReady?: boolean; wasmReady?: boolean;
requests: Map<string, (value?: PromiseLike<TEncodedImage>) => void>; requests: Map<string, (value: PromiseLike<TEncodedImage>) => void>;
} }
interface Window { interface Window {

View File

@ -463,7 +463,6 @@ function buildPollFromMedia(media: GramJs.TypeMessageMedia): ApiPoll | undefined
return buildPoll(media.poll, media.results); return buildPoll(media.poll, media.results);
} }
function buildInvoiceFromMedia(media: GramJs.TypeMessageMedia): ApiInvoice | undefined { function buildInvoiceFromMedia(media: GramJs.TypeMessageMedia): ApiInvoice | undefined {
if (!(media instanceof GramJs.MessageMediaInvoice)) { if (!(media instanceof GramJs.MessageMediaInvoice)) {
return undefined; return undefined;

View File

@ -75,7 +75,6 @@ export async function fetchChats({
return undefined; return undefined;
} }
if (resultPinned) { if (resultPinned) {
updateLocalDb(resultPinned); updateLocalDb(resultPinned);
} }

View File

@ -185,7 +185,7 @@ export async function invokeRequest<T extends GramJs.AnyRequest>(
let updatesContainer; let updatesContainer;
if (result instanceof GramJs.Updates || result instanceof GramJs.UpdatesCombined) { if (result instanceof GramJs.Updates || result instanceof GramJs.UpdatesCombined) {
updatesContainer = result; updatesContainer = result;
} else if ('updates' in result && ( } else if ('updates' in (result as ResultWithUpdates) && (
(result as ResultWithUpdates).updates instanceof GramJs.Updates (result as ResultWithUpdates).updates instanceof GramJs.Updates
|| (result as ResultWithUpdates).updates instanceof GramJs.UpdatesCombined || (result as ResultWithUpdates).updates instanceof GramJs.UpdatesCombined
)) { )) {

View File

@ -582,6 +582,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
typingStatus: buildChatTypingStatus(update, serverTimeOffset), typingStatus: buildChatTypingStatus(update, serverTimeOffset),
}); });
} else if (update instanceof GramJs.UpdateChannel) { } else if (update instanceof GramJs.UpdateChannel) {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { _entities } = update; const { _entities } = update;
if (!_entities) { if (!_entities) {
return; return;
@ -690,6 +691,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
user: { phoneNumber: phone }, user: { phoneNumber: phone },
}); });
} else if (update instanceof GramJs.UpdatePeerSettings) { } else if (update instanceof GramJs.UpdatePeerSettings) {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { _entities } = update; const { _entities } = update;
if (!_entities) { if (!_entities) {
return; return;

View File

@ -4,7 +4,7 @@ import {
export type ApiInlineResultType = ( export type ApiInlineResultType = (
'article' | 'audio' | 'contact' | 'document' | 'game' | 'gif' | 'location' | 'mpeg4_gif' | 'article' | 'audio' | 'contact' | 'document' | 'game' | 'gif' | 'location' | 'mpeg4_gif' |
'photo' | 'sticker'| 'venue' | 'video' | 'voice' 'photo' | 'sticker' | 'venue' | 'video' | 'voice'
); );
export interface ApiWebDocument { export interface ApiWebDocument {

View File

@ -365,7 +365,7 @@ export type ApiUpdateNotifyExceptions = {
'@type': 'updateNotifyExceptions'; '@type': 'updateNotifyExceptions';
} & ApiNotifyException; } & ApiNotifyException;
export type updateTwoFaStateWaitCode = { export type ApiUpdateTwoFaStateWaitCode = {
'@type': 'updateTwoFaStateWaitCode'; '@type': 'updateTwoFaStateWaitCode';
length: number; length: number;
}; };
@ -393,7 +393,6 @@ export type ApiUpdateServerTimeOffset = {
serverTimeOffset: number; serverTimeOffset: number;
}; };
export type ApiUpdate = ( export type ApiUpdate = (
ApiUpdateReady | ApiUpdateSession | ApiUpdateReady | ApiUpdateSession |
ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser | ApiUpdateAuthorizationState | ApiUpdateAuthorizationError | ApiUpdateConnectionState | ApiUpdateCurrentUser |
@ -409,7 +408,7 @@ export type ApiUpdate = (
ApiUpdateFavoriteStickers | ApiUpdateStickerSet | ApiUpdateFavoriteStickers | ApiUpdateStickerSet |
ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage | ApiUpdateNewScheduledMessage | ApiUpdateScheduledMessageSendSucceeded | ApiUpdateScheduledMessage |
ApiUpdateDeleteScheduledMessages | ApiUpdateResetMessages | ApiUpdateDeleteScheduledMessages | ApiUpdateResetMessages |
ApiUpdateTwoFaError | updateTwoFaStateWaitCode | ApiUpdateTwoFaError | ApiUpdateTwoFaStateWaitCode |
ApiUpdateNotifySettings | ApiUpdateNotifyExceptions | ApiUpdatePeerBlocked | ApiUpdatePrivacy | ApiUpdateNotifySettings | ApiUpdateNotifyExceptions | ApiUpdatePeerBlocked | ApiUpdatePrivacy |
ApiUpdateServerTimeOffset | ApiUpdateShowInvite ApiUpdateServerTimeOffset | ApiUpdateShowInvite
); );

View File

@ -217,8 +217,8 @@ const Audio: FC<OwnProps> = ({
const seekHandlers = { handleStartSeek, handleSeek, handleStopSeek }; const seekHandlers = { handleStartSeek, handleSeek, handleStopSeek };
const isOwn = isOwnMessage(message); const isOwn = isOwnMessage(message);
const renderedWaveform = useMemo( const renderedWaveform = useMemo(
() => voice && renderWaveform(voice, playProgress, isOwn, seekHandlers, theme), () => voice && renderWaveform(voice, playProgress, isOwn, { handleStartSeek, handleSeek, handleStopSeek }, theme),
[voice, playProgress, isOwn, seekHandlers, theme], [voice, playProgress, isOwn, handleStartSeek, handleSeek, handleStopSeek, theme],
); );
const fullClassName = buildClassName( const fullClassName = buildClassName(

View File

@ -51,7 +51,7 @@ const ReportMessageModal: FC<OwnProps & DispatchProps> = ({
const lang = useLang(); const lang = useLang();
const REPORT_OPTIONS: {value: ApiReportReason; label: string}[] = [ const REPORT_OPTIONS: { value: ApiReportReason; label: string }[] = [
{ value: 'spam', label: lang('lng_report_reason_spam') }, { value: 'spam', label: lang('lng_report_reason_spam') },
{ value: 'violence', label: lang('lng_report_reason_violence') }, { value: 'violence', label: lang('lng_report_reason_violence') },
{ value: 'pornography', label: lang('lng_report_reason_pornography') }, { value: 'pornography', label: lang('lng_report_reason_pornography') },

View File

@ -33,13 +33,13 @@ type DispatchProps = Pick<GlobalActions, (
enum ContentType { enum ContentType {
Main, Main,
// eslint-disable-next-line no-shadow // eslint-disable-next-line @typescript-eslint/no-shadow
Settings, Settings,
Archived, Archived,
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
NewGroup, NewGroup,
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
NewChannel NewChannel,
} }
const RENDER_COUNT = Object.keys(ContentType).length / 2; const RENDER_COUNT = Object.keys(ContentType).length / 2;

View File

@ -49,7 +49,7 @@ type DispatchProps = Pick<GlobalActions, 'loadMoreChats' | 'preloadTopChatMessag
enum FolderTypeToListType { enum FolderTypeToListType {
'all' = 'active', 'all' = 'active',
'archived' = 'archived' 'archived' = 'archived',
} }
const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({

View File

@ -130,7 +130,6 @@ const SettingsPrivacyBlockedUsers: FC<OwnProps & StateProps & DispatchProps> = (
); );
}; };
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global): StateProps => { (global): StateProps => {
const { const {

View File

@ -129,7 +129,6 @@ const SettingsPrivacyVisibilityExceptionList: FC<OwnProps & StateProps & Dispatc
useHistoryBack(isActive, onReset, onScreenSelect, screen); useHistoryBack(isActive, onReset, onScreenSelect, screen);
return ( return (
<div className="NewChat-inner step-1"> <div className="NewChat-inner step-1">
<Picker <Picker

View File

@ -71,6 +71,7 @@ const NOTIFICATION_INTERVAL = 1000;
let notificationInterval: number | undefined; let notificationInterval: number | undefined;
// eslint-disable-next-line @typescript-eslint/naming-convention
let DEBUG_isLogged = false; let DEBUG_isLogged = false;
const Main: FC<StateProps & DispatchProps> = ({ const Main: FC<StateProps & DispatchProps> = ({
@ -135,7 +136,6 @@ const Main: FC<StateProps & DispatchProps> = ({
transitionClassNames: rightColumnTransitionClassNames, transitionClassNames: rightColumnTransitionClassNames,
} = useShowTransition(isRightColumnShown, undefined, true, undefined, shouldSkipHistoryAnimations); } = useShowTransition(isRightColumnShown, undefined, true, undefined, shouldSkipHistoryAnimations);
const className = buildClassName( const className = buildClassName(
middleColumnTransitionClassNames.replace(/([\w-]+)/g, 'middle-column-$1'), middleColumnTransitionClassNames.replace(/([\w-]+)/g, 'middle-column-$1'),
rightColumnTransitionClassNames.replace(/([\w-]+)/g, 'right-column-$1'), rightColumnTransitionClassNames.replace(/([\w-]+)/g, 'right-column-$1'),

View File

@ -91,7 +91,6 @@ const ContactGreeting: FC<OwnProps & StateProps & DispatchProps> = ({
); );
}; };
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { userId }): StateProps => { (global, { userId }): StateProps => {
const { stickers } = global.stickers.greeting; const { stickers } = global.stickers.greeting;

View File

@ -300,7 +300,7 @@ const MessageList: FC<OwnProps & StateProps & DispatchProps> = ({
useLayoutEffectWithPrevDeps(([ useLayoutEffectWithPrevDeps(([
prevMessageIds, prevIsViewportNewest, prevContainerHeight, prevMessageIds, prevIsViewportNewest, prevContainerHeight,
]: [ ]: [
typeof messageIds, typeof isViewportNewest, typeof containerHeight typeof messageIds, typeof isViewportNewest, typeof containerHeight,
]) => { ]) => {
const container = containerRef.current!; const container = containerRef.current!;
listItemElementsRef.current = Array.from(container.querySelectorAll<HTMLDivElement>('.message-list-item')); listItemElementsRef.current = Array.from(container.querySelectorAll<HTMLDivElement>('.message-list-item'));

View File

@ -239,7 +239,6 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
!isSelectModeActive && 'shown', !isSelectModeActive && 'shown',
); );
const messageSendingRestrictionReason = getMessageSendingRestrictionReason( const messageSendingRestrictionReason = getMessageSendingRestrictionReason(
lang, currentUserBannedRights, defaultBannedRights, lang, currentUserBannedRights, defaultBannedRights,
); );

View File

@ -75,5 +75,4 @@ function renderGroup(lang: LangFn) {
); );
} }
export default memo(NoMessages); export default memo(NoMessages);

View File

@ -110,7 +110,6 @@ const InlineBotTooltip: FC<OwnProps & DispatchProps> = ({
} }
}, [loadMore]); }, [loadMore]);
useEffect(() => (isOpen ? captureKeyboardListeners({ useEffect(() => (isOpen ? captureKeyboardListeners({
onEsc: onClose, onEsc: onClose,
onUp: (e: KeyboardEvent) => handleArrowKey(-1, e), onUp: (e: KeyboardEvent) => handleArrowKey(-1, e),
@ -123,7 +122,6 @@ const InlineBotTooltip: FC<OwnProps & DispatchProps> = ({
sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` }); sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` });
}, [botId, openChat, sendBotCommand, switchPm]); }, [botId, openChat, sendBotCommand, switchPm]);
const prevInlineBotResults = usePrevious( const prevInlineBotResults = usePrevious(
inlineBotResults && inlineBotResults.length inlineBotResults && inlineBotResults.length
? inlineBotResults ? inlineBotResults

View File

@ -51,7 +51,6 @@ const CommentButton: FC<OwnProps & StateProps & DispatchProps> = ({
openChat({ id: chatId, threadId }); openChat({ id: chatId, threadId });
}, [openChat, chatId, threadId]); }, [openChat, chatId, threadId]);
useEffect(() => { useEffect(() => {
if (shouldRequestThreadUpdate) { if (shouldRequestThreadUpdate) {
requestThreadInfoUpdate({ chatId, threadId }); requestThreadInfoUpdate({ chatId, threadId });

View File

@ -241,7 +241,6 @@ const Message: FC<OwnProps & StateProps & DispatchProps> = ({
const appendixRef = useRef<HTMLDivElement>(null); const appendixRef = useRef<HTMLDivElement>(null);
const lang = useLang(); const lang = useLang();
useOnIntersect(bottomMarkerRef, observeIntersectionForBottom); useOnIntersect(bottomMarkerRef, observeIntersectionForBottom);
const { const {

View File

@ -261,7 +261,6 @@ function layoutWithComplexLayouter({
return result; return result;
} }
function layoutTwo(params: ILayoutParams) { function layoutTwo(params: ILayoutParams) {
const { const {
ratios, ratios,

View File

@ -205,7 +205,6 @@ const RightColumn: FC<StateProps & DispatchProps> = ({
} }
}, [contentKey, chatId]); }, [contentKey, chatId]);
useHistoryBack(isChatSelected && (contentKey === RightColumnContent.ChatInfo useHistoryBack(isChatSelected && (contentKey === RightColumnContent.ChatInfo
|| contentKey === RightColumnContent.UserInfo || contentKey === RightColumnContent.Management || contentKey === RightColumnContent.UserInfo || contentKey === RightColumnContent.Management
|| contentKey === RightColumnContent.AddingMembers), || contentKey === RightColumnContent.AddingMembers),

View File

@ -139,7 +139,6 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
onScreenSelect(ManagementScreens.ChannelSubscribers); onScreenSelect(ManagementScreens.ChannelSubscribers);
}, [onScreenSelect]); }, [onScreenSelect]);
const handleDeleteChannel = useCallback(() => { const handleDeleteChannel = useCallback(() => {
if (chat.isCreator) { if (chat.isCreator) {
deleteChannel({ chatId: chat.id }); deleteChannel({ chatId: chat.id });

View File

@ -60,7 +60,7 @@ const ManageChatPrivacyType: FC<OwnProps & StateProps & DispatchProps> = ({
const [username, setUsername] = useState(); const [username, setUsername] = useState();
const [isRevokeConfirmDialogOpen, openRevokeConfirmDialog, closeRevokeConfirmDialog] = useFlag(); const [isRevokeConfirmDialogOpen, openRevokeConfirmDialog, closeRevokeConfirmDialog] = useFlag();
const canUpdate = ( const canUpdate = Boolean(
(privacyType === 'public' && username && isUsernameAvailable) (privacyType === 'public' && username && isUsernameAvailable)
|| (privacyType === 'private' && isPublic) || (privacyType === 'private' && isPublic)
); );

View File

@ -333,7 +333,6 @@ const ManageGroupAdminRights: FC<OwnProps & StateProps & DispatchProps> = ({
); );
}; };
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId, isPromotedByCurrentUser }): StateProps => { (global, { chatId, isPromotedByCurrentUser }): StateProps => {
const chat = selectChat(global, chatId)!; const chat = selectChat(global, chatId)!;

View File

@ -259,7 +259,6 @@ const ManageGroupUserPermissions: FC<OwnProps & StateProps & DispatchProps> = ({
); );
}; };
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId, isPromotedByCurrentUser }): StateProps => { (global, { chatId, isPromotedByCurrentUser }): StateProps => {
const chat = selectChat(global, chatId)!; const chat = selectChat(global, chatId)!;

View File

@ -85,7 +85,6 @@ const ManageGroupUserPermissionsCreate: FC<OwnProps & StateProps> = ({
); );
}; };
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);

View File

@ -25,21 +25,6 @@ type BOwnProps = Pick<GlobalState, 'authState'> & {
aValue: number; aValue: number;
}; };
const TestA: FC<AStateProps> = ({ aValue }) => {
// eslint-disable-next-line no-console
console.log('!!! A MOUNT ', { aValue });
return (
<div>
<h1>A</h1>
<div>
aValue = {aValue}
</div>
<TestBContainer aValue={aValue} />
</div>
);
};
const TestB: FC<BStateProps & BOwnProps> = ({ bValue, aValue, derivedAValue }) => { const TestB: FC<BStateProps & BOwnProps> = ({ bValue, aValue, derivedAValue }) => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('!!! B MOUNT ', { bValue, aValue, derivedAValue }); console.log('!!! B MOUNT ', { bValue, aValue, derivedAValue });
@ -65,7 +50,6 @@ const TestB: FC<BStateProps & BOwnProps> = ({ bValue, aValue, derivedAValue }) =
); );
}; };
const TestBContainer = withGlobal<BOwnProps>( const TestBContainer = withGlobal<BOwnProps>(
(global, { aValue }): BStateProps => { (global, { aValue }): BStateProps => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
@ -79,6 +63,21 @@ const TestBContainer = withGlobal<BOwnProps>(
}, },
)(TestB); )(TestB);
const TestA: FC<AStateProps> = ({ aValue }) => {
// eslint-disable-next-line no-console
console.log('!!! A MOUNT ', { aValue });
return (
<div>
<h1>A</h1>
<div>
aValue = {aValue}
</div>
<TestBContainer aValue={aValue} />
</div>
);
};
export default withGlobal( export default withGlobal(
(global): AStateProps => { (global): AStateProps => {
// @ts-ignore // @ts-ignore

View File

@ -54,11 +54,11 @@ const InfiniteScroll: FC<OwnProps> = ({
} }
const stateRef = useRef<{ const stateRef = useRef<{
listItemElements: NodeListOf<HTMLDivElement>; listItemElements?: NodeListOf<HTMLDivElement>;
isScrollTopJustUpdated: boolean; isScrollTopJustUpdated?: boolean;
currentAnchor: HTMLDivElement | undefined; currentAnchor?: HTMLDivElement | undefined;
currentAnchorTop: number; currentAnchorTop?: number;
}>({} as any); }>({});
const [loadMoreBackwards, loadMoreForwards] = useMemo(() => { const [loadMoreBackwards, loadMoreForwards] = useMemo(() => {
if (!onLoadMore) { if (!onLoadMore) {
@ -105,7 +105,7 @@ const InfiniteScroll: FC<OwnProps> = ({
if (state.currentAnchor && Array.from(state.listItemElements).includes(state.currentAnchor)) { if (state.currentAnchor && Array.from(state.listItemElements).includes(state.currentAnchor)) {
const { scrollTop } = container; const { scrollTop } = container;
const newAnchorTop = state.currentAnchor.getBoundingClientRect().top; const newAnchorTop = state.currentAnchor.getBoundingClientRect().top;
newScrollTop = scrollTop + (newAnchorTop - state.currentAnchorTop); newScrollTop = scrollTop + (newAnchorTop - state.currentAnchorTop!);
} else { } else {
const nextAnchor = state.listItemElements[0]; const nextAnchor = state.listItemElements[0];
if (nextAnchor) { if (nextAnchor) {
@ -130,8 +130,9 @@ const InfiniteScroll: FC<OwnProps> = ({
const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => { const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => {
if (loadMoreForwards && loadMoreBackwards) { if (loadMoreForwards && loadMoreBackwards) {
const { const {
listItemElements, isScrollTopJustUpdated, currentAnchor, currentAnchorTop, isScrollTopJustUpdated, currentAnchor, currentAnchorTop,
} = stateRef.current; } = stateRef.current;
const listItemElements = stateRef.current.listItemElements!;
if (isScrollTopJustUpdated) { if (isScrollTopJustUpdated) {
stateRef.current.isScrollTopJustUpdated = false; stateRef.current.isScrollTopJustUpdated = false;

View File

@ -48,7 +48,7 @@ const RippleEffect: FC = () => {
return ( return (
<div className="ripple-container" onMouseDown={handleMouseDown}> <div className="ripple-container" onMouseDown={handleMouseDown}>
{ripples.map(({ x, y, size }: Ripple) => ( {ripples.map(({ x, y, size }) => (
<span <span
// @ts-ignore // @ts-ignore
style={`left: ${x}px; top: ${y}px; width: ${size}px; height: ${size}px;`} style={`left: ${x}px; top: ${y}px; width: ${size}px; height: ${size}px;`}

View File

@ -1,7 +1,6 @@
import { ChangeEvent, RefObject } from 'react'; import { ChangeEvent, RefObject } from 'react';
import React, { FC, memo } from '../../lib/teact/teact'; import React, { FC, memo } from '../../lib/teact/teact';
import buildClassName from '../../util/buildClassName'; import buildClassName from '../../util/buildClassName';
type OwnProps = { type OwnProps = {

View File

@ -99,7 +99,6 @@ export default function useHistoryBack(
state: currentState, state: currentState,
}, ''); }, '');
indexRef.current = index; indexRef.current = index;
if (shouldReplaceNext) { if (shouldReplaceNext) {

View File

@ -1,12 +1,10 @@
import { ApiMediaFormat } from '../api/types';
import * as langProvider from '../util/langProvider'; import * as langProvider from '../util/langProvider';
import useForceUpdate from './useForceUpdate'; import useForceUpdate from './useForceUpdate';
import useOnChange from './useOnChange'; import useOnChange from './useOnChange';
export type LangFn = typeof langProvider.getTranslation; export type LangFn = typeof langProvider.getTranslation;
export default <T extends ApiMediaFormat = ApiMediaFormat.BlobUrl>(): LangFn => { export default (): LangFn => {
const forceUpdate = useForceUpdate(); const forceUpdate = useForceUpdate();
useOnChange(() => { useOnChange(() => {

View File

@ -15,7 +15,6 @@ export default (
// СSS class should be added in a separate tick to turn on CSS transition. // СSS class should be added in a separate tick to turn on CSS transition.
const [hasOpenClassName, setHasOpenClassName] = useState(isOpen && noOpenTransition); const [hasOpenClassName, setHasOpenClassName] = useState(isOpen && noOpenTransition);
if (isOpen) { if (isOpen) {
setIsClosed(false); setIsClosed(false);
setHasOpenClassName(true); setHasOpenClassName(true);

View File

@ -208,7 +208,7 @@ async function signInUserWithQrCode(
} }
})(); })();
const updatePromise = new Promise((resolve) => { const updatePromise = new Promise<void>((resolve) => {
client.addEventHandler((update: Api.TypeUpdate) => { client.addEventHandler((update: Api.TypeUpdate) => {
if (update instanceof Api.UpdateLoginToken) { if (update instanceof Api.UpdateLoginToken) {
resolve(); resolve();

View File

@ -27,7 +27,9 @@ const LOW_PRIORITY_MAX_FPS = 30;
const HIGH_PRIORITY_CACHE_MODULO = IS_SAFARI ? 2 : 4; const HIGH_PRIORITY_CACHE_MODULO = IS_SAFARI ? 2 : 4;
const LOW_PRIORITY_CACHE_MODULO = 0; const LOW_PRIORITY_CACHE_MODULO = 0;
const workers = new Array(MAX_WORKERS).fill(undefined).map(() => new WorkerConnector(new Worker(new URL('./rlottie.worker.ts', import.meta.url)))); const workers = new Array(MAX_WORKERS).fill(undefined).map(
() => new WorkerConnector(new Worker(new URL('./rlottie.worker.ts', import.meta.url))),
);
let lastWorkerIndex = -1; let lastWorkerIndex = -1;
class RLottie { class RLottie {

View File

@ -12,7 +12,7 @@ declare const self: WorkerGlobalScope;
self.importScripts('rlottie-wasm.js'); self.importScripts('rlottie-wasm.js');
let rLottieApi: Record<string, Function>; let rLottieApi: Record<string, Function>;
const rLottieApiPromise = new Promise((resolve) => { const rLottieApiPromise = new Promise<void>((resolve) => {
Module.onRuntimeInitialized = () => { Module.onRuntimeInitialized = () => {
rLottieApi = { rLottieApi = {
init: Module.cwrap('lottie_init', '', []), init: Module.cwrap('lottie_init', '', []),

View File

@ -30,6 +30,7 @@ const MAPPED_ATTRIBUTES: { [k: string]: string } = {
const INDEX_KEY_PREFIX = '__indexKey#'; const INDEX_KEY_PREFIX = '__indexKey#';
const headsByElement: Record<string, VirtualDomHead> = {}; const headsByElement: Record<string, VirtualDomHead> = {};
// eslint-disable-next-line @typescript-eslint/naming-convention
let DEBUG_virtualTreeSize = 1; let DEBUG_virtualTreeSize = 1;
function render($element?: VirtualElement, parentEl?: HTMLElement | null) { function render($element?: VirtualElement, parentEl?: HTMLElement | null) {
@ -462,6 +463,7 @@ function updateAttribute(element: HTMLElement, key: string, oldValue: any, newVa
} }
} }
// eslint-disable-next-line @typescript-eslint/naming-convention
function DEBUG_addToVirtualTreeSize($current: VirtualRealElement | VirtualDomHead) { function DEBUG_addToVirtualTreeSize($current: VirtualRealElement | VirtualDomHead) {
DEBUG_virtualTreeSize += $current.children.length; DEBUG_virtualTreeSize += $current.children.length;

View File

@ -9,11 +9,12 @@ import { removeAllDelegatedListeners } from './dom-events';
export type Props = AnyLiteral; export type Props = AnyLiteral;
export type FC<P extends Props = any> = (props: P) => any; export type FC<P extends Props = any> = (props: P) => any;
// eslint-disable-next-line @typescript-eslint/naming-convention
export type FC_withDebug = export type FC_withDebug =
FC FC
& { & {
DEBUG_contentComponentName?: string; DEBUG_contentComponentName?: string;
}; };
export enum VirtualElementTypesEnum { export enum VirtualElementTypesEnum {
Empty, Empty,
@ -243,6 +244,7 @@ function buildEmptyElement(): VirtualElementEmpty {
return { type: VirtualElementTypesEnum.Empty }; return { type: VirtualElementTypesEnum.Empty };
} }
// eslint-disable-next-line @typescript-eslint/naming-convention
const DEBUG_components: AnyLiteral = {}; const DEBUG_components: AnyLiteral = {};
document.addEventListener('dblclick', () => { document.addEventListener('dblclick', () => {
@ -260,6 +262,7 @@ export function renderComponent(componentInstance: ComponentInstance) {
let newRenderedValue; let newRenderedValue;
try { try {
// eslint-disable-next-line @typescript-eslint/naming-convention
let DEBUG_startAt: number | undefined; let DEBUG_startAt: number | undefined;
if (DEBUG) { if (DEBUG) {
const componentName = componentInstance.name; const componentName = componentInstance.name;

View File

@ -78,6 +78,7 @@ function onDispatch(name: string, payload?: ActionPayload, noThrottle?: boolean)
} }
function updateContainers() { function updateContainers() {
// eslint-disable-next-line @typescript-eslint/naming-convention
let DEBUG_startAt: number | undefined; let DEBUG_startAt: number | undefined;
if (DEBUG) { if (DEBUG) {
DEBUG_startAt = performance.now(); DEBUG_startAt = performance.now();

View File

@ -237,7 +237,7 @@ addReducer('joinChannel', (global, actions, payload) => {
addReducer('deleteChatUser', (global, actions, payload) => { addReducer('deleteChatUser', (global, actions, payload) => {
(async () => { (async () => {
const { chatId, userId } : {chatId: number; userId: number} = payload!; const { chatId, userId } : { chatId: number; userId: number } = payload!;
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const user = selectUser(global, userId); const user = selectUser(global, userId);
if (!chat || !user) { if (!chat || !user) {
@ -254,7 +254,7 @@ addReducer('deleteChatUser', (global, actions, payload) => {
addReducer('deleteChat', (global, actions, payload) => { addReducer('deleteChat', (global, actions, payload) => {
(async () => { (async () => {
const { chatId } : {chatId: number } = payload!; const { chatId } : { chatId: number } = payload!;
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
if (!chat) { if (!chat) {
return; return;
@ -742,7 +742,6 @@ addReducer('unlinkDiscussionGroup', (global, actions, payload) => {
})(); })();
}); });
addReducer('setActiveChatFolder', (global, actions, payload) => { addReducer('setActiveChatFolder', (global, actions, payload) => {
return { return {
...global, ...global,
@ -857,7 +856,6 @@ async function loadChats(listType: 'active' | 'archived', offsetId?: number, off
); );
}); });
if (chatIds.length === 0 && !global.chats.isFullyLoaded[listType]) { if (chatIds.length === 0 && !global.chats.isFullyLoaded[listType]) {
global = { global = {
...global, ...global,

View File

@ -71,7 +71,6 @@ addReducer('getPaymentForm', (global, actions, payload) => {
void getPaymentForm(chat, messageId); void getPaymentForm(chat, messageId);
}); });
async function getPaymentForm(chat: ApiChat, messageId: number) { async function getPaymentForm(chat: ApiChat, messageId: number) {
const result = await callApi('getPaymentForm', { chat, messageId }); const result = await callApi('getPaymentForm', { chat, messageId });
if (!result) { if (!result) {

View File

@ -203,7 +203,6 @@ addReducer('loadProfilePhotos', (global, actions, payload) => {
})(); })();
}); });
addReducer('setUserSearchQuery', (global, actions, payload) => { addReducer('setUserSearchQuery', (global, actions, payload) => {
const { query } = payload!; const { query } = payload!;

View File

@ -211,7 +211,6 @@ export function getChatSlowModeOptions(chat?: ApiChat) {
return chat.fullInfo.slowMode; return chat.fullInfo.slowMode;
} }
export function getChatOrder(chat: ApiChat) { export function getChatOrder(chat: ApiChat) {
return Math.max( return Math.max(
chat.joinDate || 0, chat.joinDate || 0,

View File

@ -14,7 +14,6 @@ type Target =
| 'viewerFull' | 'viewerFull'
| 'download'; | 'download';
export function getMessageContent(message: ApiMessage) { export function getMessageContent(message: ApiMessage) {
return message.content; return message.content;
} }

View File

@ -47,5 +47,5 @@ export function getStripeError(error: {
const { message: description, code, param } = error; const { message: description, code, param } = error;
const { field, message } = param ? STRIPE_ERRORS[param] : STRIPE_ERRORS[code]; const { field, message } = param ? STRIPE_ERRORS[param] : STRIPE_ERRORS[code];
return { field, message, description}; return { field, message, description };
} }

View File

@ -1,7 +1,6 @@
import { GlobalState } from '../../global/types'; import { GlobalState } from '../../global/types';
import { InlineBotSettings } from '../../types'; import { InlineBotSettings } from '../../types';
export function replaceInlineBotSettings( export function replaceInlineBotSettings(
global: GlobalState, username: string, inlineBotSettings: InlineBotSettings | false, global: GlobalState, username: string, inlineBotSettings: InlineBotSettings | false,
): GlobalState { ): GlobalState {

View File

@ -228,7 +228,6 @@ export function deleteChatMessages(
} }
}); });
global = replaceThreadParam(global, chatId, threadId, 'listedIds', listedIds); global = replaceThreadParam(global, chatId, threadId, 'listedIds', listedIds);
global = replaceThreadParam(global, chatId, threadId, 'outlyingIds', outlyingIds); global = replaceThreadParam(global, chatId, threadId, 'outlyingIds', outlyingIds);
global = replaceThreadParam(global, chatId, threadId, 'viewportIds', viewportIds); global = replaceThreadParam(global, chatId, threadId, 'viewportIds', viewportIds);

View File

@ -68,7 +68,6 @@ export function updateUser(global: GlobalState, userId: number, userUpdate: Part
}); });
} }
export function updateUsers(global: GlobalState, updatedById: Record<number, ApiUser>): GlobalState { export function updateUsers(global: GlobalState, updatedById: Record<number, ApiUser>): GlobalState {
const updatedUsers = Object.keys(updatedById).map(Number).reduce<Record<number, ApiUser>>((acc, id) => { const updatedUsers = Object.keys(updatedById).map(Number).reduce<Record<number, ApiUser>>((acc, id) => {
const updatedUser = getUpdatedUser(global, id, updatedById[id]); const updatedUser = getUpdatedUser(global, id, updatedById[id]);

View File

@ -1,4 +1,3 @@
import { GlobalState } from '../../global/types'; import { GlobalState } from '../../global/types';
export function selectPaymentChatId(global: GlobalState) { export function selectPaymentChatId(global: GlobalState) {

View File

@ -4,7 +4,7 @@ declare const self: ServiceWorkerGlobalScope;
enum Boolean { enum Boolean {
True = '1', True = '1',
False = '0' False = '0',
} }
type PushData = { type PushData = {

View File

@ -278,7 +278,7 @@ export enum PaymentStep {
ShippingInfo, ShippingInfo,
Shipping, Shipping,
PaymentInfo, PaymentInfo,
Checkout Checkout,
} }
export const UPLOADING_WALLPAPER_SLUG = 'UPLOADING_WALLPAPER_SLUG'; export const UPLOADING_WALLPAPER_SLUG = 'UPLOADING_WALLPAPER_SLUG';

View File

@ -29,7 +29,6 @@ export default function fastSmoothScroll(
return; return;
} }
if (getGlobal().settings.byKey.animationLevel === ANIMATION_LEVEL_MIN) { if (getGlobal().settings.byKey.animationLevel === ANIMATION_LEVEL_MIN) {
forceDuration = 0; forceDuration = 0;
} }

View File

@ -83,7 +83,7 @@ export async function createPosterForVideo(url: string): Promise<string | undefi
return Promise.race([ return Promise.race([
pause(2000) as Promise<undefined>, pause(2000) as Promise<undefined>,
new Promise<string>((resolve, reject) => { new Promise<string | undefined>((resolve, reject) => {
video.onseeked = () => { video.onseeked = () => {
if (!video.videoWidth || !video.videoHeight) { if (!video.videoWidth || !video.videoHeight) {
resolve(undefined); resolve(undefined);

View File

@ -3,7 +3,7 @@ import { DEBUG } from '../config';
export enum Bundles { export enum Bundles {
Auth, Auth,
Main, Main,
Extra Extra,
} }
interface ImportedBundles { interface ImportedBundles {

View File

@ -7,7 +7,9 @@ export async function oggToWav(opusData: Blob): Promise<Blob> {
return new Promise((resolve) => { return new Promise((resolve) => {
const typedArray = new Uint8Array(arrayBuffer); const typedArray = new Uint8Array(arrayBuffer);
let decoderWorker: Worker | undefined = new Worker(new URL('opus-recorder/dist/decoderWorker.min.js', import.meta.url)); let decoderWorker: Worker | undefined = new Worker(
new URL('opus-recorder/dist/decoderWorker.min.js', import.meta.url),
);
let wavWorker: Worker | undefined = new Worker(new URL('opus-recorder/dist/waveWorker.min.js', import.meta.url)); let wavWorker: Worker | undefined = new Worker(new URL('opus-recorder/dist/waveWorker.min.js', import.meta.url));
decoderWorker.onmessage = (e) => { decoderWorker.onmessage = (e) => {

View File

@ -122,12 +122,12 @@ function runNow(fn: NoneToVoidFunction) {
fn(); fn();
} }
export const pause = (ms: number) => new Promise((resolve) => { export const pause = (ms: number) => new Promise<void>((resolve) => {
setTimeout(() => resolve(), ms); setTimeout(() => resolve(), ms);
}); });
export function rafPromise() { export function rafPromise() {
return new Promise((resolve) => { return new Promise<void>((resolve) => {
fastRaf(resolve); fastRaf(resolve);
}); });
} }

View File

@ -3,8 +3,8 @@ import encoderPath from 'file-loader!opus-recorder/dist/encoderWorker.min';
export type Result = { blob: Blob; duration: number; waveform: number[] }; export type Result = { blob: Blob; duration: number; waveform: number[] };
interface OpusRecorder extends Omit<MediaRecorder, 'start' | 'ondataavailable'> { interface IOpusRecorder extends Omit<MediaRecorder, 'start' | 'ondataavailable'> {
new(options: AnyLiteral): OpusRecorder; new(options: AnyLiteral): IOpusRecorder;
start(stream?: MediaStreamAudioSourceNode): void; start(stream?: MediaStreamAudioSourceNode): void;
@ -19,9 +19,9 @@ const BLOB_PARAMS = { type: 'audio/ogg' };
const FFT_SIZE = 64; const FFT_SIZE = 64;
const MIN_VOLUME = 0.1; const MIN_VOLUME = 0.1;
let opusRecorderPromise: Promise<{ default: OpusRecorder }>; let opusRecorderPromise: Promise<{ default: IOpusRecorder }>;
let OpusRecorder: OpusRecorder; let OpusRecorder: IOpusRecorder;
let mediaRecorder: OpusRecorder; let mediaRecorder: IOpusRecorder;
export async function init() { export async function init() {
if (!opusRecorderPromise) { if (!opusRecorderPromise) {
@ -84,7 +84,7 @@ async function startMediaRecorder() {
await mediaRecorder.start(); await mediaRecorder.start();
} }
function subscribeToAnalyzer(recorder: OpusRecorder, cb: Function) { function subscribeToAnalyzer(recorder: IOpusRecorder, cb: Function) {
const source = recorder.sourceNode; const source = recorder.sourceNode;
const analyser = source.context.createAnalyser(); const analyser = source.context.createAnalyser();
analyser.fftSize = FFT_SIZE; analyser.fftSize = FFT_SIZE;

View File

@ -2,12 +2,6 @@ import { isWebpSupported } from './environment';
import { dataUriToBlob, blobToDataUri } from './files'; import { dataUriToBlob, blobToDataUri } from './files';
import { pause } from './schedulers'; import { pause } from './schedulers';
type TEncodedImage = {
result: Uint8ClampedArray;
width: number;
height: number;
};
const WORKER_INITIALIZATION_TIMEOUT = 2000; const WORKER_INITIALIZATION_TIMEOUT = 2000;
let canvas: HTMLCanvasElement; let canvas: HTMLCanvasElement;
@ -96,7 +90,10 @@ function handleLibWebpMessage(e: MessageEvent) {
function getDecodePromise(url: string, blob: Blob): Promise<TEncodedImage> { function getDecodePromise(url: string, blob: Blob): Promise<TEncodedImage> {
return new Promise((resolve) => { return new Promise((resolve) => {
worker.requests = worker.requests || new Map(); if (!worker.requests) {
worker.requests = new Map();
}
worker.requests.set(url, resolve); worker.requests.set(url, resolve);
worker.postMessage({ id: url, blob }); worker.postMessage({ id: url, blob });
}); });

View File

@ -31,7 +31,7 @@ export const forceWebsync = (authed: boolean) => {
if (canRedirect !== authed || ts + WEBSYNC_TIMEOUT <= currentTs) { if (canRedirect !== authed || ts + WEBSYNC_TIMEOUT <= currentTs) {
return Promise.all(WEBSYNC_URLS.map((url) => { return Promise.all(WEBSYNC_URLS.map((url) => {
return new Promise((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const script = document.createElement('script'); const script = document.createElement('script');
const removeElement = () => !!document.body.removeChild(script); const removeElement = () => !!document.body.removeChild(script);

View File

@ -21,6 +21,7 @@
"jsx": "react" "jsx": "react"
}, },
"include": [ "include": [
"src" "src",
"tests"
] ]
} }