From 14dc9e1c1581fa04b37e81d76499f705512660b2 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 6 Nov 2024 18:42:38 -0500 Subject: Split message runs after ten minutes' silence. I've also refactored how runs are processed, to avoid re-splitting runs every time the channel view is rendered. They're generated when messages are ingested into the `$messages` store, instead. --- ui/lib/components/ActiveChannel.svelte | 27 ++------------ ui/lib/store.js | 2 +- ui/lib/store/messages.js | 40 --------------------- ui/lib/store/messages.svelte.js | 59 +++++++++++++++++++++++++++++++ ui/routes/(app)/ch/[channel]/+page.svelte | 4 ++- 5 files changed, 65 insertions(+), 67 deletions(-) delete mode 100644 ui/lib/store/messages.js create mode 100644 ui/lib/store/messages.svelte.js (limited to 'ui') diff --git a/ui/lib/components/ActiveChannel.svelte b/ui/lib/components/ActiveChannel.svelte index a4ccd24..f939dbd 100644 --- a/ui/lib/components/ActiveChannel.svelte +++ b/ui/lib/components/ActiveChannel.svelte @@ -1,34 +1,11 @@
- {#each chunkBy(messageList, (msg) => msg.sender) as [sender, messages]} + {#each messageRuns as { sender, messages }}
diff --git a/ui/lib/store.js b/ui/lib/store.js index ae17ffa..3b20e05 100644 --- a/ui/lib/store.js +++ b/ui/lib/store.js @@ -1,6 +1,6 @@ import { writable } from 'svelte/store'; import { Channels } from '$lib/store/channels'; -import { Messages } from '$lib/store/messages'; +import { Messages } from '$lib/store/messages.svelte.js'; import { Logins } from '$lib/store/logins'; export const currentUser = writable(null); diff --git a/ui/lib/store/messages.js b/ui/lib/store/messages.js deleted file mode 100644 index 62c567a..0000000 --- a/ui/lib/store/messages.js +++ /dev/null @@ -1,40 +0,0 @@ -export class Messages { - constructor() { - this.channels = {}; - } - - inChannel(channel) { - return (this.channels[channel] = this.channels[channel] || []); - } - - addMessage(channel, id, at, sender, body) { - this.updateChannel(channel, (messages) => [...messages, { id, at, sender, body }]); - return this; - } - - setMessages(messages) { - this.channels = {}; - for (let { channel, id, at, sender, body } of messages) { - this.inChannel(channel).push({ id, at, sender, body }); - } - return this; - } - - deleteMessage(message) { - for (let channel in this.channels) { - this.updateChannel(channel, (messages) => messages.filter((msg) => msg.id != message)); - } - return this; - } - - deleteChannel(id) { - delete this.channels[id]; - return this; - } - - updateChannel(channel, callback) { - let messages = callback(this.inChannel(channel)); - messages.sort((a, b) => a.at - b.at); - this.channels[channel] = messages; - } -} diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js new file mode 100644 index 0000000..1c59599 --- /dev/null +++ b/ui/lib/store/messages.svelte.js @@ -0,0 +1,59 @@ +const RUN_COALESCE_MAX_INTERVAL = 10 /* min */ * 60 /* sec */ * 1000; /* ms */ + +export class Messages { + channels = $state({}); + + inChannel(channel) { + return this.channels[channel]; + } + + addMessage(channel, id, at, sender, body) { + let parsedAt = new Date(at); + const message = { id, at: parsedAt, body }; + + let runs = (this.channels[channel] ||= []); + let currentRun = runs.slice(-1)[0]; + if (currentRun === undefined) { + currentRun = { sender, messages: [message] }; + runs.push(currentRun); + } else { + let lastMessage = currentRun.messages.slice(-1)[0]; + let newRun = + currentRun.sender !== sender || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; + + if (newRun) { + currentRun = { sender, messages: [message] }; + runs.push(currentRun); + } else { + currentRun.messages.push(message); + } + } + + return this; + } + + setMessages(messages) { + this.channels = {}; + for (let { channel, id, at, sender, body } of messages) { + this.addMessage(channel, id, at, sender, body); + } + return this; + } + + deleteMessage(messageId) { + for (let channel in this.channels) { + this.channels[channel] = this.channels[channel] + .map(({ sender, messages }) => ({ + sender, + messages: messages.filter(({ id }) => id != messageId) + })) + .filter(({ messages }) => messages.length > 0); + } + return this; + } + + deleteChannel(id) { + delete this.channels[id]; + return this; + } +} diff --git a/ui/routes/(app)/ch/[channel]/+page.svelte b/ui/routes/(app)/ch/[channel]/+page.svelte index 49c1c29..0961665 100644 --- a/ui/routes/(app)/ch/[channel]/+page.svelte +++ b/ui/routes/(app)/ch/[channel]/+page.svelte @@ -2,12 +2,14 @@ import { page } from '$app/stores'; import ActiveChannel from '$lib/components/ActiveChannel.svelte'; import MessageInput from '$lib/components/MessageInput.svelte'; + import { messages } from '$lib/store'; let channel = $derived($page.params.channel); + let messageRuns = $derived($messages.inChannel(channel));
- +
-- cgit v1.2.3 From 1d4d4ca4832a49b50f382647327706bb50c9981d Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Thu, 7 Nov 2024 10:18:30 -0500 Subject: Backport multiline logic from prop/multiline-shift --- ui/lib/components/MessageInput.svelte | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index 907391c..c071bea 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -18,7 +18,8 @@ } function onKeyDown(event) { - if (!event.altKey && event.key === 'Enter') { + let modifier = event.shiftKey || event.altKey || event.ctrlKey || event.metaKey; + if (!modifier && event.key === 'Enter') { onSubmit(event); } } -- cgit v1.2.3 From be6a2a94ffca6ffa2d007185d384d0bc06bda137 Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Thu, 7 Nov 2024 10:45:00 -0500 Subject: Tweak addMessage call signature --- ui/lib/apiServer.js | 6 +++++- ui/lib/store/messages.svelte.js | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/lib/apiServer.js b/ui/lib/apiServer.js index a6fdaa6..6ada0f7 100644 --- a/ui/lib/apiServer.js +++ b/ui/lib/apiServer.js @@ -111,7 +111,11 @@ function onMessageEvent(data) { switch (data.event) { case 'sent': messages.update((value) => - value.addMessage(data.channel, data.id, data.at, data.sender, data.body) + value.addMessage(data.channel, data.id, { + at: data.at, + sender: data.sender, + body: data.body + }) ); break; case 'deleted': diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 1c59599..4630a40 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -7,7 +7,7 @@ export class Messages { return this.channels[channel]; } - addMessage(channel, id, at, sender, body) { + addMessage(channel, id, { at, sender, body }) { let parsedAt = new Date(at); const message = { id, at: parsedAt, body }; @@ -19,7 +19,8 @@ export class Messages { } else { let lastMessage = currentRun.messages.slice(-1)[0]; let newRun = - currentRun.sender !== sender || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; + currentRun.sender !== sender + || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; if (newRun) { currentRun = { sender, messages: [message] }; -- cgit v1.2.3 From 93d204ae60fb340bb9c3dc047e375a48b98f713e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 7 Nov 2024 18:57:10 -0500 Subject: Fix up calls to `addMessage` inside `Messages`. --- ui/lib/store/messages.svelte.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 4630a40..2442675 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -19,8 +19,7 @@ export class Messages { } else { let lastMessage = currentRun.messages.slice(-1)[0]; let newRun = - currentRun.sender !== sender - || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; + currentRun.sender !== sender || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; if (newRun) { currentRun = { sender, messages: [message] }; @@ -36,7 +35,7 @@ export class Messages { setMessages(messages) { this.channels = {}; for (let { channel, id, at, sender, body } of messages) { - this.addMessage(channel, id, at, sender, body); + this.addMessage(channel, id, { at, sender, body }); } return this; } -- cgit v1.2.3 From ae9f3889de763d7841ab0acc7d7589da5bb830ff Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 6 Nov 2024 17:12:25 -0500 Subject: Sort out padding and wrapping for the chat input --- ui/lib/components/MessageInput.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/lib/components/MessageInput.svelte b/ui/lib/components/MessageInput.svelte index c071bea..26521e1 100644 --- a/ui/lib/components/MessageInput.svelte +++ b/ui/lib/components/MessageInput.svelte @@ -31,7 +31,7 @@ bind:value {disabled} type="search" - class="flex-auto h-6 input rounded-r-none" + class="flex-auto h-6 py-0 input rounded-r-none text-nowrap" >
-- cgit v1.2.3 From 9f0ba2e243be772a7677f8250893f5da7b2acbfe Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 6 Nov 2024 17:42:02 -0500 Subject: Factor out the elements of the `/me` page, and style them a little. --- ui/lib/components/ChangePassword.svelte | 60 +++++++++++++++++++++++ ui/lib/components/Invite.svelte | 5 +- ui/lib/components/Invites.svelte | 13 ++--- ui/lib/components/LogOut.svelte | 18 +++++++ ui/routes/(app)/me/+page.svelte | 84 +++++---------------------------- 5 files changed, 97 insertions(+), 83 deletions(-) create mode 100644 ui/lib/components/ChangePassword.svelte create mode 100644 ui/lib/components/LogOut.svelte (limited to 'ui') diff --git a/ui/lib/components/ChangePassword.svelte b/ui/lib/components/ChangePassword.svelte new file mode 100644 index 0000000..1e48bee --- /dev/null +++ b/ui/lib/components/ChangePassword.svelte @@ -0,0 +1,60 @@ + + +
+ + + + + + + +
diff --git a/ui/lib/components/Invite.svelte b/ui/lib/components/Invite.svelte index 35e00b4..381f483 100644 --- a/ui/lib/components/Invite.svelte +++ b/ui/lib/components/Invite.svelte @@ -5,8 +5,5 @@ let inviteUrl = $derived(new URL(`/invite/${id}`, document.location)); - + {inviteUrl} diff --git a/ui/lib/components/Invites.svelte b/ui/lib/components/Invites.svelte index cc14f3b..314782a 100644 --- a/ui/lib/components/Invites.svelte +++ b/ui/lib/components/Invites.svelte @@ -4,7 +4,7 @@ let invites = $state([]); - async function onSubmit(event) { + async function onsubmit(event) { event.preventDefault(); let response = await createInvite(); if (response.status == 200) { @@ -13,11 +13,12 @@ } -
    +
    + +
    + +
      {#each invites as invite} -
    • +
    • {/each}
    -
    - -
    diff --git a/ui/lib/components/LogOut.svelte b/ui/lib/components/LogOut.svelte new file mode 100644 index 0000000..25dd5e9 --- /dev/null +++ b/ui/lib/components/LogOut.svelte @@ -0,0 +1,18 @@ + + +
    + +
    diff --git a/ui/routes/(app)/me/+page.svelte b/ui/routes/(app)/me/+page.svelte index 8d24a61..e02bde5 100644 --- a/ui/routes/(app)/me/+page.svelte +++ b/ui/routes/(app)/me/+page.svelte @@ -1,79 +1,17 @@ -
    - -
    - -
    - - - - - +
    + +
    - -
    +
    + +
    - +
    + +
    -- cgit v1.2.3 From 549928a460696b2fc994daf7d1a375d0280b87a8 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 6 Nov 2024 17:43:08 -0500 Subject: Increase horizontal padding on the /me link so it looks a little less cramped --- ui/routes/+layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index ef3e823..0aeb144 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -33,7 +33,7 @@ understory {#if $currentUser} -
    + {/if} -- cgit v1.2.3 From d38344003092e53a84facdef1bff4fdd0ac3a017 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 6 Nov 2024 17:45:37 -0500 Subject: Better choices of margins and caps --- ui/lib/components/Invite.svelte | 2 +- ui/lib/components/Invites.svelte | 2 +- ui/routes/(app)/me/+page.svelte | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/lib/components/Invite.svelte b/ui/lib/components/Invite.svelte index 381f483..937c911 100644 --- a/ui/lib/components/Invite.svelte +++ b/ui/lib/components/Invite.svelte @@ -5,5 +5,5 @@ let inviteUrl = $derived(new URL(`/invite/${id}`, document.location)); - + {inviteUrl} diff --git a/ui/lib/components/Invites.svelte b/ui/lib/components/Invites.svelte index 314782a..493bf1c 100644 --- a/ui/lib/components/Invites.svelte +++ b/ui/lib/components/Invites.svelte @@ -14,7 +14,7 @@
    - +
      diff --git a/ui/routes/(app)/me/+page.svelte b/ui/routes/(app)/me/+page.svelte index e02bde5..aded292 100644 --- a/ui/routes/(app)/me/+page.svelte +++ b/ui/routes/(app)/me/+page.svelte @@ -4,14 +4,14 @@ import ChangePassword from '$lib/components/ChangePassword.svelte'; -
      +
      -
      +
      -
      +
      -- cgit v1.2.3 From 26477b67f500a1af74e136a8ba858ca6b0f54814 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 8 Nov 2024 01:17:21 -0500 Subject: Stop chopping the first message off of each channel (oops). --- ui/lib/store/messages.svelte.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 2442675..c0db71b 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -11,7 +11,20 @@ export class Messages { let parsedAt = new Date(at); const message = { id, at: parsedAt, body }; - let runs = (this.channels[channel] ||= []); + // You might be thinking, can't this be + // + // let runs = (this.channels[channel] ||= []); + // + // Let me tell you, I thought that too. Javascript's semantics allow it. It + // didn't work - the first message in each channel was getting lost as the + // update to `this.channels` wasn't actually happening. I suspect this is + // due to the implementation of Svelte's `$state` rune, but I don't know it + // for sure. + // + // In any case, splitting the read and write up like this has the same + // semantics, and _works_. (This time, for sure!) + let runs = this.channels[channel] || []; + let currentRun = runs.slice(-1)[0]; if (currentRun === undefined) { currentRun = { sender, messages: [message] }; @@ -29,6 +42,8 @@ export class Messages { } } + this.channels[channel] = runs; + return this; } -- cgit v1.2.3 From 7a26a75506de82ba1e2e0567f8f96fc2784874e9 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 8 Nov 2024 17:28:48 -0500 Subject: Rename the project to `pilcrow`. --- .envrc | 2 +- .gitignore | 3 ++ Cargo.lock | 70 +++++++++++++++++++++--------------------- Cargo.toml | 11 +++---- Dockerfile.builder | 4 +-- debian/default | 4 +-- debian/hi.service | 6 ++-- debian/postinst | 4 +-- docs/api/book.toml | 2 +- docs/design.md | 4 +-- docs/internal-server-errors.md | 2 +- docs/ops.md | 8 ++--- git-hooks/pre-commit | 4 +-- package-lock.json | 4 +-- package.json | 2 +- src/cli.rs | 33 ++++++++++---------- src/error.rs | 2 +- src/lib.rs | 2 +- src/main.rs | 2 +- tools/build-builder | 4 +-- tools/build-debian | 2 +- tools/run | 3 +- tools/version | 2 +- ui/routes/(app)/+layout.svelte | 2 +- ui/routes/+layout.svelte | 2 +- 25 files changed, 93 insertions(+), 91 deletions(-) (limited to 'ui') diff --git a/.envrc b/.envrc index 0423909..56295f5 100644 --- a/.envrc +++ b/.envrc @@ -1,6 +1,6 @@ PATH_add tools PATH_add target/debug -export DATABASE_URL="${DATABASE_URL:-sqlite://.hi?mode=rwc}" +export DATABASE_URL="${DATABASE_URL:-sqlite://pilcrow.db?mode=rwc}" source_env_if_exists .envrc.local diff --git a/.gitignore b/.gitignore index 7977b18..11b7d6f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ /.hi /.hi.pre-commit /.hi.backup +/pilcrow.db +/pilcrow.db.backup +/pilcrow.db.pre-commit /vite.config.js.*.mjs diff --git a/Cargo.lock b/Cargo.lock index d98f51f..0e4c143 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,41 +798,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hi" -version = "0.1.0" -dependencies = [ - "argon2", - "async-trait", - "axum", - "axum-extra", - "chrono", - "clap", - "faker_rand", - "futures", - "headers", - "hex-literal", - "itertools", - "mime", - "password-hash", - "pin-project", - "rand", - "rand_core", - "rusqlite", - "rust-embed", - "serde", - "serde_json", - "sqlx", - "thiserror", - "tokio", - "tokio-stream", - "unicode-casefold", - "unicode-normalization", - "unicode-segmentation", - "unix_path", - "uuid", -] - [[package]] name = "hkdf" version = "0.12.4" @@ -1262,6 +1227,41 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pilcrow" +version = "0.1.0" +dependencies = [ + "argon2", + "async-trait", + "axum", + "axum-extra", + "chrono", + "clap", + "faker_rand", + "futures", + "headers", + "hex-literal", + "itertools", + "mime", + "password-hash", + "pin-project", + "rand", + "rand_core", + "rusqlite", + "rust-embed", + "serde", + "serde_json", + "sqlx", + "thiserror", + "tokio", + "tokio-stream", + "unicode-casefold", + "unicode-normalization", + "unicode-segmentation", + "unix_path", + "uuid", +] + [[package]] name = "pin-project" version = "1.1.7" diff --git a/Cargo.toml b/Cargo.toml index 868308f..371ade5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,22 @@ [package] -name = "hi" +name = "pilcrow" version = "0.1.0" edition = "2021" rust-version = "1.82" -default-run = "hi" authors = [ - "Owen Jacobson ", + "Owen Jacobson ", "Kit La Touche ", ] [package.metadata.deb] -maintainer = "Owen Jacobson " +maintainer = "Owen Jacobson " maintainer-scripts = "debian" assets = [ # Binaries - ["target/release/hi", "/usr/bin/hi", "755"], + ["target/release/pilcrow", "/usr/bin/pilcrow", "755"], # Configuration - ["debian/default", "/etc/default/hi", "644"], + ["debian/default", "/etc/default/pilcrow", "644"], ] [package.metadata.deb.systemd-units] diff --git a/Dockerfile.builder b/Dockerfile.builder index da80c69..720b95a 100644 --- a/Dockerfile.builder +++ b/Dockerfile.builder @@ -1,7 +1,7 @@ FROM rust:1-slim-bookworm -COPY builder /opt/hi-builder -RUN /opt/hi-builder/image-setup +COPY builder /opt/pilcrow-builder +RUN /opt/pilcrow-builder/image-setup RUN mkdir /app WORKDIR /app diff --git a/debian/default b/debian/default index 3076699..3cabe21 100644 --- a/debian/default +++ b/debian/default @@ -1,2 +1,2 @@ -DATABASE_URL=sqlite:///var/lib/hi/hi.db -BACKUP_DATABASE_URL=sqlite:///var/lib/hi/backup.db +DATABASE_URL=sqlite:///var/lib/pilcrow/pilcrow.db +BACKUP_DATABASE_URL=sqlite:///var/lib/pilcrow/backup.db diff --git a/debian/hi.service b/debian/hi.service index cc4a951..e4c3589 100644 --- a/debian/hi.service +++ b/debian/hi.service @@ -1,10 +1,10 @@ [Unit] -Description=Hi chat service +Description=Pilcrow chat service After=network-online.target [Service] -EnvironmentFile=/etc/default/hi -ExecStart=/usr/bin/hi +EnvironmentFile=/etc/default/pilcrow +ExecStart=/usr/bin/pilcrow Restart=on-failure [Install] diff --git a/debian/postinst b/debian/postinst index d88a7ad..a3f58a0 100755 --- a/debian/postinst +++ b/debian/postinst @@ -4,7 +4,7 @@ set -e adduser \ --system \ --group \ - --home /var/lib/hi \ - hi + --home /var/lib/pilcrow \ + pilcrow #DEBHELPER# diff --git a/docs/api/book.toml b/docs/api/book.toml index 476872c..493939b 100644 --- a/docs/api/book.toml +++ b/docs/api/book.toml @@ -1,5 +1,5 @@ [book] -title = "The hi API" +title = "The Pilcrow API" authors = ["Owen Jacobson"] language = "en" multilingual = false diff --git a/docs/design.md b/docs/design.md index 1180b83..6cd0075 100644 --- a/docs/design.md +++ b/docs/design.md @@ -1,6 +1,6 @@ # Internal design -`hi`'s design is discovered and not planned. Do not take this as doctrine; continue to experiment on the structure as you find new needs. +`pilcrow`'s design is discovered and not planned. Do not take this as doctrine; continue to experiment on the structure as you find new needs. As of this writing, the basic flow of most requests hits several subsystems: @@ -15,7 +15,7 @@ This approach helps enable testing (see [testing.md] and the implementation of m Handling time in a service is always tricky. -`hi` takes the approach that a request is considered to be serviced at one time, and that that time is determined when the request is received. The internals of `hi` - the "app" and data access types described below, as well as most other supporting tools - are written with an eye towards accepting the "current time" as an argument, rather than calling out to a clock for themselves. +`pilcrow` takes the approach that a request is considered to be serviced at one time, and that that time is determined when the request is received. The internals of `pilcrow` - the "app" and data access types described below, as well as most other supporting tools - are written with an eye towards accepting the "current time" as an argument, rather than calling out to a clock for themselves. The "current time" for a request is determined in `src/clock.rs`, which runs on every request, and is available to the handler via the `RequestedAt` extractor defined in that module. diff --git a/docs/internal-server-errors.md b/docs/internal-server-errors.md index 16d61a2..7532e10 100644 --- a/docs/internal-server-errors.md +++ b/docs/internal-server-errors.md @@ -1,6 +1,6 @@ # Internal Server Errors -When `hi` encounters a problem that prevents a request from completing, it may report a `500 Internal Server Error` to clients, along with an error code. The actual error will be printed to standard error, with the error code. The following sections describe errors we've encountered, the likely operational consequences, and recommend approaches for addressing them. +When the `pilcrow` server encounters a problem that prevents a request from completing, it may report a `500 Internal Server Error` to clients, along with an error code. The actual error will be printed to standard error, with the error code. The following sections describe errors we've encountered, the likely operational consequences, and recommend approaches for addressing them. ## database is locked diff --git a/docs/ops.md b/docs/ops.md index 02644c2..4274e22 100644 --- a/docs/ops.md +++ b/docs/ops.md @@ -1,11 +1,11 @@ -# Operating `hi` +# Operating pilcrow ## Upgrades -`hi` will automatically upgrade its database on startup. Before doing so, it will create a backup of your database (at `.hi.backup`, or controlled by `--backup-database-url`). If the migration process succeeds, this backup will be deleted automatically. If the migration process _fails_, however, `hi` will attempt to restore your existing database from the backup before exiting. If the restore process also fails, then both the backup database and the suspected-broken database will be left in place. +The `pilcrow` server will automatically upgrade its database on startup. Before doing so, it will create a backup of your database (at `pilcrow.db.backup`, or controlled by `--backup-database-url`). If the migration process succeeds, this backup will be deleted automatically. If the migration process _fails_, however, `pilcrow` will attempt to restore your existing database from the backup before exiting. If the restore process also fails, then both the backup database and the suspected-broken database will be left in place. -To avoid destroying backups that may still be needed, `hi` will not start if the backup database already exists. **There is no catch-all advice on how to proceed**, but you can try the following: +To avoid destroying backups that may still be needed, `pilcrow` will not start if the backup database already exists. **There is no catch-all advice on how to proceed**, but you can try the following: * Start the server with **a copy** of the backup database, and determine if any data has been lost. If not, shut it down, replace your main database by copying the backup, and carry on. -The `hi` database is an ordinary file. While the server is not running, it can be freely copied or renamed without invalidating the data in it. +The `pilcrow` database is an ordinary file. While the server is not running, it can be freely copied or renamed without invalidating the data in it. diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index 6715430..587e349 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -13,7 +13,7 @@ npm run lint cargo check # Make sure the prepared statement data in .sqlx is up to date. Requires # `cargo-sqlx` (`cargo install cargo-sqlx`). -export DATABASE_URL=sqlite://.hi.pre-commit?mode=rwc -rm -f .hi.pre-commit +export DATABASE_URL=sqlite://pilcrow.db.pre-commit?mode=rwc +rm -f pilcrow.db.pre-commit cargo sqlx migrate run cargo sqlx prepare --check diff --git a/package-lock.json b/package-lock.json index 2f85351..01b0cce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "hi", + "name": "pilcrow", "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "hi", + "name": "pilcrow", "version": "0.0.1", "dependencies": { "axios": "^1.7.7", diff --git a/package.json b/package.json index cb57efe..c51974c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "hi", + "name": "pilcrow", "version": "0.0.1", "private": true, "engines": { diff --git a/src/cli.rs b/src/cli.rs index 308294d..0d448d2 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,6 @@ -//! The `hi` command-line interface. +//! The `pilcrow` command-line interface. //! -//! This module supports running `hi` as a freestanding program, via the +//! This module supports running `pilcrow` as a freestanding program, via the //! [`Args`] struct. use std::{future, io}; @@ -22,18 +22,18 @@ use crate::{ ui, }; -/// Command-line entry point for running the `hi` server. +/// Command-line entry point for running the `pilcrow` server. /// /// This is intended to be used as a Clap [Parser], to capture command-line -/// arguments for the `hi` server: +/// arguments for the `pilcrow` server: /// /// ```no_run -/// # use hi::cli::Error; +/// # use pilcrow::cli::Error; /// # /// # #[tokio::main] /// # async fn main() -> Result<(), Error> { /// use clap::Parser; -/// use hi::cli::Args; +/// use pilcrow::cli::Args; /// /// let args = Args::parse(); /// args.run().await?; @@ -43,35 +43,36 @@ use crate::{ #[derive(Parser)] #[command( version, - about = "Run the `hi` server.", - long_about = r#"Run the `hi` server. + about = "Run the `pilcrow` server.", + long_about = r#"Run the `pilcrow` server. The database at `--database-url` will be created, or upgraded, automatically."# )] pub struct Args { - /// The network address `hi` should listen on + /// The network address `pilcrow` should listen on #[arg(short, long, env, default_value = "localhost")] address: String, - /// The network port `hi` should listen on + /// The network port `pilcrow` should listen on #[arg(short, long, env, default_value_t = 64209)] port: u16, - /// Sqlite URL or path for the `hi` database - #[arg(short, long, env, default_value = "sqlite://.hi")] + /// Sqlite URL or path for the `pilcrow` database + #[arg(short, long, env, default_value = "sqlite://pilcrow.db")] database_url: String, - /// Sqlite URL or path for a backup of the `hi` database during upgrades - #[arg(short = 'D', long, env, default_value = "sqlite://.hi.backup")] + /// Sqlite URL or path for a backup of the `pilcrow` database during + /// upgrades + #[arg(short = 'D', long, env, default_value = "sqlite://pilcrow.db.backup")] backup_database_url: String, } impl Args { - /// Runs the `hi` server, using the parsed configuation in `self`. + /// Runs the `pilcrow` server, using the parsed configuation in `self`. /// /// This will perform the following tasks: /// - /// * Migrate the `hi` database (at `--database-url`). + /// * Migrate the `pilcrow` database (at `--database-url`). /// * Start an HTTP server (on the interface and port controlled by /// `--address` and `--port`). /// * Print a status message. diff --git a/src/error.rs b/src/error.rs index f3399c6..7483f00 100644 --- a/src/error.rs +++ b/src/error.rs @@ -40,7 +40,7 @@ impl fmt::Display for Internal { impl IntoResponse for Internal { fn into_response(self) -> Response { let Self(id, error) = &self; - eprintln!("hi: [{id}] {error}"); + eprintln!("pilcrow: [{id}] {error}"); (StatusCode::INTERNAL_SERVER_ERROR, self.to_string()).into_response() } } diff --git a/src/lib.rs b/src/lib.rs index 84b8dfc..765e625 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! `hi` - a web-based, self-hosted chat system. +//! Pilcrow - a web-based, self-hosted chat system. #![warn(clippy::all)] #![warn(clippy::pedantic)] diff --git a/src/main.rs b/src/main.rs index d0830ff..427294e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use clap::Parser; -use hi::cli; +use pilcrow::cli; #[tokio::main] async fn main() -> Result<(), cli::Error> { diff --git a/tools/build-builder b/tools/build-builder index fcb1e84..8174b4e 100755 --- a/tools/build-builder +++ b/tools/build-builder @@ -8,7 +8,7 @@ cd "$(dirname "$0")/.." docker build \ --platform "linux/arm64,linux/amd64" \ - --tag "hi-debian-builder:$(tools/version)" \ - --tag "hi-debian-builder:latest" \ + --tag "pilcrow-debian-builder:$(tools/version)" \ + --tag "pilcrow-debian-builder:latest" \ --file Dockerfile.builder \ . diff --git a/tools/build-debian b/tools/build-debian index c64fc78..0e496a8 100755 --- a/tools/build-debian +++ b/tools/build-debian @@ -15,6 +15,6 @@ for platform in linux/arm64 linux/amd64; do --interactive \ --tty \ --volume "$PWD:/app" \ - "hi-debian-builder:$(tools/version)" \ + "pilcrow-debian-builder:$(tools/version)" \ cargo deb done diff --git a/tools/run b/tools/run index 562a94d..bbe0dbd 100755 --- a/tools/run +++ b/tools/run @@ -2,8 +2,7 @@ ## tools/run [ARGS...] -if [ -z ${HI_DEV+x} ]; then - tools/build-ui +if [ -z ${PILCROW_DEV+x} ]; then cargo run -- "$@" else npm run dev & PIDS[0]=$! diff --git a/tools/version b/tools/version index 8e47a7c..f11c0e8 100755 --- a/tools/version +++ b/tools/version @@ -8,4 +8,4 @@ cd "$(dirname "$0")/.." cargo metadata \ --format-version 1 | -jq -r '.packages[] | select(.name == "hi") | .version' +jq -r '.packages[] | select(.name == "pilcrow") | .version' diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index db400c4..86bc330 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -56,7 +56,7 @@ - understory + pilcrow {#if loading} diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte index 0aeb144..8940659 100644 --- a/ui/routes/+layout.svelte +++ b/ui/routes/+layout.svelte @@ -30,7 +30,7 @@ logo - understory + pilcrow {#if $currentUser}
      -- cgit v1.2.3