refactor: rooms => zones
This commit is contained in:
parent
525568d368
commit
20a5d1bc88
27 changed files with 2466 additions and 2044 deletions
|
|
@ -13,8 +13,8 @@ import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
|
|||
*
|
||||
* @property {string} id - lurid
|
||||
* @property {string} creator_id - id of the source user
|
||||
* @property {string} room_id - id of the target room
|
||||
* @property {string} type - event type
|
||||
* @property {string} [parent_id] - optional parent event id
|
||||
* @property {string[]} [tags] - optional event tags
|
||||
* @property {Record<string,any>} [data] - optional data payload of the event
|
||||
* @property {TIMESTAMPS} timestamps - timestamps that will be set by the server
|
||||
|
|
@ -23,6 +23,7 @@ export type EVENT = {
|
|||
id: string;
|
||||
creator_id: string;
|
||||
type: string;
|
||||
parent_id?: string;
|
||||
tags?: string[];
|
||||
data?: Record<string, any>;
|
||||
timestamps: {
|
||||
|
|
@ -31,16 +32,16 @@ export type EVENT = {
|
|||
};
|
||||
};
|
||||
|
||||
type ROOM_EVENT_CACHE_ENTRY = {
|
||||
type ZONE_EVENT_CACHE_ENTRY = {
|
||||
collection: FSDB_COLLECTION<EVENT>;
|
||||
eviction_timeout: number;
|
||||
};
|
||||
|
||||
const ROOM_EVENTS: Record<string, ROOM_EVENT_CACHE_ENTRY> = {};
|
||||
export function get_events_collection_for_room(room_id: string): FSDB_COLLECTION<EVENT> {
|
||||
ROOM_EVENTS[room_id] = ROOM_EVENTS[room_id] ?? {
|
||||
const ZONE_EVENTS: Record<string, ZONE_EVENT_CACHE_ENTRY> = {};
|
||||
export function get_events_collection_for_zone(zone_id: string): FSDB_COLLECTION<EVENT> {
|
||||
ZONE_EVENTS[zone_id] = ZONE_EVENTS[zone_id] ?? {
|
||||
collection: new FSDB_COLLECTION<EVENT>({
|
||||
name: `rooms/${room_id.slice(0, 14)}/${room_id.slice(0, 34)}/${room_id}/events`,
|
||||
name: `zones/${zone_id.slice(0, 14)}/${zone_id.slice(0, 34)}/${zone_id}/events`,
|
||||
id_field: 'id',
|
||||
organize: by_lurid,
|
||||
indexers: {
|
||||
|
|
@ -64,22 +65,22 @@ export function get_events_collection_for_room(room_id: string): FSDB_COLLECTION
|
|||
eviction_timeout: 0
|
||||
};
|
||||
|
||||
if (ROOM_EVENTS[room_id].eviction_timeout) {
|
||||
clearTimeout(ROOM_EVENTS[room_id].eviction_timeout);
|
||||
if (ZONE_EVENTS[zone_id].eviction_timeout) {
|
||||
clearTimeout(ZONE_EVENTS[zone_id].eviction_timeout);
|
||||
}
|
||||
|
||||
ROOM_EVENTS[room_id].eviction_timeout = setTimeout(() => {
|
||||
delete ROOM_EVENTS[room_id];
|
||||
ZONE_EVENTS[zone_id].eviction_timeout = setTimeout(() => {
|
||||
delete ZONE_EVENTS[zone_id];
|
||||
}, 60_000 * 5);
|
||||
|
||||
return ROOM_EVENTS[room_id].collection;
|
||||
return ZONE_EVENTS[zone_id].collection;
|
||||
}
|
||||
|
||||
export function clear_room_events_cache() {
|
||||
for (const [room_id, cached] of Object.entries(ROOM_EVENTS)) {
|
||||
export function clear_zone_events_cache() {
|
||||
for (const [zone_id, cached] of Object.entries(ZONE_EVENTS)) {
|
||||
if (cached.eviction_timeout) {
|
||||
clearTimeout(cached.eviction_timeout);
|
||||
}
|
||||
delete ROOM_EVENTS[room_id];
|
||||
delete ZONE_EVENTS[zone_id];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,29 +3,29 @@ import { FSDB_COLLECTION } from '@andyburke/fsdb';
|
|||
import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
|
||||
|
||||
/**
|
||||
* @typedef {object} ROOM_PERMISSIONS
|
||||
* @property {string[]} read a list of user_ids with read permission for the room
|
||||
* @property {string[]} write a list of user_ids with write permission for the room
|
||||
* @property {string[]} read_events a list of user_ids with read_events permission for this room
|
||||
* @property {string[]} write_events a list of user_ids with write_events permission for this room
|
||||
* @typedef {object} ZONE_PERMISSIONS
|
||||
* @property {string[]} read a list of user_ids with read permission for the zone
|
||||
* @property {string[]} write a list of user_ids with write permission for the zone
|
||||
* @property {string[]} read_events a list of user_ids with read_events permission for this zone
|
||||
* @property {string[]} write_events a list of user_ids with write_events permission for this zone
|
||||
*/
|
||||
|
||||
/**
|
||||
* ROOM
|
||||
* ZONE
|
||||
*
|
||||
* @property {string} id - lurid (stable)
|
||||
* @property {string} name - channel name (max 64 characters, unique, unstable)
|
||||
* @property {string} creator_id - user id of the room creator
|
||||
* @property {ROOM_PERMISSIONS} permissions - permissions setup for the room
|
||||
* @property {string} [icon_url] - optional url for room icon
|
||||
* @property {string} [topic] - optional topic for the room
|
||||
* @property {string} [rules] - optional room rules (Markdown/text)
|
||||
* @property {string[]} [tags] - optional tags for the room
|
||||
* @property {Record<string,any>} [meta] - optional metadata about the room
|
||||
* @property {string} creator_id - user id of the zone creator
|
||||
* @property {ZONE_PERMISSIONS} permissions - permissions setup for the zone
|
||||
* @property {string} [icon_url] - optional url for zone icon
|
||||
* @property {string} [topic] - optional topic for the zone
|
||||
* @property {string} [rules] - optional zone rules (Markdown/text)
|
||||
* @property {string[]} [tags] - optional tags for the zone
|
||||
* @property {Record<string,any>} [meta] - optional metadata about the zone
|
||||
* @property {Record<string,string>} [emojis] - optional emojis table, eg: { 'rofl': 🤣, 'blap': 'https://somewhere.someplace/image.jpg' }
|
||||
*/
|
||||
|
||||
export type ROOM = {
|
||||
export type ZONE = {
|
||||
id: string;
|
||||
name: string;
|
||||
creator_id: string;
|
||||
|
|
@ -48,37 +48,37 @@ export type ROOM = {
|
|||
};
|
||||
};
|
||||
|
||||
export const ROOMS = new FSDB_COLLECTION<ROOM>({
|
||||
name: 'rooms',
|
||||
export const ZONES = new FSDB_COLLECTION<ZONE>({
|
||||
name: 'zones',
|
||||
id_field: 'id',
|
||||
organize: by_lurid,
|
||||
indexers: {
|
||||
creator_id: new FSDB_INDEXER_SYMLINKS<ROOM>({
|
||||
creator_id: new FSDB_INDEXER_SYMLINKS<ZONE>({
|
||||
name: 'creator_id',
|
||||
field: 'creator_id',
|
||||
to_many: true,
|
||||
organize: by_lurid
|
||||
}),
|
||||
|
||||
name: new FSDB_INDEXER_SYMLINKS<ROOM>({
|
||||
name: new FSDB_INDEXER_SYMLINKS<ZONE>({
|
||||
name: 'name',
|
||||
get_values_to_index: (room) => [room.name.toLowerCase()],
|
||||
get_values_to_index: (zone) => [zone.name.toLowerCase()],
|
||||
organize: by_character
|
||||
}),
|
||||
|
||||
tags: new FSDB_INDEXER_SYMLINKS<ROOM>({
|
||||
tags: new FSDB_INDEXER_SYMLINKS<ZONE>({
|
||||
name: 'tags',
|
||||
get_values_to_index: (room): string[] => {
|
||||
return (room.tags ?? []).map((tag) => tag.toLowerCase());
|
||||
get_values_to_index: (zone): string[] => {
|
||||
return (zone.tags ?? []).map((tag) => tag.toLowerCase());
|
||||
},
|
||||
to_many: true,
|
||||
organize: by_character
|
||||
}),
|
||||
|
||||
topic: new FSDB_INDEXER_SYMLINKS<ROOM>({
|
||||
topic: new FSDB_INDEXER_SYMLINKS<ZONE>({
|
||||
name: 'topic',
|
||||
get_values_to_index: (room): string[] => {
|
||||
return (room.topic ?? '').split(/\W/);
|
||||
get_values_to_index: (zone): string[] => {
|
||||
return (zone.topic ?? '').split(/\W/);
|
||||
},
|
||||
to_many: true,
|
||||
organize: by_character
|
||||
Loading…
Add table
Add a link
Reference in a new issue