channel groups

This commit is contained in:
Simon
2026-06-18 11:19:15 +00:00
parent 08c96d5903
commit 1b6fa5f924
4 changed files with 170 additions and 18 deletions

View File

@@ -166,12 +166,13 @@ App.ui = App.ui || {};
sourceSelect.onchange = () => {
const selectedServerUrl = sourceSelect.value;
const selectedServer = serverEntries.find((entry) => entry.url === selectedServerUrl);
const channels = selectedServer && selectedServer.data && selectedServer.data.channels ?
selectedServer.data.channels :
[];
const selectedServerData = selectedServer && selectedServer.data ? selectedServer.data : null;
const channels = selectedServerData && selectedServerData.channels ? selectedServerData.channels : [];
const prefs = App.storage.getPreferences();
const serverPrefs = prefs[selectedServerUrl] || {};
const preferredChannel = channels.find((channel) => channel.id === serverPrefs.channelId) || null;
const preferredChannel = selectedServerData ?
App.session.resolveChannelById(selectedServerData, serverPrefs.channelId) :
null;
const nextChannel = preferredChannel || (channels.length > 0 ? channels[0] : null);
const savedOptions = nextChannel && serverPrefs.optionsByChannel ?
serverPrefs.optionsByChannel[nextChannel.id] :
@@ -188,8 +189,9 @@ App.ui = App.ui || {};
};
const activeServer = serverEntries.find((entry) => entry.url === (session && session.server));
const availableChannels = activeServer && activeServer.data && activeServer.data.channels ?
[...activeServer.data.channels] :
const activeServerData = activeServer && activeServer.data ? activeServer.data : null;
const availableChannels = activeServerData && activeServerData.channels ?
[...activeServerData.channels] :
[];
availableChannels.sort((a, b) => {
const nameA = (a.name || a.id || '').toLowerCase();
@@ -197,21 +199,54 @@ App.ui = App.ui || {};
return nameA.localeCompare(nameB);
});
const channelGroups = activeServerData && Array.isArray(activeServerData.channelGroups) ?
activeServerData.channelGroups :
[];
channelSelect.innerHTML = "";
availableChannels.forEach((channel) => {
const option = document.createElement('option');
option.value = channel.id;
option.textContent = channel.name || channel.id;
channelSelect.appendChild(option);
const groupedChannelIds = new Set();
channelGroups.forEach((group) => {
const channelIds = Array.isArray(group.channelIds) ?
group.channelIds.filter((id) => availableChannels.some((channel) => channel.id === id)) :
[];
if (channelIds.length === 0) return;
channelIds.forEach((id) => groupedChannelIds.add(id));
const optgroup = document.createElement('optgroup');
optgroup.label = group.title || group.id;
const groupOption = document.createElement('option');
groupOption.value = `group:${group.id}`;
groupOption.textContent = `All ${group.title || group.id}`;
optgroup.appendChild(groupOption);
channelIds.forEach((id) => {
const channel = availableChannels.find((ch) => ch.id === id);
const option = document.createElement('option');
option.value = channel.id;
option.textContent = channel.name || channel.id;
optgroup.appendChild(option);
});
channelSelect.appendChild(optgroup);
});
availableChannels
.filter((channel) => !groupedChannelIds.has(channel.id))
.forEach((channel) => {
const option = document.createElement('option');
option.value = channel.id;
option.textContent = channel.name || channel.id;
channelSelect.appendChild(option);
});
if (session && session.channel) {
channelSelect.value = session.channel.id;
}
channelSelect.onchange = () => {
const selectedId = channelSelect.value;
const nextChannel = availableChannels.find((channel) => channel.id === selectedId) || null;
const nextChannel = activeServerData ? App.session.resolveChannelById(activeServerData, selectedId) : null;
const prefs = App.storage.getPreferences();
const serverPrefs = prefs[session.server] || {};
const savedOptions = nextChannel && serverPrefs.optionsByChannel ?
@@ -286,8 +321,9 @@ App.ui = App.ui || {};
const nextServerUrl = remaining[0].url;
const nextServer = remaining[0];
const serverPrefs = prefs[nextServerUrl] || {};
const channels = nextServer.data && nextServer.data.channels ? nextServer.data.channels : [];
const nextChannel = channels.find((channel) => channel.id === serverPrefs.channelId) || channels[0] || null;
const nextServerData = nextServer.data || null;
const channels = nextServerData && nextServerData.channels ? nextServerData.channels : [];
const nextChannel = (nextServerData && App.session.resolveChannelById(nextServerData, serverPrefs.channelId)) || channels[0] || null;
const savedOptions = nextChannel && serverPrefs.optionsByChannel ? serverPrefs.optionsByChannel[nextChannel.id] : null;
const nextSession = {
server: nextServerUrl,
@@ -360,7 +396,9 @@ App.ui = App.ui || {};
if (!session || !session.channel || !Array.isArray(session.channel.options)) {
const empty = document.createElement('div');
empty.className = 'filters-empty';
empty.textContent = 'No filters available for this channel.';
empty.textContent = session && session.channel && session.channel.isGroup ?
'No filters available when browsing a whole channel group.' :
'No filters available for this channel.';
container.appendChild(empty);
return;
}