forked from andyburke/autonomous.contact
feature: first pass on replies
refactor: move more smarts in the smartforms around
This commit is contained in:
parent
e1bb07a138
commit
ab63d4ba8d
6 changed files with 343 additions and 181 deletions
|
|
@ -37,6 +37,81 @@ type TOPIC_EVENT_CACHE_ENTRY = {
|
|||
eviction_timeout: number;
|
||||
};
|
||||
|
||||
// TODO: separate out these different validators somewhere?
|
||||
export function VALIDATE_EVENT(event: EVENT) {
|
||||
const errors: any[] = [];
|
||||
|
||||
const {
|
||||
groups: {
|
||||
type,
|
||||
id
|
||||
}
|
||||
} = /^(?<type>\w+)\:(?<id>[A-Za-z-]+)$/.exec(event.id ?? '') ?? { groups: {} };
|
||||
|
||||
if (typeof type !== 'string' || type.length === 0) {
|
||||
errors.push({
|
||||
cause: 'missing_event_type_in_id',
|
||||
message: 'An event must have a type that is also encoded into its id, eg: chat:able-fish-wife...'
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof id !== 'string' || id.length !== 49) {
|
||||
errors.push({
|
||||
cause: 'invalid_event_id',
|
||||
message: 'An event must have a type and a lurid id, eg: chat:able-fish-gold-wing-trip-form-seed-cost-rope-wife'
|
||||
});
|
||||
}
|
||||
|
||||
switch (event.type) {
|
||||
case 'chat':
|
||||
if (event.data?.message?.length <= 0) {
|
||||
errors.push({
|
||||
cause: 'chat_message_missing',
|
||||
message: 'A chat message event cannot be empty.'
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'post':
|
||||
if (event.data?.subject?.length <= 0) {
|
||||
errors.push({
|
||||
cause: 'post_missing_subject',
|
||||
message: 'A post cannot have an empty subject.'
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'blurb':
|
||||
if (event.data?.blurb?.length <= 0) {
|
||||
errors.push({
|
||||
cause: 'blurb_missing',
|
||||
message: 'A blurb cannot be empty.'
|
||||
});
|
||||
} else if (event.data?.blurb?.length > 2 ** 8) {
|
||||
errors.push({
|
||||
cause: 'blurb_length_limit_exceeded',
|
||||
message: 'A blurb cannot be longer than 256 characters.'
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'essay':
|
||||
if (event.data?.essay?.length <= 0) {
|
||||
errors.push({
|
||||
cause: 'essay_missing',
|
||||
message: 'An essay cannot be empty.'
|
||||
});
|
||||
} else if (event.data?.essay?.length > 2 ** 16) {
|
||||
errors.push({
|
||||
cause: 'essay_length_limit_exceeded',
|
||||
message: 'An essay cannot be longer than 65536 characters - that would be a screed, which we do not yet support.'
|
||||
});
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return errors.length ? errors : undefined;
|
||||
}
|
||||
|
||||
const TOPIC_EVENT_ID_MATCHER = /^(?<event_type>.*):(?<event_id>.*)$/;
|
||||
|
||||
const TOPIC_EVENTS: Record<string, TOPIC_EVENT_CACHE_ENTRY> = {};
|
||||
|
|
@ -73,6 +148,13 @@ export function get_events_collection_for_topic(topic_id: string): FSDB_COLLECTI
|
|||
organize: by_lurid
|
||||
}),
|
||||
|
||||
parent_id: new FSDB_INDEXER_SYMLINKS<EVENT>({
|
||||
name: 'parent_id',
|
||||
field: 'parent_id',
|
||||
to_many: true,
|
||||
organize: by_lurid
|
||||
}),
|
||||
|
||||
tags: new FSDB_INDEXER_SYMLINKS<EVENT>({
|
||||
name: 'tags',
|
||||
get_values_to_index: (event: EVENT): string[] => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue