forked from Ivasoft/mattermost-mobile
MM-48605: Calls - Fix for start time in join call banner is incorrect (#7095)
* "fix" the wrong start time * cleanup unused field
This commit is contained in:
committed by
GitHub
parent
7158de8d5e
commit
03fe46f229
@@ -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: {},
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
|
||||
|
||||
@@ -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},
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -13,14 +13,12 @@ export const DefaultGlobalCallsState: GlobalCallsState = {
|
||||
};
|
||||
|
||||
export type CallsState = {
|
||||
serverUrl: string;
|
||||
myUserId: string;
|
||||
calls: Dictionary<Call>;
|
||||
enabled: Dictionary<boolean>;
|
||||
}
|
||||
|
||||
export const DefaultCallsState: CallsState = {
|
||||
serverUrl: '',
|
||||
myUserId: '',
|
||||
calls: {},
|
||||
enabled: {},
|
||||
|
||||
Reference in New Issue
Block a user