Merge remote-tracking branch 'dskvr/main'

This commit is contained in:
kieran 2024-12-12 10:21:24 +00:00
commit c13cf88ce2
No known key found for this signature in database
GPG Key ID: DE71CEB3925BE941
2 changed files with 21 additions and 4 deletions

View File

@ -321,9 +321,9 @@ export class SqliteRelay extends EventEmitter<RelayHandlerEvents> implements Rel
operation = "delete";
}
let sql = `${operation} from events`;
const tags = Object.entries(req).filter(([k]) => k.startsWith("#"));
const orTags = Object.entries(req).filter(([k]) => k.startsWith("#"));
let tx = 0;
for (const [key, values] of tags) {
for (const [key, values] of orTags) {
const vArray = values as Array<string>;
sql += ` inner join tags t_${tx} on events.id = t_${tx}.event_id and t_${tx}.key = ? and t_${tx}.value in (${this.#repeatParams(
vArray.length,
@ -332,6 +332,15 @@ export class SqliteRelay extends EventEmitter<RelayHandlerEvents> implements Rel
params.push(...vArray);
tx++;
}
const andTags = Object.entries(req).filter(([k]) => k.startsWith("&"));
for (const [key, values] of andTags) {
for (const value of values as Array<string>) {
sql += ` inner join tags t_${tx} on events.id = t_${tx}.event_id and t_${tx}.key = ? and t_${tx}.value = ?`;
params.push(key.slice(1));
params.push(value);
tx++;
}
}
if (req.search) {
sql += " inner join search_content on search_content.id = events.id";
conditions.push("search_content match ?");

View File

@ -101,8 +101,8 @@ export function eventMatchesFilter(ev: NostrEvent, filter: ReqFilter) {
if (!(filter.kinds?.includes(ev.kind) ?? true)) {
return false;
}
const tags = Object.entries(filter).filter(([k]) => k.startsWith("#"));
for (const [k, v] of tags) {
const orTags = Object.entries(filter).filter(([k]) => k.startsWith("#"));
for (const [k, v] of orTags) {
const vargs = v as Array<string>;
for (const x of vargs) {
if (!ev.tags.find(a => a[0] === k.slice(1) && a[1] === x)) {
@ -110,6 +110,14 @@ export function eventMatchesFilter(ev: NostrEvent, filter: ReqFilter) {
}
}
}
const andTags = Object.entries(filter).filter(([k]) => k.startsWith("&"));
for (const [k, v] of andTags) {
const vargs = v as Array<string>;
const allMatch = vargs.every(x => ev.tags.some(tag => tag[0] === k.slice(1) && tag[1] === x));
if (!allMatch) {
return false;
}
}
return true;
}