Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-53081] Redux store refactor #510

Merged
merged 25 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d10ec1
Rename reducers and actions
streamer45 Aug 24, 2023
4abf824
Renaming part 2
streamer45 Aug 25, 2023
4303190
Strip unnecessary prefix
streamer45 Aug 25, 2023
0993c3e
Consistency with reducers types
streamer45 Aug 25, 2023
1eaca6f
More consistency
streamer45 Aug 25, 2023
e094c94
Selectors review part 1
streamer45 Aug 25, 2023
cf6ea3c
Add missing dispatch
streamer45 Aug 25, 2023
4371b73
usersStatusesInCurrentCall
streamer45 Aug 28, 2023
85fcabe
reactionsInCurrentCall
streamer45 Aug 28, 2023
ee28d54
Reorder
streamer45 Aug 28, 2023
2d773d8
Rename call ID selector
streamer45 Aug 28, 2023
4db12b5
hostIDInCurrentCall & hostChangeAtInCurrentCall
streamer45 Aug 28, 2023
9dd8b66
screenSharingIDInCurrentCall
streamer45 Aug 28, 2023
22d08a9
recordingInCurrentCall & isRecordingInCurrentCall
streamer45 Aug 28, 2023
e45e875
recentlyJoinedUsersInCurrentCall
streamer45 Aug 28, 2023
a9869e7
Better use of connectedChannel
streamer45 Aug 28, 2023
587f68b
callStartAt
streamer45 Aug 28, 2023
1c3c755
More consistency
streamer45 Aug 30, 2023
096a5a9
Revert spurious changes
streamer45 Aug 30, 2023
90a6fe3
More revert
streamer45 Aug 30, 2023
8769964
Merge remote-tracking branch 'origin/main' into MM-53081
streamer45 Aug 31, 2023
58e7c95
Merge remote-tracking branch 'origin/main' into MM-53081
streamer45 Sep 6, 2023
57588a5
Handle potentially undefined channel
streamer45 Sep 6, 2023
e0a6a8c
Fix potential undefined team
streamer45 Sep 6, 2023
2c9d5b8
Merge remote-tracking branch 'origin/main' into MM-53081
streamer45 Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions standalone/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import configureStore from 'mattermost-redux/store';
import {Theme} from 'mattermost-redux/types/themes';
import {
VOICE_CHANNEL_USER_SCREEN_ON,
VOICE_CHANNEL_ROOT_POST,
VOICE_CHANNEL_PROFILES_CONNECTED,
VOICE_CHANNEL_USERS_CONNECTED,
VOICE_CHANNEL_USERS_CONNECTED_STATES,
VOICE_CHANNEL_CALL_START,
USER_SCREEN_ON,
PROFILES_CONNECTED,
USERS_CONNECTED,
USERS_CONNECTED_STATES,
CALL_STATE,
CALL_HOST,
} from 'plugin/action_types';
import {getCallsConfig} from 'plugin/actions';
import CallsClient from 'plugin/client';
Expand Down Expand Up @@ -145,44 +145,44 @@ async function fetchChannelData(store: Store, channelID: string) {
}

store.dispatch({
type: VOICE_CHANNEL_USERS_CONNECTED,
type: USERS_CONNECTED,
data: {
users: resp.call.users,
channelID,
},
});

store.dispatch({
type: VOICE_CHANNEL_ROOT_POST,
data: {
channelID,
rootPost: resp.call.thread_id,
},
});

store.dispatch({
type: VOICE_CHANNEL_USER_SCREEN_ON,
type: USER_SCREEN_ON,
data: {
channelID,
userID: resp.call.screen_sharing_id,
},
});

store.dispatch({
type: VOICE_CHANNEL_CALL_START,
type: CALL_STATE,
data: {
ID: resp.call.id,
channelID: resp.channel_id,
startAt: resp.call.start_at,
ownerID: resp.call.owner_id,
threadID: resp.call.thread_id,
},
});

store.dispatch({
type: CALL_HOST,
data: {
channelID,
hostID: resp.call.host_id,
dismissedNotification: resp.call.dismissed_notification || {},
hostChangeAt: resp.call.start_at,
},
});

