Skip to content

Commit

Permalink
More peeking of group calls to prevent out-of-date member info
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Nonnenberg <scott@signal.org>
  • Loading branch information
automated-signal and scottnonnenberg-signal committed Apr 1, 2022
1 parent ee3a35d commit 3ed5c36
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions ts/components/conversation/Timeline.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ const actions = () => ({
unblurAvatar: action('unblurAvatar'),

peekGroupCallForTheFirstTime: action('peekGroupCallForTheFirstTime'),
peekGroupCallIfItHasMembers: action('peekGroupCallIfItHasMembers'),
});

const renderItem = ({
Expand Down
15 changes: 14 additions & 1 deletion ts/components/conversation/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
setScrollBottom,
} from '../../util/scrollUtil';
import { LastSeenIndicator } from './LastSeenIndicator';
import { MINUTE } from '../../util/durations';

const AT_BOTTOM_THRESHOLD = 15;
const AT_BOTTOM_DETECTOR_STYLE = { height: AT_BOTTOM_THRESHOLD };
Expand Down Expand Up @@ -162,6 +163,7 @@ export type PropsActionsType = {
onDelete: (conversationId: string) => unknown;
onUnblock: (conversationId: string) => unknown;
peekGroupCallForTheFirstTime: (conversationId: string) => unknown;
peekGroupCallIfItHasMembers: (conversationId: string) => unknown;
removeMember: (conversationId: string) => unknown;
selectMessage: (messageId: string, conversationId: string) => unknown;
clearSelectedMessage: () => unknown;
Expand Down Expand Up @@ -221,6 +223,7 @@ const getActions = createSelector(
'onDelete',
'onUnblock',
'peekGroupCallForTheFirstTime',
'peekGroupCallIfItHasMembers',
'removeMember',
'selectMessage',
'clearSelectedMessage',
Expand Down Expand Up @@ -281,6 +284,7 @@ export class Timeline extends React.Component<

private hasRecentlyScrolledTimeout?: NodeJS.Timeout;
private delayedPeekTimeout?: NodeJS.Timeout;
private peekInterval?: NodeJS.Timeout;

override state: StateType = {
hasRecentlyScrolled: true,
Expand Down Expand Up @@ -562,18 +566,27 @@ export class Timeline extends React.Component<

this.delayedPeekTimeout = setTimeout(() => {
const { id, peekGroupCallForTheFirstTime } = this.props;
this.delayedPeekTimeout = undefined;
peekGroupCallForTheFirstTime(id);
}, 500);

this.peekInterval = setInterval(() => {
const { id, peekGroupCallIfItHasMembers } = this.props;
peekGroupCallIfItHasMembers(id);
}, MINUTE);
}

public override componentWillUnmount(): void {
const { delayedPeekTimeout } = this;
const { delayedPeekTimeout, peekInterval } = this;

window.unregisterForActive(this.markNewestBottomVisibleMessageRead);

this.intersectionObserver?.disconnect();

clearTimeoutIfNecessary(delayedPeekTimeout);
if (peekInterval) {
clearInterval(peekInterval);
}
}

public override getSnapshotBeforeUpdate(
Expand Down
1 change: 0 additions & 1 deletion ts/services/audioRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export class RecorderClass {

async stop(): Promise<Blob | undefined> {
if (!this.recorder) {
log.warn('Recorder/stop: Called with no recorder');
return;
}

Expand Down
22 changes: 22 additions & 0 deletions ts/state/ducks/calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ const doGroupCallPeek = (
return;
}

log.info(
`doGroupCallPeek/groupv2(${conversation.groupId}): Found ${peekInfo.deviceCount} devices`
);

await calling.updateCallHistoryForGroupCall(conversationId, peekInfo);

const formattedPeekInfo = calling.formatGroupCallPeekInfoForRedux(peekInfo);
Expand Down Expand Up @@ -988,6 +992,23 @@ function peekGroupCallForTheFirstTime(
};
}

function peekGroupCallIfItHasMembers(
conversationId: string
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
return (dispatch, getState) => {
const call = getOwn(getState().calling.callsByConversation, conversationId);
const shouldPeek =
call &&
call.callMode === CallMode.Group &&
call.joinState === GroupCallJoinState.NotJoined &&
call.peekInfo &&
call.peekInfo.deviceCount > 0;
if (shouldPeek) {
doGroupCallPeek(conversationId, dispatch, getState);
}
};
}

function peekNotConnectedGroupCall(
payload: PeekNotConnectedGroupCallType
): ThunkAction<void, RootStateType, unknown, PeekGroupCallFulfilledActionType> {
Expand Down Expand Up @@ -1310,6 +1331,7 @@ export const actions = {
openSystemPreferencesAction,
outgoingCall,
peekGroupCallForTheFirstTime,
peekGroupCallIfItHasMembers,
peekNotConnectedGroupCall,
receiveIncomingDirectCall,
receiveIncomingGroupCall,
Expand Down

0 comments on commit 3ed5c36

Please sign in to comment.