From 1d7380a25489e176c3ab31e7b4c78d49184ba6ad Mon Sep 17 00:00:00 2001 From: William Grant Date: Fri, 13 Oct 2023 11:35:36 +1100 Subject: [PATCH] refactor: rename expirationLength to expirationDurationMs --- ts/components/conversation/ExpireTimer.tsx | 8 +++---- .../message-item/ExpirableReadableMessage.tsx | 22 +++++++++---------- ts/models/message.ts | 18 +++++++-------- ts/state/ducks/conversations.ts | 4 ++-- ts/state/selectors/conversations.ts | 4 ++-- ts/util/timer.ts | 4 ++-- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/ts/components/conversation/ExpireTimer.tsx b/ts/components/conversation/ExpireTimer.tsx index 9e0ba216a..2675ee4bd 100644 --- a/ts/components/conversation/ExpireTimer.tsx +++ b/ts/components/conversation/ExpireTimer.tsx @@ -16,13 +16,13 @@ const ExpireTimerBucket = styled.div` `; type Props = { - expirationLength: number; // should be in milliseconds + expirationDurationMs: number; expirationTimestamp: number | null; style: CSSProperties; }; export const ExpireTimer = (props: Props) => { - const { expirationLength, expirationTimestamp, style } = props; + const { expirationDurationMs, expirationTimestamp, style } = props; const initialTimeLeft = Math.max(Math.round(((expirationTimestamp || 0) - Date.now()) / 1000), 0); const [timeLeft, setTimeLeft] = useState(initialTimeLeft); @@ -39,13 +39,13 @@ export const ExpireTimer = (props: Props) => { const updateFrequency = 500; useInterval(update, updateFrequency); - if (!(expirationLength && expirationTimestamp)) { + if (!(expirationDurationMs && expirationTimestamp)) { return null; } const expireTimerColor = 'var(--primary-text-color)'; - const bucket = getTimerBucketIcon(expirationTimestamp, expirationLength); + const bucket = getTimerBucketIcon(expirationTimestamp, expirationDurationMs); return ( diff --git a/ts/components/conversation/message/message-item/ExpirableReadableMessage.tsx b/ts/components/conversation/message/message-item/ExpirableReadableMessage.tsx index d35a69253..cd1be7ac9 100644 --- a/ts/components/conversation/message/message-item/ExpirableReadableMessage.tsx +++ b/ts/components/conversation/message/message-item/ExpirableReadableMessage.tsx @@ -22,7 +22,7 @@ function useIsExpired( const { convoId, messageId, - expirationLength, + expirationDurationMs, expirationTimestamp, isExpired: isExpiredProps, } = props; @@ -34,7 +34,7 @@ function useIsExpired( const checkExpired = useCallback(async () => { const now = Date.now(); - if (!messageId || !expirationTimestamp || !expirationLength) { + if (!messageId || !expirationTimestamp || !expirationDurationMs) { return; } @@ -53,11 +53,11 @@ function useIsExpired( convo?.updateLastMessage(); } } - }, [messageId, expirationTimestamp, expirationLength, isExpired, convoId, dispatch]); + }, [messageId, expirationTimestamp, expirationDurationMs, isExpired, convoId, dispatch]); let checkFrequency: number | null = null; - if (expirationLength) { - const increment = getIncrement(expirationLength || EXPIRATION_CHECK_MINIMUM); + if (expirationDurationMs) { + const increment = getIncrement(expirationDurationMs || EXPIRATION_CHECK_MINIMUM); checkFrequency = Math.max(EXPIRATION_CHECK_MINIMUM, increment); } @@ -95,7 +95,7 @@ export const ExpirableReadableMessage = (props: ExpirableReadableMessageProps) = messageId: selected?.messageId, direction: selected?.direction, expirationTimestamp: selected?.expirationTimestamp, - expirationLength: selected?.expirationLength, + expirationDurationMs: selected?.expirationDurationMs, isExpired: selected?.isExpired, }); @@ -108,7 +108,7 @@ export const ExpirableReadableMessage = (props: ExpirableReadableMessageProps) = direction, receivedAt, isUnread, - expirationLength, + expirationDurationMs, expirationTimestamp, } = selected; @@ -126,9 +126,9 @@ export const ExpirableReadableMessage = (props: ExpirableReadableMessageProps) = key={`readable-message-${messageId}`} dataTestId={dataTestId} > - {expirationLength && expirationTimestamp ? ( + {expirationDurationMs && expirationTimestamp ? ( ) : null} {props.children} - {expirationLength && expirationTimestamp ? ( + {expirationDurationMs && expirationTimestamp ? ( { public getPropsForExpiringMessage(): PropsForExpiringMessage { const expirationType = this.getExpirationType(); - const expirationLength = this.getExpireTimer() + const expirationDurationMs = this.getExpireTimer() ? this.getExpireTimer() * DURATION.SECONDS : null; const expireTimerStart = this.getExpirationStartTimestamp() || null; const expirationTimestamp = - expirationType && expireTimerStart && expirationLength - ? expireTimerStart + expirationLength + expirationType && expireTimerStart && expirationDurationMs + ? expireTimerStart + expirationDurationMs : null; const direction = @@ -315,7 +315,7 @@ export class MessageModel extends Backbone.Model { convoId: this.get('conversationId'), messageId: this.get('id'), direction, - expirationLength, + expirationDurationMs, expirationTimestamp, isExpired: this.isExpired(), }; @@ -518,11 +518,11 @@ export class MessageModel extends Backbone.Model { public getPropsForMessage(): PropsForMessageWithoutConvoProps { const sender = this.getSource(); const expirationType = this.getExpirationType(); - const expirationLength = this.getExpireTimer() * DURATION.SECONDS; + const expirationDurationMs = this.getExpireTimer() * DURATION.SECONDS; const expireTimerStart = this.getExpirationStartTimestamp(); const expirationTimestamp = - expirationType && expireTimerStart && expirationLength - ? expireTimerStart + expirationLength + expirationType && expireTimerStart && expirationDurationMs + ? expireTimerStart + expirationDurationMs : null; const attachments = this.get('attachments') || []; @@ -557,8 +557,8 @@ export class MessageModel extends Backbone.Model { if (expirationType) { props.expirationType = expirationType; } - if (expirationLength) { - props.expirationLength = expirationLength; + if (expirationDurationMs) { + props.expirationDurationMs = expirationDurationMs; } if (expirationTimestamp) { props.expirationTimestamp = expirationTimestamp; diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 5e2b70b16..8fd12de43 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -81,7 +81,7 @@ export type PropsForExpiringMessage = { receivedAt?: number; isUnread?: boolean; expirationTimestamp?: number | null; - expirationLength?: number | null; + expirationDurationMs?: number | null; isExpired?: boolean; }; @@ -202,7 +202,7 @@ export type PropsForMessageWithoutConvoProps = { isDeleted?: boolean; isUnread?: boolean; expirationType?: DisappearingMessageType; - expirationLength?: number; + expirationDurationMs?: number; expirationTimestamp?: number | null; isExpired?: boolean; isTrustedForAttachmentDownload?: boolean; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index c44f180be..598511cbc 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -886,7 +886,7 @@ export const getMessageExpirationProps = createSelector(getMessagePropsByMessage 'receivedAt', 'isUnread', 'expirationTimestamp', - 'expirationLength', + 'expirationDurationMs', 'isExpired', ]), messageId: props.propsForMessage.id, @@ -961,7 +961,7 @@ export const getGenericReadableMessageSelectorProps = createSelector( 'convoId', 'direction', 'conversationType', - 'expirationLength', + 'expirationDurationMs', 'expirationTimestamp', 'isExpired', 'isUnread', diff --git a/ts/util/timer.ts b/ts/util/timer.ts index c47c1dbf0..c9a3b1d39 100644 --- a/ts/util/timer.ts +++ b/ts/util/timer.ts @@ -13,9 +13,9 @@ export function getIncrement(length: number): number { return Math.ceil(length / 12); } -export function getTimerBucketIcon(expiration: number, length: number): SessionIconType { +export function getTimerBucketIcon(expirationMs: number, length: number): SessionIconType { const now = Date.now(); - const delta = expiration - now; + const delta = expirationMs - now; if (delta < 0) { return 'timer60';