BlueGit

ict rusty-teams

fix(app): selectable message text, cached presence, no crash on notification windows

- Message text: drag to select, Ctrl+C to copy, links still open on click
- Presence: last known status from SQLite at start (dimmed), spinner while loading, first fetch as soon as the session is ready
- Notifications: bell, tray settings, toasts and the overflow pill open their window outside the center update; open_window draws at once and the views read the center, which panicked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-07 · 7 weeks ago

Hash
b01489694470437e760660f536e15b639354ccea
Parent
6c4ed4f5
19 files changed +837 −130
Cargo.lock +110 −9
@@ -701,15 +701,30 @@ dependencies = [
701 701 "syn 2.0.119",
702 702 ]
703 703
704 [[package]]
705 name = "bit-set"
706 version = "0.8.0"
707 source = "registry+https://github.com/rust-lang/crates.io-index"
708 checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
709 dependencies = [
710 "bit-vec 0.8.0",
711 ]
712
704 713 [[package]]
705 714 name = "bit-set"
706 715 version = "0.9.1"
707 716 source = "registry+https://github.com/rust-lang/crates.io-index"
708 717 checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd"
709 718 dependencies = [
710 "bit-vec",
719 "bit-vec 0.9.1",
711 720 ]
712 721
722 [[package]]
723 name = "bit-vec"
724 version = "0.8.0"
725 source = "registry+https://github.com/rust-lang/crates.io-index"
726 checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
727
713 728 [[package]]
714 729 name = "bit-vec"
715 730 version = "0.9.1"
@@ -1307,6 +1322,15 @@ dependencies = [
1307 1322 "unicode-segmentation",
1308 1323 ]
1309 1324
1325 [[package]]
1326 name = "convert_case"
1327 version = "0.11.0"
1328 source = "registry+https://github.com/rust-lang/crates.io-index"
1329 checksum = "affbf0190ed2caf063e3def54ff444b449371d55c58e513a95ab98eca50adb49"
1330 dependencies = [
1331 "unicode-segmentation",
1332 ]
1333
1310 1334 [[package]]
1311 1335 name = "core-foundation"
1312 1336 version = "0.9.4"
@@ -1694,7 +1718,7 @@ version = "2.1.1"
1694 1718 source = "registry+https://github.com/rust-lang/crates.io-index"
1695 1719 checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
1696 1720 dependencies = [
1697 "convert_case",
1721 "convert_case 0.10.0",
1698 1722 "proc-macro2",
1699 1723 "quote",
1700 1724 "rustc_version",
@@ -2963,6 +2987,7 @@ dependencies = [
2963 2987 "pollster 0.4.0",
2964 2988 "postage",
2965 2989 "profiling",
2990 "proptest",
2966 2991 "rand 0.9.5",
2967 2992 "raw-window-handle",
2968 2993 "regex",
@@ -3188,6 +3213,7 @@ dependencies = [
3188 3213 "gpui-pre-linux",
3189 3214 "gpui-pre-macos",
3190 3215 "gpui-pre-web",
3216 "gpui-pre-wgpu",
3191 3217 "gpui-pre-windows",
3192 3218 ]
3193 3219
@@ -3355,6 +3381,7 @@ dependencies = [
3355 3381 "gpui-pre",
3356 3382 "gpui-pre-collections",
3357 3383 "gpui-pre-util",
3384 "image",
3358 3385 "itertools 0.14.0",
3359 3386 "log",
3360 3387 "parking_lot",
@@ -3963,7 +3990,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
3963 3990 checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
3964 3991 dependencies = [
3965 3992 "byteorder-lite",
3966 "quick-error",
3993 "quick-error 2.0.1",
3967 3994 ]
3968 3995
3969 3996 [[package]]
@@ -4779,7 +4806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
4779 4806 checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df"
4780 4807 dependencies = [
4781 4808 "arrayvec",
4782 "bit-set",
4809 "bit-set 0.9.1",
4783 4810 "bitflags 2.13.2",
4784 4811 "cfg-if",
4785 4812 "cfg_aliases",
@@ -6042,6 +6069,38 @@ dependencies = [
6042 6069 "syn 2.0.119",
6043 6070 ]
6044 6071
6072 [[package]]
6073 name = "proptest"
6074 version = "1.11.0"
6075 source = "registry+https://github.com/rust-lang/crates.io-index"
6076 checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
6077 dependencies = [
6078 "bit-set 0.8.0",
6079 "bit-vec 0.8.0",
6080 "bitflags 2.13.2",
6081 "num-traits",
6082 "proptest-macro",
6083 "rand 0.9.5",
6084 "rand_chacha 0.9.0",
6085 "rand_xorshift",
6086 "regex-syntax",
6087 "rusty-fork",
6088 "tempfile",
6089 "unarray",
6090 ]
6091
6092 [[package]]
6093 name = "proptest-macro"
6094 version = "0.5.0"
6095 source = "registry+https://github.com/rust-lang/crates.io-index"
6096 checksum = "efaa288b896cb2b345da7b7f2110ab19e51565b83495b56fcec98a62f8b1f33e"
6097 dependencies = [
6098 "convert_case 0.11.0",
6099 "proc-macro2",
6100 "quote",
6101 "syn 2.0.119",
6102 ]
6103
6045 6104 [[package]]
6046 6105 name = "pulp"
6047 6106 version = "0.22.3"
@@ -6080,6 +6139,12 @@ dependencies = [
6080 6139 "bytemuck",
6081 6140 ]
6082 6141
6142 [[package]]
6143 name = "quick-error"
6144 version = "1.2.3"
6145 source = "registry+https://github.com/rust-lang/crates.io-index"
6146 checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
6147
6083 6148 [[package]]
6084 6149 name = "quick-error"
6085 6150 version = "2.0.1"
@@ -6257,6 +6322,15 @@ dependencies = [
6257 6322 "rand_core 0.10.1",
6258 6323 ]
6259 6324
6325 [[package]]
6326 name = "rand_xorshift"
6327 version = "0.4.0"
6328 source = "registry+https://github.com/rust-lang/crates.io-index"
6329 checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
6330 dependencies = [
6331 "rand_core 0.9.5",
6332 ]
6333
6260 6334 [[package]]
6261 6335 name = "range-alloc"
6262 6336 version = "0.1.5"
@@ -6313,7 +6387,7 @@ dependencies = [
6313 6387 "avif-serialize",
6314 6388 "imgref",
6315 6389 "loop9",
6316 "quick-error",
6390 "quick-error 2.0.1",
6317 6391 "rav1e",
6318 6392 "rayon",
6319 6393 "rgb",
@@ -6774,6 +6848,18 @@ version = "1.0.23"
6774 6848 source = "registry+https://github.com/rust-lang/crates.io-index"
6775 6849 checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
6776 6850
6851 [[package]]
6852 name = "rusty-fork"
6853 version = "0.3.1"
6854 source = "registry+https://github.com/rust-lang/crates.io-index"
6855 checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
6856 dependencies = [
6857 "fnv",
6858 "quick-error 1.2.3",
6859 "tempfile",
6860 "wait-timeout",
6861 ]
6862
6777 6863 [[package]]
6778 6864 name = "rustybuzz"
6779 6865 version = "0.20.1"
@@ -7852,7 +7938,7 @@ dependencies = [
7852 7938 "fax",
7853 7939 "flate2",
7854 7940 "half",
7855 "quick-error",
7941 "quick-error 2.0.1",
7856 7942 "weezl",
7857 7943 "zune-jpeg 0.5.15",
7858 7944 ]
@@ -8287,6 +8373,12 @@ dependencies = [
8287 8373 "windows-sys 0.61.2",
8288 8374 ]
8289 8375
8376 [[package]]
8377 name = "unarray"
8378 version = "0.1.4"
8379 source = "registry+https://github.com/rust-lang/crates.io-index"
8380 checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
8381
8290 8382 [[package]]
8291 8383 name = "unicase"
8292 8384 version = "2.10.0"
@@ -8559,6 +8651,15 @@ dependencies = [
8559 8651 "libc",
8560 8652 ]
8561 8653
8654 [[package]]
8655 name = "wait-timeout"
8656 version = "0.2.1"
8657 source = "registry+https://github.com/rust-lang/crates.io-index"
8658 checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
8659 dependencies = [
8660 "libc",
8661 ]
8662
8562 8663 [[package]]
8563 8664 name = "waker-fn"
8564 8665 version = "1.2.0"
@@ -8888,8 +8989,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
8888 8989 checksum = "2f519832254e56965a9940c4af57dcb75f702b6f6fa4a0b172f685395843a4d7"
8889 8990 dependencies = [
8890 8991 "arrayvec",
8891 "bit-set",
8892 "bit-vec",
8992 "bit-set 0.9.1",
8993 "bit-vec 0.9.1",
8893 8994 "bitflags 2.13.2",
8894 8995 "bytemuck",
8895 8996 "cfg_aliases",
@@ -8960,7 +9061,7 @@ dependencies = [
8960 9061 "android_system_properties",
8961 9062 "arrayvec",
8962 9063 "ash",
8963 "bit-set",
9064 "bit-set 0.9.1",
8964 9065 "bitflags 2.13.2",
8965 9066 "block2 0.6.2",
8966 9067 "bytemuck",
@@ -701,15 +701,30 @@ dependencies = [
701 "syn 2.0.119",
701 "syn 2.0.119",
702]
702]
703
703
704[[package]]
705name = "bit-set"
706version = "0.8.0"
707source = "registry+https://github.com/rust-lang/crates.io-index"
708checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
709dependencies = [
710 "bit-vec 0.8.0",
711]
712
704[[package]]
713[[package]]
705name = "bit-set"
714name = "bit-set"
706version = "0.9.1"
715version = "0.9.1"
707source = "registry+https://github.com/rust-lang/crates.io-index"
716source = "registry+https://github.com/rust-lang/crates.io-index"
708checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd"
717checksum = "34ddef2995421ab6a5c779542c81ee77c115206f4ad9d5a8e05f4ff49716a3dd"
709dependencies = [
718dependencies = [
710 "bit-vec",
719 "bit-vec 0.9.1",
711]
720]
712
721
722[[package]]
723name = "bit-vec"
724version = "0.8.0"
725source = "registry+https://github.com/rust-lang/crates.io-index"
726checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
727
713[[package]]
728[[package]]
714name = "bit-vec"
729name = "bit-vec"
715version = "0.9.1"
730version = "0.9.1"
@@ -1307,6 +1322,15 @@ dependencies = [
1307 "unicode-segmentation",
1322 "unicode-segmentation",
1308]
1323]
1309
1324
1325[[package]]
1326name = "convert_case"
1327version = "0.11.0"
1328source = "registry+https://github.com/rust-lang/crates.io-index"
1329checksum = "affbf0190ed2caf063e3def54ff444b449371d55c58e513a95ab98eca50adb49"
1330dependencies = [
1331 "unicode-segmentation",
1332]
1333
1310[[package]]
1334[[package]]
1311name = "core-foundation"
1335name = "core-foundation"
1312version = "0.9.4"
1336version = "0.9.4"
@@ -1694,7 +1718,7 @@ version = "2.1.1"
1694source = "registry+https://github.com/rust-lang/crates.io-index"
1718source = "registry+https://github.com/rust-lang/crates.io-index"
1695checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
1719checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"
1696dependencies = [
1720dependencies = [
1697 "convert_case",
1721 "convert_case 0.10.0",
1698 "proc-macro2",
1722 "proc-macro2",
1699 "quote",
1723 "quote",
1700 "rustc_version",
1724 "rustc_version",
@@ -2963,6 +2987,7 @@ dependencies = [
2963 "pollster 0.4.0",
2987 "pollster 0.4.0",
2964 "postage",
2988 "postage",
2965 "profiling",
2989 "profiling",
2990 "proptest",
2966 "rand 0.9.5",
2991 "rand 0.9.5",
2967 "raw-window-handle",
2992 "raw-window-handle",
2968 "regex",
2993 "regex",
@@ -3188,6 +3213,7 @@ dependencies = [
3188 "gpui-pre-linux",
3213 "gpui-pre-linux",
3189 "gpui-pre-macos",
3214 "gpui-pre-macos",
3190 "gpui-pre-web",
3215 "gpui-pre-web",
3216 "gpui-pre-wgpu",
3191 "gpui-pre-windows",
3217 "gpui-pre-windows",
3192]
3218]
3193
3219
@@ -3355,6 +3381,7 @@ dependencies = [
3355 "gpui-pre",
3381 "gpui-pre",
3356 "gpui-pre-collections",
3382 "gpui-pre-collections",
3357 "gpui-pre-util",
3383 "gpui-pre-util",
3384 "image",
3358 "itertools 0.14.0",
3385 "itertools 0.14.0",
3359 "log",
3386 "log",
3360 "parking_lot",
3387 "parking_lot",
@@ -3963,7 +3990,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
3963checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
3990checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3"
3964dependencies = [
3991dependencies = [
3965 "byteorder-lite",
3992 "byteorder-lite",
3966 "quick-error",
3993 "quick-error 2.0.1",
3967]
3994]
3968
3995
3969[[package]]
3996[[package]]
@@ -4779,7 +4806,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
4779checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df"
4806checksum = "b2bf919621e7975acb27d881bae2fb993e0d45c8e0446e85e6272971e00dc8df"
4780dependencies = [
4807dependencies = [
4781 "arrayvec",
4808 "arrayvec",
4782 "bit-set",
4809 "bit-set 0.9.1",
4783 "bitflags 2.13.2",
4810 "bitflags 2.13.2",
4784 "cfg-if",
4811 "cfg-if",
4785 "cfg_aliases",
4812 "cfg_aliases",
@@ -6042,6 +6069,38 @@ dependencies = [
6042 "syn 2.0.119",
6069 "syn 2.0.119",
6043]
6070]
6044
6071
6072[[package]]
6073name = "proptest"
6074version = "1.11.0"
6075source = "registry+https://github.com/rust-lang/crates.io-index"
6076checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744"
6077dependencies = [
6078 "bit-set 0.8.0",
6079 "bit-vec 0.8.0",
6080 "bitflags 2.13.2",
6081 "num-traits",
6082 "proptest-macro",
6083 "rand 0.9.5",
6084 "rand_chacha 0.9.0",
6085 "rand_xorshift",
6086 "regex-syntax",
6087 "rusty-fork",
6088 "tempfile",
6089 "unarray",
6090]
6091
6092[[package]]
6093name = "proptest-macro"
6094version = "0.5.0"
6095source = "registry+https://github.com/rust-lang/crates.io-index"
6096checksum = "efaa288b896cb2b345da7b7f2110ab19e51565b83495b56fcec98a62f8b1f33e"
6097dependencies = [
6098 "convert_case 0.11.0",
6099 "proc-macro2",
6100 "quote",
6101 "syn 2.0.119",
6102]
6103
6045[[package]]
6104[[package]]
6046name = "pulp"
6105name = "pulp"
6047version = "0.22.3"
6106version = "0.22.3"
@@ -6080,6 +6139,12 @@ dependencies = [
6080 "bytemuck",
6139 "bytemuck",
6081]
6140]
6082
6141
6142[[package]]
6143name = "quick-error"
6144version = "1.2.3"
6145source = "registry+https://github.com/rust-lang/crates.io-index"
6146checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
6147
6083[[package]]
6148[[package]]
6084name = "quick-error"
6149name = "quick-error"
6085version = "2.0.1"
6150version = "2.0.1"
@@ -6257,6 +6322,15 @@ dependencies = [
6257 "rand_core 0.10.1",
6322 "rand_core 0.10.1",
6258]
6323]
6259
6324
6325[[package]]
6326name = "rand_xorshift"
6327version = "0.4.0"
6328source = "registry+https://github.com/rust-lang/crates.io-index"
6329checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
6330dependencies = [
6331 "rand_core 0.9.5",
6332]
6333
6260[[package]]
6334[[package]]
6261name = "range-alloc"
6335name = "range-alloc"
6262version = "0.1.5"
6336version = "0.1.5"
@@ -6313,7 +6387,7 @@ dependencies = [
6313 "avif-serialize",
6387 "avif-serialize",
6314 "imgref",
6388 "imgref",
6315 "loop9",
6389 "loop9",
6316 "quick-error",
6390 "quick-error 2.0.1",
6317 "rav1e",
6391 "rav1e",
6318 "rayon",
6392 "rayon",
6319 "rgb",
6393 "rgb",
@@ -6774,6 +6848,18 @@ version = "1.0.23"
6774source = "registry+https://github.com/rust-lang/crates.io-index"
6848source = "registry+https://github.com/rust-lang/crates.io-index"
6775checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
6849checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
6776
6850
6851[[package]]
6852name = "rusty-fork"
6853version = "0.3.1"
6854source = "registry+https://github.com/rust-lang/crates.io-index"
6855checksum = "cc6bf79ff24e648f6da1f8d1f011e9cac26491b619e6b9280f2b47f1774e6ee2"
6856dependencies = [
6857 "fnv",
6858 "quick-error 1.2.3",
6859 "tempfile",
6860 "wait-timeout",
6861]
6862
6777[[package]]
6863[[package]]
6778name = "rustybuzz"
6864name = "rustybuzz"
6779version = "0.20.1"
6865version = "0.20.1"
@@ -7852,7 +7938,7 @@ dependencies = [
7852 "fax",
7938 "fax",
7853 "flate2",
7939 "flate2",
7854 "half",
7940 "half",
7855 "quick-error",
7941 "quick-error 2.0.1",
7856 "weezl",
7942 "weezl",
7857 "zune-jpeg 0.5.15",
7943 "zune-jpeg 0.5.15",
7858]
7944]
@@ -8287,6 +8373,12 @@ dependencies = [
8287 "windows-sys 0.61.2",
8373 "windows-sys 0.61.2",
8288]
8374]
8289
8375
8376[[package]]
8377name = "unarray"
8378version = "0.1.4"
8379source = "registry+https://github.com/rust-lang/crates.io-index"
8380checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94"
8381
8290[[package]]
8382[[package]]
8291name = "unicase"
8383name = "unicase"
8292version = "2.10.0"
8384version = "2.10.0"
@@ -8559,6 +8651,15 @@ dependencies = [
8559 "libc",
8651 "libc",
8560]
8652]
8561
8653
8654[[package]]
8655name = "wait-timeout"
8656version = "0.2.1"
8657source = "registry+https://github.com/rust-lang/crates.io-index"
8658checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
8659dependencies = [
8660 "libc",
8661]
8662
8562[[package]]
8663[[package]]
8563name = "waker-fn"
8664name = "waker-fn"
8564version = "1.2.0"
8665version = "1.2.0"
@@ -8888,8 +8989,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
8888checksum = "2f519832254e56965a9940c4af57dcb75f702b6f6fa4a0b172f685395843a4d7"
8989checksum = "2f519832254e56965a9940c4af57dcb75f702b6f6fa4a0b172f685395843a4d7"
8889dependencies = [
8990dependencies = [
8890 "arrayvec",
8991 "arrayvec",
8891 "bit-set",
8992 "bit-set 0.9.1",
8892 "bit-vec",
8993 "bit-vec 0.9.1",
8893 "bitflags 2.13.2",
8994 "bitflags 2.13.2",
8894 "bytemuck",
8995 "bytemuck",
8895 "cfg_aliases",
8996 "cfg_aliases",
@@ -8960,7 +9061,7 @@ dependencies = [
8960 "android_system_properties",
9061 "android_system_properties",
8961 "arrayvec",
9062 "arrayvec",
8962 "ash",
9063 "ash",
8963 "bit-set",
9064 "bit-set 0.9.1",
8964 "bitflags 2.13.2",
9065 "bitflags 2.13.2",
8965 "block2 0.6.2",
9066 "block2 0.6.2",
8966 "bytemuck",
9067 "bytemuck",
README.md +2 −1
@@ -14,7 +14,8 @@ It does chats and channels. No calls, no meetings, no apps.
14 14 - Send, edit, delete, react, quote-reply, @mentions
15 15 - Emoji by `:` code with English codes and German aliases, `:thumbsup:` and `:)` convert as you type
16 16 - Inline images, file cards, Adaptive Cards as text
17 - Read receipts, presence, unread jump
17 - Read receipts, presence (last known status shown at start), unread jump
18 - Select and copy message text, `Ctrl+A` in the composer
18 19 - Local full-text search and a `Ctrl+K` switcher, served from the cache
19 20 - Dark theme, opens instantly from the local cache
20 21 - Self-update from an update folder
@@ -14,7 +14,8 @@ It does chats and channels. No calls, no meetings, no apps.
14- Send, edit, delete, react, quote-reply, @mentions
14- Send, edit, delete, react, quote-reply, @mentions
15- Emoji by `:` code with English codes and German aliases, `:thumbsup:` and `:)` convert as you type
15- Emoji by `:` code with English codes and German aliases, `:thumbsup:` and `:)` convert as you type
16- Inline images, file cards, Adaptive Cards as text
16- Inline images, file cards, Adaptive Cards as text
17- Read receipts, presence, unread jump
17- Read receipts, presence (last known status shown at start), unread jump
18- Select and copy message text, `Ctrl+A` in the composer
18- Local full-text search and a `Ctrl+K` switcher, served from the cache
19- Local full-text search and a `Ctrl+K` switcher, served from the cache
19- Dark theme, opens instantly from the local cache
20- Dark theme, opens instantly from the local cache
20- Self-update from an update folder
21- Self-update from an update folder
crates/app/Cargo.toml +1 −0
@@ -14,6 +14,7 @@ chrono.workspace = true
14 14 embed-resource = "3"
15 15
16 16 [dev-dependencies]
17 gpui-kit = { workspace = true, features = ["test-support"] }
17 18 tempfile.workspace = true
18 19
19 20 [dependencies]
@@ -14,6 +14,7 @@ chrono.workspace = true
14embed-resource = "3"
14embed-resource = "3"
15
15
16[dev-dependencies]
16[dev-dependencies]
17gpui-kit = { workspace = true, features = ["test-support"] }
17tempfile.workspace = true
18tempfile.workspace = true
18
19
19[dependencies]
20[dependencies]
crates/app/src/app_state.rs +8 −2
@@ -116,6 +116,7 @@ impl AppState {
116 116 };
117 117 state.collapsed = state.load_collapsed();
118 118 if !mode.demo {
119 state.directory.load_cached_presence(&state.store);
119 120 state.reload_directory();
120 121 }
121 122 state
@@ -286,11 +287,14 @@ impl AppState {
286 287 if wanted.is_empty() {
287 288 return;
288 289 }
290 self.directory.mark_presence_pending(&wanted);
289 291 if let Some(engine) = self.engine.clone() {
290 292 self.directory.mark_presence_requested(&wanted, now);
291 let done = data::refresh_presence(&engine, wanted);
292 self.on_done(done, cx, |state, cx| {
293 let done = data::refresh_presence(&engine, wanted.clone());
294 self.on_done(done, cx, move |state, cx| {
293 295 state.sync_presence();
296 state.directory.save_presence(&state.store, &wanted);
297 state.directory.settle_presence(&wanted);
294 298 cx.emit(AppEvent::Directory);
295 299 cx.notify();
296 300 });
@@ -395,6 +399,8 @@ impl AppState {
395 399 }
396 400 BackendEvent::Engine(engine) => {
397 401 self.engine = Some(engine);
402 let waiting = self.directory.waiting_presence_ids();
403 self.request_presence(waiting, cx);
398 404 cx.emit(AppEvent::Status);
399 405 }
400 406 BackendEvent::Core(CoreEvent::SidebarChanged) => self.reload_sidebar(cx),
@@ -116,6 +116,7 @@ impl AppState {
116 };
116 };
117 state.collapsed = state.load_collapsed();
117 state.collapsed = state.load_collapsed();
118 if !mode.demo {
118 if !mode.demo {
119 state.directory.load_cached_presence(&state.store);
119 state.reload_directory();
120 state.reload_directory();
120 }
121 }
121 state
122 state
@@ -286,11 +287,14 @@ impl AppState {
286 if wanted.is_empty() {
287 if wanted.is_empty() {
287 return;
288 return;
288 }
289 }
290 self.directory.mark_presence_pending(&wanted);
289 if let Some(engine) = self.engine.clone() {
291 if let Some(engine) = self.engine.clone() {
290 self.directory.mark_presence_requested(&wanted, now);
292 self.directory.mark_presence_requested(&wanted, now);
291 let done = data::refresh_presence(&engine, wanted);
293 let done = data::refresh_presence(&engine, wanted.clone());
292 self.on_done(done, cx, |state, cx| {
294 self.on_done(done, cx, move |state, cx| {
293 state.sync_presence();
295 state.sync_presence();
296 state.directory.save_presence(&state.store, &wanted);
297 state.directory.settle_presence(&wanted);
294 cx.emit(AppEvent::Directory);
298 cx.emit(AppEvent::Directory);
295 cx.notify();
299 cx.notify();
296 });
300 });
@@ -395,6 +399,8 @@ impl AppState {
395 }
399 }
396 BackendEvent::Engine(engine) => {
400 BackendEvent::Engine(engine) => {
397 self.engine = Some(engine);
401 self.engine = Some(engine);
402 let waiting = self.directory.waiting_presence_ids();
403 self.request_presence(waiting, cx);
398 cx.emit(AppEvent::Status);
404 cx.emit(AppEvent::Status);
399 }
405 }
400 BackendEvent::Core(CoreEvent::SidebarChanged) => self.reload_sidebar(cx),
406 BackendEvent::Core(CoreEvent::SidebarChanged) => self.reload_sidebar(cx),
crates/app/src/data.rs +132 −5
@@ -57,6 +57,44 @@ impl PresenceKind {
57 57 PresenceKind::Unknown => "",
58 58 }
59 59 }
60
61 fn code(self) -> &'static str {
62 match self {
63 PresenceKind::Available => "Available",
64 PresenceKind::Busy => "Busy",
65 PresenceKind::DoNotDisturb => "DoNotDisturb",
66 PresenceKind::Away => "Away",
67 PresenceKind::Offline => "Offline",
68 PresenceKind::Unknown => "Unknown",
69 }
70 }
71
72 fn from_code(code: &str) -> PresenceKind {
73 match code {
74 "Available" => PresenceKind::Available,
75 "Busy" => PresenceKind::Busy,
76 "DoNotDisturb" => PresenceKind::DoNotDisturb,
77 "Away" => PresenceKind::Away,
78 "Offline" => PresenceKind::Offline,
79 _ => PresenceKind::Unknown,
80 }
81 }
82 }
83
84 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
85 pub enum Presence {
86 Live(PresenceKind),
87 Cached(PresenceKind),
88 Loading,
89 }
90
91 impl Presence {
92 pub fn kind(self) -> PresenceKind {
93 match self {
94 Presence::Live(kind) | Presence::Cached(kind) => kind,
95 Presence::Loading => PresenceKind::Unknown,
96 }
97 }
60 98 }
61 99
62 100 #[derive(Clone)]
@@ -80,7 +118,9 @@ pub struct Directory {
80 118 pub unread_counts: HashMap<String, u32>,
81 119 pub(crate) avatars: HashMap<String, AvatarState>,
82 120 pub(crate) presence: HashMap<String, (PresenceKind, Instant)>,
121 pub(crate) presence_cached: HashMap<String, PresenceKind>,
83 122 pub(crate) presence_requested: HashMap<String, Instant>,
123 pub(crate) presence_pending: HashSet<String>,
84 124 pub(crate) images: HashMap<String, ImageEntry>,
85 125 pub(crate) images_requested: HashSet<String>,
86 126 }
@@ -142,10 +182,51 @@ impl Directory {
142 182 .collect()
143 183 }
144 184
145 pub fn presence_of(&self, user_id: &str) -> PresenceKind {
146 self.presence
147 .get(user_id)
148 .map_or(PresenceKind::Unknown, |(kind, _)| *kind)
185 pub fn presence_of(&self, user_id: &str) -> Presence {
186 if let Some((kind, _)) = self.presence.get(user_id) {
187 return Presence::Live(*kind);
188 }
189 match self.presence_cached.get(user_id) {
190 Some(kind) => Presence::Cached(*kind),
191 None if self.presence_pending.contains(user_id) => Presence::Loading,
192 None => Presence::Live(PresenceKind::Unknown),
193 }
194 }
195
196 pub fn load_cached_presence(&mut self, store: &Store) {
197 self.presence_cached = store
198 .presences()
199 .unwrap_or_default()
200 .into_iter()
201 .map(|(user_id, code)| (user_id, PresenceKind::from_code(&code)))
202 .collect();
203 }
204
205 pub fn save_presence(&self, store: &Store, user_ids: &[String]) {
206 let rows: Vec<(String, String)> = user_ids
207 .iter()
208 .filter_map(|user_id| {
209 let (kind, _) = self.presence.get(user_id)?;
210 Some((user_id.clone(), kind.code().to_owned()))
211 })
212 .collect();
213 if !rows.is_empty() {
214 let _ = store.upsert_presences(&rows, chrono::Utc::now());
215 }
216 }
217
218 pub fn mark_presence_pending(&mut self, user_ids: &[String]) {
219 self.presence_pending.extend(user_ids.iter().cloned());
220 }
221
222 pub fn settle_presence(&mut self, user_ids: &[String]) {
223 for user_id in user_ids {
224 self.presence_pending.remove(user_id);
225 }
226 }
227
228 pub fn waiting_presence_ids(&self) -> Vec<String> {
229 self.presence_pending.iter().cloned().collect()
149 230 }
150 231
151 232 pub fn set_presence(&mut self, user_id: &str, kind: PresenceKind) {
@@ -443,7 +524,53 @@ mod tests {
443 524 assert!(directory.stale_presence(["u".to_owned()], start).is_empty());
444 525 let later = start + PRESENCE_MAX_AGE + Duration::from_secs(1);
445 526 assert_eq!(directory.stale_presence(["u".to_owned()], later), vec!["u"]);
446 assert_eq!(directory.presence_of("u"), PresenceKind::Unknown);
527 assert_eq!(directory.presence_of("u").kind(), PresenceKind::Unknown);
528 }
529
530 #[test]
531 fn presence_prefers_live_over_cached_over_loading() {
532 let mut directory = Directory::default();
533 let ids = ["a".to_owned(), "b".to_owned(), "c".to_owned()];
534 directory.mark_presence_pending(&ids);
535 directory
536 .presence_cached
537 .insert("b".into(), PresenceKind::Away);
538 directory
539 .presence_cached
540 .insert("c".into(), PresenceKind::Away);
541 directory.set_presence("c", PresenceKind::Busy);
542 assert_eq!(directory.presence_of("a"), Presence::Loading);
543 assert_eq!(
544 directory.presence_of("b"),
545 Presence::Cached(PresenceKind::Away)
546 );
547 assert_eq!(
548 directory.presence_of("c"),
549 Presence::Live(PresenceKind::Busy)
550 );
551 directory.settle_presence(&ids);
552 assert_eq!(
553 directory.presence_of("a"),
554 Presence::Live(PresenceKind::Unknown)
555 );
556 }
557
558 #[test]
559 fn presence_survives_a_restart_through_the_store() {
560 let store = Store::open_in_memory().unwrap();
561 let mut directory = Directory::default();
562 directory.set_presence("a", PresenceKind::DoNotDisturb);
563 directory.save_presence(&store, &["a".to_owned(), "missing".to_owned()]);
564 let mut restarted = Directory::default();
565 restarted.load_cached_presence(&store);
566 assert_eq!(
567 restarted.presence_of("a"),
568 Presence::Cached(PresenceKind::DoNotDisturb)
569 );
570 assert_eq!(
571 restarted.presence_of("missing"),
572 Presence::Live(PresenceKind::Unknown)
573 );
447 574 }
448 575
449 576 #[test]
@@ -57,6 +57,44 @@ impl PresenceKind {
57 PresenceKind::Unknown => "",
57 PresenceKind::Unknown => "",
58 }
58 }
59 }
59 }
60
61 fn code(self) -> &'static str {
62 match self {
63 PresenceKind::Available => "Available",
64 PresenceKind::Busy => "Busy",
65 PresenceKind::DoNotDisturb => "DoNotDisturb",
66 PresenceKind::Away => "Away",
67 PresenceKind::Offline => "Offline",
68 PresenceKind::Unknown => "Unknown",
69 }
70 }
71
72 fn from_code(code: &str) -> PresenceKind {
73 match code {
74 "Available" => PresenceKind::Available,
75 "Busy" => PresenceKind::Busy,
76 "DoNotDisturb" => PresenceKind::DoNotDisturb,
77 "Away" => PresenceKind::Away,
78 "Offline" => PresenceKind::Offline,
79 _ => PresenceKind::Unknown,
80 }
81 }
82}
83
84#[derive(Debug, Clone, Copy, PartialEq, Eq)]
85pub enum Presence {
86 Live(PresenceKind),
87 Cached(PresenceKind),
88 Loading,
89}
90
91impl Presence {
92 pub fn kind(self) -> PresenceKind {
93 match self {
94 Presence::Live(kind) | Presence::Cached(kind) => kind,
95 Presence::Loading => PresenceKind::Unknown,
96 }
97 }
60}
98}
61
99
62#[derive(Clone)]
100#[derive(Clone)]
@@ -80,7 +118,9 @@ pub struct Directory {
80 pub unread_counts: HashMap<String, u32>,
118 pub unread_counts: HashMap<String, u32>,
81 pub(crate) avatars: HashMap<String, AvatarState>,
119 pub(crate) avatars: HashMap<String, AvatarState>,
82 pub(crate) presence: HashMap<String, (PresenceKind, Instant)>,
120 pub(crate) presence: HashMap<String, (PresenceKind, Instant)>,
121 pub(crate) presence_cached: HashMap<String, PresenceKind>,
83 pub(crate) presence_requested: HashMap<String, Instant>,
122 pub(crate) presence_requested: HashMap<String, Instant>,
123 pub(crate) presence_pending: HashSet<String>,
84 pub(crate) images: HashMap<String, ImageEntry>,
124 pub(crate) images: HashMap<String, ImageEntry>,
85 pub(crate) images_requested: HashSet<String>,
125 pub(crate) images_requested: HashSet<String>,
86}
126}
@@ -142,10 +182,51 @@ impl Directory {
142 .collect()
182 .collect()
143 }
183 }
144
184
145 pub fn presence_of(&self, user_id: &str) -> PresenceKind {
185 pub fn presence_of(&self, user_id: &str) -> Presence {
146 self.presence
186 if let Some((kind, _)) = self.presence.get(user_id) {
147 .get(user_id)
187 return Presence::Live(*kind);
148 .map_or(PresenceKind::Unknown, |(kind, _)| *kind)
188 }
189 match self.presence_cached.get(user_id) {
190 Some(kind) => Presence::Cached(*kind),
191 None if self.presence_pending.contains(user_id) => Presence::Loading,
192 None => Presence::Live(PresenceKind::Unknown),
193 }
194 }
195
196 pub fn load_cached_presence(&mut self, store: &Store) {
197 self.presence_cached = store
198 .presences()
199 .unwrap_or_default()
200 .into_iter()
201 .map(|(user_id, code)| (user_id, PresenceKind::from_code(&code)))
202 .collect();
203 }
204
205 pub fn save_presence(&self, store: &Store, user_ids: &[String]) {
206 let rows: Vec<(String, String)> = user_ids
207 .iter()
208 .filter_map(|user_id| {
209 let (kind, _) = self.presence.get(user_id)?;
210 Some((user_id.clone(), kind.code().to_owned()))
211 })
212 .collect();
213 if !rows.is_empty() {
214 let _ = store.upsert_presences(&rows, chrono::Utc::now());
215 }
216 }
217
218 pub fn mark_presence_pending(&mut self, user_ids: &[String]) {
219 self.presence_pending.extend(user_ids.iter().cloned());
220 }
221
222 pub fn settle_presence(&mut self, user_ids: &[String]) {
223 for user_id in user_ids {
224 self.presence_pending.remove(user_id);
225 }
226 }
227
228 pub fn waiting_presence_ids(&self) -> Vec<String> {
229 self.presence_pending.iter().cloned().collect()
149 }
230 }
150
231
151 pub fn set_presence(&mut self, user_id: &str, kind: PresenceKind) {
232 pub fn set_presence(&mut self, user_id: &str, kind: PresenceKind) {
@@ -443,7 +524,53 @@ mod tests {
443 assert!(directory.stale_presence(["u".to_owned()], start).is_empty());
524 assert!(directory.stale_presence(["u".to_owned()], start).is_empty());
444 let later = start + PRESENCE_MAX_AGE + Duration::from_secs(1);
525 let later = start + PRESENCE_MAX_AGE + Duration::from_secs(1);
445 assert_eq!(directory.stale_presence(["u".to_owned()], later), vec!["u"]);
526 assert_eq!(directory.stale_presence(["u".to_owned()], later), vec!["u"]);
446 assert_eq!(directory.presence_of("u"), PresenceKind::Unknown);
527 assert_eq!(directory.presence_of("u").kind(), PresenceKind::Unknown);
528 }
529
530 #[test]
531 fn presence_prefers_live_over_cached_over_loading() {
532 let mut directory = Directory::default();
533 let ids = ["a".to_owned(), "b".to_owned(), "c".to_owned()];
534 directory.mark_presence_pending(&ids);
535 directory
536 .presence_cached
537 .insert("b".into(), PresenceKind::Away);
538 directory
539 .presence_cached
540 .insert("c".into(), PresenceKind::Away);
541 directory.set_presence("c", PresenceKind::Busy);
542 assert_eq!(directory.presence_of("a"), Presence::Loading);
543 assert_eq!(
544 directory.presence_of("b"),
545 Presence::Cached(PresenceKind::Away)
546 );
547 assert_eq!(
548 directory.presence_of("c"),
549 Presence::Live(PresenceKind::Busy)
550 );
551 directory.settle_presence(&ids);
552 assert_eq!(
553 directory.presence_of("a"),
554 Presence::Live(PresenceKind::Unknown)
555 );
556 }
557
558 #[test]
559 fn presence_survives_a_restart_through_the_store() {
560 let store = Store::open_in_memory().unwrap();
561 let mut directory = Directory::default();
562 directory.set_presence("a", PresenceKind::DoNotDisturb);
563 directory.save_presence(&store, &["a".to_owned(), "missing".to_owned()]);
564 let mut restarted = Directory::default();
565 restarted.load_cached_presence(&store);
566 assert_eq!(
567 restarted.presence_of("a"),
568 Presence::Cached(PresenceKind::DoNotDisturb)
569 );
570 assert_eq!(
571 restarted.presence_of("missing"),
572 Presence::Live(PresenceKind::Unknown)
573 );
447 }
574 }
448
575
449 #[test]
576 #[test]
crates/app/src/notify/center.rs +131 −75
@@ -14,9 +14,9 @@ use super::rules::{
14 14 should_flash,
15 15 };
16 16 use super::settings;
17 use super::settings_view::SettingsView;
17 18 use super::stack::{ReplyState, SENT_DURATION, ToastModel, ToastStack};
18 19 use super::toast::{PillView, ToastView};
19 use super::settings_view::SettingsView;
20 20 use crate::app_state::{AppEvent, AppState, Selection};
21 21 use crate::data::{self, Directory, PresenceKind};
22 22 use crate::runtime;
@@ -44,8 +44,11 @@ pub struct NotificationCenter {
44 44 tracker: IncomingTracker,
45 45 throttle: SoundThrottle,
46 46 windows: HashMap<u64, OpenWindow>,
47 opening: HashSet<u64>,
47 48 pill: Option<OpenWindow>,
49 pill_opening: bool,
48 50 settings_window: Option<AnyWindowHandle>,
51 settings_opening: bool,
49 52 unread_mentions: HashSet<String>,
50 53 tray: Option<Tray>,
51 54 shown_badge: Option<Badge>,
@@ -54,11 +57,7 @@ pub struct NotificationCenter {
54 57 }
55 58
56 59 impl NotificationCenter {
57 pub fn new(
58 app: Entity<AppState>,
59 window: &mut Window,
60 cx: &mut Context<Self>,
61 ) -> Self {
60 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
62 61 let settings = settings::load(&app.read(cx).store);
63 62 let tray = if app.read(cx).mode.demo {
64 63 None
@@ -76,8 +75,11 @@ impl NotificationCenter {
76 75 tracker: IncomingTracker::new(Utc::now()),
77 76 throttle: SoundThrottle::default(),
78 77 windows: HashMap::new(),
78 opening: HashSet::new(),
79 79 pill: None,
80 pill_opening: false,
80 81 settings_window: None,
82 settings_opening: false,
81 83 unread_mentions: HashSet::new(),
82 84 tray,
83 85 shown_badge: None,
@@ -97,7 +99,8 @@ impl NotificationCenter {
97 99 if center.app.read(cx).mode.demo {
98 100 cx.spawn(async move |this, cx| {
99 101 cx.background_executor().timer(DEMO_SPEC_DELAY).await;
100 this.update(cx, |center, cx| center.show_demo_toasts(cx)).ok();
102 this.update(cx, |center, cx| center.show_demo_toasts(cx))
103 .ok();
101 104 })
102 105 .detach();
103 106 }
@@ -186,7 +189,7 @@ impl NotificationCenter {
186 189 .as_ref()
187 190 .is_some_and(|selection| selection.conversation_id() == conversation_id);
188 191 let own_do_not_disturb = state.directory.me.as_ref().is_some_and(|me| {
189 state.directory.presence_of(&me.user_id) == PresenceKind::DoNotDisturb
192 state.directory.presence_of(&me.user_id).kind() == PresenceKind::DoNotDisturb
190 193 });
191 194 let in_call = match (state.engine.as_ref(), state.directory.me.as_ref()) {
192 195 (Some(engine), Some(me)) => data::in_call(engine, &me.user_id),
@@ -308,10 +311,8 @@ impl NotificationCenter {
308 311 fn place_toast(&mut self, id: u64, slot: Slot, area: WorkArea, cx: &mut Context<Self>) {
309 312 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
310 313 if !self.windows.contains_key(&id) {
311 let Some(window) = self.open_toast_window(id, slot, area, cx) else {
312 return;
313 };
314 self.windows.insert(id, window);
314 self.open_toast_window(id, slot, area, cx);
315 return;
315 316 }
316 317 let offset = self
317 318 .windows
@@ -329,34 +330,26 @@ impl NotificationCenter {
329 330 }
330 331 }
331 332
332 fn open_toast_window(
333 &mut self,
334 id: u64,
335 slot: Slot,
336 area: WorkArea,
337 cx: &mut Context<Self>,
338 ) -> Option<OpenWindow> {
339 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
340 let options = popup_options(slot, area);
341 let center = cx.entity();
342 let (handle, _view) = gpui_kit::open_window(options, cx, move |window, cx| {
343 cx.new(|cx| ToastView::new(center, id, window, cx))
344 })
345 .ok()?;
346 let native = handle
347 .update(cx, |_, window, _| platform::native_handle(window))
348 .ok()
349 .flatten();
350 if let Some(native) = native {
351 platform::prepare_toast_window(native);
352 platform::set_border_color(native, border_color(mention));
333 fn open_toast_window(&mut self, id: u64, slot: Slot, area: WorkArea, cx: &mut Context<Self>) {
334 if !self.opening.insert(id) {
335 return;
353 336 }
354 Some(OpenWindow {
355 handle,
356 native,
357 opened: Instant::now(),
358 mention,
359 })
337 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
338 open_popup(
339 popup_options(slot, area),
340 cx,
341 move |center, window, cx| cx.new(|cx| ToastView::new(center, id, window, cx)),
342 move |this, window| {
343 this.opening.remove(&id);
344 let Some(window) = window else {
345 return;
346 };
347 if let Some(native) = window.native {
348 platform::set_border_color(native, border_color(mention));
349 }
350 this.windows.insert(id, OpenWindow { mention, ..window });
351 },
352 );
360 353 }
361 354
362 355 fn sync_pill(
@@ -368,32 +361,26 @@ impl NotificationCenter {
368 361 ) {
369 362 let Some(slot) = slot.filter(|_| hidden > 0) else {
370 363 if let Some(pill) = self.pill.take() {
371 pill.handle.update(cx, |_, window, _| window.remove_window()).ok();
364 pill.handle
365 .update(cx, |_, window, _| window.remove_window())
366 .ok();
372 367 }
373 368 return;
374 369 };
375 if self.pill.is_none() {
376 let options = popup_options(slot, area);
377 let center = cx.entity();
378 let opened = gpui_kit::open_window(options, cx, move |_, cx| {
379 cx.new(|cx| PillView::new(center, cx))
380 });
381 if let Ok((handle, _)) = opened {
382 let native = handle
383 .update(cx, |_, window, _| platform::native_handle(window))
384 .ok()
385 .flatten();
386 if let Some(native) = native {
387 platform::prepare_toast_window(native);
388 platform::set_border_color(native, border_color(false));
389 }
390 self.pill = Some(OpenWindow {
391 handle,
392 native,
393 opened: Instant::now(),
394 mention: false,
395 });
396 }
370 if self.pill.is_none() && !self.pill_opening {
371 self.pill_opening = true;
372 open_popup(
373 popup_options(slot, area),
374 cx,
375 |center, _, cx| cx.new(|cx| PillView::new(center, cx)),
376 |this, window| {
377 this.pill_opening = false;
378 if let Some(native) = window.as_ref().and_then(|window| window.native) {
379 platform::set_border_color(native, border_color(false));
380 }
381 this.pill = window;
382 },
383 );
397 384 }
398 385 if let Some(native) = self.pill.as_ref().and_then(|pill| pill.native) {
399 386 platform::place(native, slot.x, slot.y, slot.width, slot.height);
@@ -556,7 +543,8 @@ impl NotificationCenter {
556 543 });
557 544 cx.spawn(async move |this, cx| {
558 545 let sent = matches!(receiver.await, Ok(Ok(())));
559 this.update(cx, |center, cx| center.finish_reply(id, sent, cx)).ok();
546 this.update(cx, |center, cx| center.finish_reply(id, sent, cx))
547 .ok();
560 548 })
561 549 .detach();
562 550 return;
@@ -599,7 +587,10 @@ impl NotificationCenter {
599 587 }
600 588
601 589 pub fn mark_read(&mut self, id: u64, cx: &mut Context<Self>) {
602 let Some(conversation_id) = self.stack.get(id).map(|toast| toast.conversation_id.clone())
590 let Some(conversation_id) = self
591 .stack
592 .get(id)
593 .map(|toast| toast.conversation_id.clone())
603 594 else {
604 595 return;
605 596 };
@@ -631,11 +622,18 @@ impl NotificationCenter {
631 622
632 623 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
633 624 if let Some(handle) = self.settings_window {
634 if handle.update(cx, |_, window, _| window.activate_window()).is_ok() {
625 if handle
626 .update(cx, |_, window, _| window.activate_window())
627 .is_ok()
628 {
635 629 return;
636 630 }
637 631 self.settings_window = None;
638 632 }
633 if self.settings_opening {
634 return;
635 }
636 self.settings_opening = true;
639 637 let center = cx.entity();
640 638 let options = WindowOptions {
641 639 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
@@ -651,11 +649,17 @@ impl NotificationCenter {
651 649 is_minimizable: false,
652 650 ..Default::default()
653 651 };
654 if let Ok((handle, _)) = gpui_kit::open_window(options, cx, move |_, cx| {
655 cx.new(|cx| SettingsView::new(center, cx))
656 }) {
657 self.settings_window = Some(handle);
658 }
652 // open_window draws once right away, and SettingsView reads this entity while rendering.
653 cx.defer(move |cx| {
654 let view_center = center.clone();
655 let opened = gpui_kit::open_window(options, cx, move |_, cx| {
656 cx.new(|cx| SettingsView::new(view_center, cx))
657 });
658 center.update(cx, |this, _| {
659 this.settings_opening = false;
660 this.settings_window = opened.ok().map(|(handle, _)| handle);
661 });
662 });
659 663 }
660 664
661 665 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
@@ -690,14 +694,55 @@ impl NotificationCenter {
690 694 }
691 695
692 696 fn border_color(mention: bool) -> u32 {
693 if mention { MENTION_BORDER } else { FALLBACK_BORDER }
697 if mention {
698 MENTION_BORDER
699 } else {
700 FALLBACK_BORDER
701 }
702 }
703
704 /// Opens a window outside the current update: `open_window` draws right away, and every
705 /// notification view reads the center while rendering.
706 fn open_popup<V: Render>(
707 options: WindowOptions,
708 cx: &mut Context<NotificationCenter>,
709 build: impl FnOnce(Entity<NotificationCenter>, &mut Window, &mut App) -> Entity<V> + 'static,
710 opened: impl FnOnce(&mut NotificationCenter, Option<OpenWindow>) + 'static,
711 ) {
712 let center = cx.entity();
713 cx.defer(move |cx| {
714 let view_center = center.clone();
715 let Ok((handle, _)) = gpui_kit::open_window(options, cx, move |window, cx| {
716 build(view_center, window, cx)
717 }) else {
718 center.update(cx, |this, _| opened(this, None));
719 return;
720 };
721 let native = handle
722 .update(cx, |_, window, _| platform::native_handle(window))
723 .ok()
724 .flatten();
725 if let Some(native) = native {
726 platform::prepare_toast_window(native);
727 }
728 let window = OpenWindow {
729 handle,
730 native,
731 opened: Instant::now(),
732 mention: false,
733 };
734 center.update(cx, |this, _| opened(this, Some(window)));
735 });
694 736 }
695 737
696 738 fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
697 739 let scale = area.scale;
698 740 let bounds = Bounds::new(
699 741 point(px(slot.x as f32 / scale), px(slot.y as f32 / scale)),
700 size(px(slot.width as f32 / scale), px(slot.height as f32 / scale)),
742 size(
743 px(slot.width as f32 / scale),
744 px(slot.height as f32 / scale),
745 ),
701 746 );
702 747 WindowOptions {
703 748 window_bounds: Some(WindowBounds::Windowed(bounds)),
@@ -740,7 +785,12 @@ pub fn unread_summary(sidebar: &Sidebar) -> (usize, HashSet<String>) {
740 785 }
741 786
742 787 fn demo_incoming() -> Vec<Incoming> {
743 let item = |conversation: &str, kind: ChatKind, title: &str, sender: &str, text: &str, mention: bool| Incoming {
788 let item = |conversation: &str,
789 kind: ChatKind,
790 title: &str,
791 sender: &str,
792 text: &str,
793 mention: bool| Incoming {
744 794 conversation_id: conversation.to_owned(),
745 795 message_id: format!("{conversation}-message"),
746 796 kind,
@@ -832,8 +882,14 @@ mod tests {
832 882
833 883 #[test]
834 884 fn selection_kind_follows_sidebar() {
835 assert_eq!(selection_for(&sidebar(), "a"), Some(Selection::Chat("a".into())));
836 assert_eq!(selection_for(&sidebar(), "ch"), Some(Selection::Channel("ch".into())));
885 assert_eq!(
886 selection_for(&sidebar(), "a"),
887 Some(Selection::Chat("a".into()))
888 );
889 assert_eq!(
890 selection_for(&sidebar(), "ch"),
891 Some(Selection::Channel("ch".into()))
892 );
837 893 assert_eq!(selection_for(&sidebar(), "x"), None);
838 894 }
839 895 }
@@ -14,9 +14,9 @@ use super::rules::{
14 should_flash,
14 should_flash,
15};
15};
16use super::settings;
16use super::settings;
17use super::settings_view::SettingsView;
17use super::stack::{ReplyState, SENT_DURATION, ToastModel, ToastStack};
18use super::stack::{ReplyState, SENT_DURATION, ToastModel, ToastStack};
18use super::toast::{PillView, ToastView};
19use super::toast::{PillView, ToastView};
19use super::settings_view::SettingsView;
20use crate::app_state::{AppEvent, AppState, Selection};
20use crate::app_state::{AppEvent, AppState, Selection};
21use crate::data::{self, Directory, PresenceKind};
21use crate::data::{self, Directory, PresenceKind};
22use crate::runtime;
22use crate::runtime;
@@ -44,8 +44,11 @@ pub struct NotificationCenter {
44 tracker: IncomingTracker,
44 tracker: IncomingTracker,
45 throttle: SoundThrottle,
45 throttle: SoundThrottle,
46 windows: HashMap<u64, OpenWindow>,
46 windows: HashMap<u64, OpenWindow>,
47 opening: HashSet<u64>,
47 pill: Option<OpenWindow>,
48 pill: Option<OpenWindow>,
49 pill_opening: bool,
48 settings_window: Option<AnyWindowHandle>,
50 settings_window: Option<AnyWindowHandle>,
51 settings_opening: bool,
49 unread_mentions: HashSet<String>,
52 unread_mentions: HashSet<String>,
50 tray: Option<Tray>,
53 tray: Option<Tray>,
51 shown_badge: Option<Badge>,
54 shown_badge: Option<Badge>,
@@ -54,11 +57,7 @@ pub struct NotificationCenter {
54}
57}
55
58
56impl NotificationCenter {
59impl NotificationCenter {
57 pub fn new(
60 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
58 app: Entity<AppState>,
59 window: &mut Window,
60 cx: &mut Context<Self>,
61 ) -> Self {
62 let settings = settings::load(&app.read(cx).store);
61 let settings = settings::load(&app.read(cx).store);
63 let tray = if app.read(cx).mode.demo {
62 let tray = if app.read(cx).mode.demo {
64 None
63 None
@@ -76,8 +75,11 @@ impl NotificationCenter {
76 tracker: IncomingTracker::new(Utc::now()),
75 tracker: IncomingTracker::new(Utc::now()),
77 throttle: SoundThrottle::default(),
76 throttle: SoundThrottle::default(),
78 windows: HashMap::new(),
77 windows: HashMap::new(),
78 opening: HashSet::new(),
79 pill: None,
79 pill: None,
80 pill_opening: false,
80 settings_window: None,
81 settings_window: None,
82 settings_opening: false,
81 unread_mentions: HashSet::new(),
83 unread_mentions: HashSet::new(),
82 tray,
84 tray,
83 shown_badge: None,
85 shown_badge: None,
@@ -97,7 +99,8 @@ impl NotificationCenter {
97 if center.app.read(cx).mode.demo {
99 if center.app.read(cx).mode.demo {
98 cx.spawn(async move |this, cx| {
100 cx.spawn(async move |this, cx| {
99 cx.background_executor().timer(DEMO_SPEC_DELAY).await;
101 cx.background_executor().timer(DEMO_SPEC_DELAY).await;
100 this.update(cx, |center, cx| center.show_demo_toasts(cx)).ok();
102 this.update(cx, |center, cx| center.show_demo_toasts(cx))
103 .ok();
101 })
104 })
102 .detach();
105 .detach();
103 }
106 }
@@ -186,7 +189,7 @@ impl NotificationCenter {
186 .as_ref()
189 .as_ref()
187 .is_some_and(|selection| selection.conversation_id() == conversation_id);
190 .is_some_and(|selection| selection.conversation_id() == conversation_id);
188 let own_do_not_disturb = state.directory.me.as_ref().is_some_and(|me| {
191 let own_do_not_disturb = state.directory.me.as_ref().is_some_and(|me| {
189 state.directory.presence_of(&me.user_id) == PresenceKind::DoNotDisturb
192 state.directory.presence_of(&me.user_id).kind() == PresenceKind::DoNotDisturb
190 });
193 });
191 let in_call = match (state.engine.as_ref(), state.directory.me.as_ref()) {
194 let in_call = match (state.engine.as_ref(), state.directory.me.as_ref()) {
192 (Some(engine), Some(me)) => data::in_call(engine, &me.user_id),
195 (Some(engine), Some(me)) => data::in_call(engine, &me.user_id),
@@ -308,10 +311,8 @@ impl NotificationCenter {
308 fn place_toast(&mut self, id: u64, slot: Slot, area: WorkArea, cx: &mut Context<Self>) {
311 fn place_toast(&mut self, id: u64, slot: Slot, area: WorkArea, cx: &mut Context<Self>) {
309 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
312 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
310 if !self.windows.contains_key(&id) {
313 if !self.windows.contains_key(&id) {
311 let Some(window) = self.open_toast_window(id, slot, area, cx) else {
314 self.open_toast_window(id, slot, area, cx);
312 return;
315 return;
313 };
314 self.windows.insert(id, window);
315 }
316 }
316 let offset = self
317 let offset = self
317 .windows
318 .windows
@@ -329,34 +330,26 @@ impl NotificationCenter {
329 }
330 }
330 }
331 }
331
332
332 fn open_toast_window(
333 fn open_toast_window(&mut self, id: u64, slot: Slot, area: WorkArea, cx: &mut Context<Self>) {
333 &mut self,
334 if !self.opening.insert(id) {
334 id: u64,
335 return;
335 slot: Slot,
336 area: WorkArea,
337 cx: &mut Context<Self>,
338 ) -> Option<OpenWindow> {
339 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
340 let options = popup_options(slot, area);
341 let center = cx.entity();
342 let (handle, _view) = gpui_kit::open_window(options, cx, move |window, cx| {
343 cx.new(|cx| ToastView::new(center, id, window, cx))
344 })
345 .ok()?;
346 let native = handle
347 .update(cx, |_, window, _| platform::native_handle(window))
348 .ok()
349 .flatten();
350 if let Some(native) = native {
351 platform::prepare_toast_window(native);
352 platform::set_border_color(native, border_color(mention));
353 }
336 }
354 Some(OpenWindow {
337 let mention = self.stack.get(id).is_some_and(|toast| toast.mentions_me);
355 handle,
338 open_popup(
356 native,
339 popup_options(slot, area),
357 opened: Instant::now(),
340 cx,
358 mention,
341 move |center, window, cx| cx.new(|cx| ToastView::new(center, id, window, cx)),
359 })
342 move |this, window| {
343 this.opening.remove(&id);
344 let Some(window) = window else {
345 return;
346 };
347 if let Some(native) = window.native {
348 platform::set_border_color(native, border_color(mention));
349 }
350 this.windows.insert(id, OpenWindow { mention, ..window });
351 },
352 );
360 }
353 }
361
354
362 fn sync_pill(
355 fn sync_pill(
@@ -368,32 +361,26 @@ impl NotificationCenter {
368 ) {
361 ) {
369 let Some(slot) = slot.filter(|_| hidden > 0) else {
362 let Some(slot) = slot.filter(|_| hidden > 0) else {
370 if let Some(pill) = self.pill.take() {
363 if let Some(pill) = self.pill.take() {
371 pill.handle.update(cx, |_, window, _| window.remove_window()).ok();
364 pill.handle
365 .update(cx, |_, window, _| window.remove_window())
366 .ok();
372 }
367 }
373 return;
368 return;
374 };
369 };
375 if self.pill.is_none() {
370 if self.pill.is_none() && !self.pill_opening {
376 let options = popup_options(slot, area);
371 self.pill_opening = true;
377 let center = cx.entity();
372 open_popup(
378 let opened = gpui_kit::open_window(options, cx, move |_, cx| {
373 popup_options(slot, area),
379 cx.new(|cx| PillView::new(center, cx))
374 cx,
380 });
375 |center, _, cx| cx.new(|cx| PillView::new(center, cx)),
381 if let Ok((handle, _)) = opened {
376 |this, window| {
382 let native = handle
377 this.pill_opening = false;
383 .update(cx, |_, window, _| platform::native_handle(window))
378 if let Some(native) = window.as_ref().and_then(|window| window.native) {
384 .ok()
379 platform::set_border_color(native, border_color(false));
385 .flatten();
380 }
386 if let Some(native) = native {
381 this.pill = window;
387 platform::prepare_toast_window(native);
382 },
388 platform::set_border_color(native, border_color(false));
383 );
389 }
390 self.pill = Some(OpenWindow {
391 handle,
392 native,
393 opened: Instant::now(),
394 mention: false,
395 });
396 }
397 }
384 }
398 if let Some(native) = self.pill.as_ref().and_then(|pill| pill.native) {
385 if let Some(native) = self.pill.as_ref().and_then(|pill| pill.native) {
399 platform::place(native, slot.x, slot.y, slot.width, slot.height);
386 platform::place(native, slot.x, slot.y, slot.width, slot.height);
@@ -556,7 +543,8 @@ impl NotificationCenter {
556 });
543 });
557 cx.spawn(async move |this, cx| {
544 cx.spawn(async move |this, cx| {
558 let sent = matches!(receiver.await, Ok(Ok(())));
545 let sent = matches!(receiver.await, Ok(Ok(())));
559 this.update(cx, |center, cx| center.finish_reply(id, sent, cx)).ok();
546 this.update(cx, |center, cx| center.finish_reply(id, sent, cx))
547 .ok();
560 })
548 })
561 .detach();
549 .detach();
562 return;
550 return;
@@ -599,7 +587,10 @@ impl NotificationCenter {
599 }
587 }
600
588
601 pub fn mark_read(&mut self, id: u64, cx: &mut Context<Self>) {
589 pub fn mark_read(&mut self, id: u64, cx: &mut Context<Self>) {
602 let Some(conversation_id) = self.stack.get(id).map(|toast| toast.conversation_id.clone())
590 let Some(conversation_id) = self
591 .stack
592 .get(id)
593 .map(|toast| toast.conversation_id.clone())
603 else {
594 else {
604 return;
595 return;
605 };
596 };
@@ -631,11 +622,18 @@ impl NotificationCenter {
631
622
632 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
623 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
633 if let Some(handle) = self.settings_window {
624 if let Some(handle) = self.settings_window {
634 if handle.update(cx, |_, window, _| window.activate_window()).is_ok() {
625 if handle
626 .update(cx, |_, window, _| window.activate_window())
627 .is_ok()
628 {
635 return;
629 return;
636 }
630 }
637 self.settings_window = None;
631 self.settings_window = None;
638 }
632 }
633 if self.settings_opening {
634 return;
635 }
636 self.settings_opening = true;
639 let center = cx.entity();
637 let center = cx.entity();
640 let options = WindowOptions {
638 let options = WindowOptions {
641 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
639 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
@@ -651,11 +649,17 @@ impl NotificationCenter {
651 is_minimizable: false,
649 is_minimizable: false,
652 ..Default::default()
650 ..Default::default()
653 };
651 };
654 if let Ok((handle, _)) = gpui_kit::open_window(options, cx, move |_, cx| {
652 // open_window draws once right away, and SettingsView reads this entity while rendering.
655 cx.new(|cx| SettingsView::new(center, cx))
653 cx.defer(move |cx| {
656 }) {
654 let view_center = center.clone();
657 self.settings_window = Some(handle);
655 let opened = gpui_kit::open_window(options, cx, move |_, cx| {
658 }
656 cx.new(|cx| SettingsView::new(view_center, cx))
657 });
658 center.update(cx, |this, _| {
659 this.settings_opening = false;
660 this.settings_window = opened.ok().map(|(handle, _)| handle);
661 });
662 });
659 }
663 }
660
664
661 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
665 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
@@ -690,14 +694,55 @@ impl NotificationCenter {
690}
694}
691
695
692fn border_color(mention: bool) -> u32 {
696fn border_color(mention: bool) -> u32 {
693 if mention { MENTION_BORDER } else { FALLBACK_BORDER }
697 if mention {
698 MENTION_BORDER
699 } else {
700 FALLBACK_BORDER
701 }
702}
703
704/// Opens a window outside the current update: `open_window` draws right away, and every
705/// notification view reads the center while rendering.
706fn open_popup<V: Render>(
707 options: WindowOptions,
708 cx: &mut Context<NotificationCenter>,
709 build: impl FnOnce(Entity<NotificationCenter>, &mut Window, &mut App) -> Entity<V> + 'static,
710 opened: impl FnOnce(&mut NotificationCenter, Option<OpenWindow>) + 'static,
711) {
712 let center = cx.entity();
713 cx.defer(move |cx| {
714 let view_center = center.clone();
715 let Ok((handle, _)) = gpui_kit::open_window(options, cx, move |window, cx| {
716 build(view_center, window, cx)
717 }) else {
718 center.update(cx, |this, _| opened(this, None));
719 return;
720 };
721 let native = handle
722 .update(cx, |_, window, _| platform::native_handle(window))
723 .ok()
724 .flatten();
725 if let Some(native) = native {
726 platform::prepare_toast_window(native);
727 }
728 let window = OpenWindow {
729 handle,
730 native,
731 opened: Instant::now(),
732 mention: false,
733 };
734 center.update(cx, |this, _| opened(this, Some(window)));
735 });
694}
736}
695
737
696fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
738fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
697 let scale = area.scale;
739 let scale = area.scale;
698 let bounds = Bounds::new(
740 let bounds = Bounds::new(
699 point(px(slot.x as f32 / scale), px(slot.y as f32 / scale)),
741 point(px(slot.x as f32 / scale), px(slot.y as f32 / scale)),
700 size(px(slot.width as f32 / scale), px(slot.height as f32 / scale)),
742 size(
743 px(slot.width as f32 / scale),
744 px(slot.height as f32 / scale),
745 ),
701 );
746 );
702 WindowOptions {
747 WindowOptions {
703 window_bounds: Some(WindowBounds::Windowed(bounds)),
748 window_bounds: Some(WindowBounds::Windowed(bounds)),
@@ -740,7 +785,12 @@ pub fn unread_summary(sidebar: &Sidebar) -> (usize, HashSet<String>) {
740}
785}
741
786
742fn demo_incoming() -> Vec<Incoming> {
787fn demo_incoming() -> Vec<Incoming> {
743 let item = |conversation: &str, kind: ChatKind, title: &str, sender: &str, text: &str, mention: bool| Incoming {
788 let item = |conversation: &str,
789 kind: ChatKind,
790 title: &str,
791 sender: &str,
792 text: &str,
793 mention: bool| Incoming {
744 conversation_id: conversation.to_owned(),
794 conversation_id: conversation.to_owned(),
745 message_id: format!("{conversation}-message"),
795 message_id: format!("{conversation}-message"),
746 kind,
796 kind,
@@ -832,8 +882,14 @@ mod tests {
832
882
833 #[test]
883 #[test]
834 fn selection_kind_follows_sidebar() {
884 fn selection_kind_follows_sidebar() {
835 assert_eq!(selection_for(&sidebar(), "a"), Some(Selection::Chat("a".into())));
885 assert_eq!(
836 assert_eq!(selection_for(&sidebar(), "ch"), Some(Selection::Channel("ch".into())));
886 selection_for(&sidebar(), "a"),
887 Some(Selection::Chat("a".into()))
888 );
889 assert_eq!(
890 selection_for(&sidebar(), "ch"),
891 Some(Selection::Channel("ch".into()))
892 );
837 assert_eq!(selection_for(&sidebar(), "x"), None);
893 assert_eq!(selection_for(&sidebar(), "x"), None);
838 }
894 }
839}
895}
crates/app/src/notify/toast.rs +1 −1
@@ -208,7 +208,7 @@ impl ToastView {
208 208 .sender_id
209 209 .as_deref()
210 210 .map(|user_id| directory.presence_of(user_id))
211 .unwrap_or(crate::data::PresenceKind::Unknown);
211 .unwrap_or(crate::data::Presence::Live(crate::data::PresenceKind::Unknown));
212 212 let face = spec_avatar(directory, &AvatarSpec::Single(sender), AVATAR_SIZE, fill);
213 213 with_presence(face, presence, AVATAR_SIZE, fill).into_any_element()
214 214 }
@@ -208,7 +208,7 @@ impl ToastView {
208 .sender_id
208 .sender_id
209 .as_deref()
209 .as_deref()
210 .map(|user_id| directory.presence_of(user_id))
210 .map(|user_id| directory.presence_of(user_id))
211 .unwrap_or(crate::data::PresenceKind::Unknown);
211 .unwrap_or(crate::data::Presence::Live(crate::data::PresenceKind::Unknown));
212 let face = spec_avatar(directory, &AvatarSpec::Single(sender), AVATAR_SIZE, fill);
212 let face = spec_avatar(directory, &AvatarSpec::Single(sender), AVATAR_SIZE, fill);
213 with_presence(face, presence, AVATAR_SIZE, fill).into_any_element()
213 with_presence(face, presence, AVATAR_SIZE, fill).into_any_element()
214 }
214 }
crates/app/src/render/elements.rs +8 −23
@@ -2,6 +2,7 @@ use gpui_kit::component::{h_flex, v_flex};
2 2 use gpui_kit::*;
3 3
4 4 use super::blocks::{Block, Inline, StyleFlags};
5 use super::selectable::SelectableRichText;
5 6 use crate::theme;
6 7
7 8 pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {
@@ -32,7 +33,11 @@ fn render_block(block: &Block, id: String, own: bool, cx: &App) -> AnyElement {
32 33 .font_family(code_font(cx))
33 34 .text_size(px(12.5))
34 35 .line_height(relative(1.5))
35 .child(code.clone())
36 .child(SelectableRichText::new(
37 ElementId::Name(id.into()),
38 code.clone(),
39 Vec::new(),
40 ))
36 41 .into_any_element(),
37 42 Block::Quote(children) => div()
38 43 .w_full()
@@ -71,32 +76,12 @@ fn render_inline(inline: &Inline, id: String, own: bool) -> AnyElement {
71 76 .filter(|segment| !segment.style.is_plain())
72 77 .map(|segment| (segment.range.clone(), highlight_for(segment.style, own)))
73 78 .collect::<Vec<_>>();
74 let styled = StyledText::new(inline.text.clone()).with_highlights(highlights);
75 let links = inline.links();
76 if links.is_empty() {
77 return div()
78 .w_full()
79 .text_color(theme::text())
80 .child(styled)
81 .into_any_element();
82 }
83 let ranges = links
84 .iter()
85 .map(|(range, _)| range.clone())
86 .collect::<Vec<_>>();
87 let urls = links.into_iter().map(|(_, url)| url).collect::<Vec<_>>();
88 79 div()
89 80 .w_full()
90 81 .text_color(theme::text())
91 82 .child(
92 InteractiveText::new(ElementId::Name(id.into()), styled).on_click(
93 ranges,
94 move |range_index, _, cx| {
95 if let Some(url) = urls.get(range_index) {
96 cx.open_url(url);
97 }
98 },
99 ),
83 SelectableRichText::new(ElementId::Name(id.into()), inline.text.clone(), highlights)
84 .links(inline.links()),
100 85 )
101 86 .into_any_element()
102 87 }
@@ -2,6 +2,7 @@ use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
2use gpui_kit::*;
3
3
4use super::blocks::{Block, Inline, StyleFlags};
4use super::blocks::{Block, Inline, StyleFlags};
5use super::selectable::SelectableRichText;
5use crate::theme;
6use crate::theme;
6
7
7pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {
8pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {
@@ -32,7 +33,11 @@ fn render_block(block: &Block, id: String, own: bool, cx: &App) -> AnyElement {
32 .font_family(code_font(cx))
33 .font_family(code_font(cx))
33 .text_size(px(12.5))
34 .text_size(px(12.5))
34 .line_height(relative(1.5))
35 .line_height(relative(1.5))
35 .child(code.clone())
36 .child(SelectableRichText::new(
37 ElementId::Name(id.into()),
38 code.clone(),
39 Vec::new(),
40 ))
36 .into_any_element(),
41 .into_any_element(),
37 Block::Quote(children) => div()
42 Block::Quote(children) => div()
38 .w_full()
43 .w_full()
@@ -71,32 +76,12 @@ fn render_inline(inline: &Inline, id: String, own: bool) -> AnyElement {
71 .filter(|segment| !segment.style.is_plain())
76 .filter(|segment| !segment.style.is_plain())
72 .map(|segment| (segment.range.clone(), highlight_for(segment.style, own)))
77 .map(|segment| (segment.range.clone(), highlight_for(segment.style, own)))
73 .collect::<Vec<_>>();
78 .collect::<Vec<_>>();
74 let styled = StyledText::new(inline.text.clone()).with_highlights(highlights);
75 let links = inline.links();
76 if links.is_empty() {
77 return div()
78 .w_full()
79 .text_color(theme::text())
80 .child(styled)
81 .into_any_element();
82 }
83 let ranges = links
84 .iter()
85 .map(|(range, _)| range.clone())
86 .collect::<Vec<_>>();
87 let urls = links.into_iter().map(|(_, url)| url).collect::<Vec<_>>();
88 div()
79 div()
89 .w_full()
80 .w_full()
90 .text_color(theme::text())
81 .text_color(theme::text())
91 .child(
82 .child(
92 InteractiveText::new(ElementId::Name(id.into()), styled).on_click(
83 SelectableRichText::new(ElementId::Name(id.into()), inline.text.clone(), highlights)
93 ranges,
84 .links(inline.links()),
94 move |range_index, _, cx| {
95 if let Some(url) = urls.get(range_index) {
96 cx.open_url(url);
97 }
98 },
99 ),
100 )
85 )
101 .into_any_element()
86 .into_any_element()
102}
87}
crates/app/src/render/mod.rs +1 −0
@@ -1,5 +1,6 @@
1 1 pub mod blocks;
2 2 pub mod elements;
3 mod selectable;
3 4
4 5 pub use blocks::{Block, layout_blocks};
5 6 pub use elements::render_blocks;
@@ -1,5 +1,6 @@
1pub mod blocks;
1pub mod blocks;
2pub mod elements;
2pub mod elements;
3mod selectable;
3
4
4pub use blocks::{Block, layout_blocks};
5pub use blocks::{Block, layout_blocks};
5pub use elements::render_blocks;
6pub use elements::render_blocks;
crates/app/src/render/selectable.rs added +289 −0
@@ -0,0 +1,289 @@
1 use std::ops::Range;
2
3 use gpui_kit::base::{
4 TextSelection, TextSelectionHandle, TextSelectionRegistration, TextSelectionRun, Theme,
5 };
6 use gpui_kit::*;
7
8 /// Styled text that takes part in the window text selection, with clickable link ranges.
9 pub struct SelectableRichText {
10 id: ElementId,
11 text: SharedString,
12 styled_text: StyledText,
13 links: Vec<(Range<usize>, String)>,
14 }
15
16 impl SelectableRichText {
17 pub fn new(
18 id: impl Into<ElementId>,
19 text: impl Into<SharedString>,
20 highlights: Vec<(Range<usize>, HighlightStyle)>,
21 ) -> Self {
22 let text = text.into();
23 SelectableRichText {
24 id: id.into(),
25 styled_text: StyledText::new(text.clone()).with_highlights(highlights),
26 text,
27 links: Vec::new(),
28 }
29 }
30
31 pub fn links(mut self, links: Vec<(Range<usize>, String)>) -> Self {
32 self.links = links;
33 self
34 }
35 }
36
37 fn link_at(
38 layout: &TextLayout,
39 links: &[(Range<usize>, String)],
40 position: Point<Pixels>,
41 ) -> Option<String> {
42 let index = layout.index_for_position(position).ok()?;
43 links
44 .iter()
45 .find(|(range, _)| range.contains(&index))
46 .map(|(_, url)| url.clone())
47 }
48
49 fn selection_quads(
50 start: Point<Pixels>,
51 end: Point<Pixels>,
52 bounds: Bounds<Pixels>,
53 line_height: Pixels,
54 ) -> Vec<Bounds<Pixels>> {
55 if start.y == end.y {
56 return vec![Bounds::from_corners(
57 start,
58 point(end.x, end.y + line_height),
59 )];
60 }
61 let mut quads = vec![Bounds::from_corners(
62 start,
63 point(bounds.right(), start.y + line_height),
64 )];
65 if end.y > start.y + line_height {
66 quads.push(Bounds::from_corners(
67 point(bounds.left(), start.y + line_height),
68 point(bounds.right(), end.y),
69 ));
70 }
71 quads.push(Bounds::from_corners(
72 point(bounds.left(), end.y),
73 point(end.x, end.y + line_height),
74 ));
75 quads
76 }
77
78 impl IntoElement for SelectableRichText {
79 type Element = Self;
80
81 fn into_element(self) -> Self::Element {
82 self
83 }
84 }
85
86 impl Element for SelectableRichText {
87 type RequestLayoutState = TextSelectionHandle;
88 type PrepaintState = Hitbox;
89
90 fn id(&self) -> Option<ElementId> {
91 Some(self.id.clone())
92 }
93
94 fn source_location(&self) -> Option<&'static std::panic::Location<'static>> {
95 None
96 }
97
98 fn request_layout(
99 &mut self,
100 global_id: Option<&GlobalElementId>,
101 inspector_id: Option<&InspectorElementId>,
102 window: &mut Window,
103 cx: &mut App,
104 ) -> (LayoutId, Self::RequestLayoutState) {
105 let handle = window.with_element_state(
106 global_id.expect("SelectableRichText has an element id"),
107 |retained: Option<TextSelectionHandle>, _| {
108 let handle =
109 retained.unwrap_or_else(|| TextSelectionHandle::new(self.text.clone(), cx));
110 (handle.clone(), handle)
111 },
112 );
113 let (layout_id, ()) = self
114 .styled_text
115 .request_layout(global_id, inspector_id, window, cx);
116 (layout_id, handle)
117 }
118
119 fn prepaint(
120 &mut self,
121 global_id: Option<&GlobalElementId>,
122 inspector_id: Option<&InspectorElementId>,
123 bounds: Bounds<Pixels>,
124 handle: &mut Self::RequestLayoutState,
125 window: &mut Window,
126 cx: &mut App,
127 ) -> Self::PrepaintState {
128 self.styled_text
129 .prepaint(global_id, inspector_id, bounds, &mut (), window, cx);
130 let hitbox = window.insert_hitbox(bounds, HitboxBehavior::Normal);
131 let registration = TextSelectionRegistration::new(hitbox.clone(), bounds)
132 .with_text_bounds(vec![bounds])
133 .with_rendered_element(handle, window, cx);
134 handle.register(registration, window, cx);
135 hitbox
136 }
137
138 fn paint(
139 &mut self,
140 global_id: Option<&GlobalElementId>,
141 inspector_id: Option<&InspectorElementId>,
142 bounds: Bounds<Pixels>,
143 handle: &mut Self::RequestLayoutState,
144 hitbox: &mut Self::PrepaintState,
145 window: &mut Window,
146 cx: &mut App,
147 ) {
148 let layout = self.styled_text.layout().clone();
149 let selected_before = TextSelection::selected_text(window, cx);
150 let projection = handle.update_runs(
151 &[TextSelectionRun::new(
152 self.text.clone(),
153 layout.clone(),
154 bounds,
155 )],
156 cx,
157 );
158 if selected_before != TextSelection::selected_text(window, cx) {
159 window.refresh();
160 }
161 let color = Theme::global(cx).tokens.colors.selection;
162 for range in projection.ranges().iter().flatten() {
163 let (Some(start), Some(end)) = (
164 layout.position_for_index(range.start),
165 layout.position_for_index(range.end),
166 ) else {
167 continue;
168 };
169 for quad in selection_quads(start, end, layout.bounds(), layout.line_height()) {
170 window.paint_quad(fill(quad, color));
171 }
172 }
173 self.styled_text.paint(
174 global_id,
175 inspector_id,
176 bounds,
177 &mut (),
178 &mut (),
179 window,
180 cx,
181 );
182
183 let hovered_link = hitbox.is_hovered(window)
184 && link_at(&layout, &self.links, window.mouse_position()).is_some();
185 let cursor = if hovered_link {
186 CursorStyle::PointingHand
187 } else {
188 CursorStyle::IBeam
189 };
190 window.set_cursor_style(cursor, hitbox);
191 if self.links.is_empty() {
192 return;
193 }
194 let links = std::mem::take(&mut self.links);
195 let hitbox = hitbox.clone();
196 window.on_mouse_event(move |event: &MouseUpEvent, phase, window, cx| {
197 if !phase.bubble() || event.button != MouseButton::Left || !hitbox.is_hovered(window) {
198 return;
199 }
200 if !TextSelection::selected_text(window, cx).is_empty() {
201 return;
202 }
203 if let Some(url) = link_at(&layout, &links, event.position) {
204 cx.open_url(&url);
205 }
206 });
207 }
208 }
209
210 #[cfg(test)]
211 mod tests {
212 use gpui_kit::base::TextSelection;
213 use gpui_kit::test::TestWindowExt as _;
214 use gpui_kit::{
215 AnyWindowHandle, AppContext as _, Bounds, Context, FontWeight, HighlightStyle, IntoElement,
216 ParentElement as _, Point, Render, Styled as _, TestAppContext, Window, WindowBounds,
217 WindowOptions, div, point, px, size,
218 };
219
220 use super::SelectableRichText;
221
222 const TEXT: &str = "plain bold link";
223
224 struct Message;
225
226 impl Render for Message {
227 fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
228 let bold = HighlightStyle {
229 font_weight: Some(FontWeight::BOLD),
230 ..Default::default()
231 };
232 div().w(px(400.)).child(
233 SelectableRichText::new("message", TEXT, vec![(6..10, bold)])
234 .links(vec![(11..15, "https://example.com".to_owned())]),
235 )
236 }
237 }
238
239 fn mount(cx: &mut TestAppContext) -> AnyWindowHandle {
240 cx.update(gpui_kit::init);
241 cx.update(|cx| {
242 let options = WindowOptions {
243 window_bounds: Some(WindowBounds::Windowed(Bounds {
244 origin: Point::default(),
245 size: size(px(400.), px(100.)),
246 })),
247 ..Default::default()
248 };
249 gpui_kit::open_window(options, cx, |_, cx| cx.new(|_| Message))
250 .expect("open test window")
251 .0
252 })
253 }
254
255 #[gpui_kit::test]
256 fn drag_selects_styled_text_for_copy(cx: &mut TestAppContext) {
257 let handle = mount(cx);
258 let selected = cx
259 .update_window(handle, |_, window, cx| {
260 window.render_frame(cx);
261 window.drag(point(px(1.), px(8.)), point(px(399.), px(8.)), cx);
262 window.render_frame(cx);
263 TextSelection::selected_text(window, cx)
264 })
265 .unwrap();
266 assert_eq!(selected, TEXT);
267 assert_eq!(cx.opened_url(), None);
268 }
269
270 #[gpui_kit::test]
271 fn click_on_a_link_opens_it_but_plain_text_does_not(cx: &mut TestAppContext) {
272 let handle = mount(cx);
273 let click = |x: f32, cx: &mut TestAppContext| {
274 cx.update_window(handle, |_, window, cx| {
275 window.render_frame(cx);
276 window.drag(point(px(x), px(8.)), point(px(x), px(8.)), cx);
277 })
278 .unwrap();
279 };
280 click(2., cx);
281 assert_eq!(cx.opened_url(), None);
282 let link_x = (40..400).map(|x| x as f32).find(|x| {
283 click(*x, cx);
284 cx.opened_url().is_some()
285 });
286 assert!(link_x.is_some());
287 assert_eq!(cx.opened_url().as_deref(), Some("https://example.com"));
288 }
289 }
@@ -0,0 +1,289 @@
1use std::ops::Range;
2
3use gpui_kit::base::{
4 TextSelection, TextSelectionHandle, TextSelectionRegistration, TextSelectionRun, Theme,
5};
6use gpui_kit::*;
7
8/// Styled text that takes part in the window text selection, with clickable link ranges.
9pub struct SelectableRichText {
10 id: ElementId,
11 text: SharedString,
12 styled_text: StyledText,
13 links: Vec<(Range<usize>, String)>,
14}
15
16impl SelectableRichText {
17 pub fn new(
18 id: impl Into<ElementId>,
19 text: impl Into<SharedString>,
20 highlights: Vec<(Range<usize>, HighlightStyle)>,
21 ) -> Self {
22 let text = text.into();
23 SelectableRichText {
24 id: id.into(),
25 styled_text: StyledText::new(text.clone()).with_highlights(highlights),
26 text,
27 links: Vec::new(),
28 }
29 }
30
31 pub fn links(mut self, links: Vec<(Range<usize>, String)>) -> Self {
32 self.links = links;
33 self
34 }
35}
36
37fn link_at(
38 layout: &TextLayout,
39 links: &[(Range<usize>, String)],
40 position: Point<Pixels>,
41) -> Option<String> {
42 let index = layout.index_for_position(position).ok()?;
43 links
44 .iter()
45 .find(|(range, _)| range.contains(&index))
46 .map(|(_, url)| url.clone())
47}
48
49fn selection_quads(
50 start: Point<Pixels>,
51 end: Point<Pixels>,
52 bounds: Bounds<Pixels>,
53 line_height: Pixels,
54) -> Vec<Bounds<Pixels>> {
55 if start.y == end.y {
56 return vec![Bounds::from_corners(
57 start,
58 point(end.x, end.y + line_height),
59 )];
60 }
61 let mut quads = vec![Bounds::from_corners(
62 start,
63 point(bounds.right(), start.y + line_height),
64 )];
65 if end.y > start.y + line_height {
66 quads.push(Bounds::from_corners(
67 point(bounds.left(), start.y + line_height),
68 point(bounds.right(), end.y),
69 ));
70 }
71 quads.push(Bounds::from_corners(
72 point(bounds.left(), end.y),
73 point(end.x, end.y + line_height),
74 ));
75 quads
76}
77
78impl IntoElement for SelectableRichText {
79 type Element = Self;
80
81 fn into_element(self) -> Self::Element {
82 self
83 }
84}
85
86impl Element for SelectableRichText {
87 type RequestLayoutState = TextSelectionHandle;
88 type PrepaintState = Hitbox;
89
90 fn id(&self) -> Option<ElementId> {
91 Some(self.id.clone())
92 }
93
94 fn source_location(&self) -> Option<&'static std::panic::Location<'static>> {
95 None
96 }
97
98 fn request_layout(
99 &mut self,
100 global_id: Option<&GlobalElementId>,
101 inspector_id: Option<&InspectorElementId>,
102 window: &mut Window,
103 cx: &mut App,
104 ) -> (LayoutId, Self::RequestLayoutState) {
105 let handle = window.with_element_state(
106 global_id.expect("SelectableRichText has an element id"),
107 |retained: Option<TextSelectionHandle>, _| {
108 let handle =
109 retained.unwrap_or_else(|| TextSelectionHandle::new(self.text.clone(), cx));
110 (handle.clone(), handle)
111 },
112 );
113 let (layout_id, ()) = self
114 .styled_text
115 .request_layout(global_id, inspector_id, window, cx);
116 (layout_id, handle)
117 }
118
119 fn prepaint(
120 &mut self,
121 global_id: Option<&GlobalElementId>,
122 inspector_id: Option<&InspectorElementId>,
123 bounds: Bounds<Pixels>,
124 handle: &mut Self::RequestLayoutState,
125 window: &mut Window,
126 cx: &mut App,
127 ) -> Self::PrepaintState {
128 self.styled_text
129 .prepaint(global_id, inspector_id, bounds, &mut (), window, cx);
130 let hitbox = window.insert_hitbox(bounds, HitboxBehavior::Normal);
131 let registration = TextSelectionRegistration::new(hitbox.clone(), bounds)
132 .with_text_bounds(vec![bounds])
133 .with_rendered_element(handle, window, cx);
134 handle.register(registration, window, cx);
135 hitbox
136 }
137
138 fn paint(
139 &mut self,
140 global_id: Option<&GlobalElementId>,
141 inspector_id: Option<&InspectorElementId>,
142 bounds: Bounds<Pixels>,
143 handle: &mut Self::RequestLayoutState,
144 hitbox: &mut Self::PrepaintState,
145 window: &mut Window,
146 cx: &mut App,
147 ) {
148 let layout = self.styled_text.layout().clone();
149 let selected_before = TextSelection::selected_text(window, cx);
150 let projection = handle.update_runs(
151 &[TextSelectionRun::new(
152 self.text.clone(),
153 layout.clone(),
154 bounds,
155 )],
156 cx,
157 );
158 if selected_before != TextSelection::selected_text(window, cx) {
159 window.refresh();
160 }
161 let color = Theme::global(cx).tokens.colors.selection;
162 for range in projection.ranges().iter().flatten() {
163 let (Some(start), Some(end)) = (
164 layout.position_for_index(range.start),
165 layout.position_for_index(range.end),
166 ) else {
167 continue;
168 };
169 for quad in selection_quads(start, end, layout.bounds(), layout.line_height()) {
170 window.paint_quad(fill(quad, color));
171 }
172 }
173 self.styled_text.paint(
174 global_id,
175 inspector_id,
176 bounds,
177 &mut (),
178 &mut (),
179 window,
180 cx,
181 );
182
183 let hovered_link = hitbox.is_hovered(window)
184 && link_at(&layout, &self.links, window.mouse_position()).is_some();
185 let cursor = if hovered_link {
186 CursorStyle::PointingHand
187 } else {
188 CursorStyle::IBeam
189 };
190 window.set_cursor_style(cursor, hitbox);
191 if self.links.is_empty() {
192 return;
193 }
194 let links = std::mem::take(&mut self.links);
195 let hitbox = hitbox.clone();
196 window.on_mouse_event(move |event: &MouseUpEvent, phase, window, cx| {
197 if !phase.bubble() || event.button != MouseButton::Left || !hitbox.is_hovered(window) {
198 return;
199 }
200 if !TextSelection::selected_text(window, cx).is_empty() {
201 return;
202 }
203 if let Some(url) = link_at(&layout, &links, event.position) {
204 cx.open_url(&url);
205 }
206 });
207 }
208}
209
210#[cfg(test)]
211mod tests {
212 use gpui_kit::base::TextSelection;
213 use gpui_kit::test::TestWindowExt as _;
214 use gpui_kit::{
215 AnyWindowHandle, AppContext as _, Bounds, Context, FontWeight, HighlightStyle, IntoElement,
216 ParentElement as _, Point, Render, Styled as _, TestAppContext, Window, WindowBounds,
217 WindowOptions, div, point, px, size,
218 };
219
220 use super::SelectableRichText;
221
222 const TEXT: &str = "plain bold link";
223
224 struct Message;
225
226 impl Render for Message {
227 fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
228 let bold = HighlightStyle {
229 font_weight: Some(FontWeight::BOLD),
230 ..Default::default()
231 };
232 div().w(px(400.)).child(
233 SelectableRichText::new("message", TEXT, vec![(6..10, bold)])
234 .links(vec![(11..15, "https://example.com".to_owned())]),
235 )
236 }
237 }
238
239 fn mount(cx: &mut TestAppContext) -> AnyWindowHandle {
240 cx.update(gpui_kit::init);
241 cx.update(|cx| {
242 let options = WindowOptions {
243 window_bounds: Some(WindowBounds::Windowed(Bounds {
244 origin: Point::default(),
245 size: size(px(400.), px(100.)),
246 })),
247 ..Default::default()
248 };
249 gpui_kit::open_window(options, cx, |_, cx| cx.new(|_| Message))
250 .expect("open test window")
251 .0
252 })
253 }
254
255 #[gpui_kit::test]
256 fn drag_selects_styled_text_for_copy(cx: &mut TestAppContext) {
257 let handle = mount(cx);
258 let selected = cx
259 .update_window(handle, |_, window, cx| {
260 window.render_frame(cx);
261 window.drag(point(px(1.), px(8.)), point(px(399.), px(8.)), cx);
262 window.render_frame(cx);
263 TextSelection::selected_text(window, cx)
264 })
265 .unwrap();
266 assert_eq!(selected, TEXT);
267 assert_eq!(cx.opened_url(), None);
268 }
269
270 #[gpui_kit::test]
271 fn click_on_a_link_opens_it_but_plain_text_does_not(cx: &mut TestAppContext) {
272 let handle = mount(cx);
273 let click = |x: f32, cx: &mut TestAppContext| {
274 cx.update_window(handle, |_, window, cx| {
275 window.render_frame(cx);
276 window.drag(point(px(x), px(8.)), point(px(x), px(8.)), cx);
277 })
278 .unwrap();
279 };
280 click(2., cx);
281 assert_eq!(cx.opened_url(), None);
282 let link_x = (40..400).map(|x| x as f32).find(|x| {
283 click(*x, cx);
284 cx.opened_url().is_some()
285 });
286 assert!(link_x.is_some());
287 assert_eq!(cx.opened_url().as_deref(), Some("https://example.com"));
288 }
289}
crates/app/src/views/avatar.rs +37 −6
@@ -1,16 +1,23 @@
1 1 use gpui_kit::prelude::FluentBuilder as _;
2 2 use gpui_kit::*;
3 3
4 use crate::data::{AvatarState, Directory, PresenceKind};
4 use std::time::Duration;
5
6 use gpui_kit::assets::IconName;
7
8 use crate::data::{AvatarState, Directory, Presence, PresenceKind};
5 9 use crate::format;
6 10 use crate::sidebar_model::{AvatarSpec, Face};
7 11 use crate::theme;
12 use crate::views::widgets::icon;
8 13
9 14 const PAIR_RATIO: f32 = 24. / 36.;
10 15 const PRESENCE_MIN: f32 = 10.;
11 16 const PRESENCE_MAX: f32 = 14.;
12 17 const PRESENCE_RATIO: f32 = 0.38;
13 18 const PRESENCE_RING: f32 = 2.;
19 const PRESENCE_SPIN_PERIOD: Duration = Duration::from_millis(1600);
20 const CACHED_PRESENCE_OPACITY: f32 = 0.5;
14 21 const INITIALS_RATIO: f32 = 0.36;
15 22 const PAIR_INITIALS_RATIO: f32 = 0.42;
16 23
@@ -125,12 +132,36 @@ pub fn presence_dot(kind: PresenceKind, ring: Hsla, avatar_size: f32) -> Option<
125 132 )
126 133 }
127 134
128 pub fn with_presence(avatar: AnyElement, kind: PresenceKind, size: f32, ring: Hsla) -> Div {
129 let mut wrapper = div().relative().size(px(size)).flex_none().child(avatar);
130 if let Some(dot) = presence_dot(kind, ring, size) {
131 wrapper = wrapper.child(dot);
135 fn presence_spinner(ring: Hsla, avatar_size: f32) -> Div {
136 let outer = presence_size(avatar_size);
137 let spinner = icon(IconName::Loader, outer - PRESENCE_RING, theme::text_muted())
138 .with_animation(
139 "presence-spinner",
140 Animation::new(PRESENCE_SPIN_PERIOD).repeat(),
141 |icon, delta| icon.transform(Transformation::rotate(percentage(delta))),
142 );
143 div()
144 .absolute()
145 .right(px(-2.))
146 .bottom(px(-2.))
147 .size(px(outer))
148 .rounded_full()
149 .bg(ring)
150 .flex()
151 .items_center()
152 .justify_center()
153 .child(spinner)
154 }
155
156 pub fn with_presence(avatar: AnyElement, presence: Presence, size: f32, ring: Hsla) -> Div {
157 let wrapper = div().relative().size(px(size)).flex_none().child(avatar);
158 match presence {
159 Presence::Loading => wrapper.child(presence_spinner(ring, size)),
160 Presence::Live(kind) => wrapper.children(presence_dot(kind, ring, size)),
161 Presence::Cached(kind) => wrapper.children(
162 presence_dot(kind, ring, size).map(|dot| dot.opacity(CACHED_PRESENCE_OPACITY)),
163 ),
132 164 }
133 wrapper
134 165 }
135 166
136 167 pub fn spec_avatar(directory: &Directory, spec: &AvatarSpec, size: f32, ring: Hsla) -> AnyElement {
@@ -1,16 +1,23 @@
1use gpui_kit::prelude::FluentBuilder as _;
1use gpui_kit::prelude::FluentBuilder as _;
2use gpui_kit::*;
2use gpui_kit::*;
3
3
4use crate::data::{AvatarState, Directory, PresenceKind};
4use std::time::Duration;
5
6use gpui_kit::assets::IconName;
7
8use crate::data::{AvatarState, Directory, Presence, PresenceKind};
5use crate::format;
9use crate::format;
6use crate::sidebar_model::{AvatarSpec, Face};
10use crate::sidebar_model::{AvatarSpec, Face};
7use crate::theme;
11use crate::theme;
12use crate::views::widgets::icon;
8
13
9const PAIR_RATIO: f32 = 24. / 36.;
14const PAIR_RATIO: f32 = 24. / 36.;
10const PRESENCE_MIN: f32 = 10.;
15const PRESENCE_MIN: f32 = 10.;
11const PRESENCE_MAX: f32 = 14.;
16const PRESENCE_MAX: f32 = 14.;
12const PRESENCE_RATIO: f32 = 0.38;
17const PRESENCE_RATIO: f32 = 0.38;
13const PRESENCE_RING: f32 = 2.;
18const PRESENCE_RING: f32 = 2.;
19const PRESENCE_SPIN_PERIOD: Duration = Duration::from_millis(1600);
20const CACHED_PRESENCE_OPACITY: f32 = 0.5;
14const INITIALS_RATIO: f32 = 0.36;
21const INITIALS_RATIO: f32 = 0.36;
15const PAIR_INITIALS_RATIO: f32 = 0.42;
22const PAIR_INITIALS_RATIO: f32 = 0.42;
16
23
@@ -125,12 +132,36 @@ pub fn presence_dot(kind: PresenceKind, ring: Hsla, avatar_size: f32) -> Option<
125 )
132 )
126}
133}
127
134
128pub fn with_presence(avatar: AnyElement, kind: PresenceKind, size: f32, ring: Hsla) -> Div {
135fn presence_spinner(ring: Hsla, avatar_size: f32) -> Div {
129 let mut wrapper = div().relative().size(px(size)).flex_none().child(avatar);
136 let outer = presence_size(avatar_size);
130 if let Some(dot) = presence_dot(kind, ring, size) {
137 let spinner = icon(IconName::Loader, outer - PRESENCE_RING, theme::text_muted())
131 wrapper = wrapper.child(dot);
138 .with_animation(
139 "presence-spinner",
140 Animation::new(PRESENCE_SPIN_PERIOD).repeat(),
141 |icon, delta| icon.transform(Transformation::rotate(percentage(delta))),
142 );
143 div()
144 .absolute()
145 .right(px(-2.))
146 .bottom(px(-2.))
147 .size(px(outer))
148 .rounded_full()
149 .bg(ring)
150 .flex()
151 .items_center()
152 .justify_center()
153 .child(spinner)
154}
155
156pub fn with_presence(avatar: AnyElement, presence: Presence, size: f32, ring: Hsla) -> Div {
157 let wrapper = div().relative().size(px(size)).flex_none().child(avatar);
158 match presence {
159 Presence::Loading => wrapper.child(presence_spinner(ring, size)),
160 Presence::Live(kind) => wrapper.children(presence_dot(kind, ring, size)),
161 Presence::Cached(kind) => wrapper.children(
162 presence_dot(kind, ring, size).map(|dot| dot.opacity(CACHED_PRESENCE_OPACITY)),
163 ),
132 }
164 }
133 wrapper
134}
165}
135
166
136pub fn spec_avatar(directory: &Directory, spec: &AvatarSpec, size: f32, ring: Hsla) -> AnyElement {
167pub fn spec_avatar(directory: &Directory, spec: &AvatarSpec, size: f32, ring: Hsla) -> AnyElement {
crates/app/src/views/composer.rs +42 −0
@@ -892,4 +892,46 @@ mod tests {
892 892 Some((16..19, "Pr".into()))
893 893 );
894 894 }
895
896 mod keys {
897 use std::sync::Arc;
898
899 use gpui_kit::test::TestWindowExt as _;
900 use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
901 use store::Store;
902
903 use super::super::Composer;
904 use crate::app_state::{AppState, Mode};
905
906 #[gpui_kit::test]
907 fn ctrl_a_selects_the_whole_draft(cx: &mut TestAppContext) {
908 cx.update(gpui_kit::init);
909 let store = Arc::new(Store::open_in_memory().unwrap());
910 let mode = Mode {
911 demo: true,
912 read_only: false,
913 demo_sync: None,
914 };
915 let (handle, composer) = cx.update(|cx| {
916 let app = cx.new(|_| AppState::new(store, mode));
917 gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
918 cx.new(|cx| Composer::new(app, window, cx))
919 })
920 .unwrap()
921 });
922 let value = cx
923 .update_window(handle, |_, window, cx| {
924 composer.update(cx, |composer, cx| composer.focus(window, cx));
925 window.render_frame(cx);
926 window.input("first line", cx);
927 window.press("shift-enter", cx);
928 window.input("second line", cx);
929 window.press("ctrl-a", cx);
930 window.input("X", cx);
931 composer.read(cx).input.read(cx).value()
932 })
933 .unwrap();
934 assert_eq!(value, "X");
935 }
936 }
895 937 }
@@ -892,4 +892,46 @@ mod tests {
892 Some((16..19, "Pr".into()))
892 Some((16..19, "Pr".into()))
893 );
893 );
894 }
894 }
895
896 mod keys {
897 use std::sync::Arc;
898
899 use gpui_kit::test::TestWindowExt as _;
900 use gpui_kit::{AppContext as _, TestAppContext, WindowOptions};
901 use store::Store;
902
903 use super::super::Composer;
904 use crate::app_state::{AppState, Mode};
905
906 #[gpui_kit::test]
907 fn ctrl_a_selects_the_whole_draft(cx: &mut TestAppContext) {
908 cx.update(gpui_kit::init);
909 let store = Arc::new(Store::open_in_memory().unwrap());
910 let mode = Mode {
911 demo: true,
912 read_only: false,
913 demo_sync: None,
914 };
915 let (handle, composer) = cx.update(|cx| {
916 let app = cx.new(|_| AppState::new(store, mode));
917 gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
918 cx.new(|cx| Composer::new(app, window, cx))
919 })
920 .unwrap()
921 });
922 let value = cx
923 .update_window(handle, |_, window, cx| {
924 composer.update(cx, |composer, cx| composer.focus(window, cx));
925 window.render_frame(cx);
926 window.input("first line", cx);
927 window.press("shift-enter", cx);
928 window.input("second line", cx);
929 window.press("ctrl-a", cx);
930 window.input("X", cx);
931 composer.read(cx).input.read(cx).value()
932 })
933 .unwrap();
934 assert_eq!(value, "X");
935 }
936 }
895}
937}
crates/app/src/views/conversation.rs +1 −1
@@ -1156,7 +1156,7 @@ impl ConversationView {
1156 1156 None => avatar,
1157 1157 });
1158 1158 subline = presence
1159 .map(|kind| kind.label().to_owned())
1159 .map(|presence| presence.kind().label().to_owned())
1160 1160 .unwrap_or_default();
1161 1161 } else {
1162 1162 let pair = AvatarSpec::Pair(face(faces[0].clone()), face(faces[1].clone()));
@@ -1156,7 +1156,7 @@ impl ConversationView {
1156 None => avatar,
1156 None => avatar,
1157 });
1157 });
1158 subline = presence
1158 subline = presence
1159 .map(|kind| kind.label().to_owned())
1159 .map(|presence| presence.kind().label().to_owned())
1160 .unwrap_or_default();
1160 .unwrap_or_default();
1161 } else {
1161 } else {
1162 let pair = AvatarSpec::Pair(face(faces[0].clone()), face(faces[1].clone()));
1162 let pair = AvatarSpec::Pair(face(faces[0].clone()), face(faces[1].clone()));
crates/app/src/views/message_row.rs +6 −1
@@ -1,4 +1,5 @@
1 1 use gpui_kit::assets::IconName;
2 use gpui_kit::base::TextSelection;
2 3 use gpui_kit::component::{h_flex, v_flex};
3 4 use gpui_kit::prelude::FluentBuilder as _;
4 5 use gpui_kit::*;
@@ -561,7 +562,11 @@ pub fn render_message_row(
561 562 .w_full()
562 563 .pt(spacing)
563 564 .when_some(open_thread, |element, open| {
564 element.cursor_pointer().on_click(move |_, _, cx| open(cx))
565 element.cursor_pointer().on_click(move |_, window, cx| {
566 if TextSelection::selected_text(window, cx).is_empty() {
567 open(cx);
568 }
569 })
565 570 })
566 571 .when_some(hovered, |element, hovered| {
567 572 element.on_hover(move |is_hovered, _, cx| {
@@ -1,4 +1,5 @@
1use gpui_kit::assets::IconName;
1use gpui_kit::assets::IconName;
2use gpui_kit::base::TextSelection;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5use gpui_kit::*;
@@ -561,7 +562,11 @@ pub fn render_message_row(
561 .w_full()
562 .w_full()
562 .pt(spacing)
563 .pt(spacing)
563 .when_some(open_thread, |element, open| {
564 .when_some(open_thread, |element, open| {
564 element.cursor_pointer().on_click(move |_, _, cx| open(cx))
565 element.cursor_pointer().on_click(move |_, window, cx| {
566 if TextSelection::selected_text(window, cx).is_empty() {
567 open(cx);
568 }
569 })
565 })
570 })
566 .when_some(hovered, |element, hovered| {
571 .when_some(hovered, |element, hovered| {
567 element.on_hover(move |is_hovered, _, cx| {
572 element.on_hover(move |is_hovered, _, cx| {
crates/store/src/lib.rs +1 −0
@@ -8,6 +8,7 @@ mod messages;
8 8 mod meta;
9 9 mod migrations;
10 10 mod models;
11 mod presence;
11 12 mod search;
12 13 mod sidebar;
13 14 mod store;
@@ -8,6 +8,7 @@ mod messages;
8mod meta;
8mod meta;
9mod migrations;
9mod migrations;
10mod models;
10mod models;
11mod presence;
11mod search;
12mod search;
12mod sidebar;
13mod sidebar;
13mod store;
14mod store;
crates/store/src/migrations.rs +4 −0
@@ -29,6 +29,10 @@ const MIGRATIONS: &[Migration] = &[
29 29 script: include_str!("migrations/0005_team_layout.sql"),
30 30 after: None,
31 31 },
32 Migration {
33 script: include_str!("migrations/0006_presence.sql"),
34 after: None,
35 },
32 36 ];
33 37
34 38 pub fn latest_version() -> i64 {
@@ -29,6 +29,10 @@ const MIGRATIONS: &[Migration] = &[
29 script: include_str!("migrations/0005_team_layout.sql"),
29 script: include_str!("migrations/0005_team_layout.sql"),
30 after: None,
30 after: None,
31 },
31 },
32 Migration {
33 script: include_str!("migrations/0006_presence.sql"),
34 after: None,
35 },
32];
36];
33
37
34pub fn latest_version() -> i64 {
38pub fn latest_version() -> i64 {
crates/store/src/migrations/0006_presence.sql added +5 −0
@@ -0,0 +1,5 @@
1 CREATE TABLE presence (
2 user_id TEXT PRIMARY KEY,
3 availability TEXT NOT NULL,
4 fetched_at INTEGER NOT NULL
5 ) WITHOUT ROWID;
@@ -0,0 +1,5 @@
1CREATE TABLE presence (
2 user_id TEXT PRIMARY KEY,
3 availability TEXT NOT NULL,
4 fetched_at INTEGER NOT NULL
5) WITHOUT ROWID;
crates/store/src/presence.rs added +37 −0
@@ -0,0 +1,37 @@
1 use chrono::{DateTime, Utc};
2 use rusqlite::params;
3
4 use crate::error::Result;
5 use crate::store::Store;
6 use crate::time::to_millis;
7
8 impl Store {
9 pub fn presences(&self) -> Result<Vec<(String, String)>> {
10 let connection = self.lock()?;
11 let mut statement =
12 connection.prepare_cached("SELECT user_id, availability FROM presence")?;
13 let rows = statement.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))?;
14 Ok(rows.collect::<rusqlite::Result<_>>()?)
15 }
16
17 pub fn upsert_presences(
18 &self,
19 presences: &[(String, String)],
20 fetched_at: DateTime<Utc>,
21 ) -> Result<()> {
22 let mut connection = self.lock()?;
23 let transaction = connection.transaction()?;
24 {
25 let mut statement = transaction.prepare_cached(
26 "INSERT INTO presence (user_id, availability, fetched_at) VALUES (?1, ?2, ?3)
27 ON CONFLICT (user_id) DO UPDATE SET
28 availability = excluded.availability, fetched_at = excluded.fetched_at",
29 )?;
30 for (user_id, availability) in presences {
31 statement.execute(params![user_id, availability, to_millis(fetched_at)])?;
32 }
33 }
34 transaction.commit()?;
35 Ok(())
36 }
37 }
@@ -0,0 +1,37 @@
1use chrono::{DateTime, Utc};
2use rusqlite::params;
3
4use crate::error::Result;
5use crate::store::Store;
6use crate::time::to_millis;
7
8impl Store {
9 pub fn presences(&self) -> Result<Vec<(String, String)>> {
10 let connection = self.lock()?;
11 let mut statement =
12 connection.prepare_cached("SELECT user_id, availability FROM presence")?;
13 let rows = statement.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))?;
14 Ok(rows.collect::<rusqlite::Result<_>>()?)
15 }
16
17 pub fn upsert_presences(
18 &self,
19 presences: &[(String, String)],
20 fetched_at: DateTime<Utc>,
21 ) -> Result<()> {
22 let mut connection = self.lock()?;
23 let transaction = connection.transaction()?;
24 {
25 let mut statement = transaction.prepare_cached(
26 "INSERT INTO presence (user_id, availability, fetched_at) VALUES (?1, ?2, ?3)
27 ON CONFLICT (user_id) DO UPDATE SET
28 availability = excluded.availability, fetched_at = excluded.fetched_at",
29 )?;
30 for (user_id, availability) in presences {
31 statement.execute(params![user_id, availability, to_millis(fetched_at)])?;
32 }
33 }
34 transaction.commit()?;
35 Ok(())
36 }
37}
crates/store/tests/store.rs +21 −6
@@ -326,11 +326,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
326 326 let path = directory.path().join("nested").join("cache.sqlite3");
327 327 {
328 328 let store = Store::open(&path).unwrap();
329 assert_eq!(store.schema_version().unwrap(), 5);
329 assert_eq!(store.schema_version().unwrap(), 6);
330 330 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
331 331 }
332 332 let reopened = Store::open(&path).unwrap();
333 assert_eq!(reopened.schema_version().unwrap(), 5);
333 assert_eq!(reopened.schema_version().unwrap(), 6);
334 334 assert_eq!(reopened.message_count("c").unwrap(), 1);
335 335 drop(reopened);
336 336 let mode: String = rusqlite_open(&path)
@@ -359,10 +359,10 @@ fn old_schema_is_upgraded_in_place() {
359 359 let path = directory.path().join("cache.sqlite3");
360 360 drop(Store::open(&path).unwrap());
361 361 let connection = rusqlite_open(&path);
362 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; PRAGMA user_version = 0").unwrap();
362 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; PRAGMA user_version = 0").unwrap();
363 363 drop(connection);
364 364 let store = Store::open(&path).unwrap();
365 assert_eq!(store.schema_version().unwrap(), 5);
365 assert_eq!(store.schema_version().unwrap(), 6);
366 366 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
367 367 }
368 368
@@ -428,7 +428,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
428 428 let store = Store::open(&path).unwrap();
429 429 let state = store.sync_state("c").unwrap().unwrap();
430 430 assert_eq!(state.delta_link, None);
431 assert_eq!(store.schema_version().unwrap(), 5);
431 assert_eq!(store.schema_version().unwrap(), 6);
432 432 }
433 433
434 434 #[test]
@@ -658,7 +658,7 @@ fn migration_indexes_rows_that_predate_search() {
658 658 "DROP TRIGGER chats_title_insert; DROP TRIGGER chats_title_update; DROP TRIGGER chats_title_delete;
659 659 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
660 660 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
661 DROP TABLE team_layout; DROP TABLE channel_layout;
661 DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence;
662 662 PRAGMA user_version = 3;",
663 663 )
664 664 .unwrap();
@@ -758,3 +758,18 @@ fn sync_does_not_resurrect_a_locally_read_chat() {
758 758 .unwrap();
759 759 assert!(store.chat("chat-1").unwrap().unwrap().unread);
760 760 }
761
762 #[test]
763 fn presence_upsert_keeps_the_latest_availability() {
764 let store = Store::open_in_memory().unwrap();
765 let first = [("ada".to_owned(), "Available".to_owned())];
766 store.upsert_presences(&first, at(1)).unwrap();
767 let second = [
768 ("ada".to_owned(), "Away".to_owned()),
769 ("bob".to_owned(), "Busy".to_owned()),
770 ];
771 store.upsert_presences(&second, at(2)).unwrap();
772 let mut presences = store.presences().unwrap();
773 presences.sort();
774 assert_eq!(presences, second.to_vec());
775 }
@@ -326,11 +326,11 @@ fn file_database_uses_wal_persists_and_migrates_once() {
326 let path = directory.path().join("nested").join("cache.sqlite3");
326 let path = directory.path().join("nested").join("cache.sqlite3");
327 {
327 {
328 let store = Store::open(&path).unwrap();
328 let store = Store::open(&path).unwrap();
329 assert_eq!(store.schema_version().unwrap(), 5);
329 assert_eq!(store.schema_version().unwrap(), 6);
330 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
330 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
331 }
331 }
332 let reopened = Store::open(&path).unwrap();
332 let reopened = Store::open(&path).unwrap();
333 assert_eq!(reopened.schema_version().unwrap(), 5);
333 assert_eq!(reopened.schema_version().unwrap(), 6);
334 assert_eq!(reopened.message_count("c").unwrap(), 1);
334 assert_eq!(reopened.message_count("c").unwrap(), 1);
335 drop(reopened);
335 drop(reopened);
336 let mode: String = rusqlite_open(&path)
336 let mode: String = rusqlite_open(&path)
@@ -359,10 +359,10 @@ fn old_schema_is_upgraded_in_place() {
359 let path = directory.path().join("cache.sqlite3");
359 let path = directory.path().join("cache.sqlite3");
360 drop(Store::open(&path).unwrap());
360 drop(Store::open(&path).unwrap());
361 let connection = rusqlite_open(&path);
361 let connection = rusqlite_open(&path);
362 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; PRAGMA user_version = 0").unwrap();
362 connection.execute_batch("DROP TABLE messages; DROP TABLE sync_state; DROP TABLE chats; DROP TABLE chat_members; DROP TABLE channels; DROP TABLE teams; DROP TABLE meta; DROP TABLE avatars; DROP TABLE folder_items; DROP TABLE folders; DROP TABLE pinned_channels; DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search; DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence; PRAGMA user_version = 0").unwrap();
363 drop(connection);
363 drop(connection);
364 let store = Store::open(&path).unwrap();
364 let store = Store::open(&path).unwrap();
365 assert_eq!(store.schema_version().unwrap(), 5);
365 assert_eq!(store.schema_version().unwrap(), 6);
366 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
366 store.upsert_messages(&[message("c", "m1", 1)]).unwrap();
367}
367}
368
368
@@ -428,7 +428,7 @@ fn migration_to_v2_keeps_existing_sync_state() {
428 let store = Store::open(&path).unwrap();
428 let store = Store::open(&path).unwrap();
429 let state = store.sync_state("c").unwrap().unwrap();
429 let state = store.sync_state("c").unwrap().unwrap();
430 assert_eq!(state.delta_link, None);
430 assert_eq!(state.delta_link, None);
431 assert_eq!(store.schema_version().unwrap(), 5);
431 assert_eq!(store.schema_version().unwrap(), 6);
432}
432}
433
433
434#[test]
434#[test]
@@ -658,7 +658,7 @@ fn migration_indexes_rows_that_predate_search() {
658 "DROP TRIGGER chats_title_insert; DROP TRIGGER chats_title_update; DROP TRIGGER chats_title_delete;
658 "DROP TRIGGER chats_title_insert; DROP TRIGGER chats_title_update; DROP TRIGGER chats_title_delete;
659 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
659 DROP TRIGGER channels_title_insert; DROP TRIGGER channels_title_update; DROP TRIGGER channels_title_delete;
660 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
660 DROP TABLE images; DROP TABLE search_keys; DROP TABLE message_search; DROP TABLE title_search;
661 DROP TABLE team_layout; DROP TABLE channel_layout;
661 DROP TABLE team_layout; DROP TABLE channel_layout; DROP TABLE presence;
662 PRAGMA user_version = 3;",
662 PRAGMA user_version = 3;",
663 )
663 )
664 .unwrap();
664 .unwrap();
@@ -758,3 +758,18 @@ fn sync_does_not_resurrect_a_locally_read_chat() {
758 .unwrap();
758 .unwrap();
759 assert!(store.chat("chat-1").unwrap().unwrap().unread);
759 assert!(store.chat("chat-1").unwrap().unwrap().unread);
760}
760}
761
762#[test]
763fn presence_upsert_keeps_the_latest_availability() {
764 let store = Store::open_in_memory().unwrap();
765 let first = [("ada".to_owned(), "Available".to_owned())];
766 store.upsert_presences(&first, at(1)).unwrap();
767 let second = [
768 ("ada".to_owned(), "Away".to_owned()),
769 ("bob".to_owned(), "Busy".to_owned()),
770 ];
771 store.upsert_presences(&second, at(2)).unwrap();
772 let mut presences = store.presences().unwrap();
773 presences.sort();
774 assert_eq!(presences, second.to_vec());
775}