* PATCHes the channel with the * combined stream list and updates the channelsTable store in-place * using the stream objects the caller already has. Skips requeryStreams * (stream data doesn't change) and requeryChannels (we build the * result locally). * * @param {number} channel
(channelId, existingStreams, newStreams)
| 751 | * @param {Array} newStreams - stream objects to append |
| 752 | */ |
| 753 | static async addStreamsToChannel(channelId, existingStreams, newStreams) { |
| 754 | try { |
| 755 | const existing = existingStreams || []; |
| 756 | // Deduplicate by ID, preserving order (existing first, new appended) |
| 757 | const seen = new Set(existing.map((s) => s.id)); |
| 758 | const merged = [...existing]; |
| 759 | for (const s of newStreams) { |
| 760 | if (!seen.has(s.id)) { |
| 761 | seen.add(s.id); |
| 762 | merged.push(s); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | await request(`${host}/api/channels/channels/${channelId}/`, { |
| 767 | method: 'PATCH', |
| 768 | body: { id: channelId, streams: merged.map((s) => s.id) }, |
| 769 | }); |
| 770 | |
| 771 | // Update the channelsTable store in-place with the merged streams |
| 772 | const store = useChannelsTableStore.getState(); |
| 773 | const channel = store.channels.find((c) => c.id === channelId); |
| 774 | if (channel) { |
| 775 | store.updateChannel({ ...channel, streams: merged }); |
| 776 | } |
| 777 | } catch (e) { |
| 778 | errorNotification('Failed to add streams to channel', e); |
| 779 | // On failure, requery to restore correct state |
| 780 | await API.requeryChannels(); |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | static async updateChannels(ids, values) { |
| 785 | const body = []; |
no test coverage detected