Skip to content

Commit

Permalink
docs: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhooks committed Mar 16, 2023
1 parent 3908e38 commit 0c66a7e
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions docs/database-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Create a messaging system for users inside of WordPress. It could give collabora
## Message schema

Messages data is stored separately from channel data and can be linked to many users through
the `wp_notify_queue` table.
the `wp_notifications_queue` table.

### wp_notify_messages table
### wp_notifications_messages table

* `id: int` - The ID of the notification
* `channel_id: int` - The ID of the channel this message was emitted from.
Expand All @@ -33,13 +33,11 @@ the `wp_notify_queue` table.

This should be a predefined list of values.

* `title: varchar(256) | null` - The title of the notification.
* `title_key: varchar(128) | null` - The translation key for the title of the notification.

The title should be a very condensed explanations of the notification. In some context, it will be used to show the notification in a list view.

* `content: text` - The notification message content

The content could be generated by a modified block editor. Built specifically to limit the canvas size and block types. This would give message emitters control over how the message can look, but in the context of limits required by the system.
* `content_key: varchar(128)` - The translation key for the notification message content

* `meta: JSON` - data that doesn’t have to be queried, like icon or image information.

Expand All @@ -51,28 +49,21 @@ Core should have a set registered channels.

Plugins can register channels of their own.

### wp_ notify_channels table
### wp_notifications_channels table

* `id: int` - The ID of the channel
* `created_at: timestamp` - The timestamp of when the channel was created.
* `updated_at: timestamp` - The timestamp of when the channel was last updated.
* `source: varchar(256)` - The source of the channel, aka. the name of the plugin.
* `name: varchar(256)` - The name of the channel.
* `description: text` - The description of the channel.
* `parent_id: int | null` The ID of the parent channel.
* `source: varchar(128)` - The source of the channel, aka. the name of the plugin.
* `name_key: varchar(128)` - The translation key for the name of the channel.
* `description_key: varchar(128)` - The translation key for the description of the channel.

This would allow a hierarchal system of grouping channels.

* `role: varchar(128)` The minimum required role to subscribe to messages from the channel.
* `meta: JSON` - Data that doesn’t have to be queried, like icon or images

Another way to add metadata to a channel could be the registration process in PHP and JS. Attaching icons could be done in code when calling something like `wp_notify_register_channel`.

### Ideas

Maybe even user registered channels.

Every user has a channel attached to directly to their profile. Allows for notifications targeted to a single user. How would that be discoverable? An entry in the `wp_user_meta` table? Or enqueue the message for a specific user? I like the last option best.
Another way to add metadata to a channel could be the registration process in PHP and JS. Attaching icons could be done in code when calling something like `wp_notifications_register_channel`.

## Message Queue

Expand All @@ -82,19 +73,22 @@ The full history of messages for every user is retained and could be easily look

If a message has been orphan it can safely be deleted.

### wp_notify_queue table
### wp_notifications_queue table

* `message_id: int` - The ID of the enqueued message.
* `user_id: int` - The ID of the user.
* `dismissed_at: timestamp | null` - The timestamp of when the notification was dismissed.
* `displayed_at: timestamp | null` - The timestamp of when the notification was first displayed.

There could definitely be addition statuses, and if the time of the state update is deemed unnecessary, perhaps they could be a single enum rather that timestamps.

## Subscriptions

Join table used determine for whom to enqueue messages for a specific channel.

Logic to authorize a users to subscribe to a channel would be based on a comparison of the `role` property of the channel and the user.

### wp_ notify_subscriptions
### wp_notifications_subscriptions

* `user_id: int` - The ID of the user subscribed to the channel.
* `channel_id: int` - The ID of the channel subscribed to.
Expand Down

0 comments on commit 0c66a7e

Please sign in to comment.