relay: restrict to local events unless the filter is already narrow

This commit is contained in:
Alex Gleason 2023-08-12 15:14:34 -05:00
parent 8e47c9dda2
commit a35ea6ab5d
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 5 additions and 2 deletions

View File

@ -49,11 +49,14 @@ function connectStream(socket: WebSocket) {
} }
} }
/** Enforce the filters with certain criteria. */
function prepareFilters(filters: ClientREQ[2][]): Filter[] { function prepareFilters(filters: ClientREQ[2][]): Filter[] {
return filters.map((filter) => ({ return filters.map((filter) => ({
...filter, ...filter,
// Limit the number of events returned per-filter.
limit: Math.min(filter.limit || FILTER_LIMIT, FILTER_LIMIT), limit: Math.min(filter.limit || FILTER_LIMIT, FILTER_LIMIT),
local: true, // Return only local events unless the query is already narrow.
local: !filter.ids?.length && !filter.authors?.length,
})); }));
} }
@ -65,8 +68,8 @@ const relayController: AppController = (c) => {
} }
const { socket, response } = Deno.upgradeWebSocket(c.req.raw); const { socket, response } = Deno.upgradeWebSocket(c.req.raw);
connectStream(socket); connectStream(socket);
return response; return response;
}; };