if (resp.call.users.length > 0) {
store.dispatch({
type: VOICE_CHANNEL_PROFILES_CONNECTED,
type: PROFILES_CONNECTED,
data: {
profiles: await getProfilesByIds(store.getState(), resp.call.users),
channelID,
Expand All @@ -196,7 +196,7 @@ async function fetchChannelData(store: Store, channelID: string) {
userStates[users[i]] = {...states[i], id: users[i], voice: false};
}
store.dispatch({
type: VOICE_CHANNEL_USERS_CONNECTED_STATES,
type: USERS_CONNECTED_STATES,
data: {
states: userStates,
channelID,
Expand Down
12 changes: 6 additions & 6 deletions standalone/src/recording/components/recording_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {useIntl} from 'react-intl';
import {useSelector} from 'react-redux';
import ScreenIcon from 'src/components/icons/screen_icon';
import Timestamp from 'src/components/timestamp';
import {voiceChannelCallHostID, voiceChannelScreenSharingID, voiceConnectedProfiles, voiceUsersStatuses} from 'src/selectors';
import {screenSharingIDForCurrentCall, profilesInCurrentCall, usersStatusesInCurrentCall, hostIDForCurrentCall} from 'src/selectors';

import {callProfileImages} from 'src/recording/selectors';

Expand All @@ -26,17 +26,17 @@ const RecordingView = () => {
const [screenStream, setScreenStream] = useState<MediaStream|null>(null);
const callsClient = window.callsClient;
const channelID = callsClient?.channelID || '';
const screenSharingID = useSelector((state: GlobalState) => voiceChannelScreenSharingID(state, channelID)) || '';
const statuses = useSelector(voiceUsersStatuses);
const profiles = sortedProfiles(useSelector(voiceConnectedProfiles), statuses, screenSharingID);
const screenSharingID = useSelector((state: GlobalState) => screenSharingIDForCurrentCall(state));
const statuses = useSelector(usersStatusesInCurrentCall);
const profiles = sortedProfiles(useSelector(profilesInCurrentCall), statuses, screenSharingID);
const profileImages = useSelector((state: GlobalState) => callProfileImages(state, channelID));
const pictures: {[key: string]: string} = {};
if (profileImages) {
for (let i = 0; i < profiles.length; i++) {
pictures[String(profiles[i].id)] = profileImages[profiles[i].id];
}
}
const callHostID = useSelector((state: GlobalState) => voiceChannelCallHostID(state, channelID)) || '';
const hostID = useSelector((state: GlobalState) => hostIDForCurrentCall(state));

const attachVoiceTracks = (tracks: MediaStreamTrack[]) => {
for (const track of tracks) {
Expand Down Expand Up @@ -155,7 +155,7 @@ const RecordingView = () => {
isSpeaking={isSpeaking}
isHandRaised={isHandRaised}
reaction={status?.reaction}
isHost={profile.id === callHostID}
isHost={profile.id === hostID}
/>
);
});
Expand Down
10 changes: 5 additions & 5 deletions standalone/src/recording/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {Theme} from 'mattermost-redux/types/themes';
import {getCurrentUserId} from 'mattermost-webapp/packages/mattermost-redux/src/selectors/entities/users';
import {logErr} from 'plugin/log';
import {pluginId} from 'plugin/manifest';
import {voiceConnectedProfilesInChannel, voiceChannelCallStartAt} from 'plugin/selectors';
import {profilesInCallInChannel, callStartAtForCallInChannel} from 'plugin/selectors';
import {Store} from 'plugin/types/mattermost-webapp';
import {getProfilesByIds, getPluginPath, fetchTranslationsFile, setCallsGlobalCSSVars, runWithRetry} from 'plugin/utils';
import React from 'react';
import ReactDOM from 'react-dom';
import {IntlProvider} from 'react-intl';
import {Provider} from 'react-redux';
import {VOICE_CHANNEL_USER_CONNECTED} from 'src/action_types';
import {USER_CONNECTED} from 'src/action_types';

import init from '../init';
import recordingReducer from 'src/recording/reducers';
Expand Down Expand Up @@ -70,20 +70,20 @@ async function initRecordingStore(store: Store, channelID: string) {
}

async function initRecording(store: Store, theme: Theme, channelID: string) {
if (!voiceChannelCallStartAt(store.getState(), channelID)) {
if (!callStartAtForCallInChannel(store.getState(), channelID)) {
throw new Error('call is missing from store');
}

await store.dispatch({
type: VOICE_CHANNEL_USER_CONNECTED,
type: USER_CONNECTED,
data: {
channelID,
userID: getCurrentUserId(store.getState()),
currentUserID: getCurrentUserId(store.getState()),
},
});

const profiles = voiceConnectedProfilesInChannel(store.getState(), channelID);
const profiles = profilesInCallInChannel(store.getState(), channelID);

if (profiles?.length > 0) {
store.dispatch({
Expand Down
4 changes: 2 additions & 2 deletions standalone/src/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {Theme} from 'mattermost-redux/types/themes';
import {isOpenChannel, isPrivateChannel} from 'mattermost-redux/utils/channel_utils';
import {
VOICE_CHANNEL_USER_CONNECTED,
USER_CONNECTED,
} from 'plugin/action_types';
import CallWidget from 'plugin/components/call_widget';
import {
Expand All @@ -30,7 +30,7 @@ import init from '../init';

async function initWidget(store: Store, theme: Theme, channelID: string) {
store.dispatch({
type: VOICE_CHANNEL_USER_CONNECTED,
type: USER_CONNECTED,
data: {
channelID,
userID: getCurrentUserId(store.getState()),
Expand Down
49 changes: 24 additions & 25 deletions webapp/src/action_types.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import {pluginId} from './manifest';

export const VOICE_CHANNEL_USER_CONNECTED = pluginId + '_voice_channel_user_connected';
export const VOICE_CHANNEL_USER_DISCONNECTED = pluginId + '_voice_channel_user_disconnected';
export const VOICE_CHANNEL_USER_MUTED = pluginId + '_voice_channel_user_muted';
export const VOICE_CHANNEL_USER_UNMUTED = pluginId + '_voice_channel_user_unmuted';
export const VOICE_CHANNEL_USER_VOICE_ON = pluginId + '_voice_channel_user_voice_on';
export const VOICE_CHANNEL_USER_VOICE_OFF = pluginId + '_voice_channel_user_voice_off';
export const VOICE_CHANNEL_USERS_CONNECTED = pluginId + '_voice_channel_users_connected';
export const VOICE_CHANNEL_USERS_CONNECTED_STATES = pluginId + '_voice_channel_users_connected_states';
export const VOICE_CHANNEL_PROFILES_CONNECTED = pluginId + '_voice_channel_profiles_connected';
export const VOICE_CHANNEL_PROFILE_CONNECTED = pluginId + '_voice_channel_profile_connected';
export const VOICE_CHANNEL_CALL_START = pluginId + '_voice_channel_call_start';
export const VOICE_CHANNEL_USER_SCREEN_ON = pluginId + '_voice_channel_screen_on';
export const VOICE_CHANNEL_USER_SCREEN_OFF = pluginId + '_voice_channel_screen_off';
export const VOICE_CHANNEL_UNINIT = pluginId + '_voice_channel_uninit';
export const VOICE_CHANNEL_USER_RAISE_HAND = pluginId + '_voice_channel_user_raise_hand';
export const VOICE_CHANNEL_USER_UNRAISE_HAND = pluginId + '_voice_channel_user_unraise_hand';
export const VOICE_CHANNEL_USER_REACTED = pluginId + '_voice_channel_user_reacted';
export const VOICE_CHANNEL_USER_REACTED_TIMEOUT = pluginId + '_voice_channel_user_reacted_timeout';
export const VOICE_CHANNEL_ROOT_POST = pluginId + '_voice_channel_root_post';
export const VOICE_CHANNEL_CALL_HOST = pluginId + '_voice_channel_call_host';
export const VOICE_CHANNEL_CALL_RECORDING_STATE = pluginId + '_voice_channel_call_recording_state';
export const VOICE_CHANNEL_CALL_REC_PROMPT_DISMISSED = pluginId + '_voice_channel_call_rec_prompt_dismissed';
export const VOICE_CHANNEL_USER_JOINED_TIMEOUT = pluginId + '_voice_channel_user_joined_timeout';
export const USER_CONNECTED = pluginId + '_user_connected';
export const USER_DISCONNECTED = pluginId + '_user_disconnected';
export const USER_MUTED = pluginId + '_user_muted';
export const USER_UNMUTED = pluginId + '_user_unmuted';
export const USER_VOICE_ON = pluginId + '_user_voice_on';
export const USER_VOICE_OFF = pluginId + '_user_voice_off';
export const USERS_CONNECTED = pluginId + '_users_connected';
export const USERS_CONNECTED_STATES = pluginId + '_users_connected_states';
export const PROFILE_CONNECTED = pluginId + '_profile_connected';
export const PROFILES_CONNECTED = pluginId + '_profiles_connected';
export const CALL_STATE = pluginId + '_call_state';
export const USER_SCREEN_ON = pluginId + '_screen_on';
export const USER_SCREEN_OFF = pluginId + '_screen_off';
export const UNINIT = pluginId + '_uninit';
export const USER_RAISE_HAND = pluginId + '_user_raise_hand';
export const USER_UNRAISE_HAND = pluginId + '_user_unraise_hand';
export const USER_REACTED = pluginId + '_user_reacted';
export const USER_REACTED_TIMEOUT = pluginId + '_user_reacted_timeout';
export const CALL_HOST = pluginId + '_call_host';
export const CALL_RECORDING_STATE = pluginId + '_call_recording_state';
export const CALL_REC_PROMPT_DISMISSED = pluginId + '_call_rec_prompt_dismissed';
export const USER_JOINED_TIMEOUT = pluginId + '_user_joined_timeout';

export const SHOW_EXPANDED_VIEW = pluginId + '_show_expanded_view';
export const HIDE_EXPANDED_VIEW = pluginId + '_hide_expanded_view';
Expand All @@ -39,8 +38,8 @@ export const RINGING_FOR_CALL = pluginId + '_ringing_for_call';
export const DID_RING_FOR_CALL = pluginId + '_did_ring_for_call';
export const DID_NOTIFY_FOR_CALL = pluginId + '_did_notify_for_call';

// VOICE_CHANNEL_CALL_END is sent when the `/call end` command is used
export const VOICE_CHANNEL_CALL_END = pluginId + '_voice_channel_call_end';
// CALL_END is sent when the `/call end` command is used
export const CALL_END = pluginId + '_call_end';

export const RECEIVED_CALLS_CONFIG = pluginId + '_received_calls_config';
export const RECORDINGS_ENABLED = pluginId + '_recordings_enabled';
Expand Down
26 changes: 13 additions & 13 deletions webapp/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {CallsInTestModeModal, IDTestModeUser} from 'src/components/modals';
import {RING_LENGTH} from 'src/constants';
import {logErr} from 'src/log';
import {
channelHasCall, connectedCallID, incomingCalls,
channelHasCall, idForCurrentCall, incomingCalls,
ringingEnabled,
ringingForCall,
voiceChannelCallDismissedNotification,
voiceChannelCalls,
callDismissedNotification,
calls,
} from 'src/selectors';
import * as Telemetry from 'src/types/telemetry';
import {ChannelType} from 'src/types/types';
Expand All @@ -43,9 +43,9 @@ import {
SHOW_EXPANDED_VIEW,
SHOW_SCREEN_SOURCE_MODAL,
SHOW_SWITCH_CALL_MODAL,
VOICE_CHANNEL_CALL_REC_PROMPT_DISMISSED,
VOICE_CHANNEL_CALL_RECORDING_STATE,
VOICE_CHANNEL_USER_DISCONNECTED,
CALL_REC_PROMPT_DISMISSED,
CALL_RECORDING_STATE,
USER_DISCONNECTED,
RTCD_ENABLED,
REMOVE_INCOMING_CALL,
DID_RING_FOR_CALL,
Expand Down Expand Up @@ -242,7 +242,7 @@ export const startCallRecording = (callID: string) => (dispatch: Dispatch<Generi
{method: 'post'},
).catch((err) => {
dispatch({
type: VOICE_CHANNEL_CALL_RECORDING_STATE,
type: CALL_RECORDING_STATE,
data: {
callID,
recState: {
Expand All @@ -266,7 +266,7 @@ export const stopCallRecording = async (callID: string) => {

export const recordingPromptDismissedAt = (callID: string, dismissedAt: number) => (dispatch: Dispatch<GenericAction>) => {
dispatch({
type: VOICE_CHANNEL_CALL_REC_PROMPT_DISMISSED,
type: CALL_REC_PROMPT_DISMISSED,
data: {
callID,
dismissedAt,
Expand Down Expand Up @@ -316,7 +316,7 @@ export function incomingCallOnChannel(channelID: string, callID: string, callerI
return;
}

if (voiceChannelCallDismissedNotification(getState(), channelID)) {
if (callDismissedNotification(getState(), channelID)) {
return;
}

Expand All @@ -326,8 +326,8 @@ export function incomingCallOnChannel(channelID: string, callID: string, callerI

// Never send a notification for a call you started yourself, or a call you are currently in.
const currentUserID = getCurrentUserId(getState());
const connectedID = connectedCallID(getState());
if (currentUserID === callerID || connectedID === callID) {
const currentCallID = idForCurrentCall(getState());
if (currentUserID === callerID || currentCallID === callID) {
return;
}

Expand All @@ -352,10 +352,10 @@ export function incomingCallOnChannel(channelID: string, callID: string, callerI
export const userDisconnected = (channelID: string, userID: string) => {
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
// save for later
const callID = voiceChannelCalls(getState())[channelID].ID || '';
const callID = calls(getState())[channelID].ID || '';

await dispatch({
type: VOICE_CHANNEL_USER_DISCONNECTED,
type: USER_DISCONNECTED,
data: {
channelID,
userID,
Expand Down
34 changes: 17 additions & 17 deletions webapp/src/components/call_widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import {bindActionCreators, Dispatch} from 'redux';

import {recordingPromptDismissedAt, showExpandedView, showScreenSourceModal, trackEvent} from 'src/actions';
import {
voiceUsersStatuses,
voiceChannelCallStartAt,
voiceChannelScreenSharingID,
usersStatusesInCurrentCall,
callStartAtForCurrentCall,
screenSharingIDForCurrentCall,
expandedView,
getChannelUrlAndDisplayName,
allowScreenSharing,
voiceConnectedProfiles,
voiceChannelCallHostID,
callRecording,
voiceChannelCallHostChangeAt,
recentlyJoinedUsers,
profilesInCurrentCall,
hostIDForCurrentCall,
hostChangeAtForCurrentCall,
recordingForCurrentCall,
sortedIncomingCalls,
recentlyJoinedUsersInCurrentCall,
} from 'src/selectors';
import {alphaSortProfiles, stateSortProfiles} from 'src/utils';

Expand All @@ -37,14 +37,14 @@ const mapStateToProps = (state: GlobalState) => {
const channel = getChannel(state, String(window.callsClient?.channelID));
const currentUserID = getCurrentUserId(state);

const screenSharingID = voiceChannelScreenSharingID(state, channel?.id) || '';
const screenSharingID = screenSharingIDForCurrentCall(state);

const sortedProfiles = (profiles: UserProfile[], statuses: {[key: string]: UserState}) => {
return [...profiles].sort(alphaSortProfiles).sort(stateSortProfiles(profiles, statuses, screenSharingID, true));
};

const statuses = voiceUsersStatuses(state);
const profiles = sortedProfiles(voiceConnectedProfiles(state), statuses);
const statuses = usersStatusesInCurrentCall(state);
const profiles = sortedProfiles(profilesInCurrentCall(state), statuses);

const profilesMap: IDMappedObjects<UserProfile> = {};
const picturesMap: {
Expand All @@ -67,15 +67,15 @@ const mapStateToProps = (state: GlobalState) => {
profiles,
profilesMap,
picturesMap,
statuses: voiceUsersStatuses(state) || {},
callStartAt: voiceChannelCallStartAt(state, channel?.id) || Number(window.callsClient?.initTime),
callHostID: voiceChannelCallHostID(state, channel?.id) || '',
callHostChangeAt: voiceChannelCallHostChangeAt(state, channel?.id) || 0,
callRecording: callRecording(state, channel?.id),
statuses,
callStartAt: callStartAtForCurrentCall(state),
callHostID: hostIDForCurrentCall(state),
callHostChangeAt: hostChangeAtForCurrentCall(state),
callRecording: recordingForCurrentCall(state),
screenSharingID,
allowScreenSharing: allowScreenSharing(state),
show: !expandedView(state),
recentlyJoinedUsers: recentlyJoinedUsers(state, channel?.id),
recentlyJoinedUsers: recentlyJoinedUsersInCurrentCall(state),
wider: getMyTeams(state)?.length > 1,
callsIncoming: sortedIncomingCalls(state),
};
Expand Down
Loading