Merge branch 'main' into multi-server-completions-tailwind
3
.github/workflows/publish_collab_image.yml
vendored
@ -22,6 +22,9 @@ jobs:
|
|||||||
- name: Sign into DigitalOcean docker registry
|
- name: Sign into DigitalOcean docker registry
|
||||||
run: doctl registry login
|
run: doctl registry login
|
||||||
|
|
||||||
|
- name: Prune Docker system
|
||||||
|
run: docker system prune
|
||||||
|
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
|
508
Cargo.lock
generated
@ -102,14 +102,20 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"collections",
|
"collections",
|
||||||
|
"ctor",
|
||||||
"editor",
|
"editor",
|
||||||
|
"env_logger 0.9.3",
|
||||||
"fs",
|
"fs",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"indoc",
|
||||||
"isahc",
|
"isahc",
|
||||||
"language",
|
"language",
|
||||||
|
"log",
|
||||||
"menu",
|
"menu",
|
||||||
|
"ordered-float",
|
||||||
"project",
|
"project",
|
||||||
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
"schemars",
|
"schemars",
|
||||||
"search",
|
"search",
|
||||||
@ -126,18 +132,17 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "alacritty_config"
|
name = "alacritty_config"
|
||||||
version = "0.1.2-dev"
|
version = "0.1.2-dev"
|
||||||
source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5"
|
source = "git+https://github.com/zed-industries/alacritty?rev=33306142195b354ef3485ca2b1d8a85dfc6605ca#33306142195b354ef3485ca2b1d8a85dfc6605ca"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"toml 0.7.6",
|
"toml 0.7.6",
|
||||||
"winit",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alacritty_config_derive"
|
name = "alacritty_config_derive"
|
||||||
version = "0.2.2-dev"
|
version = "0.2.2-dev"
|
||||||
source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5"
|
source = "git+https://github.com/zed-industries/alacritty?rev=33306142195b354ef3485ca2b1d8a85dfc6605ca#33306142195b354ef3485ca2b1d8a85dfc6605ca"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -147,7 +152,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "alacritty_terminal"
|
name = "alacritty_terminal"
|
||||||
version = "0.20.0-dev"
|
version = "0.20.0-dev"
|
||||||
source = "git+https://github.com/alacritty/alacritty?rev=7b9f32300ee0a249c0872302c97635b460e45ba5#7b9f32300ee0a249c0872302c97635b460e45ba5"
|
source = "git+https://github.com/zed-industries/alacritty?rev=33306142195b354ef3485ca2b1d8a85dfc6605ca#33306142195b354ef3485ca2b1d8a85dfc6605ca"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alacritty_config",
|
"alacritty_config",
|
||||||
"alacritty_config_derive",
|
"alacritty_config_derive",
|
||||||
@ -213,30 +218,6 @@ version = "0.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec8ad6edb4840b78c5c3d88de606b22252d552b55f3a4699fbb10fc070ec3049"
|
checksum = "ec8ad6edb4840b78c5c3d88de606b22252d552b55f3a4699fbb10fc070ec3049"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "android-activity"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "64529721f27c2314ced0890ce45e469574a73e5e6fdd6e9da1860eb29285f5e0"
|
|
||||||
dependencies = [
|
|
||||||
"android-properties",
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"cc",
|
|
||||||
"jni-sys",
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
"ndk",
|
|
||||||
"ndk-context",
|
|
||||||
"ndk-sys",
|
|
||||||
"num_enum 0.6.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "android-properties"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android-tzdata"
|
name = "android-tzdata"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -926,25 +907,6 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block-sys"
|
|
||||||
version = "0.1.0-beta.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146"
|
|
||||||
dependencies = [
|
|
||||||
"objc-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "block2"
|
|
||||||
version = "0.2.0-alpha.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42"
|
|
||||||
dependencies = [
|
|
||||||
"block-sys",
|
|
||||||
"objc2-encode",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blocking"
|
name = "blocking"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
@ -1107,6 +1069,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"async-broadcast",
|
"async-broadcast",
|
||||||
"audio",
|
"audio",
|
||||||
|
"channel",
|
||||||
"client",
|
"client",
|
||||||
"collections",
|
"collections",
|
||||||
"fs",
|
"fs",
|
||||||
@ -1126,20 +1089,6 @@ dependencies = [
|
|||||||
"util",
|
"util",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "calloop"
|
|
||||||
version = "0.10.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "52e0d00eb1ea24371a97d2da6201c6747a633dc6dc1988ef503403b4c59504a8"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"log",
|
|
||||||
"nix 0.25.1",
|
|
||||||
"slotmap",
|
|
||||||
"thiserror",
|
|
||||||
"vec_map",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cap-fs-ext"
|
name = "cap-fs-ext"
|
||||||
version = "0.24.4"
|
version = "0.24.4"
|
||||||
@ -1249,10 +1198,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg_aliases"
|
name = "channel"
|
||||||
version = "0.1.1"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
dependencies = [
|
||||||
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
"anyhow",
|
||||||
|
"client",
|
||||||
|
"collections",
|
||||||
|
"db",
|
||||||
|
"feature_flags",
|
||||||
|
"futures 0.3.28",
|
||||||
|
"gpui",
|
||||||
|
"image",
|
||||||
|
"language",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"parking_lot 0.11.2",
|
||||||
|
"postage",
|
||||||
|
"rand 0.8.5",
|
||||||
|
"rpc",
|
||||||
|
"schemars",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"settings",
|
||||||
|
"smol",
|
||||||
|
"sum_tree",
|
||||||
|
"tempfile",
|
||||||
|
"text",
|
||||||
|
"thiserror",
|
||||||
|
"time 0.3.24",
|
||||||
|
"tiny_http",
|
||||||
|
"url",
|
||||||
|
"util",
|
||||||
|
"uuid 1.4.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
@ -1376,12 +1354,6 @@ version = "0.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
|
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "claxon"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4bfbf56724aa9eca8afa4fcfadeb479e722935bb2a0900c2d37e0cc477af0688"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cli"
|
name = "cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -1407,6 +1379,7 @@ dependencies = [
|
|||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
"collections",
|
"collections",
|
||||||
"db",
|
"db",
|
||||||
|
"feature_flags",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
"image",
|
"image",
|
||||||
@ -1421,9 +1394,9 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
"settings",
|
"settings",
|
||||||
"smol",
|
"smol",
|
||||||
"staff_mode",
|
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"text",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"time 0.3.24",
|
"time 0.3.24",
|
||||||
"tiny_http",
|
"tiny_http",
|
||||||
@ -1479,7 +1452,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "collab"
|
name = "collab"
|
||||||
version = "0.16.0"
|
version = "0.19.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
@ -1488,8 +1461,11 @@ dependencies = [
|
|||||||
"axum-extra",
|
"axum-extra",
|
||||||
"base64 0.13.1",
|
"base64 0.13.1",
|
||||||
"call",
|
"call",
|
||||||
|
"channel",
|
||||||
"clap 3.2.25",
|
"clap 3.2.25",
|
||||||
"client",
|
"client",
|
||||||
|
"clock",
|
||||||
|
"collab_ui",
|
||||||
"collections",
|
"collections",
|
||||||
"ctor",
|
"ctor",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
@ -1514,6 +1490,7 @@ dependencies = [
|
|||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"project",
|
"project",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
|
"prost 0.8.0",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rpc",
|
"rpc",
|
||||||
@ -1526,6 +1503,7 @@ dependencies = [
|
|||||||
"settings",
|
"settings",
|
||||||
"sha-1 0.9.8",
|
"sha-1 0.9.8",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"text",
|
||||||
"theme",
|
"theme",
|
||||||
"time 0.3.24",
|
"time 0.3.24",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -1548,21 +1526,26 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"auto_update",
|
"auto_update",
|
||||||
"call",
|
"call",
|
||||||
|
"channel",
|
||||||
"client",
|
"client",
|
||||||
"clock",
|
"clock",
|
||||||
"collections",
|
"collections",
|
||||||
"context_menu",
|
"context_menu",
|
||||||
|
"db",
|
||||||
"editor",
|
"editor",
|
||||||
|
"feature_flags",
|
||||||
"feedback",
|
"feedback",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"language",
|
||||||
"log",
|
"log",
|
||||||
"menu",
|
"menu",
|
||||||
"picker",
|
"picker",
|
||||||
"postage",
|
"postage",
|
||||||
"project",
|
"project",
|
||||||
"recent_projects",
|
"recent_projects",
|
||||||
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"settings",
|
"settings",
|
||||||
@ -1623,6 +1606,19 @@ dependencies = [
|
|||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "component_test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"gpui",
|
||||||
|
"project",
|
||||||
|
"settings",
|
||||||
|
"theme",
|
||||||
|
"util",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@ -2070,15 +2066,6 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cursor-icon"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dashmap"
|
name = "dashmap"
|
||||||
version = "5.5.0"
|
version = "5.5.0"
|
||||||
@ -2161,6 +2148,15 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_refineable"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dhat"
|
name = "dhat"
|
||||||
version = "0.3.2"
|
version = "0.3.2"
|
||||||
@ -2285,12 +2281,6 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dispatch"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dlib"
|
name = "dlib"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@ -2544,6 +2534,14 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
|
checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "feature_flags"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"gpui",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "feedback"
|
name = "feedback"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -2769,6 +2767,7 @@ dependencies = [
|
|||||||
"smol",
|
"smol",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"text",
|
||||||
"time 0.3.24",
|
"time 0.3.24",
|
||||||
"util",
|
"util",
|
||||||
]
|
]
|
||||||
@ -3149,6 +3148,7 @@ dependencies = [
|
|||||||
"png",
|
"png",
|
||||||
"postage",
|
"postage",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
"refineable",
|
||||||
"resvg",
|
"resvg",
|
||||||
"schemars",
|
"schemars",
|
||||||
"seahash",
|
"seahash",
|
||||||
@ -3160,6 +3160,7 @@ dependencies = [
|
|||||||
"smol",
|
"smol",
|
||||||
"sqlez",
|
"sqlez",
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
|
"taffy",
|
||||||
"time 0.3.24",
|
"time 0.3.24",
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
"usvg",
|
"usvg",
|
||||||
@ -3172,12 +3173,18 @@ dependencies = [
|
|||||||
name = "gpui_macros"
|
name = "gpui_macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gpui",
|
"lazy_static",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "grid"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.20"
|
version = "0.3.20"
|
||||||
@ -3967,17 +3974,6 @@ version = "0.2.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lewton"
|
|
||||||
version = "0.10.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "777b48df9aaab155475a83a7df3070395ea1ac6902f5cd062b8f2b028075c030"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder",
|
|
||||||
"ogg",
|
|
||||||
"tinyvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.147"
|
version = "0.2.147"
|
||||||
@ -4530,7 +4526,7 @@ dependencies = [
|
|||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"jni-sys",
|
"jni-sys",
|
||||||
"ndk-sys",
|
"ndk-sys",
|
||||||
"num_enum 0.5.11",
|
"num_enum",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
@ -4572,19 +4568,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nix"
|
|
||||||
version = "0.25.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"cfg-if 1.0.0",
|
|
||||||
"libc",
|
|
||||||
"memoffset 0.6.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.26.2"
|
version = "0.26.2"
|
||||||
@ -4750,16 +4733,7 @@ version = "0.5.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
|
checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num_enum_derive 0.5.11",
|
"num_enum_derive",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_enum"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1"
|
|
||||||
dependencies = [
|
|
||||||
"num_enum_derive 0.6.1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -4774,18 +4748,6 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "num_enum_derive"
|
|
||||||
version = "0.6.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-crate 1.3.1",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.28",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nvim-rs"
|
name = "nvim-rs"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@ -4811,32 +4773,6 @@ dependencies = [
|
|||||||
"objc_exception",
|
"objc_exception",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc-sys"
|
|
||||||
version = "0.2.0-beta.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2"
|
|
||||||
version = "0.3.0-beta.3.patch-leaks.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468"
|
|
||||||
dependencies = [
|
|
||||||
"block2",
|
|
||||||
"objc-sys",
|
|
||||||
"objc2-encode",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "objc2-encode"
|
|
||||||
version = "2.0.0-pre.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512"
|
|
||||||
dependencies = [
|
|
||||||
"objc-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc_exception"
|
name = "objc_exception"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
@ -4890,15 +4826,6 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ogg"
|
|
||||||
version = "0.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6951b4e8bf21c8193da321bcce9c9dd2e13c858fe078bf9054a288b419ae5d6e"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.18.0"
|
version = "1.18.0"
|
||||||
@ -4955,15 +4882,6 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "orbclient"
|
|
||||||
version = "0.3.45"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "221d488cd70617f1bd599ed8ceb659df2147d9393717954d82a0f5e8032a6ab1"
|
|
||||||
dependencies = [
|
|
||||||
"redox_syscall 0.3.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ordered-float"
|
name = "ordered-float"
|
||||||
version = "2.10.0"
|
version = "2.10.0"
|
||||||
@ -5258,6 +5176,33 @@ version = "0.3.27"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "playground"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"derive_more",
|
||||||
|
"gpui",
|
||||||
|
"log",
|
||||||
|
"parking_lot 0.11.2",
|
||||||
|
"playground_macros",
|
||||||
|
"refineable",
|
||||||
|
"serde",
|
||||||
|
"simplelog",
|
||||||
|
"smallvec",
|
||||||
|
"taffy",
|
||||||
|
"util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "playground_macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plist"
|
name = "plist"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@ -5711,6 +5656,18 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick_action_bar"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"ai",
|
||||||
|
"editor",
|
||||||
|
"gpui",
|
||||||
|
"search",
|
||||||
|
"theme",
|
||||||
|
"workspace",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.32"
|
version = "1.0.32"
|
||||||
@ -5924,6 +5881,16 @@ dependencies = [
|
|||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "refineable"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"derive_refineable",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regalloc2"
|
name = "regalloc2"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
@ -6142,11 +6109,8 @@ version = "0.17.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bdf1d4dea18dff2e9eb6dca123724f8b60ef44ad74a9ad283cdfe025df7e73fa"
|
checksum = "bdf1d4dea18dff2e9eb6dca123724f8b60ef44ad74a9ad283cdfe025df7e73fa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"claxon",
|
|
||||||
"cpal",
|
"cpal",
|
||||||
"hound",
|
"hound",
|
||||||
"lewton",
|
|
||||||
"symphonia",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -6238,9 +6202,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-embed"
|
name = "rust-embed"
|
||||||
version = "6.8.1"
|
version = "8.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a36224c3276f8c4ebc8c20f158eca7ca4359c8db89991c4925132aaaf6702661"
|
checksum = "b1e7d90385b59f0a6bf3d3b757f3ca4ece2048265d70db20a2016043d4509a40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rust-embed-impl",
|
"rust-embed-impl",
|
||||||
"rust-embed-utils",
|
"rust-embed-utils",
|
||||||
@ -6249,9 +6213,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-embed-impl"
|
name = "rust-embed-impl"
|
||||||
version = "6.8.1"
|
version = "8.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49b94b81e5b2c284684141a2fb9e2a31be90638caf040bf9afbc5a0416afe1ac"
|
checksum = "3c3d8c6fd84090ae348e63a84336b112b5c3918b3bf0493a581f7bd8ee623c29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -6262,9 +6226,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-embed-utils"
|
name = "rust-embed-utils"
|
||||||
version = "7.8.1"
|
version = "8.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74"
|
checksum = "873feff8cb7bf86fdf0a71bb21c95159f4e4a37dd7a4bd1855a940909b583ada"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"globset",
|
"globset",
|
||||||
"sha2 0.10.7",
|
"sha2 0.10.7",
|
||||||
@ -6727,6 +6691,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"settings",
|
"settings",
|
||||||
|
"sha1",
|
||||||
"smol",
|
"smol",
|
||||||
"tempdir",
|
"tempdir",
|
||||||
"theme",
|
"theme",
|
||||||
@ -6890,6 +6855,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"collections",
|
"collections",
|
||||||
|
"feature_flags",
|
||||||
"fs",
|
"fs",
|
||||||
"futures 0.3.28",
|
"futures 0.3.28",
|
||||||
"gpui",
|
"gpui",
|
||||||
@ -6905,7 +6871,6 @@ dependencies = [
|
|||||||
"serde_json_lenient",
|
"serde_json_lenient",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"sqlez",
|
"sqlez",
|
||||||
"staff_mode",
|
|
||||||
"toml 0.5.11",
|
"toml 0.5.11",
|
||||||
"tree-sitter",
|
"tree-sitter",
|
||||||
"tree-sitter-json 0.19.0",
|
"tree-sitter-json 0.19.0",
|
||||||
@ -7145,15 +7110,6 @@ dependencies = [
|
|||||||
"pin-project-lite 0.1.12",
|
"pin-project-lite 0.1.12",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "smol_str"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "74212e6bbe9a4352329b2f68ba3130c15a3f26fe88ff22dbdc6cdd58fa85e99c"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "snippet"
|
name = "snippet"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -7339,14 +7295,6 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "staff_mode"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"anyhow",
|
|
||||||
"gpui",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_assertions"
|
name = "static_assertions"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -7480,56 +7428,6 @@ dependencies = [
|
|||||||
"siphasher",
|
"siphasher",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "symphonia"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62e48dba70095f265fdb269b99619b95d04c89e619538138383e63310b14d941"
|
|
||||||
dependencies = [
|
|
||||||
"lazy_static",
|
|
||||||
"symphonia-bundle-mp3",
|
|
||||||
"symphonia-core",
|
|
||||||
"symphonia-metadata",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "symphonia-bundle-mp3"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0f31d7fece546f1e6973011a9eceae948133bbd18fd3d52f6073b1e38ae6368a"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"symphonia-core",
|
|
||||||
"symphonia-metadata",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "symphonia-core"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f7c73eb88fee79705268cc7b742c7bc93a7b76e092ab751d0833866970754142"
|
|
||||||
dependencies = [
|
|
||||||
"arrayvec 0.7.4",
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
"bytemuck",
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "symphonia-metadata"
|
|
||||||
version = "0.5.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "89c3e1937e31d0e068bbe829f66b2f2bfaa28d056365279e0ef897172c3320c0"
|
|
||||||
dependencies = [
|
|
||||||
"encoding_rs",
|
|
||||||
"lazy_static",
|
|
||||||
"log",
|
|
||||||
"symphonia-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
@ -7599,6 +7497,17 @@ dependencies = [
|
|||||||
"winx",
|
"winx",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "taffy"
|
||||||
|
version = "0.3.11"
|
||||||
|
source = "git+https://github.com/DioxusLabs/taffy?rev=dab541d6104d58e2e10ce90c4a1dad0b703160cd#dab541d6104d58e2e10ce90c4a1dad0b703160cd"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec 0.7.4",
|
||||||
|
"grid",
|
||||||
|
"num-traits",
|
||||||
|
"slotmap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "take-until"
|
name = "take-until"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@ -7723,7 +7632,6 @@ dependencies = [
|
|||||||
"ctor",
|
"ctor",
|
||||||
"digest 0.9.0",
|
"digest 0.9.0",
|
||||||
"env_logger 0.9.3",
|
"env_logger 0.9.3",
|
||||||
"fs",
|
|
||||||
"gpui",
|
"gpui",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"log",
|
"log",
|
||||||
@ -7766,6 +7674,7 @@ name = "theme_selector"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"editor",
|
"editor",
|
||||||
|
"feature_flags",
|
||||||
"fs",
|
"fs",
|
||||||
"fuzzy",
|
"fuzzy",
|
||||||
"gpui",
|
"gpui",
|
||||||
@ -7775,7 +7684,6 @@ dependencies = [
|
|||||||
"postage",
|
"postage",
|
||||||
"settings",
|
"settings",
|
||||||
"smol",
|
"smol",
|
||||||
"staff_mode",
|
|
||||||
"theme",
|
"theme",
|
||||||
"util",
|
"util",
|
||||||
"workspace",
|
"workspace",
|
||||||
@ -8278,7 +8186,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tree-sitter"
|
name = "tree-sitter"
|
||||||
version = "0.20.10"
|
version = "0.20.10"
|
||||||
source = "git+https://github.com/tree-sitter/tree-sitter?rev=1c65ca24bc9a734ab70115188f465e12eecf224e#1c65ca24bc9a734ab70115188f465e12eecf224e"
|
source = "git+https://github.com/tree-sitter/tree-sitter?rev=35a6052fbcafc5e5fc0f9415b8652be7dcaf7222#35a6052fbcafc5e5fc0f9415b8652be7dcaf7222"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"regex",
|
"regex",
|
||||||
@ -8840,12 +8748,6 @@ dependencies = [
|
|||||||
"workspace",
|
"workspace",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "vec_map"
|
|
||||||
version = "0.8.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@ -9310,17 +9212,6 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "web-time"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "19353897b48e2c4d849a2d73cb0aeb16dc2be4e00c565abfc11eb65a806e47de"
|
|
||||||
dependencies = [
|
|
||||||
"js-sys",
|
|
||||||
"once_cell",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webpki"
|
name = "webpki"
|
||||||
version = "0.21.4"
|
version = "0.21.4"
|
||||||
@ -9636,42 +9527,6 @@ version = "0.48.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winit"
|
|
||||||
version = "0.29.0-beta.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2f1afaf8490cc3f1309520ebb53a4cd3fc3642c7df8064a4b074bb9867998d44"
|
|
||||||
dependencies = [
|
|
||||||
"android-activity",
|
|
||||||
"atomic-waker",
|
|
||||||
"bitflags 2.3.3",
|
|
||||||
"calloop",
|
|
||||||
"cfg_aliases",
|
|
||||||
"core-foundation",
|
|
||||||
"core-graphics",
|
|
||||||
"cursor-icon",
|
|
||||||
"dispatch",
|
|
||||||
"js-sys",
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
"ndk",
|
|
||||||
"ndk-sys",
|
|
||||||
"objc2",
|
|
||||||
"once_cell",
|
|
||||||
"orbclient",
|
|
||||||
"raw-window-handle",
|
|
||||||
"redox_syscall 0.3.5",
|
|
||||||
"serde",
|
|
||||||
"smol_str",
|
|
||||||
"unicode-segmentation",
|
|
||||||
"wasm-bindgen",
|
|
||||||
"wasm-bindgen-futures",
|
|
||||||
"web-sys",
|
|
||||||
"web-time",
|
|
||||||
"windows-sys",
|
|
||||||
"xkbcommon-dl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@ -9730,6 +9585,7 @@ dependencies = [
|
|||||||
"async-recursion 1.0.4",
|
"async-recursion 1.0.4",
|
||||||
"bincode",
|
"bincode",
|
||||||
"call",
|
"call",
|
||||||
|
"channel",
|
||||||
"client",
|
"client",
|
||||||
"collections",
|
"collections",
|
||||||
"context_menu",
|
"context_menu",
|
||||||
@ -9789,25 +9645,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xkbcommon-dl"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6924668544c48c0133152e7eec86d644a056ca3d09275eb8d5cdb9855f9d8699"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.3.3",
|
|
||||||
"dlib",
|
|
||||||
"log",
|
|
||||||
"once_cell",
|
|
||||||
"xkeysym",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xkeysym"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "054a8e68b76250b253f671d1268cb7f1ae089ec35e195b2efb2a4e9a836d0621"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xmlparser"
|
name = "xmlparser"
|
||||||
version = "0.13.5"
|
version = "0.13.5"
|
||||||
@ -9860,7 +9697,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.100.0"
|
version = "0.103.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activity_indicator",
|
"activity_indicator",
|
||||||
"ai",
|
"ai",
|
||||||
@ -9874,6 +9711,7 @@ dependencies = [
|
|||||||
"backtrace",
|
"backtrace",
|
||||||
"breadcrumbs",
|
"breadcrumbs",
|
||||||
"call",
|
"call",
|
||||||
|
"channel",
|
||||||
"chrono",
|
"chrono",
|
||||||
"cli",
|
"cli",
|
||||||
"client",
|
"client",
|
||||||
@ -9881,6 +9719,7 @@ dependencies = [
|
|||||||
"collab_ui",
|
"collab_ui",
|
||||||
"collections",
|
"collections",
|
||||||
"command_palette",
|
"command_palette",
|
||||||
|
"component_test",
|
||||||
"context_menu",
|
"context_menu",
|
||||||
"copilot",
|
"copilot",
|
||||||
"copilot_button",
|
"copilot_button",
|
||||||
@ -9889,6 +9728,7 @@ dependencies = [
|
|||||||
"diagnostics",
|
"diagnostics",
|
||||||
"editor",
|
"editor",
|
||||||
"env_logger 0.9.3",
|
"env_logger 0.9.3",
|
||||||
|
"feature_flags",
|
||||||
"feedback",
|
"feedback",
|
||||||
"file_finder",
|
"file_finder",
|
||||||
"fs",
|
"fs",
|
||||||
@ -9919,6 +9759,7 @@ dependencies = [
|
|||||||
"project",
|
"project",
|
||||||
"project_panel",
|
"project_panel",
|
||||||
"project_symbols",
|
"project_symbols",
|
||||||
|
"quick_action_bar",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"recent_projects",
|
"recent_projects",
|
||||||
"regex",
|
"regex",
|
||||||
@ -9934,7 +9775,6 @@ dependencies = [
|
|||||||
"simplelog",
|
"simplelog",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"smol",
|
"smol",
|
||||||
"staff_mode",
|
|
||||||
"sum_tree",
|
"sum_tree",
|
||||||
"tempdir",
|
"tempdir",
|
||||||
"terminal_view",
|
"terminal_view",
|
||||||
|
14
Cargo.toml
@ -6,6 +6,7 @@ members = [
|
|||||||
"crates/auto_update",
|
"crates/auto_update",
|
||||||
"crates/breadcrumbs",
|
"crates/breadcrumbs",
|
||||||
"crates/call",
|
"crates/call",
|
||||||
|
"crates/channel",
|
||||||
"crates/cli",
|
"crates/cli",
|
||||||
"crates/client",
|
"crates/client",
|
||||||
"crates/clock",
|
"crates/clock",
|
||||||
@ -13,10 +14,13 @@ members = [
|
|||||||
"crates/collab_ui",
|
"crates/collab_ui",
|
||||||
"crates/collections",
|
"crates/collections",
|
||||||
"crates/command_palette",
|
"crates/command_palette",
|
||||||
|
"crates/component_test",
|
||||||
"crates/context_menu",
|
"crates/context_menu",
|
||||||
"crates/copilot",
|
"crates/copilot",
|
||||||
"crates/copilot_button",
|
"crates/copilot_button",
|
||||||
"crates/db",
|
"crates/db",
|
||||||
|
"crates/refineable",
|
||||||
|
"crates/refineable/derive_refineable",
|
||||||
"crates/diagnostics",
|
"crates/diagnostics",
|
||||||
"crates/drag_and_drop",
|
"crates/drag_and_drop",
|
||||||
"crates/editor",
|
"crates/editor",
|
||||||
@ -28,6 +32,8 @@ members = [
|
|||||||
"crates/git",
|
"crates/git",
|
||||||
"crates/go_to_line",
|
"crates/go_to_line",
|
||||||
"crates/gpui",
|
"crates/gpui",
|
||||||
|
"crates/gpui/playground",
|
||||||
|
"crates/gpui/playground_macros",
|
||||||
"crates/gpui_macros",
|
"crates/gpui_macros",
|
||||||
"crates/install_cli",
|
"crates/install_cli",
|
||||||
"crates/journal",
|
"crates/journal",
|
||||||
@ -56,7 +62,7 @@ members = [
|
|||||||
"crates/snippet",
|
"crates/snippet",
|
||||||
"crates/sqlez",
|
"crates/sqlez",
|
||||||
"crates/sqlez_macros",
|
"crates/sqlez_macros",
|
||||||
"crates/staff_mode",
|
"crates/feature_flags",
|
||||||
"crates/sum_tree",
|
"crates/sum_tree",
|
||||||
"crates/terminal",
|
"crates/terminal",
|
||||||
"crates/text",
|
"crates/text",
|
||||||
@ -91,9 +97,11 @@ log = { version = "0.4.16", features = ["kv_unstable_serde"] }
|
|||||||
ordered-float = { version = "2.1.1" }
|
ordered-float = { version = "2.1.1" }
|
||||||
parking_lot = { version = "0.11.1" }
|
parking_lot = { version = "0.11.1" }
|
||||||
postage = { version = "0.5", features = ["futures-traits"] }
|
postage = { version = "0.5", features = ["futures-traits"] }
|
||||||
|
prost = { version = "0.8" }
|
||||||
rand = { version = "0.8.5" }
|
rand = { version = "0.8.5" }
|
||||||
|
refineable = { path = "./crates/refineable" }
|
||||||
regex = { version = "1.5" }
|
regex = { version = "1.5" }
|
||||||
rust-embed = { version = "6.3", features = ["include-exclude"] }
|
rust-embed = { version = "8.0", features = ["include-exclude"] }
|
||||||
schemars = { version = "0.8" }
|
schemars = { version = "0.8" }
|
||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||||
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
|
||||||
@ -135,7 +143,7 @@ tree-sitter-lua = "0.0.14"
|
|||||||
tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", rev = "66e3e9ce9180ae08fc57372061006ef83f0abde7" }
|
tree-sitter-nix = { git = "https://github.com/nix-community/tree-sitter-nix", rev = "66e3e9ce9180ae08fc57372061006ef83f0abde7" }
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "1c65ca24bc9a734ab70115188f465e12eecf224e" }
|
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "35a6052fbcafc5e5fc0f9415b8652be7dcaf7222" }
|
||||||
async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" }
|
async-task = { git = "https://github.com/zed-industries/async-task", rev = "341b57d6de98cdfd7b418567b8de2022ca993a6e" }
|
||||||
|
|
||||||
# TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457
|
# TODO - Remove when a version is released with this PR: https://github.com/servo/core-foundation-rs/pull/457
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# syntax = docker/dockerfile:1.2
|
# syntax = docker/dockerfile:1.2
|
||||||
|
|
||||||
FROM rust:1.71-bullseye as builder
|
FROM rust:1.72-bullseye as builder
|
||||||
WORKDIR app
|
WORKDIR app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
23
assets/icons/ai.svg
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<svg width="14" height="16" viewBox="0 0 14 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M10 8.94203V11C7.38649 11 6.61351 11 4 11V10.6812L10 5.31884V5H4V7.08696" stroke="black" stroke-width="1.25"/>
|
||||||
|
<circle cx="0.5" cy="8" r="0.5" fill="black"/>
|
||||||
|
<circle cx="1.49976" cy="5.82825" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="1.49976" cy="10.1719" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="13.5" cy="8.01581" r="0.5" fill="black"/>
|
||||||
|
<circle cx="12.5" cy="5.84387" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="12.5" cy="10.1877" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="6.99219" cy="1.48438" r="0.5" fill="black"/>
|
||||||
|
<circle cx="4.5" cy="2.5" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="0.5" cy="12.016" r="0.5" fill="black"/>
|
||||||
|
<circle cx="0.5" cy="3.98438" r="0.5" fill="black"/>
|
||||||
|
<circle cx="13.5" cy="12.016" r="0.5" fill="black"/>
|
||||||
|
<circle cx="13.5" cy="3.98438" r="0.5" fill="black"/>
|
||||||
|
<circle cx="2.49976" cy="14.516" r="0.5" fill="black"/>
|
||||||
|
<circle cx="2.48413" cy="1.48438" r="0.5" fill="black"/>
|
||||||
|
<circle cx="11.5" cy="14.516" r="0.5" fill="black"/>
|
||||||
|
<circle cx="11.5" cy="1.48438" r="0.5" fill="black"/>
|
||||||
|
<circle cx="9.49609" cy="2.48438" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="6.99219" cy="14.5" r="0.5" fill="black"/>
|
||||||
|
<circle cx="4.50391" cy="13.516" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="9.49609" cy="13.5" r="0.5" fill="black" fill-opacity="0.75"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
3
assets/icons/arrow_left.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.125 6.99344L6.35938 3.63281M3.125 6.99344L6.35938 10.3672M3.125 6.99344H11" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 275 B |
3
assets/icons/arrow_right.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M10.8906 7.00125L7.64062 3.64062M10.8906 7.00125L7.64062 10.375M10.8906 7.00125H3" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 279 B |
8
assets/icons/case_insensitive_12.svg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px" viewBox="0 0 12 12" version="1.1">
|
||||||
|
<g id="surface1">
|
||||||
|
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 2.976562 2.746094 L 4.226562 2.746094 L 6.105469 9.296875 L 5.285156 9.296875 L 4.804688 7.640625 L 2.386719 7.640625 L 1.914062 9.296875 L 1.097656 9.296875 Z M 4.621094 6.917969 L 3.640625 3.449219 L 3.5625 3.449219 L 2.582031 6.917969 Z M 4.621094 6.917969 "/>
|
||||||
|
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 2.878906 2.617188 L 4.324219 2.617188 L 6.277344 9.425781 L 5.191406 9.425781 L 4.707031 7.769531 L 2.484375 7.769531 L 2.011719 9.425781 L 0.925781 9.425781 Z M 3.601562 3.785156 L 2.75 6.789062 L 4.453125 6.789062 Z M 3.601562 3.785156 "/>
|
||||||
|
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 7.285156 9.378906 L 7.28125 9.378906 C 7.03125 9.277344 6.851562 9.101562 6.738281 8.859375 L 6.738281 8.855469 C 6.636719 8.621094 6.59375 8.296875 6.59375 7.894531 C 6.59375 7.421875 6.660156 7.035156 6.8125 6.757812 C 6.964844 6.464844 7.21875 6.265625 7.5625 6.152344 C 7.90625 6.039062 8.375 5.980469 8.96875 5.980469 L 9.75 5.980469 L 9.75 5.867188 C 9.75 5.605469 9.71875 5.417969 9.65625 5.292969 L 9.65625 5.289062 C 9.605469 5.175781 9.519531 5.09375 9.378906 5.039062 C 9.238281 4.984375 9.023438 4.949219 8.726562 4.949219 C 8.535156 4.949219 8.378906 4.964844 8.253906 4.988281 C 8.128906 5.011719 8.046875 5.042969 8 5.082031 L 7.996094 5.082031 C 7.902344 5.144531 7.832031 5.285156 7.820312 5.554688 L 7.8125 5.675781 L 6.746094 5.675781 L 6.746094 5.546875 C 6.746094 5.164062 6.804688 4.851562 6.925781 4.625 C 7.054688 4.382812 7.273438 4.21875 7.5625 4.128906 C 7.847656 4.03125 8.238281 3.984375 8.726562 3.984375 C 9.238281 3.984375 9.640625 4.039062 9.933594 4.148438 C 10.242188 4.261719 10.464844 4.464844 10.589844 4.75 C 10.714844 5.027344 10.773438 5.402344 10.773438 5.867188 L 10.773438 9.429688 L 9.78125 9.429688 L 9.78125 8.964844 C 9.644531 9.140625 9.488281 9.269531 9.316406 9.355469 C 9.078125 9.472656 8.730469 9.523438 8.289062 9.523438 C 7.871094 9.523438 7.53125 9.480469 7.285156 9.378906 Z M 8.058594 7.039062 C 7.914062 7.085938 7.816406 7.167969 7.753906 7.277344 C 7.699219 7.386719 7.664062 7.558594 7.664062 7.808594 C 7.664062 8.132812 7.730469 8.3125 7.824219 8.398438 C 7.921875 8.480469 8.132812 8.542969 8.496094 8.542969 C 8.84375 8.542969 9.097656 8.488281 9.261719 8.394531 C 9.421875 8.296875 9.546875 8.136719 9.621094 7.894531 C 9.691406 7.671875 9.734375 7.351562 9.742188 6.929688 L 8.777344 6.9375 C 8.460938 6.945312 8.222656 6.980469 8.0625 7.035156 Z M 8.058594 7.039062 "/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
6
assets/icons/channel_hash.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<line x1="10.2795" y1="2.63847" x2="7.74785" y2="11.0142" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="6.26624" y1="2.99597" x2="3.7346" y2="11.3717" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="3.15982" y1="5.3799" x2="11.9098" y2="5.3799" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="2.0983" y1="8.62407" x2="10.8483" y2="8.62407" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 571 B |
3
assets/icons/check.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.98438 7.85115L6.13569 9.44983L9.98438 4.08141" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 246 B |
4
assets/icons/check_circle.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M5 8L6.5 9L9 5.5" stroke="#11181C" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<circle cx="7" cy="7" r="4.875" stroke="#11181C" stroke-width="1.25"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 287 B |
3
assets/icons/chevron_down.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.63281 5.66406L6.99344 8.89844L10.3672 5.66406" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 246 B |
3
assets/icons/chevron_left.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8.35938 3.63281L5.125 6.99344L8.35938 10.3672" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 244 B |
3
assets/icons/chevron_right.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M5.64062 3.64062L8.89062 7.00125L5.64062 10.375" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 245 B |
3
assets/icons/chevron_up.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.63281 8.36719L6.99344 5.13281L10.3672 8.36719" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 246 B |
4
assets/icons/conversations.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M5.46115 8.43419C7.30678 8.43419 8.92229 7.43411 8.92229 5.21171C8.92229 2.98933 7.30678 1.98926 5.46115 1.98926C3.61553 1.98926 2 2.98933 2 5.21171C2 6.028 2.21794 6.67935 2.58519 7.17685C2.7184 7.35732 2.69033 7.77795 2.58387 7.97539C2.32908 8.44793 2.81048 8.9657 3.33372 8.84571C3.72539 8.75597 4.13621 8.63447 4.49574 8.4715C4.62736 8.41181 4.7727 8.38777 4.91631 8.40402C5.09471 8.42416 5.27678 8.43419 5.46115 8.43419Z" fill="black" fill-opacity="0.5" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.4661 10.6353C10.4697 10.7833 10.4914 10.9562 10.5423 11.1245C10.2394 11.0477 9.94714 10.9535 9.69757 10.8403C9.44717 10.7269 9.1668 10.6793 8.88556 10.7111C8.73612 10.728 8.58194 10.7365 8.42443 10.7365C7.68587 10.7365 7.04509 10.5503 6.58359 10.213C6.25127 9.97033 5.78501 10.0428 5.54218 10.3751C5.29939 10.7075 5.37193 11.1737 5.70427 11.4165C6.48017 11.9834 7.45185 12.2271 8.42443 12.2271C8.6356 12.2271 8.84564 12.2156 9.05296 12.1921C9.05904 12.1914 9.06942 12.1921 9.08212 12.1979C9.50348 12.3888 9.9667 12.5238 10.3854 12.6198C10.933 12.7453 11.4558 12.536 11.7761 12.1748C11.9716 11.9544 12.0298 11.6167 12.043 11.361C12.0564 11.1006 12.0238 10.8609 11.9375 10.6152C12.3875 9.98145 12.6308 9.18769 12.6308 8.2593C12.6308 7.23782 12.3361 6.3809 11.7994 5.72187C11.5395 5.4027 11.07 5.35466 10.7509 5.61459C10.4318 5.87448 10.3837 6.34387 10.6436 6.66305M10.4661 10.6353C10.4612 10.4326 10.4844 10.075 10.7008 9.78189C10.9613 9.42893 11.1403 8.93793 11.1403 8.2593C11.1403 7.53473 10.9364 7.0226 10.6436 6.66305" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
9
assets/icons/copilot.svg
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.64063 7.67017C5.97718 7.67017 6.25 7.94437 6.25 8.28263V9.60963C6.25 9.94786 5.97718 10.2221 5.64063 10.2221C5.30408 10.2221 5.03125 9.94786 5.03125 9.60963V8.28263C5.03125 7.94437 5.30408 7.67017 5.64063 7.67017Z" fill="black"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.37537 7.67017C8.71192 7.67017 8.98474 7.94437 8.98474 8.28263V9.60963C8.98474 9.94786 8.71192 10.2221 8.37537 10.2221C8.03882 10.2221 7.76599 9.94786 7.76599 9.60963V8.28263C7.76599 7.94437 8.03882 7.67017 8.37537 7.67017Z" fill="black"/>
|
||||||
|
<path d="M7 3.65625C7 5.84375 5.10754 6.3718 3.76562 6.3718C2.42371 6.3718 2.1405 5.3854 2.1405 4.16861C2.1405 2.95182 3.22834 1.96542 4.57025 1.96542C5.91216 1.96542 7 2.43946 7 3.65625Z" fill="black" fill-opacity="0.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M7 3.65625C7 5.84375 8.89246 6.3718 10.2344 6.3718C11.5763 6.3718 11.8595 5.3854 11.8595 4.16861C11.8595 2.95182 10.7717 1.96542 9.42975 1.96542C8.08784 1.96542 7 2.43946 7 3.65625Z" fill="black" fill-opacity="0.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M11.0156 6.01562C11.0156 6.01562 11.6735 6.43636 12 7.07348C12.3265 7.7106 12.3281 9.18621 12 9.7181C11.6719 10.25 11.2813 10.625 10.2931 11.16C9.30501 11.695 8 12.0156 8 12.0156H6C6 12.0156 4.70312 11.7344 3.70687 11.16C2.71061 10.5856 2.23437 10.2188 2 9.7181C1.76562 9.21746 1.6875 7.75 2 7.07348C2.31249 6.39695 3 6.01562 3 6.01562" stroke="black" stroke-width="1.25" stroke-linejoin="round"/>
|
||||||
|
<path d="M10.4454 11.0264V6.41934L12.1671 6.99323V9.5598L10.4454 11.0264Z" fill="black" fill-opacity="0.75"/>
|
||||||
|
<path d="M3.51556 11.0264V6.41934L1.79388 6.99323V9.5598L3.51556 11.0264Z" fill="black" fill-opacity="0.75"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
5
assets/icons/copy.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<rect x="2" y="5.64062" width="6.35938" height="6.35938" rx="0.5" stroke="black" stroke-width="1.25" stroke-linejoin="round"/>
|
||||||
|
<path d="M8.01562 3.75H5.625V2.03125H11.9375V8.39062H10.2656V6C10.2656 4.75736 9.25827 3.75 8.01562 3.75Z" fill="black" fill-opacity="0.5"/>
|
||||||
|
<path d="M5.625 3.125V2.5C5.625 2.22386 5.84886 2 6.125 2H11.5C11.7761 2 12 2.22386 12 2.5V7.875C12 8.15114 11.7761 8.375 11.5 8.375H10.8906" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 573 B |
5
assets/icons/ellipsis.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle cx="7" cy="7" r="1" fill="black"/>
|
||||||
|
<circle cx="11" cy="7" r="1" fill="black"/>
|
||||||
|
<circle cx="3" cy="7" r="1" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 233 B |
4
assets/icons/error.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8.86396 2C8.99657 2 9.12375 2.05268 9.21751 2.14645L11.8536 4.78249C11.9473 4.87625 12 5.00343 12 5.13604L12 8.86396C12 8.99657 11.9473 9.12375 11.8536 9.21751L9.21751 11.8536C9.12375 11.9473 8.99657 12 8.86396 12L5.13604 12C5.00343 12 4.87625 11.9473 4.78249 11.8536L2.14645 9.21751C2.05268 9.12375 2 8.99657 2 8.86396L2 5.13604C2 5.00343 2.05268 4.87625 2.14645 4.78249L4.78249 2.14645C4.87625 2.05268 5.00343 2 5.13604 2L8.86396 2Z" fill="#001A33" fill-opacity="0.157" stroke="#11181C" stroke-width="1.25" stroke-linejoin="round"/>
|
||||||
|
<path d="M8.89063 5.10938L5.10937 8.89063M8.89063 8.89063L5.10937 5.10938" stroke="#11181C" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 785 B |
4
assets/icons/exit.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M12.3594 7.00127L9.86062 4.5025M12.3594 7.00127L9.86062 9.50002M12.3594 7.00127L5 7.00127" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M6 2H2.5C2.22386 2 2 2.22386 2 2.5V11.5C2 11.7761 2.22386 12 2.5 12H6" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 427 B |
6
assets/icons/feedback.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2 3.5C2 3.22386 2.22386 3 2.5 3H11.5C11.7761 3 12 3.22386 12 3.5V10.5C12 10.7761 11.7761 11 11.5 11H2.5C2.22386 11 2 10.7761 2 10.5V3.5Z" stroke="black" stroke-width="1.25" stroke-linejoin="round"/>
|
||||||
|
<path d="M3 4L6.95312 7L11 4" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M4 9L5 8" stroke="black" stroke-opacity="0.5" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M10 9L9 8" stroke="black" stroke-opacity="0.5" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 675 B |
3
assets/icons/file_icons/elixir.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8 2L8.6165 2.10275C8.65805 1.8534 8.54532 1.60357 8.33085 1.46975C8.11639 1.33594 7.84243 1.34449 7.63673 1.49142L8 2ZM9.88714 8.62257C10.1098 9.73604 9.86526 10.3554 9.4569 10.7229C9.00367 11.1308 8.19498 11.375 7 11.375V12.625C8.30502 12.625 9.49633 12.3692 10.2931 11.6521C11.1347 10.8946 11.3902 9.76396 11.1129 8.37743L9.88714 8.62257ZM7 11.375C5.87824 11.375 5.17563 11.0417 4.75444 10.6206C4.32847 10.1946 4.125 9.61372 4.125 9H2.875C2.875 9.88628 3.17153 10.8054 3.87056 11.5044C4.57437 12.2083 5.62176 12.625 7 12.625V11.375ZM4.125 9C4.125 7.72699 5.00594 4.90668 8.36327 2.50858L7.63673 1.49142C3.99406 4.09332 2.875 7.27301 2.875 9H4.125ZM7.3835 1.89725C7.09577 3.62363 7.69108 4.78835 8.35497 5.78419C9.03189 6.79957 9.66859 7.52983 9.88714 8.62257L11.1129 8.37743C10.8314 6.97017 9.96811 5.95043 9.39503 5.09081C8.80892 4.21165 8.40423 3.37637 8.6165 2.10275L7.3835 1.89725Z" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1017 B |
@ -21,23 +21,27 @@
|
|||||||
"dll": "storage",
|
"dll": "storage",
|
||||||
"doc": "document",
|
"doc": "document",
|
||||||
"docx": "document",
|
"docx": "document",
|
||||||
|
"eex": "elixir",
|
||||||
"eslintrc": "eslint",
|
"eslintrc": "eslint",
|
||||||
"eslintrc.js": "eslint",
|
"eslintrc.js": "eslint",
|
||||||
"eslintrc.json": "eslint",
|
"eslintrc.json": "eslint",
|
||||||
|
"ex": "elixir",
|
||||||
|
"exs": "elixir",
|
||||||
|
"fish": "terminal",
|
||||||
|
"flac": "audio",
|
||||||
"fmp": "storage",
|
"fmp": "storage",
|
||||||
"fp7": "storage",
|
"fp7": "storage",
|
||||||
"flac": "audio",
|
|
||||||
"fish": "terminal",
|
|
||||||
"frm": "storage",
|
"frm": "storage",
|
||||||
"gdb": "storage",
|
"gdb": "storage",
|
||||||
|
"gif": "image",
|
||||||
"gitattributes": "vcs",
|
"gitattributes": "vcs",
|
||||||
"gitignore": "vcs",
|
"gitignore": "vcs",
|
||||||
"gitmodules": "vcs",
|
"gitmodules": "vcs",
|
||||||
"gif": "image",
|
|
||||||
"go": "code",
|
"go": "code",
|
||||||
"h": "code",
|
"h": "code",
|
||||||
"handlebars": "code",
|
"handlebars": "code",
|
||||||
"hbs": "template",
|
"hbs": "template",
|
||||||
|
"heex": "elixir",
|
||||||
"htm": "template",
|
"htm": "template",
|
||||||
"html": "template",
|
"html": "template",
|
||||||
"ib": "storage",
|
"ib": "storage",
|
||||||
@ -51,16 +55,16 @@
|
|||||||
"ldf": "storage",
|
"ldf": "storage",
|
||||||
"lock": "lock",
|
"lock": "lock",
|
||||||
"log": "log",
|
"log": "log",
|
||||||
"mdb": "storage",
|
|
||||||
"md": "document",
|
"md": "document",
|
||||||
|
"mdb": "storage",
|
||||||
"mdf": "storage",
|
"mdf": "storage",
|
||||||
"mdx": "document",
|
"mdx": "document",
|
||||||
"mp3": "audio",
|
"mp3": "audio",
|
||||||
"mp4": "video",
|
"mp4": "video",
|
||||||
"myd": "storage",
|
"myd": "storage",
|
||||||
"myi": "storage",
|
"myi": "storage",
|
||||||
"ods": "document",
|
|
||||||
"odp": "document",
|
"odp": "document",
|
||||||
|
"ods": "document",
|
||||||
"odt": "document",
|
"odt": "document",
|
||||||
"ogg": "video",
|
"ogg": "video",
|
||||||
"pdb": "storage",
|
"pdb": "storage",
|
||||||
@ -74,24 +78,24 @@
|
|||||||
"profile": "terminal",
|
"profile": "terminal",
|
||||||
"ps1": "terminal",
|
"ps1": "terminal",
|
||||||
"psd": "image",
|
"psd": "image",
|
||||||
"py": "code",
|
"py": "python",
|
||||||
"rb": "code",
|
"rb": "code",
|
||||||
"rkt": "code",
|
"rkt": "code",
|
||||||
"rs": "rust",
|
"rs": "rust",
|
||||||
"rtf": "document",
|
"rtf": "document",
|
||||||
"sav": "storage",
|
"sav": "storage",
|
||||||
"scm": "code",
|
"scm": "code",
|
||||||
|
"sdf": "storage",
|
||||||
"sh": "terminal",
|
"sh": "terminal",
|
||||||
"sqlite": "storage",
|
"sqlite": "storage",
|
||||||
"sdf": "storage",
|
|
||||||
"svelte": "template",
|
"svelte": "template",
|
||||||
"svg": "image",
|
"svg": "image",
|
||||||
"swift": "code",
|
"swift": "code",
|
||||||
"ts": "typescript",
|
|
||||||
"tsx": "code",
|
|
||||||
"tiff": "image",
|
"tiff": "image",
|
||||||
"toml": "toml",
|
"toml": "toml",
|
||||||
|
"ts": "typescript",
|
||||||
"tsv": "storage",
|
"tsv": "storage",
|
||||||
|
"tsx": "code",
|
||||||
"txt": "document",
|
"txt": "document",
|
||||||
"wav": "audio",
|
"wav": "audio",
|
||||||
"webm": "video",
|
"webm": "video",
|
||||||
@ -103,9 +107,9 @@
|
|||||||
"zlogin": "terminal",
|
"zlogin": "terminal",
|
||||||
"zsh": "terminal",
|
"zsh": "terminal",
|
||||||
"zsh_aliases": "terminal",
|
"zsh_aliases": "terminal",
|
||||||
"zshenv": "terminal",
|
|
||||||
"zsh_histfile": "terminal",
|
"zsh_histfile": "terminal",
|
||||||
"zsh_profile": "terminal",
|
"zsh_profile": "terminal",
|
||||||
|
"zshenv": "terminal",
|
||||||
"zshrc": "terminal"
|
"zshrc": "terminal"
|
||||||
},
|
},
|
||||||
"types": {
|
"types": {
|
||||||
@ -127,6 +131,9 @@
|
|||||||
"document": {
|
"document": {
|
||||||
"icon": "icons/file_icons/book.svg"
|
"icon": "icons/file_icons/book.svg"
|
||||||
},
|
},
|
||||||
|
"elixir": {
|
||||||
|
"icon": "icons/file_icons/elixir.svg"
|
||||||
|
},
|
||||||
"eslint": {
|
"eslint": {
|
||||||
"icon": "icons/file_icons/eslint.svg"
|
"icon": "icons/file_icons/eslint.svg"
|
||||||
},
|
},
|
||||||
@ -145,9 +152,15 @@
|
|||||||
"log": {
|
"log": {
|
||||||
"icon": "icons/file_icons/info.svg"
|
"icon": "icons/file_icons/info.svg"
|
||||||
},
|
},
|
||||||
|
"phoenix": {
|
||||||
|
"icon": "icons/file_icons/phoenix.svg"
|
||||||
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"icon": "icons/file_icons/prettier.svg"
|
"icon": "icons/file_icons/prettier.svg"
|
||||||
},
|
},
|
||||||
|
"python": {
|
||||||
|
"icon": "icons/file_icons/python.svg"
|
||||||
|
},
|
||||||
"rust": {
|
"rust": {
|
||||||
"icon": "icons/file_icons/rust.svg"
|
"icon": "icons/file_icons/rust.svg"
|
||||||
},
|
},
|
||||||
|
4
assets/icons/file_icons/phoenix.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M12 8C12 7.32138 11.9375 6.5 11.7188 5.75C11.0625 6.53125 9.875 7.1875 9 7.5C9.75 4.90625 8.5625 2.1875 7 2C7 3.96875 6.625 4.90625 5.5 6.5C4 4 2.5 5.5 2 6C2.5 6.5 3.21832 7.24064 3.34375 8.3125C3.6875 11.25 5.75 12 7.5 12C9.25 12 9.5 10 11.5 11" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<circle cx="4.03125" cy="6.625" r="1.53125" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 502 B |
6
assets/icons/file_icons/python.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M6.18452 1.9164C5.01625 1.9164 3.98489 2.77625 3.91991 3.9468H3.72024C2.81569 3.9468 2 4.63733 2 5.587V7.1098C2 8.05947 2.81569 8.75 3.72024 8.75H4.33631C4.67376 8.75 5.02976 8.48561 5.02976 8.06155C5.02976 7.46058 5.51694 6.9734 6.11791 6.9734H7.27976C8.18431 6.9734 9 6.28288 9 5.3332V4.0642C9 2.83419 7.93913 1.9164 6.73214 1.9164H6.18452Z" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M7.79613 12.0836C8.97889 12.0836 10.0103 11.2025 10.0702 10.0191H10.2738C11.1885 10.0191 12 9.31459 12 8.36187V6.8135C12 5.86077 11.1885 5.15625 10.2738 5.15625H9.65439C9.30991 5.15625 8.96057 5.42749 8.96057 5.84577C8.96057 6.46262 8.46051 6.96268 7.84365 6.96268H6.69494C5.78027 6.96268 4.96875 7.6672 4.96875 8.61993V9.91023C4.96875 11.148 6.02678 12.0836 7.24554 12.0836H7.79613Z" stroke="black" stroke-width="1.25"/>
|
||||||
|
<circle cx="6.03975" cy="3.9167" r="0.633501" fill="black"/>
|
||||||
|
<circle cx="7.92285" cy="10.0793" r="0.670898" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.0 KiB |
3
assets/icons/filter.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M11.6749 2.40608C11.8058 2.24239 11.6893 1.99991 11.4796 1.99991H2.51996C2.31033 1.99991 2.19379 2.24239 2.32474 2.40608L5.14583 5.93246C5.34148 6.17701 5.44808 6.48087 5.44808 6.79412C5.44808 7.46881 5.44808 10.334 5.44808 11.5016C5.44808 11.7778 5.67194 11.9999 5.94808 11.9999H8.05153C8.32767 11.9999 8.55153 11.7778 8.55153 11.5016C8.55153 10.334 8.55153 7.46881 8.55153 6.79412C8.55153 6.48087 8.65815 6.17701 8.8538 5.93246L11.6749 2.40608Z" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 644 B |
3
assets/icons/filter_12.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M10.6748 1.40617C10.8058 1.24248 10.6892 1 10.4796 1H1.51991C1.31028 1 1.19374 1.24248 1.32469 1.40617L4.14578 4.93255C4.34144 5.1771 4.44803 5.48097 4.44803 5.79421C4.44803 6.4689 4.44803 9.33412 4.44803 10.5017C4.44803 10.7779 4.67189 11 4.94803 11H7.05148C7.32762 11 7.55148 10.7779 7.55148 10.5017C7.55148 9.33412 7.55148 6.4689 7.55148 5.79421C7.55148 5.48097 7.6581 5.1771 7.85376 4.93255L10.6748 1.40617Z" stroke="#787D87" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 611 B |
6
assets/icons/filter_14.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="14px" height="14px" viewBox="0 0 14 14" version="1.1">
|
||||||
|
<g id="surface1">
|
||||||
|
<path style="fill:none;stroke-width:1.25;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(47.058824%,49.019608%,52.941176%);stroke-opacity:1;stroke-miterlimit:4;" d="M 10.674107 1.40625 C 10.804688 1.242188 10.690848 1.001116 10.479911 1.001116 L 1.520089 1.001116 C 1.309152 1.001116 1.195312 1.242188 1.325893 1.40625 L 4.145089 4.93192 C 4.342634 5.176339 4.446429 5.481027 4.446429 5.795759 C 4.446429 6.46875 4.446429 9.334821 4.446429 10.503348 C 4.446429 10.777902 4.670759 10.998884 4.948661 10.998884 L 7.051339 10.998884 C 7.329241 10.998884 7.550223 10.777902 7.550223 10.503348 C 7.550223 9.334821 7.550223 6.46875 7.550223 5.795759 C 7.550223 5.481027 7.657366 5.176339 7.854911 4.93192 Z M 10.674107 1.40625 " transform="matrix(1.166667,0,0,1.166667,0,0)"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 991 B |
6
assets/icons/hash.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<line x1="10.2795" y1="2.63847" x2="7.74786" y2="11.0142" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="6.26625" y1="2.99597" x2="3.73461" y2="11.3717" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="3.15979" y1="5.3799" x2="11.9098" y2="5.3799" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<line x1="2.09833" y1="8.62407" x2="10.8483" y2="8.62407" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 573 B |
5
assets/icons/html.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8.15735 3.17108L5.84271 10.8289" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
<path d="M4 5L2 7L4 9" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M10 9L12 7L10 5" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 423 B |
5
assets/icons/inlay_hint.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle cx="3" cy="9" r="1" fill="black"/>
|
||||||
|
<circle cx="3" cy="5" r="1" fill="black"/>
|
||||||
|
<path d="M7 3H10M13 3H10M10 3C10 3 10 11 10 11.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 276 B |
5
assets/icons/kebab.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<circle cx="7" cy="7" r="1" fill="black"/>
|
||||||
|
<circle cx="11" cy="7" r="1" fill="black"/>
|
||||||
|
<circle cx="3" cy="7" r="1" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 233 B |
6
assets/icons/lock.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<rect x="3" y="5" width="8" height="7" rx="0.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M4 4C4 2.89543 4.89543 2 6 2H8C9.10457 2 10 2.89543 10 4V5H4V4Z" stroke="black" stroke-opacity="0.75" stroke-width="1.25"/>
|
||||||
|
<circle cx="7" cy="8" r="1" fill="black"/>
|
||||||
|
<path d="M7 8V9.375" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 445 B |
3
assets/icons/magnifying_glass.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M12 12L9.41379 9.41379M2 6.31034C2 3.92981 3.92981 2 6.31034 2C8.6909 2 10.6207 3.92981 10.6207 6.31034C10.6207 8.6909 8.6909 10.6207 6.31034 10.6207C3.92981 10.6207 2 8.6909 2 6.31034Z" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 383 B |
5
assets/icons/match_case.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.47087 3.20502H4.93146L7.12233 10.845H6.16733L5.60557 8.91252H2.78552L2.235 10.845H1.28L3.47087 3.20502ZM5.3921 8.06988L4.24611 4.02519H4.15622L3.01023 8.06988H5.3921Z" fill="black"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.35784 3.05502H5.04449L7.32139 10.995H6.05473L5.49297 9.06253H2.89876L2.34823 10.995H1.08094L3.35784 3.05502ZM4.20117 4.41683L3.20863 7.91989H5.1937L4.20117 4.41683Z" fill="black"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.49755 10.9439L8.49614 10.9433C8.20513 10.8235 7.99172 10.6192 7.86261 10.3352L7.86103 10.3317C7.74397 10.0558 7.69085 9.67797 7.69085 9.21014C7.69085 8.65676 7.77089 8.20993 7.94588 7.88453C8.12486 7.54406 8.4223 7.31025 8.82246 7.17939C9.22218 7.04366 9.77245 6.97946 10.4643 6.97946H11.3773V6.84676C11.3773 6.53978 11.3365 6.32064 11.2676 6.17645L11.2652 6.17158C11.2077 6.03931 11.105 5.94128 10.942 5.87857L10.9401 5.87785C10.7779 5.81296 10.5289 5.77548 10.1816 5.77548C9.95742 5.77548 9.77444 5.79025 9.63048 5.818C9.4849 5.84607 9.38928 5.88554 9.33128 5.92772L9.32759 5.9304C9.22055 6.00339 9.13583 6.16518 9.1215 6.4804L9.11499 6.62359H7.87178V6.47359C7.87178 6.02598 7.93666 5.66152 8.08202 5.39592C8.23181 5.11455 8.48509 4.9233 8.82297 4.81582C9.15491 4.7028 9.61083 4.64999 10.1816 4.64999C10.7762 4.64999 11.2497 4.71047 11.5915 4.84054C11.9497 4.97397 12.2081 5.20795 12.3539 5.54148C12.5023 5.86386 12.5706 6.30304 12.5706 6.84676V10.9998H11.4112V10.4612C11.2513 10.6622 11.0717 10.8156 10.8706 10.9161L10.869 10.917C10.5893 11.0526 10.1848 11.1129 9.67276 11.1129C9.18264 11.1129 8.78731 11.0598 8.49755 10.9439ZM9.40357 8.21033C9.23125 8.26777 9.11727 8.36187 9.04741 8.4893C8.98131 8.61621 8.94073 8.81734 8.94073 9.10837C8.94073 9.48881 9.01919 9.69954 9.12735 9.79866C9.24209 9.89577 9.48642 9.96479 9.91023 9.96479C10.3198 9.96479 10.6134 9.90216 10.8072 9.79296C10.9944 9.68003 11.1366 9.4918 11.226 9.21004C11.3088 8.94889 11.3567 8.57563 11.3648 8.08368L10.2403 8.09363C9.87055 8.10107 9.59539 8.14186 9.40658 8.20929L9.40357 8.21033Z" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
5
assets/icons/match_word.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.74677 9.48683L4.07035 6.03229L3.38589 9.48683H2.17618L1.00285 4.00778H2.27563L2.81571 7.41751L3.48443 4.01749H4.65869L5.31824 7.41173L5.8574 4.00778H7.13018L5.95684 9.48683H4.74677Z" fill="black"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.64902 9.324C8.31295 9.13305 8.08208 8.81972 7.9472 8.40798C7.81465 8.00336 7.75312 7.44225 7.75312 6.73695C7.75312 6.03863 7.81136 5.48473 7.93685 5.08734L7.9375 5.0853C8.07226 4.67391 8.30335 4.36276 8.64083 4.17813C8.96801 3.99275 9.41114 3.91059 9.94955 3.91059C10.3406 3.91059 10.6631 3.95604 10.8967 4.06503C11.0079 4.11693 11.1098 4.18862 11.2033 4.27763V2.03046H12.4076V9.48579H11.2033V9.19001C11.0944 9.29092 10.9799 9.37114 10.8591 9.4277C10.6327 9.53666 10.3334 9.5827 9.97862 9.5827C9.43385 9.5827 8.98587 9.50374 8.6537 9.32658L8.64902 9.324ZM11.1139 7.85526C11.1841 7.60329 11.2226 7.23372 11.2226 6.73695C11.2226 6.2462 11.184 5.88349 11.114 5.63862C11.0456 5.39921 10.94 5.25882 10.8149 5.18284L10.8077 5.17844C10.6804 5.09361 10.4713 5.03744 10.1531 5.03744C9.8078 5.03744 9.57185 5.09378 9.42251 5.18338L9.41824 5.18594C9.27997 5.2643 9.16717 5.40621 9.09394 5.64281C9.01872 5.88584 8.97689 6.24686 8.97689 6.73695C8.97689 7.23381 9.01877 7.59792 9.09394 7.84078C9.16725 8.07763 9.28092 8.22495 9.42251 8.3099C9.57185 8.39951 9.8078 8.45585 10.1531 8.45585C10.4721 8.45585 10.683 8.40283 10.8113 8.32234C10.9395 8.23962 11.0456 8.09391 11.1139 7.85526Z" fill="black"/>
|
||||||
|
<rect x="1.14084" y="10.7188" width="11.7183" height="1.26565" rx="0.632824" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.6 KiB |
4
assets/icons/maximize.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2 8.5V12M2 12H5.5M2 12L6.01562 7.98437" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M12 5.5V2M12 2L8.5 2M12 2L8.01562 5.98437" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 373 B |
5
assets/icons/microphone.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M10.5 8.5C10.5 8.5 9.375 10 7 10C4.625 10 3.5 8.5 3.5 8.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
<rect x="5" y="2" width="4" height="5.40625" rx="2" fill="black" fill-opacity="0.25" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M7 10V12M7 12H9M7 12H5" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 423 B |
4
assets/icons/minimize.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M6.01563 11.4844L6.01563 7.98438M6.01563 7.98438L2.51563 7.98437M6.01563 7.98438L2 12" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M8.01562 2.48438V5.98438M8.01562 5.98438H11.5156M8.01562 5.98438L12 2" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 447 B |
3
assets/icons/plus.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M7 3V11M11 7H3" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 188 B |
5
assets/icons/project.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2.03125 2V2.03125M2.03125 8C2.03125 10 5 10 5 10M2.03125 8V2.03125M2.03125 8L2.03125 11M2.03125 2.03125C2.03125 4 5 4 5 4" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<rect x="7.375" y="2.375" width="4.25" height="3.25" rx="1.125" fill="black" fill-opacity="0.33" stroke="black" stroke-width="1.25"/>
|
||||||
|
<rect x="7.375" y="8.375" width="4.25" height="3.25" rx="1.125" fill="black" fill-opacity="0.33" stroke="black" stroke-width="1.25"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 588 B |
11
assets/icons/replace.svg
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M7 12C4.97279 12 3.22735 10.7936 2.4425 9.0595M7 2C9.11228 2 10.9186 3.30981 11.6512 5.16152" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<circle cx="1.65625" cy="1.67188" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="3.71094" cy="1.67188" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="4.96094" cy="3.36719" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="3.71094" cy="4.79688" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="4.60156" cy="6.67188" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="1.65625" cy="4.17188" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<circle cx="1.65625" cy="6.67188" r="0.625" fill="black" fill-opacity="0.75"/>
|
||||||
|
<path d="M10.7802 10.8195C10.838 10.8195 10.8906 10.8527 10.9155 10.9048L11.7174 12.5811C11.8088 12.7721 12.0017 12.8938 12.2135 12.8938H12.3394C12.7483 12.8938 13.0142 12.4635 12.8314 12.0978L12.1619 10.7589C12.1232 10.6816 12.1582 10.5823 12.241 10.5349C12.7565 10.2397 13.0695 9.66858 13.0695 9.00391C13.0695 8.43361 12.8777 7.97006 12.5248 7.64951C12.1725 7.3295 11.6652 7.15703 11.043 7.15703H9.49609C9.19234 7.15703 8.94609 7.40327 8.94609 7.70703V12.3438C8.94609 12.6475 9.19234 12.8938 9.49609 12.8938H9.60156C9.90532 12.8938 10.1516 12.6475 10.1516 12.3438V10.9695C10.1516 10.8867 10.2187 10.8195 10.3016 10.8195H10.7802ZM10.1516 8.31328C10.1516 8.23044 10.2187 8.16328 10.3016 8.16328H10.8984C11.2023 8.16328 11.4371 8.2449 11.5954 8.38814C11.7529 8.5308 11.8406 8.73993 11.8406 9.00781C11.8406 9.28155 11.751 9.49461 11.5909 9.63971C11.4302 9.7854 11.1925 9.86797 10.8867 9.86797H10.3016C10.2187 9.86797 10.1516 9.80081 10.1516 9.71797V8.31328Z" fill="black" stroke="black" stroke-width="0.1"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
5
assets/icons/replace_all.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M4.10517 5.8012C4.07193 5.73172 4.00176 5.6875 3.92475 5.6875H3.44609C3.33564 5.6875 3.24609 5.77704 3.24609 5.8875V7.26172C3.24609 7.53786 3.02224 7.76172 2.74609 7.76172H2.64062C2.36448 7.76172 2.14062 7.53786 2.14062 7.26172V2.625C2.14062 2.34886 2.36448 2.125 2.64062 2.125H4.1875C5.41406 2.125 6.16406 2.80469 6.16406 3.92188C6.16406 4.57081 5.85885 5.12418 5.36073 5.40943C5.25888 5.46775 5.20921 5.59421 5.2617 5.69918L5.93117 7.03811C6.09739 7.37056 5.85564 7.76172 5.48395 7.76172H5.35806C5.16552 7.76172 4.99009 7.65117 4.907 7.47748L4.10517 5.8012ZM3.44609 3.03125C3.33564 3.03125 3.24609 3.12079 3.24609 3.23125V4.63594C3.24609 4.74639 3.33564 4.83594 3.44609 4.83594H4.03125C4.66016 4.83594 5.03516 4.49609 5.03516 3.92578C5.03516 3.36719 4.66797 3.03125 4.04297 3.03125H3.44609Z" fill="black" fill-opacity="0.75"/>
|
||||||
|
<path d="M3.92475 5.7375C3.98251 5.7375 4.03514 5.77067 4.06006 5.82277L4.8619 7.49905C4.95329 7.69011 5.14627 7.81172 5.35806 7.81172H5.48395C5.89281 7.81172 6.15873 7.38145 5.97589 7.01575L5.30642 5.67682C5.26778 5.59953 5.30269 5.50028 5.38557 5.45282C5.90107 5.15762 6.21406 4.58655 6.21406 3.92188C6.21406 3.35158 6.02226 2.88803 5.66936 2.56748C5.31705 2.24747 4.80973 2.075 4.1875 2.075H2.64062C2.33687 2.075 2.09062 2.32124 2.09062 2.625V7.26172C2.09062 7.56548 2.33687 7.81172 2.64062 7.81172H2.74609C3.04985 7.81172 3.29609 7.56548 3.29609 7.26172V5.8875C3.29609 5.80466 3.36325 5.7375 3.44609 5.7375H3.92475ZM3.29609 3.23125C3.29609 3.14841 3.36325 3.08125 3.44609 3.08125H4.04297C4.34688 3.08125 4.58164 3.16287 4.73988 3.30611C4.89748 3.44876 4.98516 3.6579 4.98516 3.92578C4.98516 4.19952 4.89553 4.41258 4.73546 4.55768C4.57475 4.70337 4.33706 4.78594 4.03125 4.78594H3.44609C3.36325 4.78594 3.29609 4.71878 3.29609 4.63594V3.23125Z" stroke="black" stroke-opacity="0.75" stroke-width="0.1"/>
|
||||||
|
<path d="M9.5 7V9.5M9.5 12V9.5M12 9.5H9.5M7 9.5H9.5M9.5 9.5L11.1667 7.83333M9.5 9.5L7.83333 11.1667M9.5 9.5L11.1667 11.1667M9.5 9.5L7.83333 7.83333" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
5
assets/icons/replace_next.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M3.96454 5.6762C3.93131 5.60672 3.86114 5.5625 3.78412 5.5625H3.30547C3.19501 5.5625 3.10547 5.65204 3.10547 5.7625V7.13672C3.10547 7.41286 2.88161 7.63672 2.60547 7.63672H2.5C2.22386 7.63672 2 7.41286 2 7.13672V2.5C2 2.22386 2.22386 2 2.5 2H4.04688C5.27344 2 6.02344 2.67969 6.02344 3.79688C6.02344 4.44581 5.71823 4.99918 5.2201 5.28443C5.11826 5.34275 5.06859 5.46921 5.12107 5.57418L5.79054 6.91311C5.95677 7.24556 5.71502 7.63672 5.34333 7.63672H5.21743C5.02489 7.63672 4.84946 7.52617 4.76638 7.35248L3.96454 5.6762ZM3.30547 2.90625C3.19501 2.90625 3.10547 2.99579 3.10547 3.10625V4.51094C3.10547 4.62139 3.19501 4.71094 3.30547 4.71094H3.89062C4.51953 4.71094 4.89453 4.37109 4.89453 3.80078C4.89453 3.24219 4.52734 2.90625 3.90234 2.90625H3.30547Z" fill="black" fill-opacity="0.75"/>
|
||||||
|
<path d="M3.78412 5.6125C3.84188 5.6125 3.89451 5.64567 3.91944 5.69777L4.72127 7.37405C4.81266 7.56511 5.00564 7.68672 5.21743 7.68672H5.34333C5.75219 7.68672 6.01811 7.25645 5.83526 6.89075L5.1658 5.55182C5.12715 5.47453 5.16207 5.37528 5.24495 5.32782C5.76044 5.03262 6.07344 4.46155 6.07344 3.79688C6.07344 3.22658 5.88164 2.76303 5.52873 2.44248C5.17642 2.12247 4.6691 1.95 4.04688 1.95H2.5C2.19624 1.95 1.95 2.19624 1.95 2.5V7.13672C1.95 7.44048 2.19624 7.68672 2.5 7.68672H2.60547C2.90923 7.68672 3.15547 7.44048 3.15547 7.13672V5.7625C3.15547 5.67966 3.22263 5.6125 3.30547 5.6125H3.78412ZM3.15547 3.10625C3.15547 3.02341 3.22263 2.95625 3.30547 2.95625H3.90234C4.20626 2.95625 4.44101 3.03787 4.59926 3.18111C4.75686 3.32376 4.84453 3.5329 4.84453 3.80078C4.84453 4.07452 4.75491 4.28758 4.59484 4.43268C4.43413 4.57837 4.19643 4.66094 3.89062 4.66094H3.30547C3.22263 4.66094 3.15547 4.59378 3.15547 4.51094V3.10625Z" stroke="black" stroke-opacity="0.75" stroke-width="0.1"/>
|
||||||
|
<path d="M7.5 5.88672C9.433 5.88672 11 7.45372 11 9.38672V12M11 12L13 10M11 12L9 10" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.0 KiB |
4
assets/icons/screen.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<rect x="2" y="2" width="10" height="7" rx="0.5" fill="black" fill-opacity="0.25" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M7 9V12M7 12H9M7 12H5" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 314 B |
5
assets/icons/split.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M7 2H10C11.1046 2 12 2.89543 12 4V10C12 11.1046 11.1046 12 10 12H7V2Z" fill="black" fill-opacity="0.25"/>
|
||||||
|
<rect x="2" y="2" width="10" height="10" rx="0.5" stroke="black" stroke-width="1.25"/>
|
||||||
|
<line x1="7" y1="2" x2="7" y2="12" stroke="black" stroke-width="1.25"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 377 B |
4
assets/icons/success.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2 2.5C2 2.22386 2.22386 2 2.5 2H11.5C11.7761 2 12 2.22386 12 2.5V11.5C12 11.7761 11.7761 12 11.5 12H2.5C2.22386 12 2 11.7761 2 11.5V2.5Z" stroke="black" stroke-opacity="0.75" stroke-width="1.25" stroke-linejoin="round"/>
|
||||||
|
<path d="M4.60938 7.625L6.3125 8.89062L9.35938 4.64062" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 474 B |
5
assets/icons/terminal.svg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M1.65625 2.5C1.65625 2.22386 1.88011 2 2.15625 2H11.8437C12.1199 2 12.3438 2.22386 12.3438 2.5V11.5C12.3438 11.7761 12.1199 12 11.8437 12H2.15625C1.88011 12 1.65625 11.7761 1.65625 11.5V2.5Z" stroke="black" stroke-width="1.25"/>
|
||||||
|
<path d="M4.375 9L6.375 7L4.375 5" stroke="black" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M7.625 9L9.90625 9" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 549 B |
6
assets/icons/warning.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M2.45563 12.3438H11.5444C11.9137 12.3438 12.1556 11.9571 11.994 11.625L10.2346 8.00952C9.77174 7.05841 8.89104 6.37821 7.85383 6.17077C7.29019 6.05804 6.70981 6.05804 6.14617 6.17077C5.10896 6.37821 4.22826 7.05841 3.76542 8.00952L2.00603 11.625C1.84442 11.9571 2.08628 12.3438 2.45563 12.3438Z" fill="#001A33" fill-opacity="0.157"/>
|
||||||
|
<path d="M9.5 6.5L11.994 11.625C12.1556 11.9571 11.9137 12.3438 11.5444 12.3438H2.45563C2.08628 12.3438 1.84442 11.9571 2.00603 11.625L4.5 6.5" stroke="#11181C" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<path d="M7 7L7 2" stroke="#11181C" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
<circle cx="7" cy="9.24219" r="0.75" fill="#11181C"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 835 B |
8
assets/icons/word_search_12.svg
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="12px" height="12px" viewBox="0 0 12 12" version="1.1">
|
||||||
|
<g id="surface1">
|
||||||
|
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 4.070312 8.132812 L 3.488281 5.171875 L 2.902344 8.132812 L 1.867188 8.132812 L 0.859375 3.433594 L 1.949219 3.433594 L 2.414062 6.359375 L 2.988281 3.445312 L 3.992188 3.445312 L 4.558594 6.351562 L 5.019531 3.433594 L 6.113281 3.433594 L 5.105469 8.132812 Z M 4.070312 8.132812 "/>
|
||||||
|
<path style=" stroke:none;fill-rule:evenodd;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 7.414062 7.992188 C 7.125 7.828125 6.925781 7.558594 6.8125 7.207031 C 6.699219 6.859375 6.644531 6.378906 6.644531 5.773438 C 6.644531 5.175781 6.695312 4.699219 6.804688 4.359375 C 6.917969 4.007812 7.117188 3.738281 7.40625 3.582031 C 7.6875 3.421875 8.066406 3.351562 8.527344 3.351562 C 8.863281 3.351562 9.140625 3.390625 9.339844 3.484375 C 9.433594 3.527344 9.523438 3.589844 9.601562 3.667969 L 9.601562 1.738281 L 10.636719 1.738281 L 10.636719 8.128906 L 9.601562 8.128906 L 9.601562 7.878906 C 9.507812 7.964844 9.410156 8.03125 9.308594 8.082031 C 9.113281 8.175781 8.855469 8.214844 8.554688 8.214844 C 8.085938 8.214844 7.703125 8.144531 7.417969 7.992188 Z M 9.527344 6.734375 C 9.585938 6.515625 9.621094 6.199219 9.621094 5.773438 C 9.621094 5.355469 9.585938 5.042969 9.527344 4.832031 C 9.46875 4.628906 9.378906 4.507812 9.269531 4.441406 L 9.265625 4.4375 C 9.15625 4.367188 8.976562 4.316406 8.703125 4.316406 C 8.40625 4.316406 8.203125 4.367188 8.078125 4.441406 L 8.074219 4.445312 C 7.953125 4.511719 7.859375 4.632812 7.792969 4.835938 C 7.730469 5.042969 7.695312 5.355469 7.695312 5.773438 C 7.695312 6.199219 7.730469 6.511719 7.792969 6.71875 C 7.859375 6.921875 7.957031 7.050781 8.078125 7.121094 C 8.203125 7.199219 8.40625 7.246094 8.703125 7.246094 C 8.976562 7.246094 9.15625 7.203125 9.265625 7.132812 C 9.375 7.0625 9.46875 6.9375 9.527344 6.734375 Z M 9.527344 6.734375 "/>
|
||||||
|
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(47.058824%,49.019608%,52.941176%);fill-opacity:1;" d="M 1.519531 9.1875 L 10.480469 9.1875 C 10.777344 9.1875 11.023438 9.429688 11.023438 9.730469 C 11.023438 10.03125 10.777344 10.273438 10.480469 10.273438 L 1.519531 10.273438 C 1.222656 10.273438 0.976562 10.03125 0.976562 9.730469 C 0.976562 9.429688 1.222656 9.1875 1.519531 9.1875 Z M 1.519531 9.1875 "/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.5 KiB |
6
assets/icons/word_search_14.svg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.74672 9.48686L4.07031 6.03232L3.38584 9.48686H2.17614L1.00281 4.00781H2.27559L2.81566 7.41754L3.48439 4.01752H4.65865L5.31819 7.41176L5.85736 4.00781H7.13014L5.9568 9.48686H4.74672Z" fill="#787D87"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.64907 9.32382C8.313 9.13287 8.08213 8.81954 7.94725 8.4078C7.8147 8.00318 7.75317 7.44207 7.75317 6.73677C7.75317 6.03845 7.81141 5.48454 7.9369 5.08716L7.93755 5.08512C8.07231 4.67373 8.3034 4.36258 8.64088 4.17794C8.96806 3.99257 9.41119 3.9104 9.9496 3.9104C10.3406 3.9104 10.6632 3.95585 10.8967 4.06485C11.0079 4.11675 11.1099 4.18844 11.2033 4.27745V2.03027H12.4077V9.4856H11.2033V9.18983C11.0945 9.29074 10.98 9.37096 10.8591 9.42752C10.6327 9.53648 10.3335 9.58252 9.97867 9.58252C9.4339 9.58252 8.98592 9.50355 8.65375 9.3264L8.64907 9.32382ZM11.1139 7.85508C11.1841 7.60311 11.2227 7.23354 11.2227 6.73677C11.2227 6.24602 11.1841 5.88331 11.1141 5.63844C11.0457 5.39902 10.9401 5.25863 10.8149 5.18266L10.8077 5.17826C10.6804 5.09342 10.4713 5.03726 10.1531 5.03726C9.80785 5.03726 9.5719 5.09359 9.42256 5.1832L9.41829 5.18576C9.28002 5.26412 9.16722 5.40602 9.09399 5.64263C9.01876 5.88566 8.97694 6.24668 8.97694 6.73677C8.97694 7.23363 9.01882 7.59774 9.09399 7.8406C9.1673 8.07745 9.28097 8.22477 9.42256 8.30972C9.5719 8.39933 9.80785 8.45566 10.1531 8.45566C10.4721 8.45566 10.683 8.40265 10.8114 8.32216C10.9396 8.23944 11.0456 8.09373 11.1139 7.85508Z" fill="#787D87"/>
|
||||||
|
<rect x="1.14087" y="10.7188" width="11.7183" height="1.26565" rx="0.632824" fill="#787D87"/>
|
||||||
|
</svg>
|
||||||
|
|
After Width: | Height: | Size: 1.7 KiB |
3
assets/icons/x.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M9.82843 4.17157L4.17157 9.82842M9.82843 9.82842L4.17157 4.17157" stroke="black" stroke-width="1.25" stroke-linecap="round"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 238 B |
@ -13,6 +13,7 @@
|
|||||||
"cmd-up": "menu::SelectFirst",
|
"cmd-up": "menu::SelectFirst",
|
||||||
"cmd-down": "menu::SelectLast",
|
"cmd-down": "menu::SelectLast",
|
||||||
"enter": "menu::Confirm",
|
"enter": "menu::Confirm",
|
||||||
|
"ctrl-enter": "menu::ShowContextMenu",
|
||||||
"cmd-enter": "menu::SecondaryConfirm",
|
"cmd-enter": "menu::SecondaryConfirm",
|
||||||
"escape": "menu::Cancel",
|
"escape": "menu::Cancel",
|
||||||
"ctrl-c": "menu::Cancel",
|
"ctrl-c": "menu::Cancel",
|
||||||
@ -172,6 +173,7 @@
|
|||||||
"context": "Editor && mode == full",
|
"context": "Editor && mode == full",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"enter": "editor::Newline",
|
"enter": "editor::Newline",
|
||||||
|
"shift-enter": "editor::Newline",
|
||||||
"cmd-shift-enter": "editor::NewlineAbove",
|
"cmd-shift-enter": "editor::NewlineAbove",
|
||||||
"cmd-enter": "editor::NewlineBelow",
|
"cmd-enter": "editor::NewlineBelow",
|
||||||
"alt-z": "editor::ToggleSoftWrap",
|
"alt-z": "editor::ToggleSoftWrap",
|
||||||
@ -224,7 +226,8 @@
|
|||||||
"tab": "buffer_search::FocusEditor",
|
"tab": "buffer_search::FocusEditor",
|
||||||
"enter": "search::SelectNextMatch",
|
"enter": "search::SelectNextMatch",
|
||||||
"shift-enter": "search::SelectPrevMatch",
|
"shift-enter": "search::SelectPrevMatch",
|
||||||
"alt-enter": "search::SelectAllMatches"
|
"alt-enter": "search::SelectAllMatches",
|
||||||
|
"alt-tab": "search::CycleMode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -237,7 +240,8 @@
|
|||||||
{
|
{
|
||||||
"context": "ProjectSearchBar",
|
"context": "ProjectSearchBar",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"escape": "project_search::ToggleFocus"
|
"escape": "project_search::ToggleFocus",
|
||||||
|
"alt-tab": "search::CycleMode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -250,7 +254,8 @@
|
|||||||
{
|
{
|
||||||
"context": "ProjectSearchView",
|
"context": "ProjectSearchView",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"escape": "project_search::ToggleFocus"
|
"escape": "project_search::ToggleFocus",
|
||||||
|
"alt-tab": "search::CycleMode"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -262,7 +267,8 @@
|
|||||||
"alt-enter": "search::SelectAllMatches",
|
"alt-enter": "search::SelectAllMatches",
|
||||||
"alt-cmd-c": "search::ToggleCaseSensitive",
|
"alt-cmd-c": "search::ToggleCaseSensitive",
|
||||||
"alt-cmd-w": "search::ToggleWholeWord",
|
"alt-cmd-w": "search::ToggleWholeWord",
|
||||||
"alt-cmd-r": "search::ToggleRegex"
|
"alt-tab": "search::CycleMode",
|
||||||
|
"alt-cmd-f": "project_search::ToggleFilters"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Bindings from VS Code
|
// Bindings from VS Code
|
||||||
@ -513,8 +519,10 @@
|
|||||||
{
|
{
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"ctrl-alt-cmd-f": "workspace::FollowNextCollaborator",
|
"ctrl-alt-cmd-f": "workspace::FollowNextCollaborator",
|
||||||
"cmd-shift-c": "collab::ToggleContactsMenu",
|
// TODO: Move this to a dock open action
|
||||||
"cmd-alt-i": "zed::DebugElements"
|
"cmd-shift-c": "collab_panel::ToggleFocus",
|
||||||
|
"cmd-alt-i": "zed::DebugElements",
|
||||||
|
"ctrl-shift-:": "editor::ToggleInlayHints",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -522,7 +530,8 @@
|
|||||||
"bindings": {
|
"bindings": {
|
||||||
"alt-enter": "editor::OpenExcerpts",
|
"alt-enter": "editor::OpenExcerpts",
|
||||||
"cmd-f8": "editor::GoToHunk",
|
"cmd-f8": "editor::GoToHunk",
|
||||||
"cmd-shift-f8": "editor::GoToPrevHunk"
|
"cmd-shift-f8": "editor::GoToPrevHunk",
|
||||||
|
"ctrl-enter": "assistant::InlineAssist"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -536,6 +545,8 @@
|
|||||||
"bindings": {
|
"bindings": {
|
||||||
"left": "project_panel::CollapseSelectedEntry",
|
"left": "project_panel::CollapseSelectedEntry",
|
||||||
"right": "project_panel::ExpandSelectedEntry",
|
"right": "project_panel::ExpandSelectedEntry",
|
||||||
|
"cmd-n": "project_panel::NewFile",
|
||||||
|
"alt-cmd-n": "project_panel::NewDirectory",
|
||||||
"cmd-x": "project_panel::Cut",
|
"cmd-x": "project_panel::Cut",
|
||||||
"cmd-c": "project_panel::Copy",
|
"cmd-c": "project_panel::Copy",
|
||||||
"cmd-v": "project_panel::Paste",
|
"cmd-v": "project_panel::Paste",
|
||||||
@ -549,6 +560,25 @@
|
|||||||
"alt-shift-f": "project_panel::NewSearchInDirectory"
|
"alt-shift-f": "project_panel::NewSearchInDirectory"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"context": "CollabPanel",
|
||||||
|
"bindings": {
|
||||||
|
"ctrl-backspace": "collab_panel::Remove",
|
||||||
|
"space": "menu::Confirm"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"context": "ChannelModal",
|
||||||
|
"bindings": {
|
||||||
|
"tab": "channel_modal::ToggleMode"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"context": "ChannelModal > Picker > Editor",
|
||||||
|
"bindings": {
|
||||||
|
"tab": "channel_modal::ToggleMode"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"context": "Terminal",
|
"context": "Terminal",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
{
|
{
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"cmd-shift-o": "projects::OpenRecent",
|
"cmd-shift-o": "projects::OpenRecent",
|
||||||
"cmd-shift-b": "branches::OpenRecent",
|
|
||||||
"cmd-alt-tab": "project_panel::ToggleFocus"
|
"cmd-alt-tab": "project_panel::ToggleFocus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -12,8 +11,9 @@
|
|||||||
"cmd-l": "go_to_line::Toggle",
|
"cmd-l": "go_to_line::Toggle",
|
||||||
"ctrl-shift-d": "editor::DuplicateLine",
|
"ctrl-shift-d": "editor::DuplicateLine",
|
||||||
"cmd-b": "editor::GoToDefinition",
|
"cmd-b": "editor::GoToDefinition",
|
||||||
"alt-cmd-b": "editor::GoToDefinition",
|
|
||||||
"cmd-j": "editor::ScrollCursorCenter",
|
"cmd-j": "editor::ScrollCursorCenter",
|
||||||
|
"cmd-enter": "editor::NewlineBelow",
|
||||||
|
"cmd-alt-enter": "editor::NewLineAbove",
|
||||||
"cmd-shift-l": "editor::SelectLine",
|
"cmd-shift-l": "editor::SelectLine",
|
||||||
"cmd-shift-t": "outline::Toggle",
|
"cmd-shift-t": "outline::Toggle",
|
||||||
"alt-backspace": "editor::DeleteToPreviousWordStart",
|
"alt-backspace": "editor::DeleteToPreviousWordStart",
|
||||||
@ -51,14 +51,17 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ctrl-shift-left": "editor::SelectToPreviousSubwordStart",
|
"ctrl-shift-left": "editor::SelectToPreviousSubwordStart",
|
||||||
"ctrl-shift-right": "editor::SelectToNextSubwordEnd"
|
"ctrl-shift-right": "editor::SelectToNextSubwordEnd",
|
||||||
|
"ctrl-w": "editor::SelectNext",
|
||||||
|
"ctrl-u": "editor::ConvertToUpperCase",
|
||||||
|
"ctrl-shift-u": "editor::ConvertToLowerCase",
|
||||||
|
"ctrl-alt-u": "editor::ConvertToUpperCamelCase",
|
||||||
|
"ctrl-_": "editor::ConvertToSnakeCase"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "Editor && mode == full",
|
"context": "Editor && mode == full",
|
||||||
"bindings": {
|
"bindings": {}
|
||||||
"cmd-alt-enter": "editor::NewlineAbove"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "BufferSearchBar",
|
"context": "BufferSearchBar",
|
||||||
@ -85,5 +88,9 @@
|
|||||||
{
|
{
|
||||||
"context": "ProjectPanel",
|
"context": "ProjectPanel",
|
||||||
"bindings": {}
|
"bindings": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"context": "Dock",
|
||||||
|
"bindings": {}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -103,9 +103,19 @@
|
|||||||
],
|
],
|
||||||
"v": "vim::ToggleVisual",
|
"v": "vim::ToggleVisual",
|
||||||
"shift-v": "vim::ToggleVisualLine",
|
"shift-v": "vim::ToggleVisualLine",
|
||||||
|
"ctrl-v": "vim::ToggleVisualBlock",
|
||||||
|
"ctrl-q": "vim::ToggleVisualBlock",
|
||||||
"*": "vim::MoveToNext",
|
"*": "vim::MoveToNext",
|
||||||
"#": "vim::MoveToPrev",
|
"#": "vim::MoveToPrev",
|
||||||
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
"0": "vim::StartOfLine", // When no number operator present, use start of line motion
|
||||||
|
"ctrl-f": "vim::PageDown",
|
||||||
|
"pagedown": "vim::PageDown",
|
||||||
|
"ctrl-b": "vim::PageUp",
|
||||||
|
"pageup": "vim::PageUp",
|
||||||
|
"ctrl-d": "vim::ScrollDown",
|
||||||
|
"ctrl-u": "vim::ScrollUp",
|
||||||
|
"ctrl-e": "vim::LineDown",
|
||||||
|
"ctrl-y": "vim::LineUp",
|
||||||
// "g" commands
|
// "g" commands
|
||||||
"g g": "vim::StartOfDocument",
|
"g g": "vim::StartOfDocument",
|
||||||
"g h": "editor::Hover",
|
"g h": "editor::Hover",
|
||||||
@ -127,10 +137,67 @@
|
|||||||
"partialWord": true
|
"partialWord": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"g j": [
|
||||||
|
"vim::Down",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g down": [
|
||||||
|
"vim::Down",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g k": [
|
||||||
|
"vim::Up",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g up": [
|
||||||
|
"vim::Up",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g $": [
|
||||||
|
"vim::EndOfLine",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g end": [
|
||||||
|
"vim::EndOfLine",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g 0": [
|
||||||
|
"vim::StartOfLine",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g home": [
|
||||||
|
"vim::StartOfLine",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"g ^": [
|
||||||
|
"vim::FirstNonWhitespace",
|
||||||
|
{
|
||||||
|
"displayLines": true
|
||||||
|
}
|
||||||
|
],
|
||||||
// z commands
|
// z commands
|
||||||
"z t": "editor::ScrollCursorTop",
|
"z t": "editor::ScrollCursorTop",
|
||||||
"z z": "editor::ScrollCursorCenter",
|
"z z": "editor::ScrollCursorCenter",
|
||||||
"z b": "editor::ScrollCursorBottom",
|
"z b": "editor::ScrollCursorBottom",
|
||||||
|
"z c": "editor::Fold",
|
||||||
|
"z o": "editor::UnfoldLines",
|
||||||
|
"z f": "editor::FoldSelectedRanges",
|
||||||
// Count support
|
// Count support
|
||||||
"1": [
|
"1": [
|
||||||
"vim::Number",
|
"vim::Number",
|
||||||
@ -277,6 +344,12 @@
|
|||||||
"shift-o": "vim::InsertLineAbove",
|
"shift-o": "vim::InsertLineAbove",
|
||||||
"~": "vim::ChangeCase",
|
"~": "vim::ChangeCase",
|
||||||
"p": "vim::Paste",
|
"p": "vim::Paste",
|
||||||
|
"shift-p": [
|
||||||
|
"vim::Paste",
|
||||||
|
{
|
||||||
|
"before": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"u": "editor::Undo",
|
"u": "editor::Undo",
|
||||||
"ctrl-r": "editor::Redo",
|
"ctrl-r": "editor::Redo",
|
||||||
"/": "vim::Search",
|
"/": "vim::Search",
|
||||||
@ -293,14 +366,6 @@
|
|||||||
"backwards": true
|
"backwards": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ctrl-f": "vim::PageDown",
|
|
||||||
"pagedown": "vim::PageDown",
|
|
||||||
"ctrl-b": "vim::PageUp",
|
|
||||||
"pageup": "vim::PageUp",
|
|
||||||
"ctrl-d": "vim::ScrollDown",
|
|
||||||
"ctrl-u": "vim::ScrollUp",
|
|
||||||
"ctrl-e": "vim::LineDown",
|
|
||||||
"ctrl-y": "vim::LineUp",
|
|
||||||
"r": [
|
"r": [
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
"Replace"
|
"Replace"
|
||||||
@ -365,7 +430,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "Editor && vim_mode == visual && !VimWaiting",
|
"context": "Editor && vim_mode == visual && !VimWaiting && !VimObject",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"u": "editor::Undo",
|
"u": "editor::Undo",
|
||||||
"o": "vim::OtherEnd",
|
"o": "vim::OtherEnd",
|
||||||
@ -373,10 +438,21 @@
|
|||||||
"d": "vim::VisualDelete",
|
"d": "vim::VisualDelete",
|
||||||
"x": "vim::VisualDelete",
|
"x": "vim::VisualDelete",
|
||||||
"y": "vim::VisualYank",
|
"y": "vim::VisualYank",
|
||||||
"p": "vim::VisualPaste",
|
"p": "vim::Paste",
|
||||||
|
"shift-p": [
|
||||||
|
"vim::Paste",
|
||||||
|
{
|
||||||
|
"preserveClipboard": true
|
||||||
|
}
|
||||||
|
],
|
||||||
"s": "vim::Substitute",
|
"s": "vim::Substitute",
|
||||||
"c": "vim::Substitute",
|
"c": "vim::Substitute",
|
||||||
"~": "vim::ChangeCase",
|
"~": "vim::ChangeCase",
|
||||||
|
"shift-i": [
|
||||||
|
"vim::SwitchMode",
|
||||||
|
"Insert"
|
||||||
|
],
|
||||||
|
"shift-a": "vim::InsertAfter",
|
||||||
"r": [
|
"r": [
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
"Replace"
|
"Replace"
|
||||||
@ -394,11 +470,27 @@
|
|||||||
"Normal"
|
"Normal"
|
||||||
],
|
],
|
||||||
">": "editor::Indent",
|
">": "editor::Indent",
|
||||||
"<": "editor::Outdent"
|
"<": "editor::Outdent",
|
||||||
|
"i": [
|
||||||
|
"vim::PushOperator",
|
||||||
|
{
|
||||||
|
"Object": {
|
||||||
|
"around": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"a": [
|
||||||
|
"vim::PushOperator",
|
||||||
|
{
|
||||||
|
"Object": {
|
||||||
|
"around": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"context": "Editor && vim_mode == insert",
|
"context": "Editor && vim_mode == insert && !menu",
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"escape": "vim::NormalBefore",
|
"escape": "vim::NormalBefore",
|
||||||
"ctrl-c": "vim::NormalBefore",
|
"ctrl-c": "vim::NormalBefore",
|
||||||
|
@ -98,6 +98,7 @@
|
|||||||
// Whether to show selections in the scrollbar.
|
// Whether to show selections in the scrollbar.
|
||||||
"selections": true
|
"selections": true
|
||||||
},
|
},
|
||||||
|
"relative_line_numbers": false,
|
||||||
// Inlay hint related settings
|
// Inlay hint related settings
|
||||||
"inlay_hints": {
|
"inlay_hints": {
|
||||||
// Global switch to toggle hints on and off, switched off by default.
|
// Global switch to toggle hints on and off, switched off by default.
|
||||||
@ -122,13 +123,29 @@
|
|||||||
// Amount of indentation for nested items.
|
// Amount of indentation for nested items.
|
||||||
"indent_size": 20
|
"indent_size": 20
|
||||||
},
|
},
|
||||||
|
"collaboration_panel": {
|
||||||
|
// Whether to show the collaboration panel button in the status bar.
|
||||||
|
"button": true,
|
||||||
|
// Where to dock channels panel. Can be 'left' or 'right'.
|
||||||
|
"dock": "left",
|
||||||
|
// Default width of the channels panel.
|
||||||
|
"default_width": 240
|
||||||
|
},
|
||||||
"assistant": {
|
"assistant": {
|
||||||
|
// Whether to show the assistant panel button in the status bar.
|
||||||
|
"button": true,
|
||||||
// Where to dock the assistant. Can be 'left', 'right' or 'bottom'.
|
// Where to dock the assistant. Can be 'left', 'right' or 'bottom'.
|
||||||
"dock": "right",
|
"dock": "right",
|
||||||
// Default width when the assistant is docked to the left or right.
|
// Default width when the assistant is docked to the left or right.
|
||||||
"default_width": 640,
|
"default_width": 640,
|
||||||
// Default height when the assistant is docked to the bottom.
|
// Default height when the assistant is docked to the bottom.
|
||||||
"default_height": 320
|
"default_height": 320,
|
||||||
|
// The default OpenAI model to use when starting new conversations. This
|
||||||
|
// setting can take two values:
|
||||||
|
//
|
||||||
|
// 1. "gpt-3.5-turbo-0613""
|
||||||
|
// 2. "gpt-4-0613""
|
||||||
|
"default_open_ai_model": "gpt-4-0613"
|
||||||
},
|
},
|
||||||
// Whether the screen sharing icon is shown in the os status bar.
|
// Whether the screen sharing icon is shown in the os status bar.
|
||||||
"show_call_status_icon": true,
|
"show_call_status_icon": true,
|
||||||
@ -268,8 +285,6 @@
|
|||||||
// "directory": "~/zed/projects/"
|
// "directory": "~/zed/projects/"
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
//
|
|
||||||
"working_directory": "current_project_directory",
|
"working_directory": "current_project_directory",
|
||||||
// Set the cursor blinking behavior in the terminal.
|
// Set the cursor blinking behavior in the terminal.
|
||||||
// May take 4 values:
|
// May take 4 values:
|
||||||
@ -318,13 +333,32 @@
|
|||||||
// "line_height": {
|
// "line_height": {
|
||||||
// "custom": 2
|
// "custom": 2
|
||||||
// },
|
// },
|
||||||
"line_height": "comfortable"
|
"line_height": "comfortable",
|
||||||
|
// Activate the python virtual environment, if one is found, in the
|
||||||
|
// terminal's working directory (as resolved by the working_directory
|
||||||
|
// setting). Set this to "off" to disable this behavior.
|
||||||
|
"detect_venv": {
|
||||||
|
"on": {
|
||||||
|
// Default directories to search for virtual environments, relative
|
||||||
|
// to the current working directory. We recommend overriding this
|
||||||
|
// in your project's settings, rather than globally.
|
||||||
|
"directories": [
|
||||||
|
".env",
|
||||||
|
"env",
|
||||||
|
".venv",
|
||||||
|
"venv"
|
||||||
|
],
|
||||||
|
// Can also be 'csh' and 'fish'
|
||||||
|
"activate_script": "default"
|
||||||
|
}
|
||||||
|
}
|
||||||
// Set the terminal's font size. If this option is not included,
|
// Set the terminal's font size. If this option is not included,
|
||||||
// the terminal will default to matching the buffer's font size.
|
// the terminal will default to matching the buffer's font size.
|
||||||
// "font_size": "15"
|
// "font_size": "15",
|
||||||
// Set the terminal's font family. If this option is not included,
|
// Set the terminal's font family. If this option is not included,
|
||||||
// the terminal will default to matching the buffer's font family.
|
// the terminal will default to matching the buffer's font family.
|
||||||
// "font_family": "Zed Mono"
|
// "font_family": "Zed Mono",
|
||||||
|
// ---
|
||||||
},
|
},
|
||||||
// Difference settings for semantic_index
|
// Difference settings for semantic_index
|
||||||
"semantic_index": {
|
"semantic_index": {
|
||||||
|
@ -24,7 +24,9 @@ workspace = { path = "../workspace" }
|
|||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
|
indoc.workspace = true
|
||||||
isahc.workspace = true
|
isahc.workspace = true
|
||||||
|
ordered-float.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
@ -35,3 +37,8 @@ tiktoken-rs = "0.4"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
editor = { path = "../editor", features = ["test-support"] }
|
editor = { path = "../editor", features = ["test-support"] }
|
||||||
project = { path = "../project", features = ["test-support"] }
|
project = { path = "../project", features = ["test-support"] }
|
||||||
|
|
||||||
|
ctor.workspace = true
|
||||||
|
env_logger.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
rand.workspace = true
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
pub mod assistant;
|
pub mod assistant;
|
||||||
mod assistant_settings;
|
mod assistant_settings;
|
||||||
|
mod streaming_diff;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{anyhow, Result};
|
||||||
pub use assistant::AssistantPanel;
|
pub use assistant::AssistantPanel;
|
||||||
|
use assistant_settings::OpenAIModel;
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
use fs::Fs;
|
use fs::Fs;
|
||||||
use futures::StreamExt;
|
use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt};
|
||||||
use gpui::AppContext;
|
use gpui::{executor::Background, AppContext};
|
||||||
|
use isahc::{http::StatusCode, Request, RequestExt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Reverse,
|
cmp::Reverse,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
|
io,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use util::paths::CONVERSATIONS_DIR;
|
use util::paths::CONVERSATIONS_DIR;
|
||||||
|
|
||||||
|
const OPENAI_API_URL: &'static str = "https://api.openai.com/v1";
|
||||||
|
|
||||||
// Data types for chat completion requests
|
// Data types for chat completion requests
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct OpenAIRequest {
|
pub struct OpenAIRequest {
|
||||||
model: String,
|
model: String,
|
||||||
messages: Vec<RequestMessage>,
|
messages: Vec<RequestMessage>,
|
||||||
stream: bool,
|
stream: bool,
|
||||||
@ -60,7 +66,7 @@ struct SavedConversation {
|
|||||||
messages: Vec<SavedMessage>,
|
messages: Vec<SavedMessage>,
|
||||||
message_metadata: HashMap<MessageId, MessageMetadata>,
|
message_metadata: HashMap<MessageId, MessageMetadata>,
|
||||||
summary: String,
|
summary: String,
|
||||||
model: String,
|
model: OpenAIModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SavedConversation {
|
impl SavedConversation {
|
||||||
@ -115,7 +121,7 @@ struct RequestMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
|
||||||
struct ResponseMessage {
|
pub struct ResponseMessage {
|
||||||
role: Option<Role>,
|
role: Option<Role>,
|
||||||
content: Option<String>,
|
content: Option<String>,
|
||||||
}
|
}
|
||||||
@ -149,7 +155,7 @@ impl Display for Role {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct OpenAIResponseStreamEvent {
|
pub struct OpenAIResponseStreamEvent {
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
pub object: String,
|
pub object: String,
|
||||||
pub created: u32,
|
pub created: u32,
|
||||||
@ -159,14 +165,14 @@ struct OpenAIResponseStreamEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Usage {
|
pub struct Usage {
|
||||||
pub prompt_tokens: u32,
|
pub prompt_tokens: u32,
|
||||||
pub completion_tokens: u32,
|
pub completion_tokens: u32,
|
||||||
pub total_tokens: u32,
|
pub total_tokens: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct ChatChoiceDelta {
|
pub struct ChatChoiceDelta {
|
||||||
pub index: u32,
|
pub index: u32,
|
||||||
pub delta: ResponseMessage,
|
pub delta: ResponseMessage,
|
||||||
pub finish_reason: Option<String>,
|
pub finish_reason: Option<String>,
|
||||||
@ -190,3 +196,97 @@ struct OpenAIChoice {
|
|||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
assistant::init(cx);
|
assistant::init(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn stream_completion(
|
||||||
|
api_key: String,
|
||||||
|
executor: Arc<Background>,
|
||||||
|
mut request: OpenAIRequest,
|
||||||
|
) -> Result<impl Stream<Item = Result<OpenAIResponseStreamEvent>>> {
|
||||||
|
request.stream = true;
|
||||||
|
|
||||||
|
let (tx, rx) = futures::channel::mpsc::unbounded::<Result<OpenAIResponseStreamEvent>>();
|
||||||
|
|
||||||
|
let json_data = serde_json::to_string(&request)?;
|
||||||
|
let mut response = Request::post(format!("{OPENAI_API_URL}/chat/completions"))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("Authorization", format!("Bearer {}", api_key))
|
||||||
|
.body(json_data)?
|
||||||
|
.send_async()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let status = response.status();
|
||||||
|
if status == StatusCode::OK {
|
||||||
|
executor
|
||||||
|
.spawn(async move {
|
||||||
|
let mut lines = BufReader::new(response.body_mut()).lines();
|
||||||
|
|
||||||
|
fn parse_line(
|
||||||
|
line: Result<String, io::Error>,
|
||||||
|
) -> Result<Option<OpenAIResponseStreamEvent>> {
|
||||||
|
if let Some(data) = line?.strip_prefix("data: ") {
|
||||||
|
let event = serde_json::from_str(&data)?;
|
||||||
|
Ok(Some(event))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while let Some(line) = lines.next().await {
|
||||||
|
if let Some(event) = parse_line(line).transpose() {
|
||||||
|
let done = event.as_ref().map_or(false, |event| {
|
||||||
|
event
|
||||||
|
.choices
|
||||||
|
.last()
|
||||||
|
.map_or(false, |choice| choice.finish_reason.is_some())
|
||||||
|
});
|
||||||
|
if tx.unbounded_send(event).is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if done {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
anyhow::Ok(())
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
Ok(rx)
|
||||||
|
} else {
|
||||||
|
let mut body = String::new();
|
||||||
|
response.body_mut().read_to_string(&mut body).await?;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct OpenAIResponse {
|
||||||
|
error: OpenAIError,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct OpenAIError {
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
match serde_json::from_str::<OpenAIResponse>(&body) {
|
||||||
|
Ok(response) if !response.error.message.is_empty() => Err(anyhow!(
|
||||||
|
"Failed to connect to OpenAI API: {}",
|
||||||
|
response.error.message,
|
||||||
|
)),
|
||||||
|
|
||||||
|
_ => Err(anyhow!(
|
||||||
|
"Failed to connect to OpenAI API: {} {}",
|
||||||
|
response.status(),
|
||||||
|
body,
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[ctor::ctor]
|
||||||
|
fn init_logger() {
|
||||||
|
if std::env::var("RUST_LOG").is_ok() {
|
||||||
|
env_logger::init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,6 +3,37 @@ use schemars::JsonSchema;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use settings::Setting;
|
use settings::Setting;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||||
|
pub enum OpenAIModel {
|
||||||
|
#[serde(rename = "gpt-3.5-turbo-0613")]
|
||||||
|
ThreePointFiveTurbo,
|
||||||
|
#[serde(rename = "gpt-4-0613")]
|
||||||
|
Four,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OpenAIModel {
|
||||||
|
pub fn full_name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo-0613",
|
||||||
|
OpenAIModel::Four => "gpt-4-0613",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn short_name(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo",
|
||||||
|
OpenAIModel::Four => "gpt-4",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cycle(&self) -> Self {
|
||||||
|
match self {
|
||||||
|
OpenAIModel::ThreePointFiveTurbo => OpenAIModel::Four,
|
||||||
|
OpenAIModel::Four => OpenAIModel::ThreePointFiveTurbo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum AssistantDockPosition {
|
pub enum AssistantDockPosition {
|
||||||
@ -13,16 +44,20 @@ pub enum AssistantDockPosition {
|
|||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct AssistantSettings {
|
pub struct AssistantSettings {
|
||||||
|
pub button: bool,
|
||||||
pub dock: AssistantDockPosition,
|
pub dock: AssistantDockPosition,
|
||||||
pub default_width: f32,
|
pub default_width: f32,
|
||||||
pub default_height: f32,
|
pub default_height: f32,
|
||||||
|
pub default_open_ai_model: OpenAIModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
|
||||||
pub struct AssistantSettingsContent {
|
pub struct AssistantSettingsContent {
|
||||||
|
pub button: Option<bool>,
|
||||||
pub dock: Option<AssistantDockPosition>,
|
pub dock: Option<AssistantDockPosition>,
|
||||||
pub default_width: Option<f32>,
|
pub default_width: Option<f32>,
|
||||||
pub default_height: Option<f32>,
|
pub default_height: Option<f32>,
|
||||||
|
pub default_open_ai_model: Option<OpenAIModel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Setting for AssistantSettings {
|
impl Setting for AssistantSettings {
|
||||||
|
293
crates/ai/src/streaming_diff.rs
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
use collections::HashMap;
|
||||||
|
use ordered_float::OrderedFloat;
|
||||||
|
use std::{
|
||||||
|
cmp,
|
||||||
|
fmt::{self, Debug},
|
||||||
|
ops::Range,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Matrix {
|
||||||
|
cells: Vec<f64>,
|
||||||
|
rows: usize,
|
||||||
|
cols: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Matrix {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
cells: Vec::new(),
|
||||||
|
rows: 0,
|
||||||
|
cols: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resize(&mut self, rows: usize, cols: usize) {
|
||||||
|
self.cells.resize(rows * cols, 0.);
|
||||||
|
self.rows = rows;
|
||||||
|
self.cols = cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get(&self, row: usize, col: usize) -> f64 {
|
||||||
|
if row >= self.rows {
|
||||||
|
panic!("row out of bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
if col >= self.cols {
|
||||||
|
panic!("col out of bounds")
|
||||||
|
}
|
||||||
|
self.cells[col * self.rows + row]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set(&mut self, row: usize, col: usize, value: f64) {
|
||||||
|
if row >= self.rows {
|
||||||
|
panic!("row out of bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
if col >= self.cols {
|
||||||
|
panic!("col out of bounds")
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cells[col * self.rows + row] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Debug for Matrix {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
writeln!(f)?;
|
||||||
|
for i in 0..self.rows {
|
||||||
|
for j in 0..self.cols {
|
||||||
|
write!(f, "{:5}", self.get(i, j))?;
|
||||||
|
}
|
||||||
|
writeln!(f)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Hunk {
|
||||||
|
Insert { text: String },
|
||||||
|
Remove { len: usize },
|
||||||
|
Keep { len: usize },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct StreamingDiff {
|
||||||
|
old: Vec<char>,
|
||||||
|
new: Vec<char>,
|
||||||
|
scores: Matrix,
|
||||||
|
old_text_ix: usize,
|
||||||
|
new_text_ix: usize,
|
||||||
|
equal_runs: HashMap<(usize, usize), u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl StreamingDiff {
|
||||||
|
const INSERTION_SCORE: f64 = -1.;
|
||||||
|
const DELETION_SCORE: f64 = -20.;
|
||||||
|
const EQUALITY_BASE: f64 = 1.8;
|
||||||
|
const MAX_EQUALITY_EXPONENT: i32 = 16;
|
||||||
|
|
||||||
|
pub fn new(old: String) -> Self {
|
||||||
|
let old = old.chars().collect::<Vec<_>>();
|
||||||
|
let mut scores = Matrix::new();
|
||||||
|
scores.resize(old.len() + 1, 1);
|
||||||
|
for i in 0..=old.len() {
|
||||||
|
scores.set(i, 0, i as f64 * Self::DELETION_SCORE);
|
||||||
|
}
|
||||||
|
Self {
|
||||||
|
old,
|
||||||
|
new: Vec::new(),
|
||||||
|
scores,
|
||||||
|
old_text_ix: 0,
|
||||||
|
new_text_ix: 0,
|
||||||
|
equal_runs: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn push_new(&mut self, text: &str) -> Vec<Hunk> {
|
||||||
|
self.new.extend(text.chars());
|
||||||
|
self.scores.resize(self.old.len() + 1, self.new.len() + 1);
|
||||||
|
|
||||||
|
for j in self.new_text_ix + 1..=self.new.len() {
|
||||||
|
self.scores.set(0, j, j as f64 * Self::INSERTION_SCORE);
|
||||||
|
for i in 1..=self.old.len() {
|
||||||
|
let insertion_score = self.scores.get(i, j - 1) + Self::INSERTION_SCORE;
|
||||||
|
let deletion_score = self.scores.get(i - 1, j) + Self::DELETION_SCORE;
|
||||||
|
let equality_score = if self.old[i - 1] == self.new[j - 1] {
|
||||||
|
let mut equal_run = self.equal_runs.get(&(i - 1, j - 1)).copied().unwrap_or(0);
|
||||||
|
equal_run += 1;
|
||||||
|
self.equal_runs.insert((i, j), equal_run);
|
||||||
|
|
||||||
|
let exponent = cmp::min(equal_run as i32 / 4, Self::MAX_EQUALITY_EXPONENT);
|
||||||
|
self.scores.get(i - 1, j - 1) + Self::EQUALITY_BASE.powi(exponent)
|
||||||
|
} else {
|
||||||
|
f64::NEG_INFINITY
|
||||||
|
};
|
||||||
|
|
||||||
|
let score = insertion_score.max(deletion_score).max(equality_score);
|
||||||
|
self.scores.set(i, j, score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut max_score = f64::NEG_INFINITY;
|
||||||
|
let mut next_old_text_ix = self.old_text_ix;
|
||||||
|
let next_new_text_ix = self.new.len();
|
||||||
|
for i in self.old_text_ix..=self.old.len() {
|
||||||
|
let score = self.scores.get(i, next_new_text_ix);
|
||||||
|
if score > max_score {
|
||||||
|
max_score = score;
|
||||||
|
next_old_text_ix = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let hunks = self.backtrack(next_old_text_ix, next_new_text_ix);
|
||||||
|
self.old_text_ix = next_old_text_ix;
|
||||||
|
self.new_text_ix = next_new_text_ix;
|
||||||
|
hunks
|
||||||
|
}
|
||||||
|
|
||||||
|
fn backtrack(&self, old_text_ix: usize, new_text_ix: usize) -> Vec<Hunk> {
|
||||||
|
let mut pending_insert: Option<Range<usize>> = None;
|
||||||
|
let mut hunks = Vec::new();
|
||||||
|
let mut i = old_text_ix;
|
||||||
|
let mut j = new_text_ix;
|
||||||
|
while (i, j) != (self.old_text_ix, self.new_text_ix) {
|
||||||
|
let insertion_score = if j > self.new_text_ix {
|
||||||
|
Some((i, j - 1))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let deletion_score = if i > self.old_text_ix {
|
||||||
|
Some((i - 1, j))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let equality_score = if i > self.old_text_ix && j > self.new_text_ix {
|
||||||
|
if self.old[i - 1] == self.new[j - 1] {
|
||||||
|
Some((i - 1, j - 1))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let (prev_i, prev_j) = [insertion_score, deletion_score, equality_score]
|
||||||
|
.iter()
|
||||||
|
.max_by_key(|cell| cell.map(|(i, j)| OrderedFloat(self.scores.get(i, j))))
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if prev_i == i && prev_j == j - 1 {
|
||||||
|
if let Some(pending_insert) = pending_insert.as_mut() {
|
||||||
|
pending_insert.start = prev_j;
|
||||||
|
} else {
|
||||||
|
pending_insert = Some(prev_j..j);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(range) = pending_insert.take() {
|
||||||
|
hunks.push(Hunk::Insert {
|
||||||
|
text: self.new[range].iter().collect(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let char_len = self.old[i - 1].len_utf8();
|
||||||
|
if prev_i == i - 1 && prev_j == j {
|
||||||
|
if let Some(Hunk::Remove { len }) = hunks.last_mut() {
|
||||||
|
*len += char_len;
|
||||||
|
} else {
|
||||||
|
hunks.push(Hunk::Remove { len: char_len })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some(Hunk::Keep { len }) = hunks.last_mut() {
|
||||||
|
*len += char_len;
|
||||||
|
} else {
|
||||||
|
hunks.push(Hunk::Keep { len: char_len })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i = prev_i;
|
||||||
|
j = prev_j;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(range) = pending_insert.take() {
|
||||||
|
hunks.push(Hunk::Insert {
|
||||||
|
text: self.new[range].iter().collect(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
hunks.reverse();
|
||||||
|
hunks
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn finish(self) -> Vec<Hunk> {
|
||||||
|
self.backtrack(self.old.len(), self.new.len())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use rand::prelude::*;
|
||||||
|
|
||||||
|
#[gpui::test(iterations = 100)]
|
||||||
|
fn test_random_diffs(mut rng: StdRng) {
|
||||||
|
let old_text_len = env::var("OLD_TEXT_LEN")
|
||||||
|
.map(|i| i.parse().expect("invalid `OLD_TEXT_LEN` variable"))
|
||||||
|
.unwrap_or(10);
|
||||||
|
let new_text_len = env::var("NEW_TEXT_LEN")
|
||||||
|
.map(|i| i.parse().expect("invalid `NEW_TEXT_LEN` variable"))
|
||||||
|
.unwrap_or(10);
|
||||||
|
|
||||||
|
let old = util::RandomCharIter::new(&mut rng)
|
||||||
|
.take(old_text_len)
|
||||||
|
.collect::<String>();
|
||||||
|
log::info!("old text: {:?}", old);
|
||||||
|
|
||||||
|
let mut diff = StreamingDiff::new(old.clone());
|
||||||
|
let mut hunks = Vec::new();
|
||||||
|
let mut new_len = 0;
|
||||||
|
let mut new = String::new();
|
||||||
|
while new_len < new_text_len {
|
||||||
|
let new_chunk_len = rng.gen_range(1..=new_text_len - new_len);
|
||||||
|
let new_chunk = util::RandomCharIter::new(&mut rng)
|
||||||
|
.take(new_len)
|
||||||
|
.collect::<String>();
|
||||||
|
log::info!("new chunk: {:?}", new_chunk);
|
||||||
|
new_len += new_chunk_len;
|
||||||
|
new.push_str(&new_chunk);
|
||||||
|
let new_hunks = diff.push_new(&new_chunk);
|
||||||
|
log::info!("hunks: {:?}", new_hunks);
|
||||||
|
hunks.extend(new_hunks);
|
||||||
|
}
|
||||||
|
let final_hunks = diff.finish();
|
||||||
|
log::info!("final hunks: {:?}", final_hunks);
|
||||||
|
hunks.extend(final_hunks);
|
||||||
|
|
||||||
|
log::info!("new text: {:?}", new);
|
||||||
|
let mut old_ix = 0;
|
||||||
|
let mut new_ix = 0;
|
||||||
|
let mut patched = String::new();
|
||||||
|
for hunk in hunks {
|
||||||
|
match hunk {
|
||||||
|
Hunk::Keep { len } => {
|
||||||
|
assert_eq!(&old[old_ix..old_ix + len], &new[new_ix..new_ix + len]);
|
||||||
|
patched.push_str(&old[old_ix..old_ix + len]);
|
||||||
|
old_ix += len;
|
||||||
|
new_ix += len;
|
||||||
|
}
|
||||||
|
Hunk::Remove { len } => {
|
||||||
|
old_ix += len;
|
||||||
|
}
|
||||||
|
Hunk::Insert { text } => {
|
||||||
|
assert_eq!(text, &new[new_ix..new_ix + text.len()]);
|
||||||
|
patched.push_str(&text);
|
||||||
|
new_ix += text.len();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!(patched, new);
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ gpui = { path = "../gpui" }
|
|||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
|
|
||||||
rodio = "0.17.1"
|
rodio ={version = "0.17.1", default-features=false, features = ["wav"]}
|
||||||
|
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|
||||||
|
@ -39,29 +39,43 @@ pub struct Audio {
|
|||||||
|
|
||||||
impl Audio {
|
impl Audio {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let (_output_stream, output_handle) = OutputStream::try_default().log_err().unzip();
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
_output_stream,
|
_output_stream: None,
|
||||||
output_handle,
|
output_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_sound(sound: Sound, cx: &AppContext) {
|
fn ensure_output_exists(&mut self) -> Option<&OutputStreamHandle> {
|
||||||
|
if self.output_handle.is_none() {
|
||||||
|
let (_output_stream, output_handle) = OutputStream::try_default().log_err().unzip();
|
||||||
|
self.output_handle = output_handle;
|
||||||
|
self._output_stream = _output_stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.output_handle.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn play_sound(sound: Sound, cx: &mut AppContext) {
|
||||||
if !cx.has_global::<Self>() {
|
if !cx.has_global::<Self>() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let this = cx.global::<Self>();
|
cx.update_global::<Self, _, _>(|this, cx| {
|
||||||
|
let output_handle = this.ensure_output_exists()?;
|
||||||
|
let source = SoundRegistry::global(cx).get(sound.file()).log_err()?;
|
||||||
|
output_handle.play_raw(source).log_err()?;
|
||||||
|
Some(())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let Some(output_handle) = this.output_handle.as_ref() else {
|
pub fn end_call(cx: &mut AppContext) {
|
||||||
|
if !cx.has_global::<Self>() {
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
let Some(source) = SoundRegistry::global(cx).get(sound.file()).log_err() else {
|
cx.update_global::<Self, _, _>(|this, _| {
|
||||||
return;
|
this._output_stream.take();
|
||||||
};
|
this.output_handle.take();
|
||||||
|
});
|
||||||
output_handle.play_raw(source).log_err();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ impl View for Breadcrumbs {
|
|||||||
let not_editor = active_item.downcast::<editor::Editor>().is_none();
|
let not_editor = active_item.downcast::<editor::Editor>().is_none();
|
||||||
|
|
||||||
let theme = theme::current(cx).clone();
|
let theme = theme::current(cx).clone();
|
||||||
let style = &theme.workspace.breadcrumbs;
|
let style = &theme.workspace.toolbar.breadcrumbs;
|
||||||
|
|
||||||
let breadcrumbs = match active_item.breadcrumbs(&theme, cx) {
|
let breadcrumbs = match active_item.breadcrumbs(&theme, cx) {
|
||||||
Some(breadcrumbs) => breadcrumbs,
|
Some(breadcrumbs) => breadcrumbs,
|
||||||
@ -60,7 +60,7 @@ impl View for Breadcrumbs {
|
|||||||
.map(|breadcrumb| {
|
.map(|breadcrumb| {
|
||||||
Text::new(
|
Text::new(
|
||||||
breadcrumb.text,
|
breadcrumb.text,
|
||||||
theme.workspace.breadcrumbs.default.text.clone(),
|
theme.workspace.toolbar.breadcrumbs.default.text.clone(),
|
||||||
)
|
)
|
||||||
.with_highlights(breadcrumb.highlights.unwrap_or_default())
|
.with_highlights(breadcrumb.highlights.unwrap_or_default())
|
||||||
.into_any()
|
.into_any()
|
||||||
@ -68,10 +68,10 @@ impl View for Breadcrumbs {
|
|||||||
|
|
||||||
let crumbs = Flex::row()
|
let crumbs = Flex::row()
|
||||||
.with_children(Itertools::intersperse_with(breadcrumbs, || {
|
.with_children(Itertools::intersperse_with(breadcrumbs, || {
|
||||||
Label::new(" 〉 ", style.default.text.clone()).into_any()
|
Label::new(" › ", style.default.text.clone()).into_any()
|
||||||
}))
|
}))
|
||||||
.constrained()
|
.constrained()
|
||||||
.with_height(theme.workspace.breadcrumb_height)
|
.with_height(theme.workspace.toolbar.breadcrumb_height)
|
||||||
.contained();
|
.contained();
|
||||||
|
|
||||||
if not_editor || !self.pane_focused {
|
if not_editor || !self.pane_focused {
|
||||||
|
@ -20,6 +20,7 @@ test-support = [
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
audio = { path = "../audio" }
|
audio = { path = "../audio" }
|
||||||
|
channel = { path = "../channel" }
|
||||||
client = { path = "../client" }
|
client = { path = "../client" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
|
@ -5,7 +5,9 @@ pub mod room;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use audio::Audio;
|
||||||
use call_settings::CallSettings;
|
use call_settings::CallSettings;
|
||||||
|
use channel::ChannelId;
|
||||||
use client::{proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore};
|
use client::{proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore};
|
||||||
use collections::HashSet;
|
use collections::HashSet;
|
||||||
use futures::{future::Shared, FutureExt};
|
use futures::{future::Shared, FutureExt};
|
||||||
@ -75,6 +77,10 @@ impl ActiveCall {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn channel_id(&self, cx: &AppContext) -> Option<ChannelId> {
|
||||||
|
self.room()?.read(cx).channel_id()
|
||||||
|
}
|
||||||
|
|
||||||
async fn handle_incoming_call(
|
async fn handle_incoming_call(
|
||||||
this: ModelHandle<Self>,
|
this: ModelHandle<Self>,
|
||||||
envelope: TypedEnvelope<proto::IncomingCall>,
|
envelope: TypedEnvelope<proto::IncomingCall>,
|
||||||
@ -267,16 +273,43 @@ impl ActiveCall {
|
|||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.take()
|
.take()
|
||||||
.ok_or_else(|| anyhow!("no incoming call"))?;
|
.ok_or_else(|| anyhow!("no incoming call"))?;
|
||||||
Self::report_call_event_for_room("decline incoming", call.room_id, &self.client, cx);
|
Self::report_call_event_for_room("decline incoming", call.room_id, None, &self.client, cx);
|
||||||
self.client.send(proto::DeclineCall {
|
self.client.send(proto::DeclineCall {
|
||||||
room_id: call.room_id,
|
room_id: call.room_id,
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn join_channel(
|
||||||
|
&mut self,
|
||||||
|
channel_id: u64,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
if let Some(room) = self.room().cloned() {
|
||||||
|
if room.read(cx).channel_id() == Some(channel_id) {
|
||||||
|
return Task::ready(Ok(()));
|
||||||
|
} else {
|
||||||
|
room.update(cx, |room, cx| room.clear_state(cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let join = Room::join_channel(channel_id, self.client.clone(), self.user_store.clone(), cx);
|
||||||
|
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let room = join.await?;
|
||||||
|
this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx))
|
||||||
|
.await?;
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.report_call_event("join channel", cx)
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hang_up(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
pub fn hang_up(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
self.report_call_event("hang up", cx);
|
self.report_call_event("hang up", cx);
|
||||||
|
Audio::end_call(cx);
|
||||||
if let Some((room, _)) = self.room.take() {
|
if let Some((room, _)) = self.room.take() {
|
||||||
room.update(cx, |room, cx| room.leave(cx))
|
room.update(cx, |room, cx| room.leave(cx))
|
||||||
} else {
|
} else {
|
||||||
@ -372,19 +405,31 @@ impl ActiveCall {
|
|||||||
|
|
||||||
fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
|
fn report_call_event(&self, operation: &'static str, cx: &AppContext) {
|
||||||
if let Some(room) = self.room() {
|
if let Some(room) = self.room() {
|
||||||
Self::report_call_event_for_room(operation, room.read(cx).id(), &self.client, cx)
|
let room = room.read(cx);
|
||||||
|
Self::report_call_event_for_room(
|
||||||
|
operation,
|
||||||
|
room.id(),
|
||||||
|
room.channel_id(),
|
||||||
|
&self.client,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_call_event_for_room(
|
pub fn report_call_event_for_room(
|
||||||
operation: &'static str,
|
operation: &'static str,
|
||||||
room_id: u64,
|
room_id: u64,
|
||||||
|
channel_id: Option<u64>,
|
||||||
client: &Arc<Client>,
|
client: &Arc<Client>,
|
||||||
cx: &AppContext,
|
cx: &AppContext,
|
||||||
) {
|
) {
|
||||||
let telemetry = client.telemetry();
|
let telemetry = client.telemetry();
|
||||||
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
|
let telemetry_settings = *settings::get::<TelemetrySettings>(cx);
|
||||||
let event = ClickhouseEvent::Call { operation, room_id };
|
let event = ClickhouseEvent::Call {
|
||||||
|
operation,
|
||||||
|
room_id,
|
||||||
|
channel_id,
|
||||||
|
};
|
||||||
telemetry.report_clickhouse_event(event, telemetry_settings);
|
telemetry.report_clickhouse_event(event, telemetry_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ pub enum Event {
|
|||||||
|
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
id: u64,
|
id: u64,
|
||||||
|
channel_id: Option<u64>,
|
||||||
live_kit: Option<LiveKitRoom>,
|
live_kit: Option<LiveKitRoom>,
|
||||||
status: RoomStatus,
|
status: RoomStatus,
|
||||||
shared_projects: HashSet<WeakModelHandle<Project>>,
|
shared_projects: HashSet<WeakModelHandle<Project>>,
|
||||||
@ -93,8 +94,25 @@ impl Entity for Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Room {
|
impl Room {
|
||||||
|
pub fn channel_id(&self) -> Option<u64> {
|
||||||
|
self.channel_id
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn is_connected(&self) -> bool {
|
||||||
|
if let Some(live_kit) = self.live_kit.as_ref() {
|
||||||
|
matches!(
|
||||||
|
*live_kit.room.status().borrow(),
|
||||||
|
live_kit_client::ConnectionState::Connected { .. }
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new(
|
fn new(
|
||||||
id: u64,
|
id: u64,
|
||||||
|
channel_id: Option<u64>,
|
||||||
live_kit_connection_info: Option<proto::LiveKitConnectionInfo>,
|
live_kit_connection_info: Option<proto::LiveKitConnectionInfo>,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
@ -185,6 +203,7 @@ impl Room {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
channel_id,
|
||||||
live_kit: live_kit_room,
|
live_kit: live_kit_room,
|
||||||
status: RoomStatus::Online,
|
status: RoomStatus::Online,
|
||||||
shared_projects: Default::default(),
|
shared_projects: Default::default(),
|
||||||
@ -217,6 +236,7 @@ impl Room {
|
|||||||
let room = cx.add_model(|cx| {
|
let room = cx.add_model(|cx| {
|
||||||
Self::new(
|
Self::new(
|
||||||
room_proto.id,
|
room_proto.id,
|
||||||
|
None,
|
||||||
response.live_kit_connection_info,
|
response.live_kit_connection_info,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
@ -248,19 +268,50 @@ impl Room {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn join_channel(
|
||||||
|
channel_id: u64,
|
||||||
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
|
cx: &mut AppContext,
|
||||||
|
) -> Task<Result<ModelHandle<Self>>> {
|
||||||
|
cx.spawn(|cx| async move {
|
||||||
|
Self::from_join_response(
|
||||||
|
client.request(proto::JoinChannel { channel_id }).await?,
|
||||||
|
client,
|
||||||
|
user_store,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn join(
|
pub(crate) fn join(
|
||||||
call: &IncomingCall,
|
call: &IncomingCall,
|
||||||
client: Arc<Client>,
|
client: Arc<Client>,
|
||||||
user_store: ModelHandle<UserStore>,
|
user_store: ModelHandle<UserStore>,
|
||||||
cx: &mut AppContext,
|
cx: &mut AppContext,
|
||||||
) -> Task<Result<ModelHandle<Self>>> {
|
) -> Task<Result<ModelHandle<Self>>> {
|
||||||
let room_id = call.room_id;
|
let id = call.room_id;
|
||||||
cx.spawn(|mut cx| async move {
|
cx.spawn(|cx| async move {
|
||||||
let response = client.request(proto::JoinRoom { id: room_id }).await?;
|
Self::from_join_response(
|
||||||
|
client.request(proto::JoinRoom { id }).await?,
|
||||||
|
client,
|
||||||
|
user_store,
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_join_response(
|
||||||
|
response: proto::JoinRoomResponse,
|
||||||
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<ModelHandle<Self>> {
|
||||||
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?;
|
let room_proto = response.room.ok_or_else(|| anyhow!("invalid room"))?;
|
||||||
let room = cx.add_model(|cx| {
|
let room = cx.add_model(|cx| {
|
||||||
Self::new(
|
Self::new(
|
||||||
room_id,
|
room_proto.id,
|
||||||
|
response.channel_id,
|
||||||
response.live_kit_connection_info,
|
response.live_kit_connection_info,
|
||||||
client,
|
client,
|
||||||
user_store,
|
user_store,
|
||||||
@ -268,13 +319,11 @@ impl Room {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
room.update(&mut cx, |room, cx| {
|
room.update(&mut cx, |room, cx| {
|
||||||
room.leave_when_empty = true;
|
room.leave_when_empty = room.channel_id.is_none();
|
||||||
room.apply_room_update(room_proto, cx)?;
|
room.apply_room_update(room_proto, cx)?;
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(room)
|
Ok(room)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_leave(&self) -> bool {
|
fn should_leave(&self) -> bool {
|
||||||
@ -297,7 +346,18 @@ impl Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log::info!("leaving room");
|
log::info!("leaving room");
|
||||||
|
Audio::play_sound(Sound::Leave, cx);
|
||||||
|
|
||||||
|
self.clear_state(cx);
|
||||||
|
|
||||||
|
let leave_room = self.client.request(proto::LeaveRoom {});
|
||||||
|
cx.background().spawn(async move {
|
||||||
|
leave_room.await?;
|
||||||
|
anyhow::Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn clear_state(&mut self, cx: &mut AppContext) {
|
||||||
for project in self.shared_projects.drain() {
|
for project in self.shared_projects.drain() {
|
||||||
if let Some(project) = project.upgrade(cx) {
|
if let Some(project) = project.upgrade(cx) {
|
||||||
project.update(cx, |project, cx| {
|
project.update(cx, |project, cx| {
|
||||||
@ -314,8 +374,6 @@ impl Room {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Audio::play_sound(Sound::Leave, cx);
|
|
||||||
|
|
||||||
self.status = RoomStatus::Offline;
|
self.status = RoomStatus::Offline;
|
||||||
self.remote_participants.clear();
|
self.remote_participants.clear();
|
||||||
self.pending_participants.clear();
|
self.pending_participants.clear();
|
||||||
@ -324,12 +382,6 @@ impl Room {
|
|||||||
self.live_kit.take();
|
self.live_kit.take();
|
||||||
self.pending_room_update.take();
|
self.pending_room_update.take();
|
||||||
self.maintain_connection.take();
|
self.maintain_connection.take();
|
||||||
|
|
||||||
let leave_room = self.client.request(proto::LeaveRoom {});
|
|
||||||
cx.background().spawn(async move {
|
|
||||||
leave_room.await?;
|
|
||||||
anyhow::Ok(())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn maintain_connection(
|
async fn maintain_connection(
|
||||||
@ -592,7 +644,9 @@ impl Room {
|
|||||||
|
|
||||||
if let Some(participants) = remote_participants.log_err() {
|
if let Some(participants) = remote_participants.log_err() {
|
||||||
for (participant, user) in room.participants.into_iter().zip(participants) {
|
for (participant, user) in room.participants.into_iter().zip(participants) {
|
||||||
let Some(peer_id) = participant.peer_id else { continue };
|
let Some(peer_id) = participant.peer_id else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
this.participant_user_ids.insert(participant.user_id);
|
this.participant_user_ids.insert(participant.user_id);
|
||||||
|
|
||||||
let old_projects = this
|
let old_projects = this
|
||||||
@ -1066,11 +1120,11 @@ impl Room {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_muted(&self) -> bool {
|
pub fn is_muted(&self, cx: &AppContext) -> bool {
|
||||||
self.live_kit
|
self.live_kit
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|live_kit| match &live_kit.microphone_track {
|
.and_then(|live_kit| match &live_kit.microphone_track {
|
||||||
LocalTrack::None => Some(true),
|
LocalTrack::None => Some(settings::get::<CallSettings>(cx).mute_on_join),
|
||||||
LocalTrack::Pending { muted, .. } => Some(*muted),
|
LocalTrack::Pending { muted, .. } => Some(*muted),
|
||||||
LocalTrack::Published { muted, .. } => Some(*muted),
|
LocalTrack::Published { muted, .. } => Some(*muted),
|
||||||
})
|
})
|
||||||
@ -1260,7 +1314,7 @@ impl Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_mute(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
|
pub fn toggle_mute(&mut self, cx: &mut ModelContext<Self>) -> Result<Task<Result<()>>> {
|
||||||
let should_mute = !self.is_muted();
|
let should_mute = !self.is_muted(cx);
|
||||||
if let Some(live_kit) = self.live_kit.as_mut() {
|
if let Some(live_kit) = self.live_kit.as_mut() {
|
||||||
if matches!(live_kit.microphone_track, LocalTrack::None) {
|
if matches!(live_kit.microphone_track, LocalTrack::None) {
|
||||||
return Ok(self.share_microphone(cx));
|
return Ok(self.share_microphone(cx));
|
||||||
|
51
crates/channel/Cargo.toml
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
[package]
|
||||||
|
name = "channel"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/channel.rs"
|
||||||
|
doctest = false
|
||||||
|
|
||||||
|
[features]
|
||||||
|
test-support = ["collections/test-support", "gpui/test-support", "rpc/test-support"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
client = { path = "../client" }
|
||||||
|
collections = { path = "../collections" }
|
||||||
|
db = { path = "../db" }
|
||||||
|
gpui = { path = "../gpui" }
|
||||||
|
util = { path = "../util" }
|
||||||
|
rpc = { path = "../rpc" }
|
||||||
|
text = { path = "../text" }
|
||||||
|
language = { path = "../language" }
|
||||||
|
settings = { path = "../settings" }
|
||||||
|
feature_flags = { path = "../feature_flags" }
|
||||||
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
|
||||||
|
anyhow.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
|
image = "0.23"
|
||||||
|
lazy_static.workspace = true
|
||||||
|
log.workspace = true
|
||||||
|
parking_lot.workspace = true
|
||||||
|
postage.workspace = true
|
||||||
|
rand.workspace = true
|
||||||
|
schemars.workspace = true
|
||||||
|
smol.workspace = true
|
||||||
|
thiserror.workspace = true
|
||||||
|
time.workspace = true
|
||||||
|
tiny_http = "0.8"
|
||||||
|
uuid = { version = "1.1.2", features = ["v4"] }
|
||||||
|
url = "2.2"
|
||||||
|
serde.workspace = true
|
||||||
|
serde_derive.workspace = true
|
||||||
|
tempfile = "3"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
collections = { path = "../collections", features = ["test-support"] }
|
||||||
|
gpui = { path = "../gpui", features = ["test-support"] }
|
||||||
|
rpc = { path = "../rpc", features = ["test-support"] }
|
||||||
|
settings = { path = "../settings", features = ["test-support"] }
|
||||||
|
util = { path = "../util", features = ["test-support"] }
|
14
crates/channel/src/channel.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
mod channel_store;
|
||||||
|
|
||||||
|
pub mod channel_buffer;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub use channel_store::*;
|
||||||
|
use client::Client;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod channel_store_tests;
|
||||||
|
|
||||||
|
pub fn init(client: &Arc<Client>) {
|
||||||
|
channel_buffer::init(client);
|
||||||
|
}
|
197
crates/channel/src/channel_buffer.rs
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
use crate::Channel;
|
||||||
|
use anyhow::Result;
|
||||||
|
use client::Client;
|
||||||
|
use gpui::{AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle};
|
||||||
|
use rpc::{proto, TypedEnvelope};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use util::ResultExt;
|
||||||
|
|
||||||
|
pub(crate) fn init(client: &Arc<Client>) {
|
||||||
|
client.add_model_message_handler(ChannelBuffer::handle_update_channel_buffer);
|
||||||
|
client.add_model_message_handler(ChannelBuffer::handle_add_channel_buffer_collaborator);
|
||||||
|
client.add_model_message_handler(ChannelBuffer::handle_remove_channel_buffer_collaborator);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ChannelBuffer {
|
||||||
|
pub(crate) channel: Arc<Channel>,
|
||||||
|
connected: bool,
|
||||||
|
collaborators: Vec<proto::Collaborator>,
|
||||||
|
buffer: ModelHandle<language::Buffer>,
|
||||||
|
client: Arc<Client>,
|
||||||
|
subscription: Option<client::Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
CollaboratorsChanged,
|
||||||
|
Disconnected,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for ChannelBuffer {
|
||||||
|
type Event = Event;
|
||||||
|
|
||||||
|
fn release(&mut self, _: &mut AppContext) {
|
||||||
|
if self.connected {
|
||||||
|
self.client
|
||||||
|
.send(proto::LeaveChannelBuffer {
|
||||||
|
channel_id: self.channel.id,
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChannelBuffer {
|
||||||
|
pub(crate) async fn new(
|
||||||
|
channel: Arc<Channel>,
|
||||||
|
client: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<ModelHandle<Self>> {
|
||||||
|
let response = client
|
||||||
|
.request(proto::JoinChannelBuffer {
|
||||||
|
channel_id: channel.id,
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let base_text = response.base_text;
|
||||||
|
let operations = response
|
||||||
|
.operations
|
||||||
|
.into_iter()
|
||||||
|
.map(language::proto::deserialize_operation)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
let collaborators = response.collaborators;
|
||||||
|
|
||||||
|
let buffer = cx.add_model(|_| {
|
||||||
|
language::Buffer::remote(response.buffer_id, response.replica_id as u16, base_text)
|
||||||
|
});
|
||||||
|
buffer.update(&mut cx, |buffer, cx| buffer.apply_ops(operations, cx))?;
|
||||||
|
|
||||||
|
let subscription = client.subscribe_to_entity(channel.id)?;
|
||||||
|
|
||||||
|
anyhow::Ok(cx.add_model(|cx| {
|
||||||
|
cx.subscribe(&buffer, Self::on_buffer_update).detach();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
buffer,
|
||||||
|
client,
|
||||||
|
connected: true,
|
||||||
|
collaborators,
|
||||||
|
channel,
|
||||||
|
subscription: Some(subscription.set_model(&cx.handle(), &mut cx.to_async())),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_update_channel_buffer(
|
||||||
|
this: ModelHandle<Self>,
|
||||||
|
update_channel_buffer: TypedEnvelope<proto::UpdateChannelBuffer>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<()> {
|
||||||
|
let ops = update_channel_buffer
|
||||||
|
.payload
|
||||||
|
.operations
|
||||||
|
.into_iter()
|
||||||
|
.map(language::proto::deserialize_operation)
|
||||||
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
cx.notify();
|
||||||
|
this.buffer
|
||||||
|
.update(cx, |buffer, cx| buffer.apply_ops(ops, cx))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_add_channel_buffer_collaborator(
|
||||||
|
this: ModelHandle<Self>,
|
||||||
|
envelope: TypedEnvelope<proto::AddChannelBufferCollaborator>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<()> {
|
||||||
|
let collaborator = envelope.payload.collaborator.ok_or_else(|| {
|
||||||
|
anyhow::anyhow!(
|
||||||
|
"Should have gotten a collaborator in the AddChannelBufferCollaborator message"
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.collaborators.push(collaborator);
|
||||||
|
cx.emit(Event::CollaboratorsChanged);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_remove_channel_buffer_collaborator(
|
||||||
|
this: ModelHandle<Self>,
|
||||||
|
message: TypedEnvelope<proto::RemoveChannelBufferCollaborator>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<()> {
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.collaborators.retain(|collaborator| {
|
||||||
|
if collaborator.peer_id == message.payload.peer_id {
|
||||||
|
this.buffer.update(cx, |buffer, cx| {
|
||||||
|
buffer.remove_peer(collaborator.replica_id as u16, cx)
|
||||||
|
});
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cx.emit(Event::CollaboratorsChanged);
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_buffer_update(
|
||||||
|
&mut self,
|
||||||
|
_: ModelHandle<language::Buffer>,
|
||||||
|
event: &language::Event,
|
||||||
|
_: &mut ModelContext<Self>,
|
||||||
|
) {
|
||||||
|
if let language::Event::Operation(operation) = event {
|
||||||
|
let operation = language::proto::serialize_operation(operation);
|
||||||
|
self.client
|
||||||
|
.send(proto::UpdateChannelBuffer {
|
||||||
|
channel_id: self.channel.id,
|
||||||
|
operations: vec![operation],
|
||||||
|
})
|
||||||
|
.log_err();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn buffer(&self) -> ModelHandle<language::Buffer> {
|
||||||
|
self.buffer.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn collaborators(&self) -> &[proto::Collaborator] {
|
||||||
|
&self.collaborators
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel(&self) -> Arc<Channel> {
|
||||||
|
self.channel.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn disconnect(&mut self, cx: &mut ModelContext<Self>) {
|
||||||
|
if self.connected {
|
||||||
|
self.connected = false;
|
||||||
|
self.subscription.take();
|
||||||
|
cx.emit(Event::Disconnected);
|
||||||
|
cx.notify()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_connected(&self) -> bool {
|
||||||
|
self.connected
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn replica_id(&self, cx: &AppContext) -> u16 {
|
||||||
|
self.buffer.read(cx).replica_id()
|
||||||
|
}
|
||||||
|
}
|
656
crates/channel/src/channel_store.rs
Normal file
@ -0,0 +1,656 @@
|
|||||||
|
use crate::channel_buffer::ChannelBuffer;
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
use client::{Client, Status, Subscription, User, UserId, UserStore};
|
||||||
|
use collections::{hash_map, HashMap, HashSet};
|
||||||
|
use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt};
|
||||||
|
use gpui::{AsyncAppContext, Entity, ModelContext, ModelHandle, Task, WeakModelHandle};
|
||||||
|
use rpc::{proto, TypedEnvelope};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use util::ResultExt;
|
||||||
|
|
||||||
|
pub type ChannelId = u64;
|
||||||
|
|
||||||
|
pub struct ChannelStore {
|
||||||
|
channels_by_id: HashMap<ChannelId, Arc<Channel>>,
|
||||||
|
channel_paths: Vec<Vec<ChannelId>>,
|
||||||
|
channel_invitations: Vec<Arc<Channel>>,
|
||||||
|
channel_participants: HashMap<ChannelId, Vec<Arc<User>>>,
|
||||||
|
channels_with_admin_privileges: HashSet<ChannelId>,
|
||||||
|
outgoing_invites: HashSet<(ChannelId, UserId)>,
|
||||||
|
update_channels_tx: mpsc::UnboundedSender<proto::UpdateChannels>,
|
||||||
|
opened_buffers: HashMap<ChannelId, OpenedChannelBuffer>,
|
||||||
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
|
_rpc_subscription: Subscription,
|
||||||
|
_watch_connection_status: Task<()>,
|
||||||
|
_update_channels: Task<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct Channel {
|
||||||
|
pub id: ChannelId,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ChannelMembership {
|
||||||
|
pub user: Arc<User>,
|
||||||
|
pub kind: proto::channel_member::Kind,
|
||||||
|
pub admin: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ChannelEvent {
|
||||||
|
ChannelCreated(ChannelId),
|
||||||
|
ChannelRenamed(ChannelId),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Entity for ChannelStore {
|
||||||
|
type Event = ChannelEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum ChannelMemberStatus {
|
||||||
|
Invited,
|
||||||
|
Member,
|
||||||
|
NotMember,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum OpenedChannelBuffer {
|
||||||
|
Open(WeakModelHandle<ChannelBuffer>),
|
||||||
|
Loading(Shared<Task<Result<ModelHandle<ChannelBuffer>, Arc<anyhow::Error>>>>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChannelStore {
|
||||||
|
pub fn new(
|
||||||
|
client: Arc<Client>,
|
||||||
|
user_store: ModelHandle<UserStore>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Self {
|
||||||
|
let rpc_subscription =
|
||||||
|
client.add_message_handler(cx.handle(), Self::handle_update_channels);
|
||||||
|
|
||||||
|
let (update_channels_tx, mut update_channels_rx) = mpsc::unbounded();
|
||||||
|
let mut connection_status = client.status();
|
||||||
|
let watch_connection_status = cx.spawn_weak(|this, mut cx| async move {
|
||||||
|
while let Some(status) = connection_status.next().await {
|
||||||
|
if !status.is_connected() {
|
||||||
|
if let Some(this) = this.upgrade(&cx) {
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
if matches!(status, Status::ConnectionLost | Status::SignedOut) {
|
||||||
|
this.handle_disconnect(cx);
|
||||||
|
} else {
|
||||||
|
this.disconnect_buffers(cx);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
channels_by_id: HashMap::default(),
|
||||||
|
channel_invitations: Vec::default(),
|
||||||
|
channel_paths: Vec::default(),
|
||||||
|
channel_participants: Default::default(),
|
||||||
|
channels_with_admin_privileges: Default::default(),
|
||||||
|
outgoing_invites: Default::default(),
|
||||||
|
opened_buffers: Default::default(),
|
||||||
|
update_channels_tx,
|
||||||
|
client,
|
||||||
|
user_store,
|
||||||
|
_rpc_subscription: rpc_subscription,
|
||||||
|
_watch_connection_status: watch_connection_status,
|
||||||
|
_update_channels: cx.spawn_weak(|this, mut cx| async move {
|
||||||
|
while let Some(update_channels) = update_channels_rx.next().await {
|
||||||
|
if let Some(this) = this.upgrade(&cx) {
|
||||||
|
let update_task = this.update(&mut cx, |this, cx| {
|
||||||
|
this.update_channels(update_channels, cx)
|
||||||
|
});
|
||||||
|
if let Some(update_task) = update_task {
|
||||||
|
update_task.await.log_err();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_children(&self, channel_id: ChannelId) -> bool {
|
||||||
|
self.channel_paths.iter().any(|path| {
|
||||||
|
if let Some(ix) = path.iter().position(|id| *id == channel_id) {
|
||||||
|
path.len() > ix + 1
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel_count(&self) -> usize {
|
||||||
|
self.channel_paths.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channels(&self) -> impl '_ + Iterator<Item = (usize, &Arc<Channel>)> {
|
||||||
|
self.channel_paths.iter().map(move |path| {
|
||||||
|
let id = path.last().unwrap();
|
||||||
|
let channel = self.channel_for_id(*id).unwrap();
|
||||||
|
(path.len() - 1, channel)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel_at_index(&self, ix: usize) -> Option<(usize, &Arc<Channel>)> {
|
||||||
|
let path = self.channel_paths.get(ix)?;
|
||||||
|
let id = path.last().unwrap();
|
||||||
|
let channel = self.channel_for_id(*id).unwrap();
|
||||||
|
Some((path.len() - 1, channel))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel_invitations(&self) -> &[Arc<Channel>] {
|
||||||
|
&self.channel_invitations
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel_for_id(&self, channel_id: ChannelId) -> Option<&Arc<Channel>> {
|
||||||
|
self.channels_by_id.get(&channel_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_channel_buffer(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<ModelHandle<ChannelBuffer>>> {
|
||||||
|
// Make sure that a given channel buffer is only opened once per
|
||||||
|
// app instance, even if this method is called multiple times
|
||||||
|
// with the same channel id while the first task is still running.
|
||||||
|
let task = loop {
|
||||||
|
match self.opened_buffers.entry(channel_id) {
|
||||||
|
hash_map::Entry::Occupied(e) => match e.get() {
|
||||||
|
OpenedChannelBuffer::Open(buffer) => {
|
||||||
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
|
break Task::ready(Ok(buffer)).shared();
|
||||||
|
} else {
|
||||||
|
self.opened_buffers.remove(&channel_id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OpenedChannelBuffer::Loading(task) => break task.clone(),
|
||||||
|
},
|
||||||
|
hash_map::Entry::Vacant(e) => {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let task = cx
|
||||||
|
.spawn(|this, cx| async move {
|
||||||
|
let channel = this.read_with(&cx, |this, _| {
|
||||||
|
this.channel_for_id(channel_id).cloned().ok_or_else(|| {
|
||||||
|
Arc::new(anyhow!("no channel for id: {}", channel_id))
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
ChannelBuffer::new(channel, client, cx)
|
||||||
|
.await
|
||||||
|
.map_err(Arc::new)
|
||||||
|
})
|
||||||
|
.shared();
|
||||||
|
e.insert(OpenedChannelBuffer::Loading(task.clone()));
|
||||||
|
cx.spawn({
|
||||||
|
let task = task.clone();
|
||||||
|
|this, mut cx| async move {
|
||||||
|
let result = task.await;
|
||||||
|
this.update(&mut cx, |this, cx| match result {
|
||||||
|
Ok(buffer) => {
|
||||||
|
cx.observe_release(&buffer, move |this, _, _| {
|
||||||
|
this.opened_buffers.remove(&channel_id);
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
this.opened_buffers.insert(
|
||||||
|
channel_id,
|
||||||
|
OpenedChannelBuffer::Open(buffer.downgrade()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
log::error!("failed to open channel buffer {error:?}");
|
||||||
|
this.opened_buffers.remove(&channel_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
break task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
cx.foreground()
|
||||||
|
.spawn(async move { task.await.map_err(|error| anyhow!("{}", error)) })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_user_admin(&self, channel_id: ChannelId) -> bool {
|
||||||
|
self.channel_paths.iter().any(|path| {
|
||||||
|
if let Some(ix) = path.iter().position(|id| *id == channel_id) {
|
||||||
|
path[..=ix]
|
||||||
|
.iter()
|
||||||
|
.any(|id| self.channels_with_admin_privileges.contains(id))
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel_participants(&self, channel_id: ChannelId) -> &[Arc<User>] {
|
||||||
|
self.channel_participants
|
||||||
|
.get(&channel_id)
|
||||||
|
.map_or(&[], |v| v.as_slice())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_channel(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
parent_id: Option<ChannelId>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<ChannelId>> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let name = name.trim_start_matches("#").to_owned();
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let channel = client
|
||||||
|
.request(proto::CreateChannel { name, parent_id })
|
||||||
|
.await?
|
||||||
|
.channel
|
||||||
|
.ok_or_else(|| anyhow!("missing channel in response"))?;
|
||||||
|
|
||||||
|
let channel_id = channel.id;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
let task = this.update_channels(
|
||||||
|
proto::UpdateChannels {
|
||||||
|
channels: vec![channel],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
assert!(task.is_none());
|
||||||
|
|
||||||
|
// This event is emitted because the collab panel wants to clear the pending edit state
|
||||||
|
// before this frame is rendered. But we can't guarantee that the collab panel's future
|
||||||
|
// will resolve before this flush_effects finishes. Synchronously emitting this event
|
||||||
|
// ensures that the collab panel will observe this creation before the frame completes
|
||||||
|
cx.emit(ChannelEvent::ChannelCreated(channel_id));
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(channel_id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn invite_member(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
admin: bool,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
if !self.outgoing_invites.insert((channel_id, user_id)) {
|
||||||
|
return Task::ready(Err(anyhow!("invite request already in progress")));
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
let client = self.client.clone();
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let result = client
|
||||||
|
.request(proto::InviteChannelMember {
|
||||||
|
channel_id,
|
||||||
|
user_id,
|
||||||
|
admin,
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.outgoing_invites.remove(&(channel_id, user_id));
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
result?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_member(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: u64,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
if !self.outgoing_invites.insert((channel_id, user_id)) {
|
||||||
|
return Task::ready(Err(anyhow!("invite request already in progress")));
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
let client = self.client.clone();
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let result = client
|
||||||
|
.request(proto::RemoveChannelMember {
|
||||||
|
channel_id,
|
||||||
|
user_id,
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.outgoing_invites.remove(&(channel_id, user_id));
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
result?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_member_admin(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
admin: bool,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
if !self.outgoing_invites.insert((channel_id, user_id)) {
|
||||||
|
return Task::ready(Err(anyhow!("member request already in progress")));
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
let client = self.client.clone();
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let result = client
|
||||||
|
.request(proto::SetChannelMemberAdmin {
|
||||||
|
channel_id,
|
||||||
|
user_id,
|
||||||
|
admin,
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
this.outgoing_invites.remove(&(channel_id, user_id));
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
|
||||||
|
result?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn rename(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
new_name: &str,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<()>> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let name = new_name.to_string();
|
||||||
|
cx.spawn(|this, mut cx| async move {
|
||||||
|
let channel = client
|
||||||
|
.request(proto::RenameChannel { channel_id, name })
|
||||||
|
.await?
|
||||||
|
.channel
|
||||||
|
.ok_or_else(|| anyhow!("missing channel in response"))?;
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
let task = this.update_channels(
|
||||||
|
proto::UpdateChannels {
|
||||||
|
channels: vec![channel],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
assert!(task.is_none());
|
||||||
|
|
||||||
|
// This event is emitted because the collab panel wants to clear the pending edit state
|
||||||
|
// before this frame is rendered. But we can't guarantee that the collab panel's future
|
||||||
|
// will resolve before this flush_effects finishes. Synchronously emitting this event
|
||||||
|
// ensures that the collab panel will observe this creation before the frame complete
|
||||||
|
cx.emit(ChannelEvent::ChannelRenamed(channel_id))
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn respond_to_channel_invite(
|
||||||
|
&mut self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
accept: bool,
|
||||||
|
) -> impl Future<Output = Result<()>> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
async move {
|
||||||
|
client
|
||||||
|
.request(proto::RespondToChannelInvite { channel_id, accept })
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_channel_member_details(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<ChannelMembership>>> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
let user_store = self.user_store.downgrade();
|
||||||
|
cx.spawn(|_, mut cx| async move {
|
||||||
|
let response = client
|
||||||
|
.request(proto::GetChannelMembers { channel_id })
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let user_ids = response.members.iter().map(|m| m.user_id).collect();
|
||||||
|
let user_store = user_store
|
||||||
|
.upgrade(&cx)
|
||||||
|
.ok_or_else(|| anyhow!("user store dropped"))?;
|
||||||
|
let users = user_store
|
||||||
|
.update(&mut cx, |user_store, cx| user_store.get_users(user_ids, cx))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(users
|
||||||
|
.into_iter()
|
||||||
|
.zip(response.members)
|
||||||
|
.filter_map(|(user, member)| {
|
||||||
|
Some(ChannelMembership {
|
||||||
|
user,
|
||||||
|
admin: member.admin,
|
||||||
|
kind: proto::channel_member::Kind::from_i32(member.kind)?,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_channel(&self, channel_id: ChannelId) -> impl Future<Output = Result<()>> {
|
||||||
|
let client = self.client.clone();
|
||||||
|
async move {
|
||||||
|
client.request(proto::RemoveChannel { channel_id }).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_pending_channel_invite_response(&self, _: &Arc<Channel>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_pending_channel_invite(&self, channel_id: ChannelId, user_id: UserId) -> bool {
|
||||||
|
self.outgoing_invites.contains(&(channel_id, user_id))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_update_channels(
|
||||||
|
this: ModelHandle<Self>,
|
||||||
|
message: TypedEnvelope<proto::UpdateChannels>,
|
||||||
|
_: Arc<Client>,
|
||||||
|
mut cx: AsyncAppContext,
|
||||||
|
) -> Result<()> {
|
||||||
|
this.update(&mut cx, |this, _| {
|
||||||
|
this.update_channels_tx
|
||||||
|
.unbounded_send(message.payload)
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_disconnect(&mut self, cx: &mut ModelContext<'_, ChannelStore>) {
|
||||||
|
self.disconnect_buffers(cx);
|
||||||
|
self.channels_by_id.clear();
|
||||||
|
self.channel_invitations.clear();
|
||||||
|
self.channel_participants.clear();
|
||||||
|
self.channels_with_admin_privileges.clear();
|
||||||
|
self.channel_paths.clear();
|
||||||
|
self.outgoing_invites.clear();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn disconnect_buffers(&mut self, cx: &mut ModelContext<ChannelStore>) {
|
||||||
|
for (_, buffer) in self.opened_buffers.drain() {
|
||||||
|
if let OpenedChannelBuffer::Open(buffer) = buffer {
|
||||||
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
|
buffer.update(cx, |buffer, cx| buffer.disconnect(cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn update_channels(
|
||||||
|
&mut self,
|
||||||
|
payload: proto::UpdateChannels,
|
||||||
|
cx: &mut ModelContext<ChannelStore>,
|
||||||
|
) -> Option<Task<Result<()>>> {
|
||||||
|
if !payload.remove_channel_invitations.is_empty() {
|
||||||
|
self.channel_invitations
|
||||||
|
.retain(|channel| !payload.remove_channel_invitations.contains(&channel.id));
|
||||||
|
}
|
||||||
|
for channel in payload.channel_invitations {
|
||||||
|
match self
|
||||||
|
.channel_invitations
|
||||||
|
.binary_search_by_key(&channel.id, |c| c.id)
|
||||||
|
{
|
||||||
|
Ok(ix) => Arc::make_mut(&mut self.channel_invitations[ix]).name = channel.name,
|
||||||
|
Err(ix) => self.channel_invitations.insert(
|
||||||
|
ix,
|
||||||
|
Arc::new(Channel {
|
||||||
|
id: channel.id,
|
||||||
|
name: channel.name,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let channels_changed = !payload.channels.is_empty() || !payload.remove_channels.is_empty();
|
||||||
|
if channels_changed {
|
||||||
|
if !payload.remove_channels.is_empty() {
|
||||||
|
self.channels_by_id
|
||||||
|
.retain(|channel_id, _| !payload.remove_channels.contains(channel_id));
|
||||||
|
self.channel_participants
|
||||||
|
.retain(|channel_id, _| !payload.remove_channels.contains(channel_id));
|
||||||
|
self.channels_with_admin_privileges
|
||||||
|
.retain(|channel_id| !payload.remove_channels.contains(channel_id));
|
||||||
|
|
||||||
|
for channel_id in &payload.remove_channels {
|
||||||
|
let channel_id = *channel_id;
|
||||||
|
if let Some(OpenedChannelBuffer::Open(buffer)) =
|
||||||
|
self.opened_buffers.remove(&channel_id)
|
||||||
|
{
|
||||||
|
if let Some(buffer) = buffer.upgrade(cx) {
|
||||||
|
buffer.update(cx, ChannelBuffer::disconnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for channel_proto in payload.channels {
|
||||||
|
if let Some(existing_channel) = self.channels_by_id.get_mut(&channel_proto.id) {
|
||||||
|
Arc::make_mut(existing_channel).name = channel_proto.name;
|
||||||
|
} else {
|
||||||
|
let channel = Arc::new(Channel {
|
||||||
|
id: channel_proto.id,
|
||||||
|
name: channel_proto.name,
|
||||||
|
});
|
||||||
|
self.channels_by_id.insert(channel.id, channel.clone());
|
||||||
|
|
||||||
|
if let Some(parent_id) = channel_proto.parent_id {
|
||||||
|
let mut ix = 0;
|
||||||
|
while ix < self.channel_paths.len() {
|
||||||
|
let path = &self.channel_paths[ix];
|
||||||
|
if path.ends_with(&[parent_id]) {
|
||||||
|
let mut new_path = path.clone();
|
||||||
|
new_path.push(channel.id);
|
||||||
|
self.channel_paths.insert(ix + 1, new_path);
|
||||||
|
ix += 1;
|
||||||
|
}
|
||||||
|
ix += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.channel_paths.push(vec![channel.id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.channel_paths.sort_by(|a, b| {
|
||||||
|
let a = Self::channel_path_sorting_key(a, &self.channels_by_id);
|
||||||
|
let b = Self::channel_path_sorting_key(b, &self.channels_by_id);
|
||||||
|
a.cmp(b)
|
||||||
|
});
|
||||||
|
self.channel_paths.dedup();
|
||||||
|
self.channel_paths.retain(|path| {
|
||||||
|
path.iter()
|
||||||
|
.all(|channel_id| self.channels_by_id.contains_key(channel_id))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for permission in payload.channel_permissions {
|
||||||
|
if permission.is_admin {
|
||||||
|
self.channels_with_admin_privileges
|
||||||
|
.insert(permission.channel_id);
|
||||||
|
} else {
|
||||||
|
self.channels_with_admin_privileges
|
||||||
|
.remove(&permission.channel_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
if payload.channel_participants.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut all_user_ids = Vec::new();
|
||||||
|
let channel_participants = payload.channel_participants;
|
||||||
|
for entry in &channel_participants {
|
||||||
|
for user_id in entry.participant_user_ids.iter() {
|
||||||
|
if let Err(ix) = all_user_ids.binary_search(user_id) {
|
||||||
|
all_user_ids.insert(ix, *user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let users = self
|
||||||
|
.user_store
|
||||||
|
.update(cx, |user_store, cx| user_store.get_users(all_user_ids, cx));
|
||||||
|
Some(cx.spawn(|this, mut cx| async move {
|
||||||
|
let users = users.await?;
|
||||||
|
|
||||||
|
this.update(&mut cx, |this, cx| {
|
||||||
|
for entry in &channel_participants {
|
||||||
|
let mut participants: Vec<_> = entry
|
||||||
|
.participant_user_ids
|
||||||
|
.iter()
|
||||||
|
.filter_map(|user_id| {
|
||||||
|
users
|
||||||
|
.binary_search_by_key(&user_id, |user| &user.id)
|
||||||
|
.ok()
|
||||||
|
.map(|ix| users[ix].clone())
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
participants.sort_by_key(|u| u.id);
|
||||||
|
|
||||||
|
this.channel_participants
|
||||||
|
.insert(entry.channel_id, participants);
|
||||||
|
}
|
||||||
|
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
anyhow::Ok(())
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn channel_path_sorting_key<'a>(
|
||||||
|
path: &'a [ChannelId],
|
||||||
|
channels_by_id: &'a HashMap<ChannelId, Arc<Channel>>,
|
||||||
|
) -> impl 'a + Iterator<Item = Option<&'a str>> {
|
||||||
|
path.iter()
|
||||||
|
.map(|id| Some(channels_by_id.get(id)?.name.as_str()))
|
||||||
|
}
|
||||||
|
}
|
168
crates/channel/src/channel_store_tests.rs
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
use super::*;
|
||||||
|
use client::{Client, UserStore};
|
||||||
|
use gpui::{AppContext, ModelHandle};
|
||||||
|
use rpc::proto;
|
||||||
|
use util::http::FakeHttpClient;
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_update_channels(cx: &mut AppContext) {
|
||||||
|
let http = FakeHttpClient::with_404_response();
|
||||||
|
let client = Client::new(http.clone(), cx);
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
|
||||||
|
|
||||||
|
let channel_store = cx.add_model(|cx| ChannelStore::new(client, user_store, cx));
|
||||||
|
|
||||||
|
update_channels(
|
||||||
|
&channel_store,
|
||||||
|
proto::UpdateChannels {
|
||||||
|
channels: vec![
|
||||||
|
proto::Channel {
|
||||||
|
id: 1,
|
||||||
|
name: "b".to_string(),
|
||||||
|
parent_id: None,
|
||||||
|
},
|
||||||
|
proto::Channel {
|
||||||
|
id: 2,
|
||||||
|
name: "a".to_string(),
|
||||||
|
parent_id: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
channel_permissions: vec![proto::ChannelPermission {
|
||||||
|
channel_id: 1,
|
||||||
|
is_admin: true,
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
assert_channels(
|
||||||
|
&channel_store,
|
||||||
|
&[
|
||||||
|
//
|
||||||
|
(0, "a".to_string(), false),
|
||||||
|
(0, "b".to_string(), true),
|
||||||
|
],
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
|
update_channels(
|
||||||
|
&channel_store,
|
||||||
|
proto::UpdateChannels {
|
||||||
|
channels: vec![
|
||||||
|
proto::Channel {
|
||||||
|
id: 3,
|
||||||
|
name: "x".to_string(),
|
||||||
|
parent_id: Some(1),
|
||||||
|
},
|
||||||
|
proto::Channel {
|
||||||
|
id: 4,
|
||||||
|
name: "y".to_string(),
|
||||||
|
parent_id: Some(2),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
assert_channels(
|
||||||
|
&channel_store,
|
||||||
|
&[
|
||||||
|
(0, "a".to_string(), false),
|
||||||
|
(1, "y".to_string(), false),
|
||||||
|
(0, "b".to_string(), true),
|
||||||
|
(1, "x".to_string(), true),
|
||||||
|
],
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
fn test_dangling_channel_paths(cx: &mut AppContext) {
|
||||||
|
let http = FakeHttpClient::with_404_response();
|
||||||
|
let client = Client::new(http.clone(), cx);
|
||||||
|
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
|
||||||
|
|
||||||
|
let channel_store = cx.add_model(|cx| ChannelStore::new(client, user_store, cx));
|
||||||
|
|
||||||
|
update_channels(
|
||||||
|
&channel_store,
|
||||||
|
proto::UpdateChannels {
|
||||||
|
channels: vec![
|
||||||
|
proto::Channel {
|
||||||
|
id: 0,
|
||||||
|
name: "a".to_string(),
|
||||||
|
parent_id: None,
|
||||||
|
},
|
||||||
|
proto::Channel {
|
||||||
|
id: 1,
|
||||||
|
name: "b".to_string(),
|
||||||
|
parent_id: Some(0),
|
||||||
|
},
|
||||||
|
proto::Channel {
|
||||||
|
id: 2,
|
||||||
|
name: "c".to_string(),
|
||||||
|
parent_id: Some(1),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
channel_permissions: vec![proto::ChannelPermission {
|
||||||
|
channel_id: 0,
|
||||||
|
is_admin: true,
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
// Sanity check
|
||||||
|
assert_channels(
|
||||||
|
&channel_store,
|
||||||
|
&[
|
||||||
|
//
|
||||||
|
(0, "a".to_string(), true),
|
||||||
|
(1, "b".to_string(), true),
|
||||||
|
(2, "c".to_string(), true),
|
||||||
|
],
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
|
update_channels(
|
||||||
|
&channel_store,
|
||||||
|
proto::UpdateChannels {
|
||||||
|
remove_channels: vec![1, 2],
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Make sure that the 1/2/3 path is gone
|
||||||
|
assert_channels(&channel_store, &[(0, "a".to_string(), true)], cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_channels(
|
||||||
|
channel_store: &ModelHandle<ChannelStore>,
|
||||||
|
message: proto::UpdateChannels,
|
||||||
|
cx: &mut AppContext,
|
||||||
|
) {
|
||||||
|
let task = channel_store.update(cx, |store, cx| store.update_channels(message, cx));
|
||||||
|
assert!(task.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
fn assert_channels(
|
||||||
|
channel_store: &ModelHandle<ChannelStore>,
|
||||||
|
expected_channels: &[(usize, String, bool)],
|
||||||
|
cx: &AppContext,
|
||||||
|
) {
|
||||||
|
let actual = channel_store.read_with(cx, |store, _| {
|
||||||
|
store
|
||||||
|
.channels()
|
||||||
|
.map(|(depth, channel)| {
|
||||||
|
(
|
||||||
|
depth,
|
||||||
|
channel.name.to_string(),
|
||||||
|
store.is_user_admin(channel.id),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
});
|
||||||
|
assert_eq!(actual, expected_channels);
|
||||||
|
}
|
@ -17,8 +17,9 @@ db = { path = "../db" }
|
|||||||
gpui = { path = "../gpui" }
|
gpui = { path = "../gpui" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
rpc = { path = "../rpc" }
|
rpc = { path = "../rpc" }
|
||||||
|
text = { path = "../text" }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
staff_mode = { path = "../staff_mode" }
|
feature_flags = { path = "../feature_flags" }
|
||||||
sum_tree = { path = "../sum_tree" }
|
sum_tree = { path = "../sum_tree" }
|
||||||
|
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
@ -535,6 +535,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
pub fn add_message_handler<M, E, H, F>(
|
pub fn add_message_handler<M, E, H, F>(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
model: ModelHandle<E>,
|
model: ModelHandle<E>,
|
||||||
@ -570,7 +571,13 @@ impl Client {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if prev_handler.is_some() {
|
if prev_handler.is_some() {
|
||||||
panic!("registered handler for the same message twice");
|
let location = std::panic::Location::caller();
|
||||||
|
panic!(
|
||||||
|
"{}:{} registered handler for the same message {} twice",
|
||||||
|
location.file(),
|
||||||
|
location.line(),
|
||||||
|
std::any::type_name::<M>()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Subscription::Message {
|
Subscription::Message {
|
||||||
|
@ -74,6 +74,7 @@ pub enum ClickhouseEvent {
|
|||||||
Call {
|
Call {
|
||||||
operation: &'static str,
|
operation: &'static str,
|
||||||
room_id: u64,
|
room_id: u64,
|
||||||
|
channel_id: Option<u64>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,8 +135,6 @@ impl Telemetry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method takes the entire TelemetrySettings struct in order to force client code
|
|
||||||
/// to pull the struct out of the settings global. Do not remove!
|
|
||||||
pub fn set_authenticated_user_info(
|
pub fn set_authenticated_user_info(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
metrics_id: Option<String>,
|
metrics_id: Option<String>,
|
||||||
|
@ -168,6 +168,7 @@ impl FakeServer {
|
|||||||
GetPrivateUserInfoResponse {
|
GetPrivateUserInfoResponse {
|
||||||
metrics_id: "the-metrics-id".into(),
|
metrics_id: "the-metrics-id".into(),
|
||||||
staff: false,
|
staff: false,
|
||||||
|
flags: Default::default(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
use super::{proto, Client, Status, TypedEnvelope};
|
use super::{proto, Client, Status, TypedEnvelope};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use collections::{hash_map::Entry, HashMap, HashSet};
|
use collections::{hash_map::Entry, HashMap, HashSet};
|
||||||
|
use feature_flags::FeatureFlagAppExt;
|
||||||
use futures::{channel::mpsc, future, AsyncReadExt, Future, StreamExt};
|
use futures::{channel::mpsc, future, AsyncReadExt, Future, StreamExt};
|
||||||
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
|
use gpui::{AsyncAppContext, Entity, ImageData, ModelContext, ModelHandle, Task};
|
||||||
use postage::{sink::Sink, watch};
|
use postage::{sink::Sink, watch};
|
||||||
use rpc::proto::{RequestMessage, UsersResponse};
|
use rpc::proto::{RequestMessage, UsersResponse};
|
||||||
use staff_mode::StaffMode;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use util::http::HttpClient;
|
use util::http::HttpClient;
|
||||||
use util::TryFutureExt as _;
|
use util::TryFutureExt as _;
|
||||||
|
|
||||||
|
pub type UserId = u64;
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub id: u64,
|
pub id: UserId,
|
||||||
pub github_login: String,
|
pub github_login: String,
|
||||||
pub avatar: Option<Arc<ImageData>>,
|
pub avatar: Option<Arc<ImageData>>,
|
||||||
}
|
}
|
||||||
@ -143,39 +145,48 @@ impl UserStore {
|
|||||||
let fetch_metrics_id =
|
let fetch_metrics_id =
|
||||||
client.request(proto::GetPrivateUserInfo {}).log_err();
|
client.request(proto::GetPrivateUserInfo {}).log_err();
|
||||||
let (user, info) = futures::join!(fetch_user, fetch_metrics_id);
|
let (user, info) = futures::join!(fetch_user, fetch_metrics_id);
|
||||||
cx.read(|cx| {
|
|
||||||
|
if let Some(info) = info {
|
||||||
|
cx.update(|cx| {
|
||||||
|
cx.update_flags(info.staff, info.flags);
|
||||||
client.telemetry.set_authenticated_user_info(
|
client.telemetry.set_authenticated_user_info(
|
||||||
info.as_ref().map(|info| info.metrics_id.clone()),
|
Some(info.metrics_id.clone()),
|
||||||
info.as_ref().map(|info| info.staff).unwrap_or(false),
|
info.staff,
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
cx.update(|cx| {
|
cx.read(|cx| {
|
||||||
cx.update_default_global(|staff_mode: &mut StaffMode, _| {
|
client
|
||||||
if !staff_mode.0 {
|
.telemetry
|
||||||
*staff_mode = StaffMode(
|
.set_authenticated_user_info(None, false, cx)
|
||||||
info.as_ref()
|
});
|
||||||
.map(|info| info.staff)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
current_user_tx.send(user).await.ok();
|
current_user_tx.send(user).await.ok();
|
||||||
|
|
||||||
|
this.update(&mut cx, |_, cx| {
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Status::SignedOut => {
|
Status::SignedOut => {
|
||||||
current_user_tx.send(None).await.ok();
|
current_user_tx.send(None).await.ok();
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
if let Some(this) = this.upgrade(&cx) {
|
||||||
this.update(&mut cx, |this, _| this.clear_contacts()).await;
|
this.update(&mut cx, |this, cx| {
|
||||||
|
cx.notify();
|
||||||
|
this.clear_contacts()
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Status::ConnectionLost => {
|
Status::ConnectionLost => {
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
if let Some(this) = this.upgrade(&cx) {
|
||||||
this.update(&mut cx, |this, _| this.clear_contacts()).await;
|
this.update(&mut cx, |this, cx| {
|
||||||
|
cx.notify();
|
||||||
|
this.clear_contacts()
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathan@zed.dev>"]
|
|||||||
default-run = "collab"
|
default-run = "collab"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "collab"
|
name = "collab"
|
||||||
version = "0.16.0"
|
version = "0.19.0"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
@ -14,8 +14,10 @@ name = "seed"
|
|||||||
required-features = ["seed-support"]
|
required-features = ["seed-support"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clock = { path = "../clock" }
|
||||||
collections = { path = "../collections" }
|
collections = { path = "../collections" }
|
||||||
live_kit_server = { path = "../live_kit_server" }
|
live_kit_server = { path = "../live_kit_server" }
|
||||||
|
text = { path = "../text" }
|
||||||
rpc = { path = "../rpc" }
|
rpc = { path = "../rpc" }
|
||||||
util = { path = "../util" }
|
util = { path = "../util" }
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ log.workspace = true
|
|||||||
nanoid = "0.4"
|
nanoid = "0.4"
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
prometheus = "0.13"
|
prometheus = "0.13"
|
||||||
|
prost.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
reqwest = { version = "0.11", features = ["json"], optional = true }
|
reqwest = { version = "0.11", features = ["json"], optional = true }
|
||||||
scrypt = "0.7"
|
scrypt = "0.7"
|
||||||
@ -62,6 +65,7 @@ collections = { path = "../collections", features = ["test-support"] }
|
|||||||
gpui = { path = "../gpui", features = ["test-support"] }
|
gpui = { path = "../gpui", features = ["test-support"] }
|
||||||
call = { path = "../call", features = ["test-support"] }
|
call = { path = "../call", features = ["test-support"] }
|
||||||
client = { path = "../client", features = ["test-support"] }
|
client = { path = "../client", features = ["test-support"] }
|
||||||
|
channel = { path = "../channel" }
|
||||||
editor = { path = "../editor", features = ["test-support"] }
|
editor = { path = "../editor", features = ["test-support"] }
|
||||||
language = { path = "../language", features = ["test-support"] }
|
language = { path = "../language", features = ["test-support"] }
|
||||||
fs = { path = "../fs", features = ["test-support"] }
|
fs = { path = "../fs", features = ["test-support"] }
|
||||||
@ -74,6 +78,7 @@ rpc = { path = "../rpc", features = ["test-support"] }
|
|||||||
settings = { path = "../settings", features = ["test-support"] }
|
settings = { path = "../settings", features = ["test-support"] }
|
||||||
theme = { path = "../theme" }
|
theme = { path = "../theme" }
|
||||||
workspace = { path = "../workspace", features = ["test-support"] }
|
workspace = { path = "../workspace", features = ["test-support"] }
|
||||||
|
collab_ui = { path = "../collab_ui", features = ["test-support"] }
|
||||||
|
|
||||||
ctor.workspace = true
|
ctor.workspace = true
|
||||||
env_logger.workspace = true
|
env_logger.workspace = true
|
||||||
|
@ -36,7 +36,8 @@ CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
|
|||||||
|
|
||||||
CREATE TABLE "rooms" (
|
CREATE TABLE "rooms" (
|
||||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
"live_kit_room" VARCHAR NOT NULL
|
"live_kit_room" VARCHAR NOT NULL,
|
||||||
|
"channel_id" INTEGER REFERENCES channels (id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE "projects" (
|
CREATE TABLE "projects" (
|
||||||
@ -184,3 +185,86 @@ CREATE UNIQUE INDEX
|
|||||||
"index_followers_on_project_id_and_leader_connection_server_id_and_leader_connection_id_and_follower_connection_server_id_and_follower_connection_id"
|
"index_followers_on_project_id_and_leader_connection_server_id_and_leader_connection_id_and_follower_connection_server_id_and_follower_connection_id"
|
||||||
ON "followers" ("project_id", "leader_connection_server_id", "leader_connection_id", "follower_connection_server_id", "follower_connection_id");
|
ON "followers" ("project_id", "leader_connection_server_id", "leader_connection_id", "follower_connection_server_id", "follower_connection_id");
|
||||||
CREATE INDEX "index_followers_on_room_id" ON "followers" ("room_id");
|
CREATE INDEX "index_followers_on_room_id" ON "followers" ("room_id");
|
||||||
|
|
||||||
|
CREATE TABLE "channels" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"name" VARCHAR NOT NULL,
|
||||||
|
"created_at" TIMESTAMP NOT NULL DEFAULT now
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "channel_paths" (
|
||||||
|
"id_path" TEXT NOT NULL PRIMARY KEY,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX "index_channel_paths_on_channel_id" ON "channel_paths" ("channel_id");
|
||||||
|
|
||||||
|
CREATE TABLE "channel_members" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
|
"admin" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"accepted" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"updated_at" TIMESTAMP NOT NULL DEFAULT now
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX "index_channel_members_on_channel_id_and_user_id" ON "channel_members" ("channel_id", "user_id");
|
||||||
|
|
||||||
|
CREATE TABLE "buffers" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX "index_buffers_on_channel_id" ON "buffers" ("channel_id");
|
||||||
|
|
||||||
|
CREATE TABLE "buffer_operations" (
|
||||||
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL,
|
||||||
|
"replica_id" INTEGER NOT NULL,
|
||||||
|
"lamport_timestamp" INTEGER NOT NULL,
|
||||||
|
"value" BLOB NOT NULL,
|
||||||
|
PRIMARY KEY(buffer_id, epoch, lamport_timestamp, replica_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "buffer_snapshots" (
|
||||||
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL,
|
||||||
|
"text" TEXT NOT NULL,
|
||||||
|
"operation_serialization_version" INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY(buffer_id, epoch)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "channel_buffer_collaborators" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"connection_id" INTEGER NOT NULL,
|
||||||
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
||||||
|
"connection_lost" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
|
"replica_id" INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_channel_id" ON "channel_buffer_collaborators" ("channel_id");
|
||||||
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_and_replica_id" ON "channel_buffer_collaborators" ("channel_id", "replica_id");
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_server_id" ON "channel_buffer_collaborators" ("connection_server_id");
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_id" ON "channel_buffer_collaborators" ("connection_id");
|
||||||
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_connection_id_and_server_id" ON "channel_buffer_collaborators" ("channel_id", "connection_id", "connection_server_id");
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE "feature_flags" (
|
||||||
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"flag" TEXT NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX "index_feature_flags" ON "feature_flags" ("id");
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE "user_features" (
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
|
"feature_id" INTEGER NOT NULL REFERENCES feature_flags (id) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (user_id, feature_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX "index_user_features_user_id_and_feature_id" ON "user_features" ("user_id", "feature_id");
|
||||||
|
CREATE INDEX "index_user_features_on_user_id" ON "user_features" ("user_id");
|
||||||
|
CREATE INDEX "index_user_features_on_feature_id" ON "user_features" ("feature_id");
|
||||||
|
30
crates/collab/migrations/20230727150500_add_channels.sql
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
DROP TABLE "channel_messages";
|
||||||
|
DROP TABLE "channel_memberships";
|
||||||
|
DROP TABLE "org_memberships";
|
||||||
|
DROP TABLE "orgs";
|
||||||
|
DROP TABLE "channels";
|
||||||
|
|
||||||
|
CREATE TABLE "channels" (
|
||||||
|
"id" SERIAL PRIMARY KEY,
|
||||||
|
"name" VARCHAR NOT NULL,
|
||||||
|
"created_at" TIMESTAMP NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "channel_paths" (
|
||||||
|
"id_path" VARCHAR NOT NULL PRIMARY KEY,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX "index_channel_paths_on_channel_id" ON "channel_paths" ("channel_id");
|
||||||
|
|
||||||
|
CREATE TABLE "channel_members" (
|
||||||
|
"id" SERIAL PRIMARY KEY,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
|
"admin" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"accepted" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"updated_at" TIMESTAMP NOT NULL DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX "index_channel_members_on_channel_id_and_user_id" ON "channel_members" ("channel_id", "user_id");
|
||||||
|
|
||||||
|
ALTER TABLE rooms ADD COLUMN "channel_id" INTEGER REFERENCES channels (id) ON DELETE CASCADE;
|
@ -0,0 +1,40 @@
|
|||||||
|
CREATE TABLE "buffers" (
|
||||||
|
"id" SERIAL PRIMARY KEY,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL DEFAULT 0
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX "index_buffers_on_channel_id" ON "buffers" ("channel_id");
|
||||||
|
|
||||||
|
CREATE TABLE "buffer_operations" (
|
||||||
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL,
|
||||||
|
"replica_id" INTEGER NOT NULL,
|
||||||
|
"lamport_timestamp" INTEGER NOT NULL,
|
||||||
|
"value" BYTEA NOT NULL,
|
||||||
|
PRIMARY KEY(buffer_id, epoch, lamport_timestamp, replica_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "buffer_snapshots" (
|
||||||
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
||||||
|
"epoch" INTEGER NOT NULL,
|
||||||
|
"text" TEXT NOT NULL,
|
||||||
|
"operation_serialization_version" INTEGER NOT NULL,
|
||||||
|
PRIMARY KEY(buffer_id, epoch)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "channel_buffer_collaborators" (
|
||||||
|
"id" SERIAL PRIMARY KEY,
|
||||||
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
||||||
|
"connection_id" INTEGER NOT NULL,
|
||||||
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
||||||
|
"connection_lost" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||||
|
"replica_id" INTEGER NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_channel_id" ON "channel_buffer_collaborators" ("channel_id");
|
||||||
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_and_replica_id" ON "channel_buffer_collaborators" ("channel_id", "replica_id");
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_server_id" ON "channel_buffer_collaborators" ("connection_server_id");
|
||||||
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_id" ON "channel_buffer_collaborators" ("connection_id");
|
||||||
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_connection_id_and_server_id" ON "channel_buffer_collaborators" ("channel_id", "connection_id", "connection_server_id");
|
@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE "feature_flags" (
|
||||||
|
"id" SERIAL PRIMARY KEY,
|
||||||
|
"flag" VARCHAR(255) NOT NULL UNIQUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX "index_feature_flags" ON "feature_flags" ("id");
|
||||||
|
|
||||||
|
CREATE TABLE "user_features" (
|
||||||
|
"user_id" INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
"feature_id" INTEGER NOT NULL REFERENCES feature_flags(id) ON DELETE CASCADE,
|
||||||
|
PRIMARY KEY (user_id, feature_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX "index_user_features_user_id_and_feature_id" ON "user_features" ("user_id", "feature_id");
|
||||||
|
CREATE INDEX "index_user_features_on_user_id" ON "user_features" ("user_id");
|
||||||
|
CREATE INDEX "index_user_features_on_feature_id" ON "user_features" ("feature_id");
|
@ -64,9 +64,9 @@ async fn main() {
|
|||||||
.expect("failed to fetch user")
|
.expect("failed to fetch user")
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
if let Some(email) = &github_user.email {
|
if admin {
|
||||||
db.create_user(
|
db.create_user(
|
||||||
email,
|
&format!("{}@zed.dev", github_user.login),
|
||||||
admin,
|
admin,
|
||||||
db::NewUserParams {
|
db::NewUserParams {
|
||||||
github_login: github_user.login,
|
github_login: github_user.login,
|
||||||
@ -76,15 +76,11 @@ async fn main() {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to insert user");
|
.expect("failed to insert user");
|
||||||
} else if admin {
|
} else {
|
||||||
db.create_user(
|
db.get_or_create_user_by_github_account(
|
||||||
&format!("{}@zed.dev", github_user.login),
|
&github_user.login,
|
||||||
admin,
|
Some(github_user.id),
|
||||||
db::NewUserParams {
|
github_user.email.as_deref(),
|
||||||
github_login: github_user.login,
|
|
||||||
github_user_id: github_user.id,
|
|
||||||
invite_count: 5,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to insert user");
|
.expect("failed to insert user");
|
||||||
|
128
crates/collab/src/db/ids.rs
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
use crate::Result;
|
||||||
|
use sea_orm::DbErr;
|
||||||
|
use sea_query::{Value, ValueTypeErr};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
macro_rules! id_type {
|
||||||
|
($name:ident) => {
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
Default,
|
||||||
|
PartialEq,
|
||||||
|
Eq,
|
||||||
|
PartialOrd,
|
||||||
|
Ord,
|
||||||
|
Hash,
|
||||||
|
Serialize,
|
||||||
|
Deserialize,
|
||||||
|
)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
pub struct $name(pub i32);
|
||||||
|
|
||||||
|
impl $name {
|
||||||
|
#[allow(unused)]
|
||||||
|
pub const MAX: Self = Self(i32::MAX);
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn from_proto(value: u64) -> Self {
|
||||||
|
Self(value as i32)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
pub fn to_proto(self) -> u64 {
|
||||||
|
self.0 as u64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for $name {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<$name> for sea_query::Value {
|
||||||
|
fn from(value: $name) -> Self {
|
||||||
|
sea_query::Value::Int(Some(value.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sea_orm::TryGetable for $name {
|
||||||
|
fn try_get(
|
||||||
|
res: &sea_orm::QueryResult,
|
||||||
|
pre: &str,
|
||||||
|
col: &str,
|
||||||
|
) -> Result<Self, sea_orm::TryGetError> {
|
||||||
|
Ok(Self(i32::try_get(res, pre, col)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sea_query::ValueType for $name {
|
||||||
|
fn try_from(v: Value) -> Result<Self, sea_query::ValueTypeErr> {
|
||||||
|
Ok(Self(value_to_integer(v)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn type_name() -> String {
|
||||||
|
stringify!($name).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn array_type() -> sea_query::ArrayType {
|
||||||
|
sea_query::ArrayType::Int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn column_type() -> sea_query::ColumnType {
|
||||||
|
sea_query::ColumnType::Integer(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sea_orm::TryFromU64 for $name {
|
||||||
|
fn try_from_u64(n: u64) -> Result<Self, DbErr> {
|
||||||
|
Ok(Self(n.try_into().map_err(|_| {
|
||||||
|
DbErr::ConvertFromU64(concat!(
|
||||||
|
"error converting ",
|
||||||
|
stringify!($name),
|
||||||
|
" to u64"
|
||||||
|
))
|
||||||
|
})?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sea_query::Nullable for $name {
|
||||||
|
fn null() -> Value {
|
||||||
|
Value::Int(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value_to_integer(v: Value) -> Result<i32, ValueTypeErr> {
|
||||||
|
match v {
|
||||||
|
Value::TinyInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::SmallInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::Int(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::BigInt(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::TinyUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::SmallUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::Unsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
Value::BigUnsigned(Some(int)) => int.try_into().map_err(|_| ValueTypeErr),
|
||||||
|
_ => Err(ValueTypeErr),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
id_type!(BufferId);
|
||||||
|
id_type!(AccessTokenId);
|
||||||
|
id_type!(ChannelId);
|
||||||
|
id_type!(ChannelMemberId);
|
||||||
|
id_type!(ContactId);
|
||||||
|
id_type!(FollowerId);
|
||||||
|
id_type!(RoomId);
|
||||||
|
id_type!(RoomParticipantId);
|
||||||
|
id_type!(ProjectId);
|
||||||
|
id_type!(ProjectCollaboratorId);
|
||||||
|
id_type!(ReplicaId);
|
||||||
|
id_type!(ServerId);
|
||||||
|
id_type!(SignupId);
|
||||||
|
id_type!(UserId);
|
||||||
|
id_type!(ChannelBufferCollaboratorId);
|
||||||
|
id_type!(FlagId);
|
11
crates/collab/src/db/queries.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub mod access_tokens;
|
||||||
|
pub mod buffers;
|
||||||
|
pub mod channels;
|
||||||
|
pub mod contacts;
|
||||||
|
pub mod projects;
|
||||||
|
pub mod rooms;
|
||||||
|
pub mod servers;
|
||||||
|
pub mod signups;
|
||||||
|
pub mod users;
|
53
crates/collab/src/db/queries/access_tokens.rs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn create_access_token(
|
||||||
|
&self,
|
||||||
|
user_id: UserId,
|
||||||
|
access_token_hash: &str,
|
||||||
|
max_access_token_count: usize,
|
||||||
|
) -> Result<AccessTokenId> {
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
|
||||||
|
let token = access_token::ActiveModel {
|
||||||
|
user_id: ActiveValue::set(user_id),
|
||||||
|
hash: ActiveValue::set(access_token_hash.into()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
access_token::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
access_token::Column::Id.in_subquery(
|
||||||
|
Query::select()
|
||||||
|
.column(access_token::Column::Id)
|
||||||
|
.from(access_token::Entity)
|
||||||
|
.and_where(access_token::Column::UserId.eq(user_id))
|
||||||
|
.order_by(access_token::Column::Id, sea_orm::Order::Desc)
|
||||||
|
.limit(10000)
|
||||||
|
.offset(max_access_token_count as u64)
|
||||||
|
.to_owned(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(token.id)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_access_token(
|
||||||
|
&self,
|
||||||
|
access_token_id: AccessTokenId,
|
||||||
|
) -> Result<access_token::Model> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(access_token::Entity::find_by_id(access_token_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such access token"))?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
588
crates/collab/src/db/queries/buffers.rs
Normal file
@ -0,0 +1,588 @@
|
|||||||
|
use super::*;
|
||||||
|
use prost::Message;
|
||||||
|
use text::{EditOperation, InsertionTimestamp, UndoOperation};
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn join_channel_buffer(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<proto::JoinChannelBufferResponse> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let tx = tx;
|
||||||
|
|
||||||
|
self.check_user_is_channel_member(channel_id, user_id, &tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let buffer = channel::Model {
|
||||||
|
id: channel_id,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.find_related(buffer::Entity)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let buffer = if let Some(buffer) = buffer {
|
||||||
|
buffer
|
||||||
|
} else {
|
||||||
|
let buffer = buffer::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(channel_id),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
buffer_snapshot::ActiveModel {
|
||||||
|
buffer_id: ActiveValue::Set(buffer.id),
|
||||||
|
epoch: ActiveValue::Set(0),
|
||||||
|
text: ActiveValue::Set(String::new()),
|
||||||
|
operation_serialization_version: ActiveValue::Set(
|
||||||
|
storage::SERIALIZATION_VERSION,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
buffer
|
||||||
|
};
|
||||||
|
|
||||||
|
// Join the collaborators
|
||||||
|
let mut collaborators = channel_buffer_collaborator::Entity::find()
|
||||||
|
.filter(channel_buffer_collaborator::Column::ChannelId.eq(channel_id))
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
let replica_ids = collaborators
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.replica_id)
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
let mut replica_id = ReplicaId(0);
|
||||||
|
while replica_ids.contains(&replica_id) {
|
||||||
|
replica_id.0 += 1;
|
||||||
|
}
|
||||||
|
let collaborator = channel_buffer_collaborator::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(channel_id),
|
||||||
|
connection_id: ActiveValue::Set(connection.id as i32),
|
||||||
|
connection_server_id: ActiveValue::Set(ServerId(connection.owner_id as i32)),
|
||||||
|
user_id: ActiveValue::Set(user_id),
|
||||||
|
replica_id: ActiveValue::Set(replica_id),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
collaborators.push(collaborator);
|
||||||
|
|
||||||
|
// Assemble the buffer state
|
||||||
|
let (base_text, operations) = self.get_buffer_state(&buffer, &tx).await?;
|
||||||
|
|
||||||
|
Ok(proto::JoinChannelBufferResponse {
|
||||||
|
buffer_id: buffer.id.to_proto(),
|
||||||
|
replica_id: replica_id.to_proto() as u32,
|
||||||
|
base_text,
|
||||||
|
operations,
|
||||||
|
collaborators: collaborators
|
||||||
|
.into_iter()
|
||||||
|
.map(|collaborator| proto::Collaborator {
|
||||||
|
peer_id: Some(collaborator.connection().into()),
|
||||||
|
user_id: collaborator.user_id.to_proto(),
|
||||||
|
replica_id: collaborator.replica_id.0 as u32,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn leave_channel_buffer(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<Vec<ConnectionId>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
self.leave_channel_buffer_internal(channel_id, connection, &*tx)
|
||||||
|
.await
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn leave_channel_buffer_internal(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<Vec<ConnectionId>> {
|
||||||
|
let result = channel_buffer_collaborator::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(channel_buffer_collaborator::Column::ChannelId.eq(channel_id))
|
||||||
|
.add(channel_buffer_collaborator::Column::ConnectionId.eq(connection.id as i32))
|
||||||
|
.add(
|
||||||
|
channel_buffer_collaborator::Column::ConnectionServerId
|
||||||
|
.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("not a collaborator on this project"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut connections = Vec::new();
|
||||||
|
let mut rows = channel_buffer_collaborator::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all().add(channel_buffer_collaborator::Column::ChannelId.eq(channel_id)),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(row) = rows.next().await {
|
||||||
|
let row = row?;
|
||||||
|
connections.push(ConnectionId {
|
||||||
|
id: row.connection_id as u32,
|
||||||
|
owner_id: row.connection_server_id.0 as u32,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
drop(rows);
|
||||||
|
|
||||||
|
if connections.is_empty() {
|
||||||
|
self.snapshot_buffer(channel_id, &tx).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(connections)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn leave_channel_buffers(
|
||||||
|
&self,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<Vec<(ChannelId, Vec<ConnectionId>)>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
#[derive(Debug, Clone, Copy, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryChannelIds {
|
||||||
|
ChannelId,
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel_ids: Vec<ChannelId> = channel_buffer_collaborator::Entity::find()
|
||||||
|
.select_only()
|
||||||
|
.column(channel_buffer_collaborator::Column::ChannelId)
|
||||||
|
.filter(Condition::all().add(
|
||||||
|
channel_buffer_collaborator::Column::ConnectionId.eq(connection.id as i32),
|
||||||
|
))
|
||||||
|
.into_values::<_, QueryChannelIds>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut result = Vec::new();
|
||||||
|
for channel_id in channel_ids {
|
||||||
|
let collaborators = self
|
||||||
|
.leave_channel_buffer_internal(channel_id, connection, &*tx)
|
||||||
|
.await?;
|
||||||
|
result.push((channel_id, collaborators));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
pub async fn get_channel_buffer_collaborators(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
) -> Result<Vec<UserId>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
#[derive(Debug, Clone, Copy, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryUserIds {
|
||||||
|
UserId,
|
||||||
|
}
|
||||||
|
|
||||||
|
let users: Vec<UserId> = channel_buffer_collaborator::Entity::find()
|
||||||
|
.select_only()
|
||||||
|
.column(channel_buffer_collaborator::Column::UserId)
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(channel_buffer_collaborator::Column::ChannelId.eq(channel_id)),
|
||||||
|
)
|
||||||
|
.into_values::<_, QueryUserIds>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(users)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_channel_buffer(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user: UserId,
|
||||||
|
operations: &[proto::Operation],
|
||||||
|
) -> Result<Vec<ConnectionId>> {
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
self.check_user_is_channel_member(channel_id, user, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let buffer = buffer::Entity::find()
|
||||||
|
.filter(buffer::Column::ChannelId.eq(channel_id))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such buffer"))?;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryVersion {
|
||||||
|
OperationSerializationVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
let serialization_version: i32 = buffer
|
||||||
|
.find_related(buffer_snapshot::Entity)
|
||||||
|
.select_only()
|
||||||
|
.column(buffer_snapshot::Column::OperationSerializationVersion)
|
||||||
|
.filter(buffer_snapshot::Column::Epoch.eq(buffer.epoch))
|
||||||
|
.into_values::<_, QueryVersion>()
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("missing buffer snapshot"))?;
|
||||||
|
|
||||||
|
let operations = operations
|
||||||
|
.iter()
|
||||||
|
.filter_map(|op| operation_to_storage(op, &buffer, serialization_version))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
if !operations.is_empty() {
|
||||||
|
buffer_operation::Entity::insert_many(operations)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut connections = Vec::new();
|
||||||
|
let mut rows = channel_buffer_collaborator::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(channel_buffer_collaborator::Column::ChannelId.eq(channel_id)),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(row) = rows.next().await {
|
||||||
|
let row = row?;
|
||||||
|
connections.push(ConnectionId {
|
||||||
|
id: row.connection_id as u32,
|
||||||
|
owner_id: row.connection_server_id.0 as u32,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(connections)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_buffer_state(
|
||||||
|
&self,
|
||||||
|
buffer: &buffer::Model,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<(String, Vec<proto::Operation>)> {
|
||||||
|
let id = buffer.id;
|
||||||
|
let (base_text, version) = if buffer.epoch > 0 {
|
||||||
|
let snapshot = buffer_snapshot::Entity::find()
|
||||||
|
.filter(
|
||||||
|
buffer_snapshot::Column::BufferId
|
||||||
|
.eq(id)
|
||||||
|
.and(buffer_snapshot::Column::Epoch.eq(buffer.epoch)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such snapshot"))?;
|
||||||
|
|
||||||
|
let version = snapshot.operation_serialization_version;
|
||||||
|
(snapshot.text, version)
|
||||||
|
} else {
|
||||||
|
(String::new(), storage::SERIALIZATION_VERSION)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut rows = buffer_operation::Entity::find()
|
||||||
|
.filter(
|
||||||
|
buffer_operation::Column::BufferId
|
||||||
|
.eq(id)
|
||||||
|
.and(buffer_operation::Column::Epoch.eq(buffer.epoch)),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
let mut operations = Vec::new();
|
||||||
|
while let Some(row) = rows.next().await {
|
||||||
|
let row = row?;
|
||||||
|
|
||||||
|
let operation = operation_from_storage(row, version)?;
|
||||||
|
operations.push(proto::Operation {
|
||||||
|
variant: Some(operation),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((base_text, operations))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn snapshot_buffer(&self, channel_id: ChannelId, tx: &DatabaseTransaction) -> Result<()> {
|
||||||
|
let buffer = channel::Model {
|
||||||
|
id: channel_id,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.find_related(buffer::Entity)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such buffer"))?;
|
||||||
|
|
||||||
|
let (base_text, operations) = self.get_buffer_state(&buffer, tx).await?;
|
||||||
|
if operations.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut text_buffer = text::Buffer::new(0, 0, base_text);
|
||||||
|
text_buffer
|
||||||
|
.apply_ops(operations.into_iter().filter_map(operation_from_wire))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let base_text = text_buffer.text();
|
||||||
|
let epoch = buffer.epoch + 1;
|
||||||
|
|
||||||
|
buffer_snapshot::Model {
|
||||||
|
buffer_id: buffer.id,
|
||||||
|
epoch,
|
||||||
|
text: base_text,
|
||||||
|
operation_serialization_version: storage::SERIALIZATION_VERSION,
|
||||||
|
}
|
||||||
|
.into_active_model()
|
||||||
|
.insert(tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
buffer::ActiveModel {
|
||||||
|
id: ActiveValue::Unchanged(buffer.id),
|
||||||
|
epoch: ActiveValue::Set(epoch),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.save(tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn operation_to_storage(
|
||||||
|
operation: &proto::Operation,
|
||||||
|
buffer: &buffer::Model,
|
||||||
|
_format: i32,
|
||||||
|
) -> Option<buffer_operation::ActiveModel> {
|
||||||
|
let (replica_id, lamport_timestamp, value) = match operation.variant.as_ref()? {
|
||||||
|
proto::operation::Variant::Edit(operation) => (
|
||||||
|
operation.replica_id,
|
||||||
|
operation.lamport_timestamp,
|
||||||
|
storage::Operation {
|
||||||
|
local_timestamp: operation.local_timestamp,
|
||||||
|
version: version_to_storage(&operation.version),
|
||||||
|
is_undo: false,
|
||||||
|
edit_ranges: operation
|
||||||
|
.ranges
|
||||||
|
.iter()
|
||||||
|
.map(|range| storage::Range {
|
||||||
|
start: range.start,
|
||||||
|
end: range.end,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
edit_texts: operation.new_text.clone(),
|
||||||
|
undo_counts: Vec::new(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
proto::operation::Variant::Undo(operation) => (
|
||||||
|
operation.replica_id,
|
||||||
|
operation.lamport_timestamp,
|
||||||
|
storage::Operation {
|
||||||
|
local_timestamp: operation.local_timestamp,
|
||||||
|
version: version_to_storage(&operation.version),
|
||||||
|
is_undo: true,
|
||||||
|
edit_ranges: Vec::new(),
|
||||||
|
edit_texts: Vec::new(),
|
||||||
|
undo_counts: operation
|
||||||
|
.counts
|
||||||
|
.iter()
|
||||||
|
.map(|entry| storage::UndoCount {
|
||||||
|
replica_id: entry.replica_id,
|
||||||
|
local_timestamp: entry.local_timestamp,
|
||||||
|
count: entry.count,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
},
|
||||||
|
),
|
||||||
|
_ => None?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(buffer_operation::ActiveModel {
|
||||||
|
buffer_id: ActiveValue::Set(buffer.id),
|
||||||
|
epoch: ActiveValue::Set(buffer.epoch),
|
||||||
|
replica_id: ActiveValue::Set(replica_id as i32),
|
||||||
|
lamport_timestamp: ActiveValue::Set(lamport_timestamp as i32),
|
||||||
|
value: ActiveValue::Set(value.encode_to_vec()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn operation_from_storage(
|
||||||
|
row: buffer_operation::Model,
|
||||||
|
_format_version: i32,
|
||||||
|
) -> Result<proto::operation::Variant, Error> {
|
||||||
|
let operation =
|
||||||
|
storage::Operation::decode(row.value.as_slice()).map_err(|error| anyhow!("{}", error))?;
|
||||||
|
let version = version_from_storage(&operation.version);
|
||||||
|
Ok(if operation.is_undo {
|
||||||
|
proto::operation::Variant::Undo(proto::operation::Undo {
|
||||||
|
replica_id: row.replica_id as u32,
|
||||||
|
local_timestamp: operation.local_timestamp as u32,
|
||||||
|
lamport_timestamp: row.lamport_timestamp as u32,
|
||||||
|
version,
|
||||||
|
counts: operation
|
||||||
|
.undo_counts
|
||||||
|
.iter()
|
||||||
|
.map(|entry| proto::UndoCount {
|
||||||
|
replica_id: entry.replica_id,
|
||||||
|
local_timestamp: entry.local_timestamp,
|
||||||
|
count: entry.count,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
proto::operation::Variant::Edit(proto::operation::Edit {
|
||||||
|
replica_id: row.replica_id as u32,
|
||||||
|
local_timestamp: operation.local_timestamp as u32,
|
||||||
|
lamport_timestamp: row.lamport_timestamp as u32,
|
||||||
|
version,
|
||||||
|
ranges: operation
|
||||||
|
.edit_ranges
|
||||||
|
.into_iter()
|
||||||
|
.map(|range| proto::Range {
|
||||||
|
start: range.start,
|
||||||
|
end: range.end,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
new_text: operation.edit_texts,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version_to_storage(version: &Vec<proto::VectorClockEntry>) -> Vec<storage::VectorClockEntry> {
|
||||||
|
version
|
||||||
|
.iter()
|
||||||
|
.map(|entry| storage::VectorClockEntry {
|
||||||
|
replica_id: entry.replica_id,
|
||||||
|
timestamp: entry.timestamp,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version_from_storage(version: &Vec<storage::VectorClockEntry>) -> Vec<proto::VectorClockEntry> {
|
||||||
|
version
|
||||||
|
.iter()
|
||||||
|
.map(|entry| proto::VectorClockEntry {
|
||||||
|
replica_id: entry.replica_id,
|
||||||
|
timestamp: entry.timestamp,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is currently a manual copy of the deserialization code in the client's langauge crate
|
||||||
|
pub fn operation_from_wire(operation: proto::Operation) -> Option<text::Operation> {
|
||||||
|
match operation.variant? {
|
||||||
|
proto::operation::Variant::Edit(edit) => Some(text::Operation::Edit(EditOperation {
|
||||||
|
timestamp: InsertionTimestamp {
|
||||||
|
replica_id: edit.replica_id as text::ReplicaId,
|
||||||
|
local: edit.local_timestamp,
|
||||||
|
lamport: edit.lamport_timestamp,
|
||||||
|
},
|
||||||
|
version: version_from_wire(&edit.version),
|
||||||
|
ranges: edit
|
||||||
|
.ranges
|
||||||
|
.into_iter()
|
||||||
|
.map(|range| {
|
||||||
|
text::FullOffset(range.start as usize)..text::FullOffset(range.end as usize)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
new_text: edit.new_text.into_iter().map(Arc::from).collect(),
|
||||||
|
})),
|
||||||
|
proto::operation::Variant::Undo(undo) => Some(text::Operation::Undo {
|
||||||
|
lamport_timestamp: clock::Lamport {
|
||||||
|
replica_id: undo.replica_id as text::ReplicaId,
|
||||||
|
value: undo.lamport_timestamp,
|
||||||
|
},
|
||||||
|
undo: UndoOperation {
|
||||||
|
id: clock::Local {
|
||||||
|
replica_id: undo.replica_id as text::ReplicaId,
|
||||||
|
value: undo.local_timestamp,
|
||||||
|
},
|
||||||
|
version: version_from_wire(&undo.version),
|
||||||
|
counts: undo
|
||||||
|
.counts
|
||||||
|
.into_iter()
|
||||||
|
.map(|c| {
|
||||||
|
(
|
||||||
|
clock::Local {
|
||||||
|
replica_id: c.replica_id as text::ReplicaId,
|
||||||
|
value: c.local_timestamp,
|
||||||
|
},
|
||||||
|
c.count,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version_from_wire(message: &[proto::VectorClockEntry]) -> clock::Global {
|
||||||
|
let mut version = clock::Global::new();
|
||||||
|
for entry in message {
|
||||||
|
version.observe(clock::Local {
|
||||||
|
replica_id: entry.replica_id as text::ReplicaId,
|
||||||
|
value: entry.timestamp,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
version
|
||||||
|
}
|
||||||
|
|
||||||
|
mod storage {
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
use prost::Message;
|
||||||
|
pub const SERIALIZATION_VERSION: i32 = 1;
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct Operation {
|
||||||
|
#[prost(uint32, tag = "1")]
|
||||||
|
pub local_timestamp: u32,
|
||||||
|
#[prost(message, repeated, tag = "2")]
|
||||||
|
pub version: Vec<VectorClockEntry>,
|
||||||
|
#[prost(bool, tag = "3")]
|
||||||
|
pub is_undo: bool,
|
||||||
|
#[prost(message, repeated, tag = "4")]
|
||||||
|
pub edit_ranges: Vec<Range>,
|
||||||
|
#[prost(string, repeated, tag = "5")]
|
||||||
|
pub edit_texts: Vec<String>,
|
||||||
|
#[prost(message, repeated, tag = "6")]
|
||||||
|
pub undo_counts: Vec<UndoCount>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct VectorClockEntry {
|
||||||
|
#[prost(uint32, tag = "1")]
|
||||||
|
pub replica_id: u32,
|
||||||
|
#[prost(uint32, tag = "2")]
|
||||||
|
pub timestamp: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct Range {
|
||||||
|
#[prost(uint64, tag = "1")]
|
||||||
|
pub start: u64,
|
||||||
|
#[prost(uint64, tag = "2")]
|
||||||
|
pub end: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Message)]
|
||||||
|
pub struct UndoCount {
|
||||||
|
#[prost(uint32, tag = "1")]
|
||||||
|
pub replica_id: u32,
|
||||||
|
#[prost(uint32, tag = "2")]
|
||||||
|
pub local_timestamp: u32,
|
||||||
|
#[prost(uint32, tag = "3")]
|
||||||
|
pub count: u32,
|
||||||
|
}
|
||||||
|
}
|
697
crates/collab/src/db/queries/channels.rs
Normal file
@ -0,0 +1,697 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn create_root_channel(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
live_kit_room: &str,
|
||||||
|
creator_id: UserId,
|
||||||
|
) -> Result<ChannelId> {
|
||||||
|
self.create_channel(name, None, live_kit_room, creator_id)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_channel(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
parent: Option<ChannelId>,
|
||||||
|
live_kit_room: &str,
|
||||||
|
creator_id: UserId,
|
||||||
|
) -> Result<ChannelId> {
|
||||||
|
let name = Self::sanitize_channel_name(name)?;
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
if let Some(parent) = parent {
|
||||||
|
self.check_user_is_channel_admin(parent, creator_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel = channel::ActiveModel {
|
||||||
|
name: ActiveValue::Set(name.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let channel_paths_stmt;
|
||||||
|
if let Some(parent) = parent {
|
||||||
|
let sql = r#"
|
||||||
|
INSERT INTO channel_paths
|
||||||
|
(id_path, channel_id)
|
||||||
|
SELECT
|
||||||
|
id_path || $1 || '/', $2
|
||||||
|
FROM
|
||||||
|
channel_paths
|
||||||
|
WHERE
|
||||||
|
channel_id = $3
|
||||||
|
"#;
|
||||||
|
channel_paths_stmt = Statement::from_sql_and_values(
|
||||||
|
self.pool.get_database_backend(),
|
||||||
|
sql,
|
||||||
|
[
|
||||||
|
channel.id.to_proto().into(),
|
||||||
|
channel.id.to_proto().into(),
|
||||||
|
parent.to_proto().into(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
tx.execute(channel_paths_stmt).await?;
|
||||||
|
} else {
|
||||||
|
channel_path::Entity::insert(channel_path::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(channel.id),
|
||||||
|
id_path: ActiveValue::Set(format!("/{}/", channel.id)),
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
channel_member::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(channel.id),
|
||||||
|
user_id: ActiveValue::Set(creator_id),
|
||||||
|
accepted: ActiveValue::Set(true),
|
||||||
|
admin: ActiveValue::Set(true),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
room::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(Some(channel.id)),
|
||||||
|
live_kit_room: ActiveValue::Set(live_kit_room.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(channel.id)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove_channel(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
) -> Result<(Vec<ChannelId>, Vec<UserId>)> {
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
self.check_user_is_channel_admin(channel_id, user_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Don't remove descendant channels that have additional parents.
|
||||||
|
let mut channels_to_remove = self.get_channel_descendants([channel_id], &*tx).await?;
|
||||||
|
{
|
||||||
|
let mut channels_to_keep = channel_path::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_path::Column::ChannelId
|
||||||
|
.is_in(
|
||||||
|
channels_to_remove
|
||||||
|
.keys()
|
||||||
|
.copied()
|
||||||
|
.filter(|&id| id != channel_id),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
channel_path::Column::IdPath
|
||||||
|
.not_like(&format!("%/{}/%", channel_id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(row) = channels_to_keep.next().await {
|
||||||
|
let row = row?;
|
||||||
|
channels_to_remove.remove(&row.channel_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel_ancestors = self.get_channel_ancestors(channel_id, &*tx).await?;
|
||||||
|
let members_to_notify: Vec<UserId> = channel_member::Entity::find()
|
||||||
|
.filter(channel_member::Column::ChannelId.is_in(channel_ancestors))
|
||||||
|
.select_only()
|
||||||
|
.column(channel_member::Column::UserId)
|
||||||
|
.distinct()
|
||||||
|
.into_values::<_, QueryUserIds>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
channel::Entity::delete_many()
|
||||||
|
.filter(channel::Column::Id.is_in(channels_to_remove.keys().copied()))
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok((channels_to_remove.into_keys().collect(), members_to_notify))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn invite_channel_member(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
invitee_id: UserId,
|
||||||
|
inviter_id: UserId,
|
||||||
|
is_admin: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
self.check_user_is_channel_admin(channel_id, inviter_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
channel_member::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Set(channel_id),
|
||||||
|
user_id: ActiveValue::Set(invitee_id),
|
||||||
|
accepted: ActiveValue::Set(false),
|
||||||
|
admin: ActiveValue::Set(is_admin),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sanitize_channel_name(name: &str) -> Result<&str> {
|
||||||
|
let new_name = name.trim().trim_start_matches('#');
|
||||||
|
if new_name == "" {
|
||||||
|
Err(anyhow!("channel name can't be blank"))?;
|
||||||
|
}
|
||||||
|
Ok(new_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn rename_channel(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
new_name: &str,
|
||||||
|
) -> Result<String> {
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
let new_name = Self::sanitize_channel_name(new_name)?.to_string();
|
||||||
|
|
||||||
|
self.check_user_is_channel_admin(channel_id, user_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
channel::ActiveModel {
|
||||||
|
id: ActiveValue::Unchanged(channel_id),
|
||||||
|
name: ActiveValue::Set(new_name.clone()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.update(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(new_name)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn respond_to_channel_invite(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
accept: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(move |tx| async move {
|
||||||
|
let rows_affected = if accept {
|
||||||
|
channel_member::Entity::update_many()
|
||||||
|
.set(channel_member::ActiveModel {
|
||||||
|
accepted: ActiveValue::Set(accept),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.eq(channel_id)
|
||||||
|
.and(channel_member::Column::UserId.eq(user_id))
|
||||||
|
.and(channel_member::Column::Accepted.eq(false)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?
|
||||||
|
.rows_affected
|
||||||
|
} else {
|
||||||
|
channel_member::ActiveModel {
|
||||||
|
channel_id: ActiveValue::Unchanged(channel_id),
|
||||||
|
user_id: ActiveValue::Unchanged(user_id),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.delete(&*tx)
|
||||||
|
.await?
|
||||||
|
.rows_affected
|
||||||
|
};
|
||||||
|
|
||||||
|
if rows_affected == 0 {
|
||||||
|
Err(anyhow!("no such invitation"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove_channel_member(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
member_id: UserId,
|
||||||
|
remover_id: UserId,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
self.check_user_is_channel_admin(channel_id, remover_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let result = channel_member::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.eq(channel_id)
|
||||||
|
.and(channel_member::Column::UserId.eq(member_id)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("no such member"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channel_invites_for_user(&self, user_id: UserId) -> Result<Vec<Channel>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let channel_invites = channel_member::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::UserId
|
||||||
|
.eq(user_id)
|
||||||
|
.and(channel_member::Column::Accepted.eq(false)),
|
||||||
|
)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let channels = channel::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel::Column::Id.is_in(
|
||||||
|
channel_invites
|
||||||
|
.into_iter()
|
||||||
|
.map(|channel_member| channel_member.channel_id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let channels = channels
|
||||||
|
.into_iter()
|
||||||
|
.map(|channel| Channel {
|
||||||
|
id: channel.id,
|
||||||
|
name: channel.name,
|
||||||
|
parent_id: None,
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(channels)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channels_for_user(&self, user_id: UserId) -> Result<ChannelsForUser> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let tx = tx;
|
||||||
|
|
||||||
|
let channel_memberships = channel_member::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::UserId
|
||||||
|
.eq(user_id)
|
||||||
|
.and(channel_member::Column::Accepted.eq(true)),
|
||||||
|
)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let parents_by_child_id = self
|
||||||
|
.get_channel_descendants(channel_memberships.iter().map(|m| m.channel_id), &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let channels_with_admin_privileges = channel_memberships
|
||||||
|
.iter()
|
||||||
|
.filter_map(|membership| membership.admin.then_some(membership.channel_id))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut channels = Vec::with_capacity(parents_by_child_id.len());
|
||||||
|
{
|
||||||
|
let mut rows = channel::Entity::find()
|
||||||
|
.filter(channel::Column::Id.is_in(parents_by_child_id.keys().copied()))
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(row) = rows.next().await {
|
||||||
|
let row = row?;
|
||||||
|
channels.push(Channel {
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
parent_id: parents_by_child_id.get(&row.id).copied().flatten(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryUserIdsAndChannelIds {
|
||||||
|
ChannelId,
|
||||||
|
UserId,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut channel_participants: HashMap<ChannelId, Vec<UserId>> = HashMap::default();
|
||||||
|
{
|
||||||
|
let mut rows = room_participant::Entity::find()
|
||||||
|
.inner_join(room::Entity)
|
||||||
|
.filter(room::Column::ChannelId.is_in(channels.iter().map(|c| c.id)))
|
||||||
|
.select_only()
|
||||||
|
.column(room::Column::ChannelId)
|
||||||
|
.column(room_participant::Column::UserId)
|
||||||
|
.into_values::<_, QueryUserIdsAndChannelIds>()
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(row) = rows.next().await {
|
||||||
|
let row: (ChannelId, UserId) = row?;
|
||||||
|
channel_participants.entry(row.0).or_default().push(row.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ChannelsForUser {
|
||||||
|
channels,
|
||||||
|
channel_participants,
|
||||||
|
channels_with_admin_privileges,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channel_members(&self, id: ChannelId) -> Result<Vec<UserId>> {
|
||||||
|
self.transaction(|tx| async move { self.get_channel_members_internal(id, &*tx).await })
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_channel_member_admin(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
from: UserId,
|
||||||
|
for_user: UserId,
|
||||||
|
admin: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
self.check_user_is_channel_admin(channel_id, from, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let result = channel_member::Entity::update_many()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.eq(channel_id)
|
||||||
|
.and(channel_member::Column::UserId.eq(for_user)),
|
||||||
|
)
|
||||||
|
.set(channel_member::ActiveModel {
|
||||||
|
admin: ActiveValue::set(admin),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("no such member"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channel_member_details(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
) -> Result<Vec<proto::ChannelMember>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
self.check_user_is_channel_admin(channel_id, user_id, &*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryMemberDetails {
|
||||||
|
UserId,
|
||||||
|
Admin,
|
||||||
|
IsDirectMember,
|
||||||
|
Accepted,
|
||||||
|
}
|
||||||
|
|
||||||
|
let tx = tx;
|
||||||
|
let ancestor_ids = self.get_channel_ancestors(channel_id, &*tx).await?;
|
||||||
|
let mut stream = channel_member::Entity::find()
|
||||||
|
.distinct()
|
||||||
|
.filter(channel_member::Column::ChannelId.is_in(ancestor_ids.iter().copied()))
|
||||||
|
.select_only()
|
||||||
|
.column(channel_member::Column::UserId)
|
||||||
|
.column(channel_member::Column::Admin)
|
||||||
|
.column_as(
|
||||||
|
channel_member::Column::ChannelId.eq(channel_id),
|
||||||
|
QueryMemberDetails::IsDirectMember,
|
||||||
|
)
|
||||||
|
.column(channel_member::Column::Accepted)
|
||||||
|
.order_by_asc(channel_member::Column::UserId)
|
||||||
|
.into_values::<_, QueryMemberDetails>()
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut rows = Vec::<proto::ChannelMember>::new();
|
||||||
|
while let Some(row) = stream.next().await {
|
||||||
|
let (user_id, is_admin, is_direct_member, is_invite_accepted): (
|
||||||
|
UserId,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
bool,
|
||||||
|
) = row?;
|
||||||
|
let kind = match (is_direct_member, is_invite_accepted) {
|
||||||
|
(true, true) => proto::channel_member::Kind::Member,
|
||||||
|
(true, false) => proto::channel_member::Kind::Invitee,
|
||||||
|
(false, true) => proto::channel_member::Kind::AncestorMember,
|
||||||
|
(false, false) => continue,
|
||||||
|
};
|
||||||
|
let user_id = user_id.to_proto();
|
||||||
|
let kind = kind.into();
|
||||||
|
if let Some(last_row) = rows.last_mut() {
|
||||||
|
if last_row.user_id == user_id {
|
||||||
|
if is_direct_member {
|
||||||
|
last_row.kind = kind;
|
||||||
|
last_row.admin = is_admin;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rows.push(proto::ChannelMember {
|
||||||
|
user_id,
|
||||||
|
kind,
|
||||||
|
admin: is_admin,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(rows)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channel_members_internal(
|
||||||
|
&self,
|
||||||
|
id: ChannelId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<Vec<UserId>> {
|
||||||
|
let ancestor_ids = self.get_channel_ancestors(id, tx).await?;
|
||||||
|
let user_ids = channel_member::Entity::find()
|
||||||
|
.distinct()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.is_in(ancestor_ids.iter().copied())
|
||||||
|
.and(channel_member::Column::Accepted.eq(true)),
|
||||||
|
)
|
||||||
|
.select_only()
|
||||||
|
.column(channel_member::Column::UserId)
|
||||||
|
.into_values::<_, QueryUserIds>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(user_ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_user_is_channel_member(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<()> {
|
||||||
|
let channel_ids = self.get_channel_ancestors(channel_id, tx).await?;
|
||||||
|
channel_member::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.is_in(channel_ids)
|
||||||
|
.and(channel_member::Column::UserId.eq(user_id)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("user is not a channel member or channel does not exist"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn check_user_is_channel_admin(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<()> {
|
||||||
|
let channel_ids = self.get_channel_ancestors(channel_id, tx).await?;
|
||||||
|
channel_member::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.is_in(channel_ids)
|
||||||
|
.and(channel_member::Column::UserId.eq(user_id))
|
||||||
|
.and(channel_member::Column::Admin.eq(true)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("user is not a channel admin or channel does not exist"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_channel_ancestors(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<Vec<ChannelId>> {
|
||||||
|
let paths = channel_path::Entity::find()
|
||||||
|
.filter(channel_path::Column::ChannelId.eq(channel_id))
|
||||||
|
.all(tx)
|
||||||
|
.await?;
|
||||||
|
let mut channel_ids = Vec::new();
|
||||||
|
for path in paths {
|
||||||
|
for id in path.id_path.trim_matches('/').split('/') {
|
||||||
|
if let Ok(id) = id.parse() {
|
||||||
|
let id = ChannelId::from_proto(id);
|
||||||
|
if let Err(ix) = channel_ids.binary_search(&id) {
|
||||||
|
channel_ids.insert(ix, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(channel_ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_channel_descendants(
|
||||||
|
&self,
|
||||||
|
channel_ids: impl IntoIterator<Item = ChannelId>,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<HashMap<ChannelId, Option<ChannelId>>> {
|
||||||
|
let mut values = String::new();
|
||||||
|
for id in channel_ids {
|
||||||
|
if !values.is_empty() {
|
||||||
|
values.push_str(", ");
|
||||||
|
}
|
||||||
|
write!(&mut values, "({})", id).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if values.is_empty() {
|
||||||
|
return Ok(HashMap::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
let sql = format!(
|
||||||
|
r#"
|
||||||
|
SELECT
|
||||||
|
descendant_paths.*
|
||||||
|
FROM
|
||||||
|
channel_paths parent_paths, channel_paths descendant_paths
|
||||||
|
WHERE
|
||||||
|
parent_paths.channel_id IN ({values}) AND
|
||||||
|
descendant_paths.id_path LIKE (parent_paths.id_path || '%')
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
||||||
|
let stmt = Statement::from_string(self.pool.get_database_backend(), sql);
|
||||||
|
|
||||||
|
let mut parents_by_child_id = HashMap::default();
|
||||||
|
let mut paths = channel_path::Entity::find()
|
||||||
|
.from_raw_sql(stmt)
|
||||||
|
.stream(tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
while let Some(path) = paths.next().await {
|
||||||
|
let path = path?;
|
||||||
|
let ids = path.id_path.trim_matches('/').split('/');
|
||||||
|
let mut parent_id = None;
|
||||||
|
for id in ids {
|
||||||
|
if let Ok(id) = id.parse() {
|
||||||
|
let id = ChannelId::from_proto(id);
|
||||||
|
if id == path.channel_id {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
parent_id = Some(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parents_by_child_id.insert(path.channel_id, parent_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(parents_by_child_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the channel with the given ID and:
|
||||||
|
/// - true if the user is a member
|
||||||
|
/// - false if the user hasn't accepted the invitation yet
|
||||||
|
pub async fn get_channel(
|
||||||
|
&self,
|
||||||
|
channel_id: ChannelId,
|
||||||
|
user_id: UserId,
|
||||||
|
) -> Result<Option<(Channel, bool)>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let tx = tx;
|
||||||
|
|
||||||
|
let channel = channel::Entity::find_by_id(channel_id).one(&*tx).await?;
|
||||||
|
|
||||||
|
if let Some(channel) = channel {
|
||||||
|
if self
|
||||||
|
.check_user_is_channel_member(channel_id, user_id, &*tx)
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let channel_membership = channel_member::Entity::find()
|
||||||
|
.filter(
|
||||||
|
channel_member::Column::ChannelId
|
||||||
|
.eq(channel_id)
|
||||||
|
.and(channel_member::Column::UserId.eq(user_id)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let is_accepted = channel_membership
|
||||||
|
.map(|membership| membership.accepted)
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
|
Ok(Some((
|
||||||
|
Channel {
|
||||||
|
id: channel.id,
|
||||||
|
name: channel.name,
|
||||||
|
parent_id: None,
|
||||||
|
},
|
||||||
|
is_accepted,
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn room_id_for_channel(&self, channel_id: ChannelId) -> Result<RoomId> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let tx = tx;
|
||||||
|
let room = channel::Model {
|
||||||
|
id: channel_id,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.find_related(room::Entity)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("invalid channel"))?;
|
||||||
|
Ok(room.id)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryUserIds {
|
||||||
|
UserId,
|
||||||
|
}
|
298
crates/collab/src/db/queries/contacts.rs
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn get_contacts(&self, user_id: UserId) -> Result<Vec<Contact>> {
|
||||||
|
#[derive(Debug, FromQueryResult)]
|
||||||
|
struct ContactWithUserBusyStatuses {
|
||||||
|
user_id_a: UserId,
|
||||||
|
user_id_b: UserId,
|
||||||
|
a_to_b: bool,
|
||||||
|
accepted: bool,
|
||||||
|
should_notify: bool,
|
||||||
|
user_a_busy: bool,
|
||||||
|
user_b_busy: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let user_a_participant = Alias::new("user_a_participant");
|
||||||
|
let user_b_participant = Alias::new("user_b_participant");
|
||||||
|
let mut db_contacts = contact::Entity::find()
|
||||||
|
.column_as(
|
||||||
|
Expr::tbl(user_a_participant.clone(), room_participant::Column::Id)
|
||||||
|
.is_not_null(),
|
||||||
|
"user_a_busy",
|
||||||
|
)
|
||||||
|
.column_as(
|
||||||
|
Expr::tbl(user_b_participant.clone(), room_participant::Column::Id)
|
||||||
|
.is_not_null(),
|
||||||
|
"user_b_busy",
|
||||||
|
)
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(user_id)
|
||||||
|
.or(contact::Column::UserIdB.eq(user_id)),
|
||||||
|
)
|
||||||
|
.join_as(
|
||||||
|
JoinType::LeftJoin,
|
||||||
|
contact::Relation::UserARoomParticipant.def(),
|
||||||
|
user_a_participant,
|
||||||
|
)
|
||||||
|
.join_as(
|
||||||
|
JoinType::LeftJoin,
|
||||||
|
contact::Relation::UserBRoomParticipant.def(),
|
||||||
|
user_b_participant,
|
||||||
|
)
|
||||||
|
.into_model::<ContactWithUserBusyStatuses>()
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut contacts = Vec::new();
|
||||||
|
while let Some(db_contact) = db_contacts.next().await {
|
||||||
|
let db_contact = db_contact?;
|
||||||
|
if db_contact.user_id_a == user_id {
|
||||||
|
if db_contact.accepted {
|
||||||
|
contacts.push(Contact::Accepted {
|
||||||
|
user_id: db_contact.user_id_b,
|
||||||
|
should_notify: db_contact.should_notify && db_contact.a_to_b,
|
||||||
|
busy: db_contact.user_b_busy,
|
||||||
|
});
|
||||||
|
} else if db_contact.a_to_b {
|
||||||
|
contacts.push(Contact::Outgoing {
|
||||||
|
user_id: db_contact.user_id_b,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
contacts.push(Contact::Incoming {
|
||||||
|
user_id: db_contact.user_id_b,
|
||||||
|
should_notify: db_contact.should_notify,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if db_contact.accepted {
|
||||||
|
contacts.push(Contact::Accepted {
|
||||||
|
user_id: db_contact.user_id_a,
|
||||||
|
should_notify: db_contact.should_notify && !db_contact.a_to_b,
|
||||||
|
busy: db_contact.user_a_busy,
|
||||||
|
});
|
||||||
|
} else if db_contact.a_to_b {
|
||||||
|
contacts.push(Contact::Incoming {
|
||||||
|
user_id: db_contact.user_id_a,
|
||||||
|
should_notify: db_contact.should_notify,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
contacts.push(Contact::Outgoing {
|
||||||
|
user_id: db_contact.user_id_a,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts.sort_unstable_by_key(|contact| contact.user_id());
|
||||||
|
|
||||||
|
Ok(contacts)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_user_busy(&self, user_id: UserId) -> Result<bool> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let participant = room_participant::Entity::find()
|
||||||
|
.filter(room_participant::Column::UserId.eq(user_id))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(participant.is_some())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn has_contact(&self, user_id_1: UserId, user_id_2: UserId) -> Result<bool> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let (id_a, id_b) = if user_id_1 < user_id_2 {
|
||||||
|
(user_id_1, user_id_2)
|
||||||
|
} else {
|
||||||
|
(user_id_2, user_id_1)
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(contact::Entity::find()
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(id_a)
|
||||||
|
.and(contact::Column::UserIdB.eq(id_b))
|
||||||
|
.and(contact::Column::Accepted.eq(true)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.is_some())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn send_contact_request(&self, sender_id: UserId, receiver_id: UserId) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let (id_a, id_b, a_to_b) = if sender_id < receiver_id {
|
||||||
|
(sender_id, receiver_id, true)
|
||||||
|
} else {
|
||||||
|
(receiver_id, sender_id, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
let rows_affected = contact::Entity::insert(contact::ActiveModel {
|
||||||
|
user_id_a: ActiveValue::set(id_a),
|
||||||
|
user_id_b: ActiveValue::set(id_b),
|
||||||
|
a_to_b: ActiveValue::set(a_to_b),
|
||||||
|
accepted: ActiveValue::set(false),
|
||||||
|
should_notify: ActiveValue::set(true),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([contact::Column::UserIdA, contact::Column::UserIdB])
|
||||||
|
.values([
|
||||||
|
(contact::Column::Accepted, true.into()),
|
||||||
|
(contact::Column::ShouldNotify, false.into()),
|
||||||
|
])
|
||||||
|
.action_and_where(
|
||||||
|
contact::Column::Accepted.eq(false).and(
|
||||||
|
contact::Column::AToB
|
||||||
|
.eq(a_to_b)
|
||||||
|
.and(contact::Column::UserIdA.eq(id_b))
|
||||||
|
.or(contact::Column::AToB
|
||||||
|
.ne(a_to_b)
|
||||||
|
.and(contact::Column::UserIdA.eq(id_a))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec_without_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if rows_affected == 1 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("contact already requested"))?
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a bool indicating whether the removed contact had originally accepted or not
|
||||||
|
///
|
||||||
|
/// Deletes the contact identified by the requester and responder ids, and then returns
|
||||||
|
/// whether the deleted contact had originally accepted or was a pending contact request.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `requester_id` - The user that initiates this request
|
||||||
|
/// * `responder_id` - The user that will be removed
|
||||||
|
pub async fn remove_contact(&self, requester_id: UserId, responder_id: UserId) -> Result<bool> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let (id_a, id_b) = if responder_id < requester_id {
|
||||||
|
(responder_id, requester_id)
|
||||||
|
} else {
|
||||||
|
(requester_id, responder_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
let contact = contact::Entity::find()
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(id_a)
|
||||||
|
.and(contact::Column::UserIdB.eq(id_b)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such contact"))?;
|
||||||
|
|
||||||
|
contact::Entity::delete_by_id(contact.id).exec(&*tx).await?;
|
||||||
|
Ok(contact.accepted)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn dismiss_contact_notification(
|
||||||
|
&self,
|
||||||
|
user_id: UserId,
|
||||||
|
contact_user_id: UserId,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let (id_a, id_b, a_to_b) = if user_id < contact_user_id {
|
||||||
|
(user_id, contact_user_id, true)
|
||||||
|
} else {
|
||||||
|
(contact_user_id, user_id, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = contact::Entity::update_many()
|
||||||
|
.set(contact::ActiveModel {
|
||||||
|
should_notify: ActiveValue::set(false),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(id_a)
|
||||||
|
.and(contact::Column::UserIdB.eq(id_b))
|
||||||
|
.and(
|
||||||
|
contact::Column::AToB
|
||||||
|
.eq(a_to_b)
|
||||||
|
.and(contact::Column::Accepted.eq(true))
|
||||||
|
.or(contact::Column::AToB
|
||||||
|
.ne(a_to_b)
|
||||||
|
.and(contact::Column::Accepted.eq(false))),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("no such contact request"))?
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn respond_to_contact_request(
|
||||||
|
&self,
|
||||||
|
responder_id: UserId,
|
||||||
|
requester_id: UserId,
|
||||||
|
accept: bool,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let (id_a, id_b, a_to_b) = if responder_id < requester_id {
|
||||||
|
(responder_id, requester_id, false)
|
||||||
|
} else {
|
||||||
|
(requester_id, responder_id, true)
|
||||||
|
};
|
||||||
|
let rows_affected = if accept {
|
||||||
|
let result = contact::Entity::update_many()
|
||||||
|
.set(contact::ActiveModel {
|
||||||
|
accepted: ActiveValue::set(true),
|
||||||
|
should_notify: ActiveValue::set(true),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(id_a)
|
||||||
|
.and(contact::Column::UserIdB.eq(id_b))
|
||||||
|
.and(contact::Column::AToB.eq(a_to_b)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
result.rows_affected
|
||||||
|
} else {
|
||||||
|
let result = contact::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
contact::Column::UserIdA
|
||||||
|
.eq(id_a)
|
||||||
|
.and(contact::Column::UserIdB.eq(id_b))
|
||||||
|
.and(contact::Column::AToB.eq(a_to_b))
|
||||||
|
.and(contact::Column::Accepted.eq(false)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
result.rows_affected
|
||||||
|
};
|
||||||
|
|
||||||
|
if rows_affected == 1 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("no such contact request"))?
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
926
crates/collab/src/db/queries/projects.rs
Normal file
@ -0,0 +1,926 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn project_count_excluding_admins(&self) -> Result<usize> {
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryAs {
|
||||||
|
Count,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(project::Entity::find()
|
||||||
|
.select_only()
|
||||||
|
.column_as(project::Column::Id.count(), QueryAs::Count)
|
||||||
|
.inner_join(user::Entity)
|
||||||
|
.filter(user::Column::Admin.eq(false))
|
||||||
|
.into_values::<_, QueryAs>()
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.unwrap_or(0i64) as usize)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn share_project(
|
||||||
|
&self,
|
||||||
|
room_id: RoomId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
worktrees: &[proto::WorktreeMetadata],
|
||||||
|
) -> Result<RoomGuard<(ProjectId, proto::Room)>> {
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let participant = room_participant::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(
|
||||||
|
room_participant::Column::AnsweringConnectionId
|
||||||
|
.eq(connection.id as i32),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
room_participant::Column::AnsweringConnectionServerId
|
||||||
|
.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("could not find participant"))?;
|
||||||
|
if participant.room_id != room_id {
|
||||||
|
return Err(anyhow!("shared project on unexpected room"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let project = project::ActiveModel {
|
||||||
|
room_id: ActiveValue::set(participant.room_id),
|
||||||
|
host_user_id: ActiveValue::set(participant.user_id),
|
||||||
|
host_connection_id: ActiveValue::set(Some(connection.id as i32)),
|
||||||
|
host_connection_server_id: ActiveValue::set(Some(ServerId(
|
||||||
|
connection.owner_id as i32,
|
||||||
|
))),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !worktrees.is_empty() {
|
||||||
|
worktree::Entity::insert_many(worktrees.iter().map(|worktree| {
|
||||||
|
worktree::ActiveModel {
|
||||||
|
id: ActiveValue::set(worktree.id as i64),
|
||||||
|
project_id: ActiveValue::set(project.id),
|
||||||
|
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
||||||
|
root_name: ActiveValue::set(worktree.root_name.clone()),
|
||||||
|
visible: ActiveValue::set(worktree.visible),
|
||||||
|
scan_id: ActiveValue::set(0),
|
||||||
|
completed_scan_id: ActiveValue::set(0),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
project_collaborator::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project.id),
|
||||||
|
connection_id: ActiveValue::set(connection.id as i32),
|
||||||
|
connection_server_id: ActiveValue::set(ServerId(connection.owner_id as i32)),
|
||||||
|
user_id: ActiveValue::set(participant.user_id),
|
||||||
|
replica_id: ActiveValue::set(ReplicaId(0)),
|
||||||
|
is_host: ActiveValue::set(true),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let room = self.get_room(room_id, &tx).await?;
|
||||||
|
Ok((project.id, room))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn unshare_project(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<(proto::Room, Vec<ConnectionId>)>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let guest_connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
|
||||||
|
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("project not found"))?;
|
||||||
|
if project.host_connection()? == connection {
|
||||||
|
project::Entity::delete(project.into_active_model())
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
let room = self.get_room(room_id, &tx).await?;
|
||||||
|
Ok((room, guest_connection_ids))
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("cannot unshare a project hosted by another user"))?
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_project(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
worktrees: &[proto::WorktreeMetadata],
|
||||||
|
) -> Result<RoomGuard<(proto::Room, Vec<ConnectionId>)>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(project::Column::HostConnectionId.eq(connection.id as i32))
|
||||||
|
.add(
|
||||||
|
project::Column::HostConnectionServerId.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
|
||||||
|
self.update_project_worktrees(project.id, worktrees, &tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let guest_connection_ids = self.project_guest_connection_ids(project.id, &tx).await?;
|
||||||
|
let room = self.get_room(project.room_id, &tx).await?;
|
||||||
|
Ok((room, guest_connection_ids))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(in crate::db) async fn update_project_worktrees(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
worktrees: &[proto::WorktreeMetadata],
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<()> {
|
||||||
|
if !worktrees.is_empty() {
|
||||||
|
worktree::Entity::insert_many(worktrees.iter().map(|worktree| worktree::ActiveModel {
|
||||||
|
id: ActiveValue::set(worktree.id as i64),
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
abs_path: ActiveValue::set(worktree.abs_path.clone()),
|
||||||
|
root_name: ActiveValue::set(worktree.root_name.clone()),
|
||||||
|
visible: ActiveValue::set(worktree.visible),
|
||||||
|
scan_id: ActiveValue::set(0),
|
||||||
|
completed_scan_id: ActiveValue::set(0),
|
||||||
|
}))
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([worktree::Column::ProjectId, worktree::Column::Id])
|
||||||
|
.update_column(worktree::Column::RootName)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
worktree::Entity::delete_many()
|
||||||
|
.filter(worktree::Column::ProjectId.eq(project_id).and(
|
||||||
|
worktree::Column::Id.is_not_in(worktrees.iter().map(|worktree| worktree.id as i64)),
|
||||||
|
))
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_worktree(
|
||||||
|
&self,
|
||||||
|
update: &proto::UpdateWorktree,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<Vec<ConnectionId>>> {
|
||||||
|
let project_id = ProjectId::from_proto(update.project_id);
|
||||||
|
let worktree_id = update.worktree_id as i64;
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
// Ensure the update comes from the host.
|
||||||
|
let _project = project::Entity::find_by_id(project_id)
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(project::Column::HostConnectionId.eq(connection.id as i32))
|
||||||
|
.add(
|
||||||
|
project::Column::HostConnectionServerId.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
|
||||||
|
// Update metadata.
|
||||||
|
worktree::Entity::update(worktree::ActiveModel {
|
||||||
|
id: ActiveValue::set(worktree_id),
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
root_name: ActiveValue::set(update.root_name.clone()),
|
||||||
|
scan_id: ActiveValue::set(update.scan_id as i64),
|
||||||
|
completed_scan_id: if update.is_last_update {
|
||||||
|
ActiveValue::set(update.scan_id as i64)
|
||||||
|
} else {
|
||||||
|
ActiveValue::default()
|
||||||
|
},
|
||||||
|
abs_path: ActiveValue::set(update.abs_path.clone()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !update.updated_entries.is_empty() {
|
||||||
|
worktree_entry::Entity::insert_many(update.updated_entries.iter().map(|entry| {
|
||||||
|
let mtime = entry.mtime.clone().unwrap_or_default();
|
||||||
|
worktree_entry::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
worktree_id: ActiveValue::set(worktree_id),
|
||||||
|
id: ActiveValue::set(entry.id as i64),
|
||||||
|
is_dir: ActiveValue::set(entry.is_dir),
|
||||||
|
path: ActiveValue::set(entry.path.clone()),
|
||||||
|
inode: ActiveValue::set(entry.inode as i64),
|
||||||
|
mtime_seconds: ActiveValue::set(mtime.seconds as i64),
|
||||||
|
mtime_nanos: ActiveValue::set(mtime.nanos as i32),
|
||||||
|
is_symlink: ActiveValue::set(entry.is_symlink),
|
||||||
|
is_ignored: ActiveValue::set(entry.is_ignored),
|
||||||
|
is_external: ActiveValue::set(entry.is_external),
|
||||||
|
git_status: ActiveValue::set(entry.git_status.map(|status| status as i64)),
|
||||||
|
is_deleted: ActiveValue::set(false),
|
||||||
|
scan_id: ActiveValue::set(update.scan_id as i64),
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([
|
||||||
|
worktree_entry::Column::ProjectId,
|
||||||
|
worktree_entry::Column::WorktreeId,
|
||||||
|
worktree_entry::Column::Id,
|
||||||
|
])
|
||||||
|
.update_columns([
|
||||||
|
worktree_entry::Column::IsDir,
|
||||||
|
worktree_entry::Column::Path,
|
||||||
|
worktree_entry::Column::Inode,
|
||||||
|
worktree_entry::Column::MtimeSeconds,
|
||||||
|
worktree_entry::Column::MtimeNanos,
|
||||||
|
worktree_entry::Column::IsSymlink,
|
||||||
|
worktree_entry::Column::IsIgnored,
|
||||||
|
worktree_entry::Column::GitStatus,
|
||||||
|
worktree_entry::Column::ScanId,
|
||||||
|
])
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !update.removed_entries.is_empty() {
|
||||||
|
worktree_entry::Entity::update_many()
|
||||||
|
.filter(
|
||||||
|
worktree_entry::Column::ProjectId
|
||||||
|
.eq(project_id)
|
||||||
|
.and(worktree_entry::Column::WorktreeId.eq(worktree_id))
|
||||||
|
.and(
|
||||||
|
worktree_entry::Column::Id
|
||||||
|
.is_in(update.removed_entries.iter().map(|id| *id as i64)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.set(worktree_entry::ActiveModel {
|
||||||
|
is_deleted: ActiveValue::Set(true),
|
||||||
|
scan_id: ActiveValue::Set(update.scan_id as i64),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !update.updated_repositories.is_empty() {
|
||||||
|
worktree_repository::Entity::insert_many(update.updated_repositories.iter().map(
|
||||||
|
|repository| worktree_repository::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
worktree_id: ActiveValue::set(worktree_id),
|
||||||
|
work_directory_id: ActiveValue::set(repository.work_directory_id as i64),
|
||||||
|
scan_id: ActiveValue::set(update.scan_id as i64),
|
||||||
|
branch: ActiveValue::set(repository.branch.clone()),
|
||||||
|
is_deleted: ActiveValue::set(false),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([
|
||||||
|
worktree_repository::Column::ProjectId,
|
||||||
|
worktree_repository::Column::WorktreeId,
|
||||||
|
worktree_repository::Column::WorkDirectoryId,
|
||||||
|
])
|
||||||
|
.update_columns([
|
||||||
|
worktree_repository::Column::ScanId,
|
||||||
|
worktree_repository::Column::Branch,
|
||||||
|
])
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !update.removed_repositories.is_empty() {
|
||||||
|
worktree_repository::Entity::update_many()
|
||||||
|
.filter(
|
||||||
|
worktree_repository::Column::ProjectId
|
||||||
|
.eq(project_id)
|
||||||
|
.and(worktree_repository::Column::WorktreeId.eq(worktree_id))
|
||||||
|
.and(
|
||||||
|
worktree_repository::Column::WorkDirectoryId
|
||||||
|
.is_in(update.removed_repositories.iter().map(|id| *id as i64)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.set(worktree_repository::ActiveModel {
|
||||||
|
is_deleted: ActiveValue::Set(true),
|
||||||
|
scan_id: ActiveValue::Set(update.scan_id as i64),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
|
||||||
|
Ok(connection_ids)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_diagnostic_summary(
|
||||||
|
&self,
|
||||||
|
update: &proto::UpdateDiagnosticSummary,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<Vec<ConnectionId>>> {
|
||||||
|
let project_id = ProjectId::from_proto(update.project_id);
|
||||||
|
let worktree_id = update.worktree_id as i64;
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let summary = update
|
||||||
|
.summary
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| anyhow!("invalid summary"))?;
|
||||||
|
|
||||||
|
// Ensure the update comes from the host.
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
if project.host_connection()? != connection {
|
||||||
|
return Err(anyhow!("can't update a project hosted by someone else"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update summary.
|
||||||
|
worktree_diagnostic_summary::Entity::insert(worktree_diagnostic_summary::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
worktree_id: ActiveValue::set(worktree_id),
|
||||||
|
path: ActiveValue::set(summary.path.clone()),
|
||||||
|
language_server_id: ActiveValue::set(summary.language_server_id as i64),
|
||||||
|
error_count: ActiveValue::set(summary.error_count as i32),
|
||||||
|
warning_count: ActiveValue::set(summary.warning_count as i32),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([
|
||||||
|
worktree_diagnostic_summary::Column::ProjectId,
|
||||||
|
worktree_diagnostic_summary::Column::WorktreeId,
|
||||||
|
worktree_diagnostic_summary::Column::Path,
|
||||||
|
])
|
||||||
|
.update_columns([
|
||||||
|
worktree_diagnostic_summary::Column::LanguageServerId,
|
||||||
|
worktree_diagnostic_summary::Column::ErrorCount,
|
||||||
|
worktree_diagnostic_summary::Column::WarningCount,
|
||||||
|
])
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
|
||||||
|
Ok(connection_ids)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn start_language_server(
|
||||||
|
&self,
|
||||||
|
update: &proto::StartLanguageServer,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<Vec<ConnectionId>>> {
|
||||||
|
let project_id = ProjectId::from_proto(update.project_id);
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let server = update
|
||||||
|
.server
|
||||||
|
.as_ref()
|
||||||
|
.ok_or_else(|| anyhow!("invalid language server"))?;
|
||||||
|
|
||||||
|
// Ensure the update comes from the host.
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
if project.host_connection()? != connection {
|
||||||
|
return Err(anyhow!("can't update a project hosted by someone else"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the newly-started language server.
|
||||||
|
language_server::Entity::insert(language_server::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
id: ActiveValue::set(server.id as i64),
|
||||||
|
name: ActiveValue::set(server.name.clone()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([
|
||||||
|
language_server::Column::ProjectId,
|
||||||
|
language_server::Column::Id,
|
||||||
|
])
|
||||||
|
.update_column(language_server::Column::Name)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
|
||||||
|
Ok(connection_ids)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_worktree_settings(
|
||||||
|
&self,
|
||||||
|
update: &proto::UpdateWorktreeSettings,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<Vec<ConnectionId>>> {
|
||||||
|
let project_id = ProjectId::from_proto(update.project_id);
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
// Ensure the update comes from the host.
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
if project.host_connection()? != connection {
|
||||||
|
return Err(anyhow!("can't update a project hosted by someone else"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(content) = &update.content {
|
||||||
|
worktree_settings_file::Entity::insert(worktree_settings_file::ActiveModel {
|
||||||
|
project_id: ActiveValue::Set(project_id),
|
||||||
|
worktree_id: ActiveValue::Set(update.worktree_id as i64),
|
||||||
|
path: ActiveValue::Set(update.path.clone()),
|
||||||
|
content: ActiveValue::Set(content.clone()),
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::columns([
|
||||||
|
worktree_settings_file::Column::ProjectId,
|
||||||
|
worktree_settings_file::Column::WorktreeId,
|
||||||
|
worktree_settings_file::Column::Path,
|
||||||
|
])
|
||||||
|
.update_column(worktree_settings_file::Column::Content)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
worktree_settings_file::Entity::delete(worktree_settings_file::ActiveModel {
|
||||||
|
project_id: ActiveValue::Set(project_id),
|
||||||
|
worktree_id: ActiveValue::Set(update.worktree_id as i64),
|
||||||
|
path: ActiveValue::Set(update.path.clone()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let connection_ids = self.project_guest_connection_ids(project_id, &tx).await?;
|
||||||
|
Ok(connection_ids)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn join_project(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<(Project, ReplicaId)>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let participant = room_participant::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(
|
||||||
|
room_participant::Column::AnsweringConnectionId
|
||||||
|
.eq(connection.id as i32),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
room_participant::Column::AnsweringConnectionServerId
|
||||||
|
.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("must join a room first"))?;
|
||||||
|
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
if project.room_id != participant.room_id {
|
||||||
|
return Err(anyhow!("no such project"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut collaborators = project
|
||||||
|
.find_related(project_collaborator::Entity)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
let replica_ids = collaborators
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.replica_id)
|
||||||
|
.collect::<HashSet<_>>();
|
||||||
|
let mut replica_id = ReplicaId(1);
|
||||||
|
while replica_ids.contains(&replica_id) {
|
||||||
|
replica_id.0 += 1;
|
||||||
|
}
|
||||||
|
let new_collaborator = project_collaborator::ActiveModel {
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
connection_id: ActiveValue::set(connection.id as i32),
|
||||||
|
connection_server_id: ActiveValue::set(ServerId(connection.owner_id as i32)),
|
||||||
|
user_id: ActiveValue::set(participant.user_id),
|
||||||
|
replica_id: ActiveValue::set(replica_id),
|
||||||
|
is_host: ActiveValue::set(false),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
collaborators.push(new_collaborator);
|
||||||
|
|
||||||
|
let db_worktrees = project.find_related(worktree::Entity).all(&*tx).await?;
|
||||||
|
let mut worktrees = db_worktrees
|
||||||
|
.into_iter()
|
||||||
|
.map(|db_worktree| {
|
||||||
|
(
|
||||||
|
db_worktree.id as u64,
|
||||||
|
Worktree {
|
||||||
|
id: db_worktree.id as u64,
|
||||||
|
abs_path: db_worktree.abs_path,
|
||||||
|
root_name: db_worktree.root_name,
|
||||||
|
visible: db_worktree.visible,
|
||||||
|
entries: Default::default(),
|
||||||
|
repository_entries: Default::default(),
|
||||||
|
diagnostic_summaries: Default::default(),
|
||||||
|
settings_files: Default::default(),
|
||||||
|
scan_id: db_worktree.scan_id as u64,
|
||||||
|
completed_scan_id: db_worktree.completed_scan_id as u64,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<BTreeMap<_, _>>();
|
||||||
|
|
||||||
|
// Populate worktree entries.
|
||||||
|
{
|
||||||
|
let mut db_entries = worktree_entry::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(worktree_entry::Column::ProjectId.eq(project_id))
|
||||||
|
.add(worktree_entry::Column::IsDeleted.eq(false)),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(db_entry) = db_entries.next().await {
|
||||||
|
let db_entry = db_entry?;
|
||||||
|
if let Some(worktree) = worktrees.get_mut(&(db_entry.worktree_id as u64)) {
|
||||||
|
worktree.entries.push(proto::Entry {
|
||||||
|
id: db_entry.id as u64,
|
||||||
|
is_dir: db_entry.is_dir,
|
||||||
|
path: db_entry.path,
|
||||||
|
inode: db_entry.inode as u64,
|
||||||
|
mtime: Some(proto::Timestamp {
|
||||||
|
seconds: db_entry.mtime_seconds as u64,
|
||||||
|
nanos: db_entry.mtime_nanos as u32,
|
||||||
|
}),
|
||||||
|
is_symlink: db_entry.is_symlink,
|
||||||
|
is_ignored: db_entry.is_ignored,
|
||||||
|
is_external: db_entry.is_external,
|
||||||
|
git_status: db_entry.git_status.map(|status| status as i32),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate repository entries.
|
||||||
|
{
|
||||||
|
let mut db_repository_entries = worktree_repository::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(worktree_repository::Column::ProjectId.eq(project_id))
|
||||||
|
.add(worktree_repository::Column::IsDeleted.eq(false)),
|
||||||
|
)
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(db_repository_entry) = db_repository_entries.next().await {
|
||||||
|
let db_repository_entry = db_repository_entry?;
|
||||||
|
if let Some(worktree) =
|
||||||
|
worktrees.get_mut(&(db_repository_entry.worktree_id as u64))
|
||||||
|
{
|
||||||
|
worktree.repository_entries.insert(
|
||||||
|
db_repository_entry.work_directory_id as u64,
|
||||||
|
proto::RepositoryEntry {
|
||||||
|
work_directory_id: db_repository_entry.work_directory_id as u64,
|
||||||
|
branch: db_repository_entry.branch,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate worktree diagnostic summaries.
|
||||||
|
{
|
||||||
|
let mut db_summaries = worktree_diagnostic_summary::Entity::find()
|
||||||
|
.filter(worktree_diagnostic_summary::Column::ProjectId.eq(project_id))
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(db_summary) = db_summaries.next().await {
|
||||||
|
let db_summary = db_summary?;
|
||||||
|
if let Some(worktree) = worktrees.get_mut(&(db_summary.worktree_id as u64)) {
|
||||||
|
worktree
|
||||||
|
.diagnostic_summaries
|
||||||
|
.push(proto::DiagnosticSummary {
|
||||||
|
path: db_summary.path,
|
||||||
|
language_server_id: db_summary.language_server_id as u64,
|
||||||
|
error_count: db_summary.error_count as u32,
|
||||||
|
warning_count: db_summary.warning_count as u32,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate worktree settings files
|
||||||
|
{
|
||||||
|
let mut db_settings_files = worktree_settings_file::Entity::find()
|
||||||
|
.filter(worktree_settings_file::Column::ProjectId.eq(project_id))
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
while let Some(db_settings_file) = db_settings_files.next().await {
|
||||||
|
let db_settings_file = db_settings_file?;
|
||||||
|
if let Some(worktree) =
|
||||||
|
worktrees.get_mut(&(db_settings_file.worktree_id as u64))
|
||||||
|
{
|
||||||
|
worktree.settings_files.push(WorktreeSettingsFile {
|
||||||
|
path: db_settings_file.path,
|
||||||
|
content: db_settings_file.content,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate language servers.
|
||||||
|
let language_servers = project
|
||||||
|
.find_related(language_server::Entity)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let project = Project {
|
||||||
|
collaborators: collaborators
|
||||||
|
.into_iter()
|
||||||
|
.map(|collaborator| ProjectCollaborator {
|
||||||
|
connection_id: collaborator.connection(),
|
||||||
|
user_id: collaborator.user_id,
|
||||||
|
replica_id: collaborator.replica_id,
|
||||||
|
is_host: collaborator.is_host,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
worktrees,
|
||||||
|
language_servers: language_servers
|
||||||
|
.into_iter()
|
||||||
|
.map(|language_server| proto::LanguageServer {
|
||||||
|
id: language_server.id as u64,
|
||||||
|
name: language_server.name,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
Ok((project, replica_id as ReplicaId))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn leave_project(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<(proto::Room, LeftProject)>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let result = project_collaborator::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(project_collaborator::Column::ProjectId.eq(project_id))
|
||||||
|
.add(project_collaborator::Column::ConnectionId.eq(connection.id as i32))
|
||||||
|
.add(
|
||||||
|
project_collaborator::Column::ConnectionServerId
|
||||||
|
.eq(connection.owner_id as i32),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("not a collaborator on this project"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("no such project"))?;
|
||||||
|
let collaborators = project
|
||||||
|
.find_related(project_collaborator::Entity)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
let connection_ids = collaborators
|
||||||
|
.into_iter()
|
||||||
|
.map(|collaborator| collaborator.connection())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
follower::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::any()
|
||||||
|
.add(
|
||||||
|
Condition::all()
|
||||||
|
.add(follower::Column::ProjectId.eq(project_id))
|
||||||
|
.add(
|
||||||
|
follower::Column::LeaderConnectionServerId
|
||||||
|
.eq(connection.owner_id),
|
||||||
|
)
|
||||||
|
.add(follower::Column::LeaderConnectionId.eq(connection.id)),
|
||||||
|
)
|
||||||
|
.add(
|
||||||
|
Condition::all()
|
||||||
|
.add(follower::Column::ProjectId.eq(project_id))
|
||||||
|
.add(
|
||||||
|
follower::Column::FollowerConnectionServerId
|
||||||
|
.eq(connection.owner_id),
|
||||||
|
)
|
||||||
|
.add(follower::Column::FollowerConnectionId.eq(connection.id)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let room = self.get_room(project.room_id, &tx).await?;
|
||||||
|
let left_project = LeftProject {
|
||||||
|
id: project_id,
|
||||||
|
host_user_id: project.host_user_id,
|
||||||
|
host_connection_id: project.host_connection()?,
|
||||||
|
connection_ids,
|
||||||
|
};
|
||||||
|
Ok((room, left_project))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn project_collaborators(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection_id: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<Vec<ProjectCollaborator>>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let collaborators = project_collaborator::Entity::find()
|
||||||
|
.filter(project_collaborator::Column::ProjectId.eq(project_id))
|
||||||
|
.all(&*tx)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|collaborator| ProjectCollaborator {
|
||||||
|
connection_id: collaborator.connection(),
|
||||||
|
user_id: collaborator.user_id,
|
||||||
|
replica_id: collaborator.replica_id,
|
||||||
|
is_host: collaborator.is_host,
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
if collaborators
|
||||||
|
.iter()
|
||||||
|
.any(|collaborator| collaborator.connection_id == connection_id)
|
||||||
|
{
|
||||||
|
Ok(collaborators)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("no such project"))?
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn project_connection_ids(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
connection_id: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<HashSet<ConnectionId>>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
let mut collaborators = project_collaborator::Entity::find()
|
||||||
|
.filter(project_collaborator::Column::ProjectId.eq(project_id))
|
||||||
|
.stream(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut connection_ids = HashSet::default();
|
||||||
|
while let Some(collaborator) = collaborators.next().await {
|
||||||
|
let collaborator = collaborator?;
|
||||||
|
connection_ids.insert(collaborator.connection());
|
||||||
|
}
|
||||||
|
|
||||||
|
if connection_ids.contains(&connection_id) {
|
||||||
|
Ok(connection_ids)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("no such project"))?
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn project_guest_connection_ids(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<Vec<ConnectionId>> {
|
||||||
|
let mut collaborators = project_collaborator::Entity::find()
|
||||||
|
.filter(
|
||||||
|
project_collaborator::Column::ProjectId
|
||||||
|
.eq(project_id)
|
||||||
|
.and(project_collaborator::Column::IsHost.eq(false)),
|
||||||
|
)
|
||||||
|
.stream(tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut guest_connection_ids = Vec::new();
|
||||||
|
while let Some(collaborator) = collaborators.next().await {
|
||||||
|
let collaborator = collaborator?;
|
||||||
|
guest_connection_ids.push(collaborator.connection());
|
||||||
|
}
|
||||||
|
Ok(guest_connection_ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn room_id_for_project(&self, project_id: ProjectId) -> Result<RoomId> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let project = project::Entity::find_by_id(project_id)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("project {} not found", project_id))?;
|
||||||
|
Ok(project.room_id)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn follow(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
leader_connection: ConnectionId,
|
||||||
|
follower_connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<proto::Room>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
follower::ActiveModel {
|
||||||
|
room_id: ActiveValue::set(room_id),
|
||||||
|
project_id: ActiveValue::set(project_id),
|
||||||
|
leader_connection_server_id: ActiveValue::set(ServerId(
|
||||||
|
leader_connection.owner_id as i32,
|
||||||
|
)),
|
||||||
|
leader_connection_id: ActiveValue::set(leader_connection.id as i32),
|
||||||
|
follower_connection_server_id: ActiveValue::set(ServerId(
|
||||||
|
follower_connection.owner_id as i32,
|
||||||
|
)),
|
||||||
|
follower_connection_id: ActiveValue::set(follower_connection.id as i32),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let room = self.get_room(room_id, &*tx).await?;
|
||||||
|
Ok(room)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn unfollow(
|
||||||
|
&self,
|
||||||
|
project_id: ProjectId,
|
||||||
|
leader_connection: ConnectionId,
|
||||||
|
follower_connection: ConnectionId,
|
||||||
|
) -> Result<RoomGuard<proto::Room>> {
|
||||||
|
let room_id = self.room_id_for_project(project_id).await?;
|
||||||
|
self.room_transaction(room_id, |tx| async move {
|
||||||
|
follower::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(follower::Column::ProjectId.eq(project_id))
|
||||||
|
.add(
|
||||||
|
follower::Column::LeaderConnectionServerId
|
||||||
|
.eq(leader_connection.owner_id),
|
||||||
|
)
|
||||||
|
.add(follower::Column::LeaderConnectionId.eq(leader_connection.id))
|
||||||
|
.add(
|
||||||
|
follower::Column::FollowerConnectionServerId
|
||||||
|
.eq(follower_connection.owner_id),
|
||||||
|
)
|
||||||
|
.add(follower::Column::FollowerConnectionId.eq(follower_connection.id)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let room = self.get_room(room_id, &*tx).await?;
|
||||||
|
Ok(room)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
1093
crates/collab/src/db/queries/rooms.rs
Normal file
81
crates/collab/src/db/queries/servers.rs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn create_server(&self, environment: &str) -> Result<ServerId> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let server = server::ActiveModel {
|
||||||
|
environment: ActiveValue::set(environment.into()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(server.id)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn stale_room_ids(
|
||||||
|
&self,
|
||||||
|
environment: &str,
|
||||||
|
new_server_id: ServerId,
|
||||||
|
) -> Result<Vec<RoomId>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryAs {
|
||||||
|
RoomId,
|
||||||
|
}
|
||||||
|
|
||||||
|
let stale_server_epochs = self
|
||||||
|
.stale_server_ids(environment, new_server_id, &tx)
|
||||||
|
.await?;
|
||||||
|
Ok(room_participant::Entity::find()
|
||||||
|
.select_only()
|
||||||
|
.column(room_participant::Column::RoomId)
|
||||||
|
.distinct()
|
||||||
|
.filter(
|
||||||
|
room_participant::Column::AnsweringConnectionServerId
|
||||||
|
.is_in(stale_server_epochs),
|
||||||
|
)
|
||||||
|
.into_values::<_, QueryAs>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_stale_servers(
|
||||||
|
&self,
|
||||||
|
environment: &str,
|
||||||
|
new_server_id: ServerId,
|
||||||
|
) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
server::Entity::delete_many()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(server::Column::Environment.eq(environment))
|
||||||
|
.add(server::Column::Id.ne(new_server_id)),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn stale_server_ids(
|
||||||
|
&self,
|
||||||
|
environment: &str,
|
||||||
|
new_server_id: ServerId,
|
||||||
|
tx: &DatabaseTransaction,
|
||||||
|
) -> Result<Vec<ServerId>> {
|
||||||
|
let stale_servers = server::Entity::find()
|
||||||
|
.filter(
|
||||||
|
Condition::all()
|
||||||
|
.add(server::Column::Environment.eq(environment))
|
||||||
|
.add(server::Column::Id.ne(new_server_id)),
|
||||||
|
)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(stale_servers.into_iter().map(|server| server.id).collect())
|
||||||
|
}
|
||||||
|
}
|
349
crates/collab/src/db/queries/signups.rs
Normal file
@ -0,0 +1,349 @@
|
|||||||
|
use super::*;
|
||||||
|
use hyper::StatusCode;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn create_invite_from_code(
|
||||||
|
&self,
|
||||||
|
code: &str,
|
||||||
|
email_address: &str,
|
||||||
|
device_id: Option<&str>,
|
||||||
|
added_to_mailing_list: bool,
|
||||||
|
) -> Result<Invite> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let existing_user = user::Entity::find()
|
||||||
|
.filter(user::Column::EmailAddress.eq(email_address))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if existing_user.is_some() {
|
||||||
|
Err(anyhow!("email address is already in use"))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let inviting_user_with_invites = match user::Entity::find()
|
||||||
|
.filter(
|
||||||
|
user::Column::InviteCode
|
||||||
|
.eq(code)
|
||||||
|
.and(user::Column::InviteCount.gt(0)),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
Some(inviting_user) => inviting_user,
|
||||||
|
None => {
|
||||||
|
return Err(Error::Http(
|
||||||
|
StatusCode::UNAUTHORIZED,
|
||||||
|
"unable to find an invite code with invites remaining".to_string(),
|
||||||
|
))?
|
||||||
|
}
|
||||||
|
};
|
||||||
|
user::Entity::update_many()
|
||||||
|
.filter(
|
||||||
|
user::Column::Id
|
||||||
|
.eq(inviting_user_with_invites.id)
|
||||||
|
.and(user::Column::InviteCount.gt(0)),
|
||||||
|
)
|
||||||
|
.col_expr(
|
||||||
|
user::Column::InviteCount,
|
||||||
|
Expr::col(user::Column::InviteCount).sub(1),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let signup = signup::Entity::insert(signup::ActiveModel {
|
||||||
|
email_address: ActiveValue::set(email_address.into()),
|
||||||
|
email_confirmation_code: ActiveValue::set(random_email_confirmation_code()),
|
||||||
|
email_confirmation_sent: ActiveValue::set(false),
|
||||||
|
inviting_user_id: ActiveValue::set(Some(inviting_user_with_invites.id)),
|
||||||
|
platform_linux: ActiveValue::set(false),
|
||||||
|
platform_mac: ActiveValue::set(false),
|
||||||
|
platform_windows: ActiveValue::set(false),
|
||||||
|
platform_unknown: ActiveValue::set(true),
|
||||||
|
device_id: ActiveValue::set(device_id.map(|device_id| device_id.into())),
|
||||||
|
added_to_mailing_list: ActiveValue::set(added_to_mailing_list),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::column(signup::Column::EmailAddress)
|
||||||
|
.update_column(signup::Column::InvitingUserId)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec_with_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Invite {
|
||||||
|
email_address: signup.email_address,
|
||||||
|
email_confirmation_code: signup.email_confirmation_code,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_user_from_invite(
|
||||||
|
&self,
|
||||||
|
invite: &Invite,
|
||||||
|
user: NewUserParams,
|
||||||
|
) -> Result<Option<NewUserResult>> {
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
let signup = signup::Entity::find()
|
||||||
|
.filter(
|
||||||
|
signup::Column::EmailAddress
|
||||||
|
.eq(invite.email_address.as_str())
|
||||||
|
.and(
|
||||||
|
signup::Column::EmailConfirmationCode
|
||||||
|
.eq(invite.email_confirmation_code.as_str()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| Error::Http(StatusCode::NOT_FOUND, "no such invite".to_string()))?;
|
||||||
|
|
||||||
|
if signup.user_id.is_some() {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = user::Entity::insert(user::ActiveModel {
|
||||||
|
email_address: ActiveValue::set(Some(invite.email_address.clone())),
|
||||||
|
github_login: ActiveValue::set(user.github_login.clone()),
|
||||||
|
github_user_id: ActiveValue::set(Some(user.github_user_id)),
|
||||||
|
admin: ActiveValue::set(false),
|
||||||
|
invite_count: ActiveValue::set(user.invite_count),
|
||||||
|
invite_code: ActiveValue::set(Some(random_invite_code())),
|
||||||
|
metrics_id: ActiveValue::set(Uuid::new_v4()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::column(user::Column::GithubLogin)
|
||||||
|
.update_columns([
|
||||||
|
user::Column::EmailAddress,
|
||||||
|
user::Column::GithubUserId,
|
||||||
|
user::Column::Admin,
|
||||||
|
])
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec_with_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut signup = signup.into_active_model();
|
||||||
|
signup.user_id = ActiveValue::set(Some(user.id));
|
||||||
|
let signup = signup.update(&*tx).await?;
|
||||||
|
|
||||||
|
if let Some(inviting_user_id) = signup.inviting_user_id {
|
||||||
|
let (user_id_a, user_id_b, a_to_b) = if inviting_user_id < user.id {
|
||||||
|
(inviting_user_id, user.id, true)
|
||||||
|
} else {
|
||||||
|
(user.id, inviting_user_id, false)
|
||||||
|
};
|
||||||
|
|
||||||
|
contact::Entity::insert(contact::ActiveModel {
|
||||||
|
user_id_a: ActiveValue::set(user_id_a),
|
||||||
|
user_id_b: ActiveValue::set(user_id_b),
|
||||||
|
a_to_b: ActiveValue::set(a_to_b),
|
||||||
|
should_notify: ActiveValue::set(true),
|
||||||
|
accepted: ActiveValue::set(true),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(OnConflict::new().do_nothing().to_owned())
|
||||||
|
.exec_without_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(NewUserResult {
|
||||||
|
user_id: user.id,
|
||||||
|
metrics_id: user.metrics_id.to_string(),
|
||||||
|
inviting_user_id: signup.inviting_user_id,
|
||||||
|
signup_device_id: signup.device_id,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_invite_count_for_user(&self, id: UserId, count: i32) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
if count > 0 {
|
||||||
|
user::Entity::update_many()
|
||||||
|
.filter(
|
||||||
|
user::Column::Id
|
||||||
|
.eq(id)
|
||||||
|
.and(user::Column::InviteCode.is_null()),
|
||||||
|
)
|
||||||
|
.set(user::ActiveModel {
|
||||||
|
invite_code: ActiveValue::set(Some(random_invite_code())),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
user::Entity::update_many()
|
||||||
|
.filter(user::Column::Id.eq(id))
|
||||||
|
.set(user::ActiveModel {
|
||||||
|
invite_count: ActiveValue::set(count),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_invite_code_for_user(&self, id: UserId) -> Result<Option<(String, i32)>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
match user::Entity::find_by_id(id).one(&*tx).await? {
|
||||||
|
Some(user) if user.invite_code.is_some() => {
|
||||||
|
Ok(Some((user.invite_code.unwrap(), user.invite_count)))
|
||||||
|
}
|
||||||
|
_ => Ok(None),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_for_invite_code(&self, code: &str) -> Result<User> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
user::Entity::find()
|
||||||
|
.filter(user::Column::InviteCode.eq(code))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
Error::Http(
|
||||||
|
StatusCode::NOT_FOUND,
|
||||||
|
"that invite code does not exist".to_string(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_signup(&self, signup: &NewSignup) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
signup::Entity::insert(signup::ActiveModel {
|
||||||
|
email_address: ActiveValue::set(signup.email_address.clone()),
|
||||||
|
email_confirmation_code: ActiveValue::set(random_email_confirmation_code()),
|
||||||
|
email_confirmation_sent: ActiveValue::set(false),
|
||||||
|
platform_mac: ActiveValue::set(signup.platform_mac),
|
||||||
|
platform_windows: ActiveValue::set(signup.platform_windows),
|
||||||
|
platform_linux: ActiveValue::set(signup.platform_linux),
|
||||||
|
platform_unknown: ActiveValue::set(false),
|
||||||
|
editor_features: ActiveValue::set(Some(signup.editor_features.clone())),
|
||||||
|
programming_languages: ActiveValue::set(Some(signup.programming_languages.clone())),
|
||||||
|
device_id: ActiveValue::set(signup.device_id.clone()),
|
||||||
|
added_to_mailing_list: ActiveValue::set(signup.added_to_mailing_list),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::column(signup::Column::EmailAddress)
|
||||||
|
.update_columns([
|
||||||
|
signup::Column::PlatformMac,
|
||||||
|
signup::Column::PlatformWindows,
|
||||||
|
signup::Column::PlatformLinux,
|
||||||
|
signup::Column::EditorFeatures,
|
||||||
|
signup::Column::ProgrammingLanguages,
|
||||||
|
signup::Column::DeviceId,
|
||||||
|
signup::Column::AddedToMailingList,
|
||||||
|
])
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_signup(&self, email_address: &str) -> Result<signup::Model> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let signup = signup::Entity::find()
|
||||||
|
.filter(signup::Column::EmailAddress.eq(email_address))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| {
|
||||||
|
anyhow!("signup with email address {} doesn't exist", email_address)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(signup)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_waitlist_summary(&self) -> Result<WaitlistSummary> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let query = "
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as count,
|
||||||
|
COALESCE(SUM(CASE WHEN platform_linux THEN 1 ELSE 0 END), 0) as linux_count,
|
||||||
|
COALESCE(SUM(CASE WHEN platform_mac THEN 1 ELSE 0 END), 0) as mac_count,
|
||||||
|
COALESCE(SUM(CASE WHEN platform_windows THEN 1 ELSE 0 END), 0) as windows_count,
|
||||||
|
COALESCE(SUM(CASE WHEN platform_unknown THEN 1 ELSE 0 END), 0) as unknown_count
|
||||||
|
FROM (
|
||||||
|
SELECT *
|
||||||
|
FROM signups
|
||||||
|
WHERE
|
||||||
|
NOT email_confirmation_sent
|
||||||
|
) AS unsent
|
||||||
|
";
|
||||||
|
Ok(
|
||||||
|
WaitlistSummary::find_by_statement(Statement::from_sql_and_values(
|
||||||
|
self.pool.get_database_backend(),
|
||||||
|
query.into(),
|
||||||
|
vec![],
|
||||||
|
))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("invalid result"))?,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn record_sent_invites(&self, invites: &[Invite]) -> Result<()> {
|
||||||
|
let emails = invites
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.email_address.as_str())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
signup::Entity::update_many()
|
||||||
|
.filter(signup::Column::EmailAddress.is_in(emails.iter().copied()))
|
||||||
|
.set(signup::ActiveModel {
|
||||||
|
email_confirmation_sent: ActiveValue::set(true),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_unsent_invites(&self, count: usize) -> Result<Vec<Invite>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(signup::Entity::find()
|
||||||
|
.select_only()
|
||||||
|
.column(signup::Column::EmailAddress)
|
||||||
|
.column(signup::Column::EmailConfirmationCode)
|
||||||
|
.filter(
|
||||||
|
signup::Column::EmailConfirmationSent.eq(false).and(
|
||||||
|
signup::Column::PlatformMac
|
||||||
|
.eq(true)
|
||||||
|
.or(signup::Column::PlatformUnknown.eq(true)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.order_by_asc(signup::Column::CreatedAt)
|
||||||
|
.limit(count as u64)
|
||||||
|
.into_model()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_invite_code() -> String {
|
||||||
|
nanoid::nanoid!(16)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn random_email_confirmation_code() -> String {
|
||||||
|
nanoid::nanoid!(64)
|
||||||
|
}
|
297
crates/collab/src/db/queries/users.rs
Normal file
@ -0,0 +1,297 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
pub async fn create_user(
|
||||||
|
&self,
|
||||||
|
email_address: &str,
|
||||||
|
admin: bool,
|
||||||
|
params: NewUserParams,
|
||||||
|
) -> Result<NewUserResult> {
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
let user = user::Entity::insert(user::ActiveModel {
|
||||||
|
email_address: ActiveValue::set(Some(email_address.into())),
|
||||||
|
github_login: ActiveValue::set(params.github_login.clone()),
|
||||||
|
github_user_id: ActiveValue::set(Some(params.github_user_id)),
|
||||||
|
admin: ActiveValue::set(admin),
|
||||||
|
metrics_id: ActiveValue::set(Uuid::new_v4()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.on_conflict(
|
||||||
|
OnConflict::column(user::Column::GithubLogin)
|
||||||
|
.update_column(user::Column::GithubLogin)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.exec_with_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(NewUserResult {
|
||||||
|
user_id: user.id,
|
||||||
|
metrics_id: user.metrics_id.to_string(),
|
||||||
|
signup_device_id: None,
|
||||||
|
inviting_user_id: None,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_by_id(&self, id: UserId) -> Result<Option<user::Model>> {
|
||||||
|
self.transaction(|tx| async move { Ok(user::Entity::find_by_id(id).one(&*tx).await?) })
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_users_by_ids(&self, ids: Vec<UserId>) -> Result<Vec<user::Model>> {
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.filter(user::Column::Id.is_in(ids.iter().copied()))
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_by_github_login(&self, github_login: &str) -> Result<Option<User>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.filter(user::Column::GithubLogin.eq(github_login))
|
||||||
|
.one(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_or_create_user_by_github_account(
|
||||||
|
&self,
|
||||||
|
github_login: &str,
|
||||||
|
github_user_id: Option<i32>,
|
||||||
|
github_email: Option<&str>,
|
||||||
|
) -> Result<Option<User>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let tx = &*tx;
|
||||||
|
if let Some(github_user_id) = github_user_id {
|
||||||
|
if let Some(user_by_github_user_id) = user::Entity::find()
|
||||||
|
.filter(user::Column::GithubUserId.eq(github_user_id))
|
||||||
|
.one(tx)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
let mut user_by_github_user_id = user_by_github_user_id.into_active_model();
|
||||||
|
user_by_github_user_id.github_login = ActiveValue::set(github_login.into());
|
||||||
|
Ok(Some(user_by_github_user_id.update(tx).await?))
|
||||||
|
} else if let Some(user_by_github_login) = user::Entity::find()
|
||||||
|
.filter(user::Column::GithubLogin.eq(github_login))
|
||||||
|
.one(tx)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
let mut user_by_github_login = user_by_github_login.into_active_model();
|
||||||
|
user_by_github_login.github_user_id = ActiveValue::set(Some(github_user_id));
|
||||||
|
Ok(Some(user_by_github_login.update(tx).await?))
|
||||||
|
} else {
|
||||||
|
let user = user::Entity::insert(user::ActiveModel {
|
||||||
|
email_address: ActiveValue::set(github_email.map(|email| email.into())),
|
||||||
|
github_login: ActiveValue::set(github_login.into()),
|
||||||
|
github_user_id: ActiveValue::set(Some(github_user_id)),
|
||||||
|
admin: ActiveValue::set(false),
|
||||||
|
invite_count: ActiveValue::set(0),
|
||||||
|
invite_code: ActiveValue::set(None),
|
||||||
|
metrics_id: ActiveValue::set(Uuid::new_v4()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec_with_returning(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(Some(user))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.filter(user::Column::GithubLogin.eq(github_login))
|
||||||
|
.one(tx)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_all_users(&self, page: u32, limit: u32) -> Result<Vec<User>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.order_by_asc(user::Column::GithubLogin)
|
||||||
|
.limit(limit as u64)
|
||||||
|
.offset(page as u64 * limit as u64)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_users_with_no_invites(
|
||||||
|
&self,
|
||||||
|
invited_by_another_user: bool,
|
||||||
|
) -> Result<Vec<User>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.filter(
|
||||||
|
user::Column::InviteCount
|
||||||
|
.eq(0)
|
||||||
|
.and(if invited_by_another_user {
|
||||||
|
user::Column::InviterId.is_not_null()
|
||||||
|
} else {
|
||||||
|
user::Column::InviterId.is_null()
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_metrics_id(&self, id: UserId) -> Result<String> {
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryAs {
|
||||||
|
MetricsId,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let metrics_id: Uuid = user::Entity::find_by_id(id)
|
||||||
|
.select_only()
|
||||||
|
.column(user::Column::MetricsId)
|
||||||
|
.into_values::<_, QueryAs>()
|
||||||
|
.one(&*tx)
|
||||||
|
.await?
|
||||||
|
.ok_or_else(|| anyhow!("could not find user"))?;
|
||||||
|
Ok(metrics_id.to_string())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_user_is_admin(&self, id: UserId, is_admin: bool) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
user::Entity::update_many()
|
||||||
|
.filter(user::Column::Id.eq(id))
|
||||||
|
.set(user::ActiveModel {
|
||||||
|
admin: ActiveValue::set(is_admin),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_user_connected_once(&self, id: UserId, connected_once: bool) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
user::Entity::update_many()
|
||||||
|
.filter(user::Column::Id.eq(id))
|
||||||
|
.set(user::ActiveModel {
|
||||||
|
connected_once: ActiveValue::set(connected_once),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn destroy_user(&self, id: UserId) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
access_token::Entity::delete_many()
|
||||||
|
.filter(access_token::Column::UserId.eq(id))
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
user::Entity::delete_by_id(id).exec(&*tx).await?;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn fuzzy_search_users(&self, name_query: &str, limit: u32) -> Result<Vec<User>> {
|
||||||
|
self.transaction(|tx| async {
|
||||||
|
let tx = tx;
|
||||||
|
let like_string = Self::fuzzy_like_string(name_query);
|
||||||
|
let query = "
|
||||||
|
SELECT users.*
|
||||||
|
FROM users
|
||||||
|
WHERE github_login ILIKE $1
|
||||||
|
ORDER BY github_login <-> $2
|
||||||
|
LIMIT $3
|
||||||
|
";
|
||||||
|
|
||||||
|
Ok(user::Entity::find()
|
||||||
|
.from_raw_sql(Statement::from_sql_and_values(
|
||||||
|
self.pool.get_database_backend(),
|
||||||
|
query.into(),
|
||||||
|
vec![like_string.into(), name_query.into(), limit.into()],
|
||||||
|
))
|
||||||
|
.all(&*tx)
|
||||||
|
.await?)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fuzzy_like_string(string: &str) -> String {
|
||||||
|
let mut result = String::with_capacity(string.len() * 2 + 1);
|
||||||
|
for c in string.chars() {
|
||||||
|
if c.is_alphanumeric() {
|
||||||
|
result.push('%');
|
||||||
|
result.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push('%');
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
pub async fn create_user_flag(&self, flag: &str) -> Result<FlagId> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
let flag = feature_flag::Entity::insert(feature_flag::ActiveModel {
|
||||||
|
flag: ActiveValue::set(flag.to_string()),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?
|
||||||
|
.last_insert_id;
|
||||||
|
|
||||||
|
Ok(flag)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
pub async fn add_user_flag(&self, user: UserId, flag: FlagId) -> Result<()> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
user_feature::Entity::insert(user_feature::ActiveModel {
|
||||||
|
user_id: ActiveValue::set(user),
|
||||||
|
feature_id: ActiveValue::set(flag),
|
||||||
|
})
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_user_flags(&self, user: UserId) -> Result<Vec<String>> {
|
||||||
|
self.transaction(|tx| async move {
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
|
enum QueryAs {
|
||||||
|
Flag,
|
||||||
|
}
|
||||||
|
|
||||||
|
let flags = user::Model {
|
||||||
|
id: user,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.find_linked(user::UserFlags)
|
||||||
|
.select_only()
|
||||||
|
.column(feature_flag::Column::Flag)
|
||||||
|
.into_values::<_, QueryAs>()
|
||||||
|
.all(&*tx)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(flags)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
@ -1,57 +0,0 @@
|
|||||||
use super::{SignupId, UserId};
|
|
||||||
use sea_orm::{entity::prelude::*, FromQueryResult};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
|
||||||
#[sea_orm(table_name = "signups")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key)]
|
|
||||||
pub id: SignupId,
|
|
||||||
pub email_address: String,
|
|
||||||
pub email_confirmation_code: String,
|
|
||||||
pub email_confirmation_sent: bool,
|
|
||||||
pub created_at: DateTime,
|
|
||||||
pub device_id: Option<String>,
|
|
||||||
pub user_id: Option<UserId>,
|
|
||||||
pub inviting_user_id: Option<UserId>,
|
|
||||||
pub platform_mac: bool,
|
|
||||||
pub platform_linux: bool,
|
|
||||||
pub platform_windows: bool,
|
|
||||||
pub platform_unknown: bool,
|
|
||||||
pub editor_features: Option<Vec<String>>,
|
|
||||||
pub programming_languages: Option<Vec<String>>,
|
|
||||||
pub added_to_mailing_list: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
|
||||||
pub enum Relation {}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, FromQueryResult, Serialize, Deserialize)]
|
|
||||||
pub struct Invite {
|
|
||||||
pub email_address: String,
|
|
||||||
pub email_confirmation_code: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
|
||||||
pub struct NewSignup {
|
|
||||||
pub email_address: String,
|
|
||||||
pub platform_mac: bool,
|
|
||||||
pub platform_windows: bool,
|
|
||||||
pub platform_linux: bool,
|
|
||||||
pub editor_features: Vec<String>,
|
|
||||||
pub programming_languages: Vec<String>,
|
|
||||||
pub device_id: Option<String>,
|
|
||||||
pub added_to_mailing_list: bool,
|
|
||||||
pub created_at: Option<DateTime>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, FromQueryResult)]
|
|
||||||
pub struct WaitlistSummary {
|
|
||||||
pub count: i64,
|
|
||||||
pub linux_count: i64,
|
|
||||||
pub mac_count: i64,
|
|
||||||
pub windows_count: i64,
|
|
||||||
pub unknown_count: i64,
|
|
||||||
}
|
|
26
crates/collab/src/db/tables.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
pub mod access_token;
|
||||||
|
pub mod buffer;
|
||||||
|
pub mod buffer_operation;
|
||||||
|
pub mod buffer_snapshot;
|
||||||
|
pub mod channel;
|
||||||
|
pub mod channel_buffer_collaborator;
|
||||||
|
pub mod channel_member;
|
||||||
|
pub mod channel_path;
|
||||||
|
pub mod contact;
|
||||||
|
pub mod feature_flag;
|
||||||
|
pub mod follower;
|
||||||
|
pub mod language_server;
|
||||||
|
pub mod project;
|
||||||
|
pub mod project_collaborator;
|
||||||
|
pub mod room;
|
||||||
|
pub mod room_participant;
|
||||||
|
pub mod server;
|
||||||
|
pub mod signup;
|
||||||
|
pub mod user;
|
||||||
|
pub mod user_feature;
|
||||||
|
pub mod worktree;
|
||||||
|
pub mod worktree_diagnostic_summary;
|
||||||
|
pub mod worktree_entry;
|
||||||
|
pub mod worktree_repository;
|
||||||
|
pub mod worktree_repository_statuses;
|
||||||
|
pub mod worktree_settings_file;
|
@ -1,4 +1,4 @@
|
|||||||
use super::{AccessTokenId, UserId};
|
use crate::db::{AccessTokenId, UserId};
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
45
crates/collab/src/db/tables/buffer.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use crate::db::{BufferId, ChannelId};
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "buffers")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: BufferId,
|
||||||
|
pub epoch: i32,
|
||||||
|
pub channel_id: ChannelId,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "super::buffer_operation::Entity")]
|
||||||
|
Operations,
|
||||||
|
#[sea_orm(has_many = "super::buffer_snapshot::Entity")]
|
||||||
|
Snapshots,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::channel::Entity",
|
||||||
|
from = "Column::ChannelId",
|
||||||
|
to = "super::channel::Column::Id"
|
||||||
|
)]
|
||||||
|
Channel,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::buffer_operation::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Operations.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::buffer_snapshot::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Snapshots.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::channel::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Channel.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|