|
|
|
@ -93,6 +93,7 @@ import {
|
|
|
|
|
} from '../../interactions/messageInteractions';
|
|
|
|
|
import { updateUserDetailsModal } from '../../state/ducks/modalDialog';
|
|
|
|
|
import { MessageInteraction } from '../../interactions';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
|
|
|
|
// Same as MIN_WIDTH in ImageGrid.tsx
|
|
|
|
|
const MINIMUM_LINK_PREVIEW_IMAGE_WIDTH = 200;
|
|
|
|
@ -107,90 +108,98 @@ interface State {
|
|
|
|
|
const EXPIRATION_CHECK_MINIMUM = 2000;
|
|
|
|
|
const EXPIRED_DELAY = 600;
|
|
|
|
|
|
|
|
|
|
class MessageInner extends React.PureComponent<MessageRegularProps, State> {
|
|
|
|
|
public handleImageErrorBound: () => void;
|
|
|
|
|
const MessageInner = (props: MessageRegularProps) => {
|
|
|
|
|
|
|
|
|
|
public expirationCheckInterval: any;
|
|
|
|
|
public expiredTimeout: any;
|
|
|
|
|
public ctxMenuID: string;
|
|
|
|
|
let handleImageErrorBound: () => void;
|
|
|
|
|
|
|
|
|
|
public constructor(props: MessageRegularProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
let expirationCheckInterval: any;
|
|
|
|
|
let expiredTimeout: any;
|
|
|
|
|
let ctxMenuID: string;
|
|
|
|
|
|
|
|
|
|
this.handleImageErrorBound = this.handleImageError.bind(this);
|
|
|
|
|
this.onReplyPrivate = this.onReplyPrivate.bind(this);
|
|
|
|
|
this.handleContextMenu = this.handleContextMenu.bind(this);
|
|
|
|
|
this.onAddModerator = this.onAddModerator.bind(this);
|
|
|
|
|
this.onRemoveFromModerator = this.onRemoveFromModerator.bind(this);
|
|
|
|
|
this.updatePlaybackSpeed = this.updatePlaybackSpeed.bind(this);
|
|
|
|
|
// public constructor(props: MessageRegularProps) {
|
|
|
|
|
// super(props);
|
|
|
|
|
|
|
|
|
|
// this.handleImageErrorBound = this.handleImageError.bind(this);
|
|
|
|
|
// this.onReplyPrivate = this.onReplyPrivate.bind(this);
|
|
|
|
|
// this.handleContextMenu = this.handleContextMenu.bind(this);
|
|
|
|
|
// this.onAddModerator = this.onAddModerator.bind(this);
|
|
|
|
|
// this.onRemoveFromModerator = this.onRemoveFromModerator.bind(this);
|
|
|
|
|
// this.updatePlaybackSpeed = this.updatePlaybackSpeed.bind(this);
|
|
|
|
|
|
|
|
|
|
// this.state = {
|
|
|
|
|
// expiring: false,
|
|
|
|
|
// expired: false,
|
|
|
|
|
// imageBroken: false,
|
|
|
|
|
// playbackSpeed: 1,
|
|
|
|
|
// };
|
|
|
|
|
// this.ctxMenuID = `ctx-menu-message-${uuid()}`;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
const [expiring, setExpiring] = useState(false);
|
|
|
|
|
const [expired, setExpired] = useState(false);
|
|
|
|
|
const [image, setImageBroken] = useState(false);
|
|
|
|
|
const [playbackSpeed, setPlaybackSpeed] = useState(1);
|
|
|
|
|
|
|
|
|
|
ctxMenuID = `ctx-menu-message-${uuid()}`;
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
expiring: false,
|
|
|
|
|
expired: false,
|
|
|
|
|
imageBroken: false,
|
|
|
|
|
playbackSpeed: 1,
|
|
|
|
|
};
|
|
|
|
|
this.ctxMenuID = `ctx-menu-message-${uuid()}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentDidMount() {
|
|
|
|
|
const { expirationLength } = this.props;
|
|
|
|
|
if (!expirationLength) {
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!props.expirationLength) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { expirationLength } = props;
|
|
|
|
|
|
|
|
|
|
const increment = getIncrement(expirationLength);
|
|
|
|
|
const checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment);
|
|
|
|
|
|
|
|
|
|
this.checkExpired();
|
|
|
|
|
checkExpired();
|
|
|
|
|
|
|
|
|
|
this.expirationCheckInterval = setInterval(() => {
|
|
|
|
|
this.checkExpired();
|
|
|
|
|
expirationCheckInterval = setInterval(() => {
|
|
|
|
|
checkExpired();
|
|
|
|
|
}, checkFrequency);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentWillUnmount() {
|
|
|
|
|
if (this.expirationCheckInterval) {
|
|
|
|
|
clearInterval(this.expirationCheckInterval);
|
|
|
|
|
}
|
|
|
|
|
if (this.expiredTimeout) {
|
|
|
|
|
clearTimeout(this.expiredTimeout);
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// equivalent to componentWillUpdate
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
checkExpired();
|
|
|
|
|
|
|
|
|
|
// return occurs on unmount equivalent to componentWillUnmount
|
|
|
|
|
return () => {
|
|
|
|
|
if (expirationCheckInterval) {
|
|
|
|
|
clearInterval(expirationCheckInterval);
|
|
|
|
|
}
|
|
|
|
|
if (expiredTimeout) {
|
|
|
|
|
clearTimeout(expiredTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentDidUpdate() {
|
|
|
|
|
this.checkExpired();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
public checkExpired() {
|
|
|
|
|
const checkExpired = () => {
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
const { isExpired, expirationTimestamp, expirationLength } = this.props;
|
|
|
|
|
const { isExpired, expirationTimestamp, expirationLength } = props;
|
|
|
|
|
|
|
|
|
|
if (!expirationTimestamp || !expirationLength) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this.expiredTimeout) {
|
|
|
|
|
if (expiredTimeout) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isExpired || now >= expirationTimestamp) {
|
|
|
|
|
this.setState({
|
|
|
|
|
expiring: true,
|
|
|
|
|
});
|
|
|
|
|
setExpiring(true);
|
|
|
|
|
|
|
|
|
|
const setExpired = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
expired: true,
|
|
|
|
|
});
|
|
|
|
|
const triggerSetExpired = () => {
|
|
|
|
|
setExpired(true)
|
|
|
|
|
};
|
|
|
|
|
this.expiredTimeout = setTimeout(setExpired, EXPIRED_DELAY);
|
|
|
|
|
expiredTimeout = setTimeout(triggerSetExpired(), EXPIRED_DELAY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public handleImageError() {
|
|
|
|
|
this.setState({
|
|
|
|
|
imageBroken: true,
|
|
|
|
|
});
|
|
|
|
|
const handleImageError = () => {
|
|
|
|
|
setImageBroken(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tslint:disable-next-line max-func-body-length cyclomatic-complexity
|
|
|
|
|