Skip to content

Commit

Permalink
fix: resend client sources if usergroups are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 17, 2024
1 parent d6a525e commit b5a7212
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
filterSourcesForClient,
hasSourceLinksChanged,
updateRecievedSourceLink,
updateSettingsInSourceLinks
updateSettingsInSourceLinks,
} from "./utils/handleSourceLinks";
import { getSettings } from "./utils/storage";

let oldSettings: ISource[] = [];
let sourceLinks: ISource[] = [];
const updateSourceListTimer = setInterval(() => {
const settings = getSettings();
if (hasSourceLinksChanged(settings, oldSettings)) {
if (hasSourceLinksChanged(settings, oldSettings)) {
oldSettings = settings;
sourceLinks = updateSettingsInSourceLinks(sourceLinks, settings);
}
Expand All @@ -30,20 +30,28 @@ const updateSourceListTimer = setInterval(() => {
io.on("connection", (socket: any) => {
console.log("User connected :", socket.id);
let clientUserGroups: string[];
let clientOldUserGroups: string[];
let clientsOldSourceLinks: ISource[] = [];

const sendSourcesToClient = () => {
if (hasSourceLinksChanged(clientsOldSourceLinks, sourceLinks)) {
const clientSideSources = filterSourcesForClient(
sourceLinks,
clientUserGroups
);
console.log("Sending sources");
socket.emit(IO.SOURCE_LIST, clientSideSources);
clientsOldSourceLinks = JSON.parse(JSON.stringify(sourceLinks));
}
};
const thisClientTimer = setInterval(() => sendSourcesToClient(), 1000);

const thisClientTimer = setInterval(() => {
if (
hasSourceLinksChanged(clientsOldSourceLinks, sourceLinks) ||
clientUserGroups !== clientOldUserGroups
) {
clientOldUserGroups = clientUserGroups;
sendSourcesToClient();
}
}, 5000);

socket
.on(IO.GET_SOURCES, (userGroups: string[]) => {
Expand Down

0 comments on commit b5a7212

Please sign in to comment.