Simplify group call peeking logic

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2025-12-17 13:20:08 -06:00
committed by GitHub
parent a4de19f473
commit 91c3588927
4 changed files with 24 additions and 38 deletions

View File

@@ -348,8 +348,7 @@ const actions = () => ({
closeContactSpoofingReview: action('closeContactSpoofingReview'), closeContactSpoofingReview: action('closeContactSpoofingReview'),
reviewConversationNameCollision: action('reviewConversationNameCollision'), reviewConversationNameCollision: action('reviewConversationNameCollision'),
peekGroupCallForTheFirstTime: action('peekGroupCallForTheFirstTime'), maybePeekGroupCall: action('maybePeekGroupCall'),
peekGroupCallIfItHasMembers: action('peekGroupCallIfItHasMembers'),
viewStory: action('viewStory'), viewStory: action('viewStory'),

View File

@@ -165,14 +165,13 @@ export type PropsActionsType = {
setFocus?: boolean setFocus?: boolean
) => unknown; ) => unknown;
markMessageRead: (conversationId: string, messageId: string) => unknown; markMessageRead: (conversationId: string, messageId: string) => unknown;
maybePeekGroupCall: (conversationId: string) => unknown;
targetMessage: (messageId: string, conversationId: string) => unknown; targetMessage: (messageId: string, conversationId: string) => unknown;
setCenterMessage: ( setCenterMessage: (
conversationId: string, conversationId: string,
messageId: string | undefined messageId: string | undefined
) => void; ) => void;
setIsNearBottom: (conversationId: string, isNearBottom: boolean) => void; setIsNearBottom: (conversationId: string, isNearBottom: boolean) => void;
peekGroupCallForTheFirstTime: (conversationId: string) => unknown;
peekGroupCallIfItHasMembers: (conversationId: string) => unknown;
reviewConversationNameCollision: () => void; reviewConversationNameCollision: () => void;
scrollToOldestUnreadMention: (conversationId: string) => unknown; scrollToOldestUnreadMention: (conversationId: string) => unknown;
}; };
@@ -590,15 +589,14 @@ export class Timeline extends React.Component<
this.#cleanupGroupCallPeekTimeouts(); this.#cleanupGroupCallPeekTimeouts();
this.#delayedPeekTimeout = setTimeout(() => { this.#delayedPeekTimeout = setTimeout(() => {
const { id, peekGroupCallForTheFirstTime } = this.props; const { id, maybePeekGroupCall } = this.props;
this.#delayedPeekTimeout = undefined; this.#delayedPeekTimeout = undefined;
peekGroupCallForTheFirstTime(id); maybePeekGroupCall(id);
}, 500);
this.#peekInterval = setInterval(() => { this.#peekInterval = setInterval(() => {
const { id, peekGroupCallIfItHasMembers } = this.props; maybePeekGroupCall(id);
peekGroupCallIfItHasMembers(id);
}, MINUTE); }, MINUTE);
}, 500);
} }
#cleanupGroupCallPeekTimeouts(): void { #cleanupGroupCallPeekTimeouts(): void {

View File

