From 03fe46f229a929477bf2c9b6e84b3de95b25ddc1 Mon Sep 17 00:00:00 2001 From: Christopher Poile Date: Wed, 8 Feb 2023 09:25:41 -0500 Subject: [PATCH] MM-48605: Calls - Fix for start time in join call banner is incorrect (#7095) * "fix" the wrong start time * cleanup unused field --- app/products/calls/actions/calls.test.ts | 3 +-- .../calls/components/join_call_banner/index.ts | 10 +++++++--- app/products/calls/state/actions.test.ts | 2 -- app/products/calls/state/actions.ts | 2 +- app/products/calls/types/calls.ts | 2 -- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/products/calls/actions/calls.test.ts b/app/products/calls/actions/calls.test.ts index f87e9095f..a5e7191d9 100644 --- a/app/products/calls/actions/calls.test.ts +++ b/app/products/calls/actions/calls.test.ts @@ -97,7 +97,7 @@ const addFakeCall = (serverUrl: string, channelId: string) => { hostId: 'xohi8cki9787fgiryne716u84o', } as Call; act(() => { - State.setCallsState(serverUrl, {serverUrl, myUserId: 'myUserId', calls: {}, enabled: {}}); + State.setCallsState(serverUrl, {myUserId: 'myUserId', calls: {}, enabled: {}}); State.callStarted(serverUrl, call); }); }; @@ -277,7 +277,6 @@ describe('Actions.Calls', () => { it('loadCalls fails from server', async () => { const expectedCallsState: CallsState = { - serverUrl: 'server1', myUserId: 'userId1', calls: {}, enabled: {}, diff --git a/app/products/calls/components/join_call_banner/index.ts b/app/products/calls/components/join_call_banner/index.ts index 5e4a2ebc1..9fd4f5439 100644 --- a/app/products/calls/components/join_call_banner/index.ts +++ b/app/products/calls/components/join_call_banner/index.ts @@ -3,6 +3,7 @@ import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider'; import withObservables from '@nozbe/with-observables'; +import moment from 'moment-timezone'; import {of as of$} from 'rxjs'; import {distinctUntilChanged, switchMap} from 'rxjs/operators'; @@ -24,16 +25,19 @@ const enhanced = withObservables(['serverUrl', 'channelId'], ({ channelId, database, }: OwnProps & WithDatabaseArgs) => { - const callsState = observeCallsState(serverUrl); - const participants = callsState.pipe( + const callsState = observeCallsState(serverUrl).pipe( switchMap((state) => of$(state.calls[channelId])), + ); + const participants = callsState.pipe( distinctUntilChanged((prev, curr) => prev?.participants === curr?.participants), // Did the participants object ref change? switchMap((call) => (call ? of$(Object.keys(call.participants)) : of$([]))), distinctUntilChanged((prev, curr) => idsAreEqual(prev, curr)), // Continue only if we have a different set of participant ids switchMap((ids) => (ids.length > 0 ? queryUsersById(database, ids).observeWithColumns(['last_picture_update']) : of$([]))), ); const channelCallStartTime = callsState.pipe( - switchMap((cs) => of$(cs.calls[channelId]?.startTime || 0)), + + // if for some reason we don't have a startTime, use 'a few seconds ago' instead of '53 years ago' + switchMap((state) => of$(state && state.startTime ? state.startTime : moment.now())), distinctUntilChanged(), ); diff --git a/app/products/calls/state/actions.test.ts b/app/products/calls/state/actions.test.ts index c401be6b7..01ffae9f7 100644 --- a/app/products/calls/state/actions.test.ts +++ b/app/products/calls/state/actions.test.ts @@ -152,7 +152,6 @@ describe('useCallsState', () => { const expectedCallsState = { ...initialCallsState, - serverUrl: 'server1', myUserId: 'myId', calls: {'channel-1': testNewCall1, 'channel-2': call2, 'channel-3': call3}, enabled: {'channel-2': true}, @@ -758,7 +757,6 @@ describe('useCallsState', () => { it('voiceOn and Off', () => { const initialCallsState = { ...DefaultCallsState, - serverUrl: 'server1', myUserId: 'myUserId', calls: {'channel-1': call1, 'channel-2': call2}, }; diff --git a/app/products/calls/state/actions.ts b/app/products/calls/state/actions.ts index b172511aa..074e82d03 100644 --- a/app/products/calls/state/actions.ts +++ b/app/products/calls/state/actions.ts @@ -35,7 +35,7 @@ export const setCalls = (serverUrl: string, myUserId: string, calls: Dictionary< }, {} as ChannelsWithCalls); setChannelsWithCalls(serverUrl, channelsWithCalls); - setCallsState(serverUrl, {serverUrl, myUserId, calls, enabled}); + setCallsState(serverUrl, {myUserId, calls, enabled}); // Does the current call need to be updated? const currentCall = getCurrentCall(); diff --git a/app/products/calls/types/calls.ts b/app/products/calls/types/calls.ts index 53bdbec5c..b7e503e82 100644 --- a/app/products/calls/types/calls.ts +++ b/app/products/calls/types/calls.ts @@ -13,14 +13,12 @@ export const DefaultGlobalCallsState: GlobalCallsState = { }; export type CallsState = { - serverUrl: string; myUserId: string; calls: Dictionary; enabled: Dictionary; } export const DefaultCallsState: CallsState = { - serverUrl: '', myUserId: '', calls: {}, enabled: {},