Skip to content

Commit

Permalink
Merge branch 'main' into MM-44946-fix-start-trial-path
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoile committed Jun 10, 2022
2 parents a1f127a + 23e94a5 commit 967678f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,29 @@ export default class Plugin {
});

registry.registerWebSocketEventHandler(`custom_${pluginId}_call_start`, (ev) => {
const channelID = ev.broadcast.channel_id;

store.dispatch({
type: VOICE_CHANNEL_CALL_START,
data: {
channelID: ev.broadcast.channel_id,
channelID,
startAt: ev.data.start_at,
ownerID: ev.data.owner_id,
},
});
store.dispatch({
type: VOICE_CHANNEL_ROOT_POST,
data: {
channelID: ev.broadcast.channel_id,
channelID,
rootPost: ev.data.thread_id,
},
});

const channel = getChannel(store.getState(), ev.broadcast.channel_id);
if (channel) {
followThread(channel.id, channel.team_id);
if (window.callsClient?.channelID === channelID) {
const channel = getChannel(store.getState(), channelID);
if (channel) {
followThread(channel.id, channel.team_id);
}
}
});

Expand Down Expand Up @@ -544,6 +548,11 @@ export default class Plugin {
};

const fetchChannelData = async (channelID: string) => {
if (!channelID) {
// Must be Global threads view, or another view that isn't a channel.
return;
}

let channel = getChannel(store.getState(), channelID);
if (!channel) {
await getChannelAction(channelID)(store.dispatch as any, store.getState);
Expand Down Expand Up @@ -635,8 +644,15 @@ export default class Plugin {
}
};

let configRetrieved = false;
const onActivate = async () => {
store.dispatch(getCallsConfig());
const res = await store.dispatch(getCallsConfig());

// @ts-ignore
if (!res.error) {
configRetrieved = true;
}

fetchChannels();
const currChannelId = getCurrentChannelId(store.getState());
if (currChannelId) {
Expand Down Expand Up @@ -687,6 +703,13 @@ export default class Plugin {
const currentChannelId = getCurrentChannelId(store.getState());
if (currChannelId !== currentChannelId) {
currChannelId = currentChannelId;

// If we haven't retrieved config, user must not have been logged in during onActivate
if (!configRetrieved) {
store.dispatch(getCallsConfig());
configRetrieved = true;
}

fetchChannelData(currChannelId);
if (currChannelId && Boolean(joinCallParam) && !connectedChannelID(store.getState())) {
connectCall(currChannelId);
Expand Down

0 comments on commit 967678f

Please sign in to comment.