@@ -1880,41 +1880,33 @@ function joinedAdhocCall(
}; };
} }
function peekGroupCallForTheFirstTime( function maybePeekGroupCall(
conversationId: string conversationId: string
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> { ): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
return (dispatch, getState) => { return (dispatch, getState) => {
const call = getOwn(getState().calling.callsByConversation, conversationId); const call = getOwn(getState().calling.callsByConversation, conversationId);
const shouldPeek =
!call || (isGroupOrAdhocCallState(call) && !call.peekInfo); if (call && !isGroupOrAdhocCallState(call)) {
const callMode = call?.callMode ?? CallMode.Group;
if (callMode === CallMode.Direct) {
return; return;
} }
if (shouldPeek) { const existingPeekInfo = call?.peekInfo;
// We peek if:
// 1. this is the first time since app has started that we've peeked, or
// 2. we've peeked prior and there is an ongoing group call
if (existingPeekInfo == null) {
doGroupCallPeek({ doGroupCallPeek({
conversationId, conversationId,
callMode, callMode: call?.callMode ?? CallMode.Group,
dispatch, dispatch,
getState, getState,
}); });
} } else if (
};
}
function peekGroupCallIfItHasMembers(
conversationId: string
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
return (dispatch, getState) => {
const call = getOwn(getState().calling.callsByConversation, conversationId);
const shouldPeek =
call && call &&
isGroupOrAdhocCallState(call) &&
call.joinState === GroupCallJoinState.NotJoined && call.joinState === GroupCallJoinState.NotJoined &&
call.peekInfo && existingPeekInfo.deviceCount > 0
call.peekInfo.deviceCount > 0; ) {
if (shouldPeek) {
doGroupCallPeek({ doGroupCallPeek({
conversationId, conversationId,
callMode: call.callMode, callMode: call.callMode,
@@ -3088,13 +3080,12 @@ export const actions = {
handleCallLinkDelete, handleCallLinkDelete,
joinedAdhocCall, joinedAdhocCall,
leaveCurrentCallAndStartCallingLobby, leaveCurrentCallAndStartCallingLobby,
maybePeekGroupCall,
onObservedRemoteMute, onObservedRemoteMute,
onOutgoingVideoCallInConversation, onOutgoingVideoCallInConversation,
onOutgoingAudioCallInConversation, onOutgoingAudioCallInConversation,
openSystemPreferencesAction, openSystemPreferencesAction,
outgoingCall, outgoingCall,
peekGroupCallForTheFirstTime,
peekGroupCallIfItHasMembers,
peekNotConnectedGroupCall, peekNotConnectedGroupCall,
receiveGroupCallReactions, receiveGroupCallReactions,
receiveIncomingDirectCall, receiveIncomingDirectCall,

View File

@@ -209,8 +209,7 @@ export const SmartTimeline = memo(function SmartTimeline({
setIsNearBottom, setIsNearBottom,
targetMessage, targetMessage,
} = useConversationsActions(); } = useConversationsActions();
const { peekGroupCallForTheFirstTime, peekGroupCallIfItHasMembers } = const { maybePeekGroupCall } = useCallingActions();
useCallingActions();
const getTimestampForMessage = useCallback( const getTimestampForMessage = useCallback(
(messageId: string): undefined | number => { (messageId: string): undefined | number => {
@@ -282,14 +281,13 @@ export const SmartTimeline = memo(function SmartTimeline({
loadNewestMessages={loadNewestMessages} loadNewestMessages={loadNewestMessages}
loadOlderMessages={loadOlderMessages} loadOlderMessages={loadOlderMessages}
markMessageRead={markMessageRead} markMessageRead={markMessageRead}
maybePeekGroupCall={maybePeekGroupCall}
messageChangeCounter={messageChangeCounter} messageChangeCounter={messageChangeCounter}
messageLoadingState={messageLoadingState} messageLoadingState={messageLoadingState}
updateVisibleMessages={ updateVisibleMessages={
AttachmentDownloadManager.updateVisibleTimelineMessages AttachmentDownloadManager.updateVisibleTimelineMessages
} }
oldestUnseenIndex={oldestUnseenIndex} oldestUnseenIndex={oldestUnseenIndex}
peekGroupCallForTheFirstTime={peekGroupCallForTheFirstTime}
peekGroupCallIfItHasMembers={peekGroupCallIfItHasMembers}
renderCollidingAvatars={renderCollidingAvatars} renderCollidingAvatars={renderCollidingAvatars}
renderContactSpoofingReviewDialog={renderContactSpoofingReviewDialog} renderContactSpoofingReviewDialog={renderContactSpoofingReviewDialog}
renderHeroRow={renderHeroRow} renderHeroRow={renderHeroRow}