Fix Timeline to not peek group call for direct calls

This commit is contained in:
ayumi-signal 2024-03-18 12:47:22 -07:00 committed by GitHub
parent 9ebdf6e399
commit b359d28771
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 21 deletions

View file

@ -463,6 +463,7 @@ const useProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
overrideProps.invitedContactsForNewlyCreatedGroup || [],
warning: overrideProps.warning,
hasContactSpoofingReview: false,
conversationType: 'direct',
id: uuid(),
renderItem,

View file

@ -88,6 +88,7 @@ type PropsHousekeepingType = {
isSomeoneTyping: boolean;
unreadCount?: number;
unreadMentionsCount?: number;
conversationType: 'direct' | 'group';
targetedMessageId?: string;
invitedContactsForNewlyCreatedGroup: Array<ConversationType>;
@ -497,21 +498,8 @@ export class Timeline extends React.Component<
}
}, 500);
public override componentDidMount(): void {
const containerEl = this.containerRef.current;
const messagesEl = this.messagesRef.current;
const { isConversationSelected } = this.props;
strictAssert(
// We don't render anything unless the conversation is selected
(containerEl && messagesEl) || !isConversationSelected,
'<Timeline> mounted without some refs'
);
this.updateIntersectionObserver();
window.SignalContext.activeWindowService.registerForActive(
this.markNewestBottomVisibleMessageRead
);
private setupGroupCallPeekTimeouts(): void {
this.cleanupGroupCallPeekTimeouts();
this.delayedPeekTimeout = setTimeout(() => {
const { id, peekGroupCallForTheFirstTime } = this.props;
@ -525,19 +513,46 @@ export class Timeline extends React.Component<
}, MINUTE);
}
public override componentWillUnmount(): void {
private cleanupGroupCallPeekTimeouts(): void {
const { delayedPeekTimeout, peekInterval } = this;
clearTimeoutIfNecessary(delayedPeekTimeout);
this.delayedPeekTimeout = undefined;
if (peekInterval) {
clearInterval(peekInterval);
this.peekInterval = undefined;
}
}
public override componentDidMount(): void {
const containerEl = this.containerRef.current;
const messagesEl = this.messagesRef.current;
const { conversationType, isConversationSelected } = this.props;
strictAssert(
// We don't render anything unless the conversation is selected
(containerEl && messagesEl) || !isConversationSelected,
'<Timeline> mounted without some refs'
);
this.updateIntersectionObserver();
window.SignalContext.activeWindowService.registerForActive(
this.markNewestBottomVisibleMessageRead
);
if (conversationType === 'group') {
this.setupGroupCallPeekTimeouts();
}
}
public override componentWillUnmount(): void {
window.SignalContext.activeWindowService.unregisterForActive(
this.markNewestBottomVisibleMessageRead
);
this.intersectionObserver?.disconnect();
clearTimeoutIfNecessary(delayedPeekTimeout);
if (peekInterval) {
clearInterval(peekInterval);
}
this.cleanupGroupCallPeekTimeouts();
}
public override getSnapshotBeforeUpdate(
@ -588,11 +603,13 @@ export class Timeline extends React.Component<
snapshot: Readonly<SnapshotType>
): void {
const {
conversationType: previousConversationType,
items: oldItems,
messageChangeCounter: previousMessageChangeCounter,
messageLoadingState: previousMessageLoadingState,
} = prevProps;
const {
conversationType,
discardMessages,
id,
items: newItems,
@ -666,6 +683,13 @@ export class Timeline extends React.Component<
if (previousMessageChangeCounter !== messageChangeCounter) {
this.markNewestBottomVisibleMessageRead();
}
if (previousConversationType !== conversationType) {
this.cleanupGroupCallPeekTimeouts();
if (conversationType === 'group') {
this.setupGroupCallPeekTimeouts();
}
}
}
private handleBlur = (event: React.FocusEvent): void => {

View file

@ -210,6 +210,7 @@ export const SmartTimeline = memo(function SmartTimeline({
typingContactIdTimestamps = {},
unreadCount,
unreadMentionsCount,
type: conversationType,
} = conversation ?? {};
const {
haveNewest,
@ -240,6 +241,7 @@ export const SmartTimeline = memo(function SmartTimeline({
}
clearTargetedMessage={clearTargetedMessage}
closeContactSpoofingReview={closeContactSpoofingReview}
conversationType={conversationType}
discardMessages={discardMessages}
getPreferredBadge={getPreferredBadge}
getTimestampForMessage={getTimestampForMessage}

View file

@ -1,6 +1,10 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/**
* Calls clearTimeout on a timeout if it is defined.
* Note: Do not use with intervals (e.g. setInterval). Results may be unexpected.
* */
export function clearTimeoutIfNecessary(
timeout: undefined | null | ReturnType<typeof setTimeout>
): void {