make sure we do not useInterval if not expiring for expiretimer

pull/2137/head
audric 3 years ago
parent cea2c2460a
commit 8159613626

@ -7,7 +7,7 @@
window.Whisper = window.Whisper || {}; window.Whisper = window.Whisper || {};
let lastTime; let lastTime;
const interval = 1000; const interval = 10000;
let events; let events;
function checkTime() { function checkTime() {
const currentTime = Date.now(); const currentTime = Date.now();

@ -17,7 +17,7 @@
"postinstall": "electron-builder install-app-deps && rimraf node_modules/dtrace-provider", "postinstall": "electron-builder install-app-deps && rimraf node_modules/dtrace-provider",
"start": "cross-env NODE_APP_INSTANCE=$MULTI electron .", "start": "cross-env NODE_APP_INSTANCE=$MULTI electron .",
"start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod$MULTI electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod$MULTI electron .",
"grunt": "grunt", "grunt": "yarn clean-transpile; grunt",
"grunt:dev": "yarn clean-transpile; yarn grunt dev --force", "grunt:dev": "yarn clean-transpile; yarn grunt dev --force",
"generate": "yarn grunt --force", "generate": "yarn grunt --force",
"build-release": "run-script-os", "build-release": "run-script-os",

@ -1,7 +1,9 @@
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import { getTimerBucketIcon } from '../../util/timer'; import { getTimerBucketIcon } from '../../util/timer';
import { useInterval } from '../../hooks/useInterval';
// tslint:disable-next-line: no-submodule-imports
import useInterval from 'react-use/lib/useInterval';
import styled from 'styled-components'; import styled from 'styled-components';
import { SessionIcon } from '../icon/SessionIcon'; import { SessionIcon } from '../icon/SessionIcon';

@ -2,7 +2,9 @@ import React, { useCallback, useState } from 'react';
import moment from 'moment'; import moment from 'moment';
import { formatRelativeTime } from '../../util/formatRelativeTime'; import { formatRelativeTime } from '../../util/formatRelativeTime';
import { useInterval } from '../../hooks/useInterval';
// tslint:disable-next-line: no-submodule-imports
import useInterval from 'react-use/lib/useInterval';
import styled from 'styled-components'; import styled from 'styled-components';
type Props = { type Props = {

@ -56,7 +56,8 @@ function useIsExpired(props: ExpiringProps) {
const dispatch = useDispatch(); const dispatch = useDispatch();
const [isExpired] = useState(isExpiredProps); const [isExpired] = useState(isExpiredProps);
async function checkExpired() {
const checkExpired = useCallback(async () => {
const now = Date.now(); const now = Date.now();
if (!expirationTimestamp || !expirationLength) { if (!expirationTimestamp || !expirationLength) {
@ -76,10 +77,13 @@ function useIsExpired(props: ExpiringProps) {
convo?.updateLastMessage(); convo?.updateLastMessage();
} }
} }
} }, [expirationTimestamp, expirationLength, isExpired, messageId, convoId]);
let checkFrequency: number | null = null;
if (expirationLength) {
const increment = getIncrement(expirationLength || EXPIRATION_CHECK_MINIMUM); const increment = getIncrement(expirationLength || EXPIRATION_CHECK_MINIMUM);
const checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment); checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment);
}
useEffect(() => { useEffect(() => {
void checkExpired(); void checkExpired();
@ -171,22 +175,26 @@ export const GenericReadableMessage = (props: Props) => {
key={`readable-message-${messageId}`} key={`readable-message-${messageId}`}
> >
<MessageAvatar messageId={messageId} /> <MessageAvatar messageId={messageId} />
{expirationLength && expirationTimestamp && (
<ExpireTimer <ExpireTimer
isCorrectSide={!isIncoming} isCorrectSide={!isIncoming}
expirationLength={expirationLength || 0} expirationLength={expirationLength}
expirationTimestamp={expirationTimestamp || null} expirationTimestamp={expirationTimestamp}
/> />
)}
<MessageContentWithStatuses <MessageContentWithStatuses
ctxMenuID={props.ctxMenuID} ctxMenuID={props.ctxMenuID}
messageId={messageId} messageId={messageId}
onQuoteClick={props.onQuoteClick} onQuoteClick={props.onQuoteClick}
isDetailView={isDetailView} isDetailView={isDetailView}
/> />
{expirationLength && expirationTimestamp && (
<ExpireTimer <ExpireTimer
isCorrectSide={isIncoming} isCorrectSide={isIncoming}
expirationLength={expirationLength || 0} expirationLength={expirationLength}
expirationTimestamp={expirationTimestamp || null} expirationTimestamp={expirationTimestamp}
/> />
)}
</ReadableMessage> </ReadableMessage>
); );
}; };

@ -1,25 +0,0 @@
import React from 'react';
export const useInterval = (callback: any, delay: number | null) => {
const savedCallback = React.useRef<any>();
React.useEffect(() => {
savedCallback.current = callback;
}, [callback]);
React.useEffect(() => {
function tick() {
if (savedCallback && savedCallback.current && savedCallback.current) {
savedCallback.current();
}
}
if (delay !== null) {
const id = global.setInterval(tick, delay);
tick();
return () => {
global.clearInterval(id);
};
}
return;
}, [delay]);
};
Loading…
Cancel
Save