Skip to content

Commit

Permalink
Limit fetching channels to initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 committed Feb 2, 2022
1 parent 868f0c4 commit 0f9cc26
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion e2e/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const baseURL = 'http://localhost:8065';
export const baseURL = process.env.MM_SITE_URL || 'http://localhost:8065';
export const defaultTeam = 'calls';
export const userState = {
admin: {
Expand Down
3 changes: 3 additions & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"

"github.com/prometheus/client_golang/prometheus"
)

var chRE = regexp.MustCompile(`^\/([a-z0-9]+)$`)
Expand Down Expand Up @@ -83,6 +85,7 @@ func (p *Plugin) handleGetAllChannels(w http.ResponseWriter, r *http.Request) {
var channels []ChannelState
perPage := 200
for {
p.metrics.StoreOpCounters.With(prometheus.Labels{"type": "KVList"}).Inc()
channelIDs, appErr := p.API.KVList(page, perPage)
if appErr != nil {
p.LogError(appErr.Error())
Expand Down
82 changes: 40 additions & 42 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,32 @@ export default class Plugin {
);
};

const fetchChannels = async () => {
try {
const resp = await axios.get(`${getPluginPath()}/channels`);
for (let i = 0; i < resp.data.length; i++) {
store.dispatch({
type: VOICE_CHANNEL_USERS_CONNECTED,
data: {
users: resp.data[i].call?.users,
channelID: resp.data[i].channel_id,
},
});
if (!voiceChannelCallStartAt(store.getState(), resp.data[i].channel_id)) {
store.dispatch({
type: VOICE_CHANNEL_CALL_START,
data: {
channelID: resp.data[i].channel_id,
startAt: resp.data[i].call?.start_at,
},
});
}
}
} catch (err) {
console.log(err);
}
};

const fetchChannelData = async (channelID: string) => {
const channel = getChannel(store.getState(), channelID);
const roles = getMyRoles(store.getState());
Expand Down Expand Up @@ -417,6 +443,16 @@ export default class Plugin {
},
});

if (resp.data.call?.users && resp.data.call?.users.length > 0) {
store.dispatch({
type: VOICE_CHANNEL_PROFILES_CONNECTED,
data: {
profiles: await getProfilesByIds(store.getState(), resp.data.call?.users),
channelID,
},
});
}

if (resp.data.call?.screen_sharing_id) {
store.dispatch({
type: VOICE_CHANNEL_USER_SCREEN_ON,
Expand Down Expand Up @@ -446,48 +482,10 @@ export default class Plugin {
type: VOICE_CHANNEL_DISABLE,
});
}

try {
const resp = await axios.get(`${getPluginPath()}/channels`);
let currentChannelData;
for (let i = 0; i < resp.data.length; i++) {
store.dispatch({
type: VOICE_CHANNEL_USERS_CONNECTED,
data: {
users: resp.data[i].call?.users,
channelID: resp.data[i].channel_id,
},
});
if (resp.data[i].channel_id === channelID) {
currentChannelData = resp.data[i];
}

if (!voiceChannelCallStartAt(store.getState(), resp.data[i].channel_id)) {
store.dispatch({
type: VOICE_CHANNEL_CALL_START,
data: {
channelID: resp.data[i].channel_id,
startAt: resp.data[i].call?.start_at,
},
});
}
}

if (currentChannelData && currentChannelData.call?.users.length > 0) {
store.dispatch({
type: VOICE_CHANNEL_PROFILES_CONNECTED,
data: {
profiles: await getProfilesByIds(store.getState(), currentChannelData.call?.users),
channelID: currentChannelData.channel_id,
},
});
}
} catch (err) {
console.log(err);
}
};

this.registerWebSocketEvents(registry, store);
fetchChannels();

let currChannelId = getCurrentChannelId(store.getState());
if (currChannelId) {
Expand All @@ -507,16 +505,16 @@ export default class Plugin {
}
}

let joinCall = new URLSearchParams(window.location.search).get('join_call');
let joinCallParam = new URLSearchParams(window.location.search).get('join_call');
this.unsubscribers.push(store.subscribe(() => {
const currentChannelId = getCurrentChannelId(store.getState());
if (currChannelId !== currentChannelId) {
currChannelId = currentChannelId;
fetchChannelData(currChannelId);
if (currChannelId && Boolean(joinCall) && !connectedChannelID(store.getState())) {
if (currChannelId && Boolean(joinCallParam) && !connectedChannelID(store.getState())) {
connectCall(currChannelId);
}
joinCall = false;
joinCallParam = '';
}
}));

Expand Down

0 comments on commit 0f9cc26

Please sign in to comment.