Skip to content

Commit 1164164

Browse files
committed
Operator fix
1 parent e581429 commit 1164164

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/socket/socket.io.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class SocketIOServer extends SocketServer {
9292
},
9393
enter: async (context) => {
9494
socket.contexts.add(context);
95-
for (const entry of this.combineValues(socket, { context })) {
95+
for (const entry of this.combineValues(socket, { context: [context] })) {
9696
socket.join(room(entry));
9797
}
9898
},
9999
exit: async (context) => {
100100
socket.contexts.delete(context);
101-
for (const entry of this.combineValues(socket, { context })) {
101+
for (const entry of this.combineValues(socket, { context: [context] })) {
102102
socket.leave(room(entry));
103103
}
104104
},
@@ -157,11 +157,11 @@ class SocketIOServer extends SocketServer {
157157
break;
158158
case "and":
159159
for (const entry of this.combineValues(undefined, {
160-
tenant,
160+
tenant: [tenant],
161161
user: user?.include?.length > 0 ? user.include : undefined,
162-
role: role?.include?.length ? role.include : undefined,
162+
role: role?.include?.length > 0 ? role.include : undefined,
163163
context: context?.include?.length > 0 ? context.include : undefined,
164-
identifier: identifier?.include?.length ? identifier.include : undefined,
164+
identifier: identifier?.include?.length > 0 ? identifier.include : undefined,
165165
})) {
166166
to = to.to(room(entry));
167167
}
@@ -189,11 +189,11 @@ class SocketIOServer extends SocketServer {
189189
break;
190190
case "and":
191191
for (const entry of this.combineValues(undefined, {
192-
tenant,
192+
tenant: [tenant],
193193
user: user?.exclude?.length > 0 ? user.exclude : undefined,
194-
role: role?.exclude?.length ? role.exclude : undefined,
194+
role: role?.exclude?.length > 0 ? role.exclude : undefined,
195195
context: context?.exclude?.length > 0 ? context.exclude : undefined,
196-
identifier: identifier?.exclude?.length ? identifier.exclude : undefined,
196+
identifier: identifier?.exclude?.length > 0 ? identifier.exclude : undefined,
197197
})) {
198198
to = to.except(room(entry));
199199
}
@@ -234,32 +234,30 @@ class SocketIOServer extends SocketServer {
234234

235235
combineValues(socket, filter) {
236236
const values = {
237-
tenant: undefined,
238-
user: undefined,
237+
tenant: [],
238+
user: [],
239239
roles: [],
240240
contexts: [],
241-
identifier: undefined,
241+
identifier: [],
242242
};
243243
if (socket) {
244-
values.tenant = socket.context.tenant;
245-
values.user = socket.context.user?.id;
244+
values.tenant = [socket.context.tenant];
245+
values.user = [socket.context.user?.id];
246246
if (this.config?.roles && socket.context.user?.is) {
247247
for (const role of this.config.roles) {
248248
if (socket.context.user.is(role)) {
249249
values.roles.push(role);
250250
}
251251
}
252252
}
253-
values.identifier = socket.request.id;
253+
values.identifier = [socket.request.id];
254254
}
255255
const combinations = [];
256-
for (const tenant of unique(filter?.tenant ? [filter.tenant] : [undefined, values.tenant])) {
257-
for (const user of unique(filter?.user ? [filter.user] : [undefined, values.user])) {
258-
for (const role of unique(filter?.role ? [filter.role] : [undefined, ...values.roles])) {
259-
for (const context of unique(filter?.context ? [filter.context] : [undefined, ...values.contexts])) {
260-
for (const identifier of unique(
261-
filter?.identifier ? [filter.identifier] : [undefined, values.identifier],
262-
)) {
256+
for (const tenant of unique(filter?.tenant ?? values.tenant)) {
257+
for (const user of unique(filter?.user ?? [undefined, ...values.user])) {
258+
for (const role of unique(filter?.role ?? [undefined, ...values.roles])) {
259+
for (const context of unique(filter?.context ?? [undefined, ...values.contexts])) {
260+
for (const identifier of unique(filter?.identifier ?? [undefined, ...values.identifier])) {
263261
combinations.push({ tenant, user, role, context, identifier });
264262
}
265263
}

0 commit comments

Comments
 (0)