add initial chat server stuff

This commit is contained in:
sam 2024-01-16 22:20:19 +01:00
parent 3025f1380c
commit 0e71e9dc5f
18 changed files with 722 additions and 40 deletions

View file

@ -6,3 +6,19 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
foxchat = { path = "../foxchat" }
axum = { version = "0.7.4", features = ["macros", "query", "tracing", "ws"] }
clap = { version = "4.4.16", features = ["env", "derive"] }
sqlx = { version = "0.7.3", features = ["runtime-tokio", "tls-rustls", "postgres", "migrate", "chrono", "json"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
ulid = { version = "1.1.0", features = ["serde"] }
eyre = "0.6.11"
color-eyre = "0.6.2"
rsa = { version = "0.9.6", features = ["serde", "sha2"] }
rand = "0.8.5"
toml = "0.8.8"
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = "0.3.18"
tracing = "0.1.40"
tower-http = { version = "0.5.1", features = ["trace"] }

View file

@ -0,0 +1,51 @@
create type instance_status as enum ('active', 'suspended');
create table identity_instances (
id text primary key,
domain text not null unique,
base_url text not null,
public_key text not null,
status instance_status not null default 'active',
reason text
);
create table users (
id text primary key,
instance_id text not null references identity_instances (id) on delete cascade,
remote_user_id text not null,
username text not null,
avatar text -- URL, not hash, as this is a remote file
);
create unique index users_remote_user_id_idx on users (instance_id, remote_user_id);
create unique index users_username_idx on users (instance_id, lower(username));
create table guilds (
id text primary key,
owner_id text not null references users (id) on delete cascade,
name text not null
);
create table guilds_users (
guild_id text not null references guilds (id) on delete cascade,
user_id text not null references users (id) on delete cascade,
primary key (guild_id, user_id)
);
create table channels (
id text primary key,
guild_id text not null references guilds (id) on delete cascade,
name text not null,
topic text
);
create table messages (
id text primary key,
channel_id text not null references channels (id) on delete cascade,
author_id text not null,
updated_at timestamptz not null default now(),
content text not null
);