Skip to content

Commit

Permalink
Merge pull request #1401 from Oneirocom/event-recall-filtering-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
parzival418 authored Nov 17, 2023
2 parents a5c9f49 + 964f29f commit 439d62a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
15 changes: 2 additions & 13 deletions packages/core/server/src/services/events/events.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export class EventService<
async find(params?: ServiceParams) {
const db = app.get('dbClient')

const entities = params?.query?.entities
// entities is an array of strings

const query = db.from('events').select('*')

if (params?.query?.embedding) {
Expand All @@ -65,21 +62,15 @@ export class EventService<
// If not searching by embedding, perform a normal query
query.orderBy('date', 'desc')
}

if (entities && entities.length > 0) {
// Safely check if all entities are included in the `entities` column
entities.forEach(entity => {
query.whereRaw(`'${entity}' = ANY (entities)`)
})
}

const param = params?.query

if (!param) {
return await db('events').select('*').limit(100)
}

if (param.type) query.where({ type: param.type })
if (param.sender) query.where({ sender: param.sender })
if (param.observer) query.where({ observer: param.observer })
if (param.id) query.where({ id: param.id })
if (param.client) query.where({ client: param.client })
if (param.channel) query.where({ channel: param.channel })
Expand All @@ -91,8 +82,6 @@ export class EventService<

const res = await query



return { events: res as unknown as { data: Array<any> } }
}
}
Expand Down
25 changes: 17 additions & 8 deletions packages/core/shared/src/nodes/events/EventRecall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type InputReturn = {
}

enum FilterTypes {
ChannelAndSender = 'Channel And Sender (DMs OK)',
ChannelAndSender = 'Channel And Sender',
AllInChannel = 'All In Channel',
AllFromSender = 'All From Sender (No DMs)',
AllFromSender = 'All From Sender',
AllFromConnector = 'All From Connector',
All = 'All',
}
Expand Down Expand Up @@ -181,6 +181,7 @@ export class EventRecall extends MagickComponent<Promise<InputReturn>> {

return events
}

const typeSocket = (inputs['type'] && inputs['type'][0]) as
| string
| undefined
Expand All @@ -197,8 +198,15 @@ export class EventRecall extends MagickComponent<Promise<InputReturn>> {
embedding = (embedding as string)?.split(',')
}

const { client, channel, connector, channelType, projectId, entities } =
event
const {
client,
channel,
connector,
channelType,
projectId,
sender,
observer,
} = event

const typeData = node?.data?.type as string | undefined
const typeRaw =
Expand All @@ -217,11 +225,12 @@ export class EventRecall extends MagickComponent<Promise<InputReturn>> {
const data = {
type,
client,
entities,
channel,
connector,
channelType,
projectId,
sender,
observer,
$limit: max_count ?? 1,
}

Expand All @@ -230,20 +239,20 @@ export class EventRecall extends MagickComponent<Promise<InputReturn>> {
// no need to do anything, should just work
} else if (filterBy === FilterTypes.AllInChannel) {
// filter by observer but not sender
delete data['entities']
delete data['sender']
} else if (filterBy === FilterTypes.AllFromSender) {
// filter by sender but not channel
delete data['channel']
delete data['channelType']
} else if (filterBy === FilterTypes.AllFromConnector) {
// filter by connector but not channel or sender
delete data['sender']
delete data['channel']
delete data['channelType']
delete data['entities']
} else if (filterBy === FilterTypes.All) {
// filter by all except sender, channel, and connector -- basically all for this observer
delete data['channel']
delete data['entities']
delete data['sender']
delete data['connector']
delete data['channelType']
}
Expand Down

2 comments on commit 439d62a

@vercel
Copy link

@vercel vercel bot commented on 439d62a Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 439d62a Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.