refactor(app): cut the cycles between state and views
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -0,0 +1,74 @@
1
use std::io::Cursor;
2
3
use gpui_kit::ImageFormat;
4
5
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6
pub enum InlineFormat {
7
Png,
8
Jpeg,
9
Gif,
10
Webp,
11
}
12
13
impl InlineFormat {
14
pub fn image_format(self) -> ImageFormat {
15
match self {
16
InlineFormat::Png => ImageFormat::Png,
17
InlineFormat::Jpeg => ImageFormat::Jpeg,
18
InlineFormat::Gif => ImageFormat::Gif,
19
InlineFormat::Webp => ImageFormat::Webp,
20
}
21
}
22
23
pub fn decoder_format(self) -> Option<image::ImageFormat> {
24
match self {
25
InlineFormat::Png => Some(image::ImageFormat::Png),
26
InlineFormat::Jpeg => Some(image::ImageFormat::Jpeg),
27
InlineFormat::Webp => Some(image::ImageFormat::WebP),
28
InlineFormat::Gif => None,
29
}
30
}
31
}
32
33
pub fn sniff_inline_format(bytes: &[u8]) -> Option<InlineFormat> {
34
match bytes {
35
[0x89, b'P', b'N', b'G', ..] => Some(InlineFormat::Png),
36
[0xFF, 0xD8, 0xFF, ..] => Some(InlineFormat::Jpeg),
37
[b'G', b'I', b'F', b'8', ..] => Some(InlineFormat::Gif),
38
[
39
b'R',
40
b'I',
41
b'F',
42
b'F',
43
_,
44
_,
45
_,
46
_,
47
b'W',
48
b'E',
49
b'B',
50
b'P',
51
..,
52
] => Some(InlineFormat::Webp),
53
_ => None,
54
}
55
}
56
57
pub fn image_dimensions(format: InlineFormat, bytes: &[u8]) -> Option<(u32, u32)> {
58
match format.decoder_format() {
59
Some(decoder) => image::ImageReader::with_format(Cursor::new(bytes), decoder)
60
.into_dimensions()
61
.ok(),
62
None => {
63
let header = bytes.get(6..10)?;
64
Some((
65
u32::from(u16::from_le_bytes([header[0], header[1]])),
66
u32::from(u16::from_le_bytes([header[2], header[3]])),
67
))
68
}
69
}
70
}
71
72
pub fn dimensions_of(bytes: &[u8]) -> Option<(u32, u32)> {
73
image_dimensions(sniff_inline_format(bytes)?, bytes)
74
}
@@ -0,0 +1,74 @@1
use std::io::Cursor;2
3
use gpui_kit::ImageFormat;4
5
#[derive(Debug, Clone, Copy, PartialEq, Eq)]6
pub enum InlineFormat {7
Png,8
Jpeg,9
Gif,10
Webp,11
}12
13
impl InlineFormat {14
pub fn image_format(self) -> ImageFormat {15
match self {16
InlineFormat::Png => ImageFormat::Png,17
InlineFormat::Jpeg => ImageFormat::Jpeg,18
InlineFormat::Gif => ImageFormat::Gif,19
InlineFormat::Webp => ImageFormat::Webp,20
}21
}22
23
pub fn decoder_format(self) -> Option<image::ImageFormat> {24
match self {25
InlineFormat::Png => Some(image::ImageFormat::Png),26
InlineFormat::Jpeg => Some(image::ImageFormat::Jpeg),27
InlineFormat::Webp => Some(image::ImageFormat::WebP),28
InlineFormat::Gif => None,29
}30
}31
}32
33
pub fn sniff_inline_format(bytes: &[u8]) -> Option<InlineFormat> {34
match bytes {35
[0x89, b'P', b'N', b'G', ..] => Some(InlineFormat::Png),36
[0xFF, 0xD8, 0xFF, ..] => Some(InlineFormat::Jpeg),37
[b'G', b'I', b'F', b'8', ..] => Some(InlineFormat::Gif),38
[39
b'R',40
b'I',41
b'F',42
b'F',43
_,44
_,45
_,46
_,47
b'W',48
b'E',49
b'B',50
b'P',51
..,52
] => Some(InlineFormat::Webp),53
_ => None,54
}55
}56
57
pub fn image_dimensions(format: InlineFormat, bytes: &[u8]) -> Option<(u32, u32)> {58
match format.decoder_format() {59
Some(decoder) => image::ImageReader::with_format(Cursor::new(bytes), decoder)60
.into_dimensions()61
.ok(),62
None => {63
let header = bytes.get(6..10)?;64
Some((65
u32::from(u16::from_le_bytes([header[0], header[1]])),66
u32::from(u16::from_le_bytes([header[2], header[3]])),67
))68
}69
}70
}71
72
pub fn dimensions_of(bytes: &[u8]) -> Option<(u32, u32)> {73
image_dimensions(sniff_inline_format(bytes)?, bytes)74
}@@ -17,6 +17,7 @@ pub mod format;
17
17
pub mod frame_log;
18
18
pub mod fuzzy;
19
19
pub mod image_view_math;
20
pub mod inline_image;
20
21
pub mod notify;
21
22
pub mod presence_link;
22
23
pub mod read_state;
@@ -17,6 +17,7 @@ pub mod format;17
pub mod frame_log;17
pub mod frame_log;18
pub mod fuzzy;18
pub mod fuzzy;19
pub mod image_view_math;19
pub mod image_view_math;20
pub mod inline_image;20
pub mod notify;21
pub mod notify;21
pub mod presence_link;22
pub mod presence_link;22
pub mod read_state;23
pub mod read_state;@@ -20,5 +20,6 @@ pub mod report;
20
20
pub mod ring;
21
21
pub mod share_view;
22
22
pub mod stage_layout;
23
pub mod stage_split;
23
24
pub mod transcript;
24
25
pub mod view_settings;
@@ -20,5 +20,6 @@ pub mod report;20
pub mod ring;20
pub mod ring;21
pub mod share_view;21
pub mod share_view;22
pub mod stage_layout;22
pub mod stage_layout;23
pub mod stage_split;23
pub mod transcript;24
pub mod transcript;24
pub mod view_settings;25
pub mod view_settings;@@ -0,0 +1,220 @@
1
use calling::{TileDetail, VideoWant};
2
3
use crate::model::{ActiveCall, CallModel, Focus, Tile};
4
use crate::stage_layout::{
5
FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, share_strip, split_overflow,
6
};
7
use crate::view_settings::CallLayout;
8
9
pub const TILE_GAP: f32 = 20.;
10
pub const GRID_PADDING: f32 = 24.;
11
pub const STRIP_GAP: f32 = 12.;
12
pub const FILMSTRIP_TILE_MAX: f32 = 220.;
13
const FALLBACK_STAGE: (f32, f32) = (900., 560.);
14
15
pub fn measured_stage(call: &ActiveCall) -> (f32, f32) {
16
let (width, height) = call.stage_size.get();
17
if width < 1. || height < 1. {
18
return FALLBACK_STAGE;
19
}
20
(width, height)
21
}
22
23
pub fn gallery_split(model: &CallModel) -> (Vec<&Tile>, Overflow) {
24
let others = model.layout_tiles();
25
let overflow = split_overflow(others.len(), model.own_cells(), GALLERY_MAX);
26
(others, overflow)
27
}
28
29
pub struct SpeakerSplit<'a> {
30
pub focus: Option<Focus>,
31
pub others: Vec<&'a Tile>,
32
pub own_cells: usize,
33
pub plan: Filmstrip,
34
}
35
36
pub fn speaker_split(model: &CallModel, stage: (f32, f32)) -> SpeakerSplit<'_> {
37
let focus = model.speaker_focus();
38
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
39
let mut others: Vec<&Tile> = model
40
.layout_tiles()
41
.into_iter()
42
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)
43
.collect();
44
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
45
let plan = filmstrip(
46
others.len(),
47
own_cells,
48
stage.0 - 2. * GRID_PADDING,
49
TILE_GAP,
50
FILMSTRIP_TILE_MAX,
51
);
52
if plan.overflow.shown < FILMSTRIP_MAX.min(others.len()) {
53
others.sort_by_key(|tile| !model.is_recent_speaker(&tile.mri));
54
}
55
SpeakerSplit { focus, others, own_cells, plan }
56
}
57
58
pub struct StripSplit<'a> {
59
pub width: f32,
60
pub others: Vec<&'a Tile>,
61
pub plan: Filmstrip,
62
}
63
64
pub fn strip_split(model: &CallModel, strip_width: f32, stage: (f32, f32)) -> StripSplit<'_> {
65
let available = (stage.0 - 2. * GRID_PADDING, (stage.1 - 2. * GRID_PADDING).max(0.));
66
let width = strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));
67
let others: Vec<&Tile> = model
68
.strip_tiles()
69
.into_iter()
70
.filter(|tile| !model.hidden_for_no_video(tile))
71
.collect();
72
let plan = share_strip(others.len(), model.own_cells(), (width, available.1), STRIP_GAP);
73
StripSplit { width, others, plan }
74
}
75
76
const LARGE_GALLERY_TILES: usize = 4;
77
78
fn want(tile: &Tile, detail: TileDetail) -> VideoWant {
79
VideoWant { mri: tile.mri.clone(), detail }
80
}
81
82
pub fn video_wants(model: &CallModel, stage: (f32, f32), strip_width: f32) -> Vec<VideoWant> {
83
if model.has_content() {
84
if model.effective_layout() == CallLayout::Content {
85
return Vec::new();
86
}
87
let split = strip_split(model, strip_width, stage);
88
return split.others[..split.plan.overflow.shown]
89
.iter()
90
.map(|tile| want(tile, TileDetail::Small))
91
.collect();
92
}
93
if model.effective_layout() == CallLayout::Speaker {
94
let split = speaker_split(model, stage);
95
let stage_person = split.focus.iter().filter(|focus| !focus.own).map(|focus| VideoWant {
96
mri: focus.mri.clone(),
97
detail: TileDetail::Stage,
98
});
99
return stage_person
100
.chain(split.others[..split.plan.overflow.shown].iter().map(|tile| want(tile, TileDetail::Small)))
101
.collect();
102
}
103
let (others, overflow) = gallery_split(model);
104
let detail = if overflow.shown <= LARGE_GALLERY_TILES { TileDetail::Stage } else { TileDetail::Small };
105
others[..overflow.shown].iter().map(|tile| want(tile, detail)).collect()
106
}
107
108
#[cfg(test)]
109
mod tests {
110
use std::time::Instant;
111
112
use calling::{CallUpdate, RosterEntry, TileDetail, VideoWant};
113
114
use super::{FILMSTRIP_TILE_MAX, GRID_PADDING, TILE_GAP, video_wants};
115
use crate::model::CallModel;
116
use crate::share_view::STRIP_DEFAULT_WIDTH;
117
use crate::stage_layout::{GALLERY_MAX, filmstrip, split_overflow};
118
use crate::view_settings::CallLayout;
119
120
const STAGE: (f32, f32) = (1400., 800.);
121
122
fn person(index: usize, has_video: bool) -> RosterEntry {
123
RosterEntry {
124
mri: format!("8:orgid:p{index}"),
125
display_name: format!("P{index}"),
126
muted: false,
127
in_lobby: false,
128
has_video,
129
sharing: false,
130
hand: None,
131
spotlight: None,
132
organizer: false,
133
role: None,
134
limits: Default::default(),
135
}
136
}
137
138
fn meeting(people: Vec<RosterEntry>) -> CallModel {
139
let mut model = CallModel::meeting("Standup", false);
140
model.apply(CallUpdate::OwnIdentity { mri: "8:orgid:me".into() });
141
model.apply(CallUpdate::Roster(people));
142
model
143
}
144
145
fn crowd(count: usize) -> CallModel {
146
meeting((0..count).map(|index| person(index, true)).collect())
147
}
148
149
fn details(wants: &[VideoWant]) -> Vec<TileDetail> {
150
wants.iter().map(|want| want.detail).collect()
151
}
152
153
#[test]
154
fn a_small_gallery_asks_for_large_pictures() {
155
let wants = video_wants(&crowd(3), STAGE, STRIP_DEFAULT_WIDTH);
156
assert_eq!(wants.len(), 3);
157
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Stage));
158
}
159
160
#[test]
161
fn a_big_gallery_asks_for_small_pictures_and_skips_the_plus_n_people() {
162
let model = crowd(14);
163
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
164
assert_eq!(wants.len(), split_overflow(14, 1, GALLERY_MAX).shown);
165
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
166
let hidden: Vec<&str> = model.layout_tiles()[wants.len()..].iter().map(|tile| tile.mri.as_str()).collect();
167
assert!(wants.iter().all(|want| !hidden.contains(&want.mri.as_str())));
168
}
169
170
#[test]
171
fn people_hidden_for_having_no_video_get_no_picture_request() {
172
let mut model = meeting(vec![person(0, true), person(1, false), person(2, false)]);
173
model.view.hide_no_video = true;
174
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
175
assert_eq!(wants.iter().map(|want| want.mri.as_str()).collect::<Vec<_>>(), vec!["8:orgid:p0"]);
176
}
177
178
#[test]
179
fn the_speaker_stage_is_large_and_the_filmstrip_small() {
180
let mut model = crowd(5);
181
model.view.choose(CallLayout::Speaker);
182
model.refresh_layout(Instant::now());
183
let focus = model.speaker_focus().expect("a stage person").mri;
184
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
185
assert_eq!(wants[0], VideoWant { mri: focus.clone(), detail: TileDetail::Stage });
186
assert_eq!(wants.len(), 5);
187
assert!(wants[1..].iter().all(|want| want.detail == TileDetail::Small && want.mri != focus));
188
}
189
190
#[test]
191
fn the_speaker_filmstrip_drops_people_that_do_not_fit() {
192
let mut model = crowd(12);
193
model.view.choose(CallLayout::Speaker);
194
model.refresh_layout(Instant::now());
195
let wants = video_wants(&model, (500., 800.), STRIP_DEFAULT_WIDTH);
196
let fitting = filmstrip(11, 1, 500. - 2. * GRID_PADDING, TILE_GAP, FILMSTRIP_TILE_MAX).overflow.shown;
197
assert!(fitting < 11);
198
assert_eq!(wants.len(), 1 + fitting);
199
}
200
201
#[test]
202
fn next_to_shared_content_everybody_in_the_strip_is_small_and_content_focus_wants_nobody() {
203
let mut model = crowd(3);
204
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
205
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
206
assert_eq!(wants.len(), 3);
207
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
208
model.view.choose(CallLayout::Content);
209
assert!(video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH).is_empty());
210
}
211
212
#[test]
213
fn a_full_share_strip_wants_video_for_every_shown_tile_and_none_behind_the_plus_tile() {
214
let mut model = crowd(9);
215
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
216
assert_eq!(video_wants(&model, (1400., 1100.), STRIP_DEFAULT_WIDTH).len(), 9);
217
let short = video_wants(&model, (1400., 600.), STRIP_DEFAULT_WIDTH);
218
assert!(short.len() >= 3 && short.len() < 9, "{} wants", short.len());
219
}
220
}
@@ -0,0 +1,220 @@1
use calling::{TileDetail, VideoWant};2
3
use crate::model::{ActiveCall, CallModel, Focus, Tile};4
use crate::stage_layout::{5
FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, filmstrip, share_strip, split_overflow,6
};7
use crate::view_settings::CallLayout;8
9
pub const TILE_GAP: f32 = 20.;10
pub const GRID_PADDING: f32 = 24.;11
pub const STRIP_GAP: f32 = 12.;12
pub const FILMSTRIP_TILE_MAX: f32 = 220.;13
const FALLBACK_STAGE: (f32, f32) = (900., 560.);14
15
pub fn measured_stage(call: &ActiveCall) -> (f32, f32) {16
let (width, height) = call.stage_size.get();17
if width < 1. || height < 1. {18
return FALLBACK_STAGE;19
}20
(width, height)21
}22
23
pub fn gallery_split(model: &CallModel) -> (Vec<&Tile>, Overflow) {24
let others = model.layout_tiles();25
let overflow = split_overflow(others.len(), model.own_cells(), GALLERY_MAX);26
(others, overflow)27
}28
29
pub struct SpeakerSplit<'a> {30
pub focus: Option<Focus>,31
pub others: Vec<&'a Tile>,32
pub own_cells: usize,33
pub plan: Filmstrip,34
}35
36
pub fn speaker_split(model: &CallModel, stage: (f32, f32)) -> SpeakerSplit<'_> {37
let focus = model.speaker_focus();38
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());39
let mut others: Vec<&Tile> = model40
.layout_tiles()41
.into_iter()42
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)43
.collect();44
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));45
let plan = filmstrip(46
others.len(),47
own_cells,48
stage.0 - 2. * GRID_PADDING,49
TILE_GAP,50
FILMSTRIP_TILE_MAX,51
);52
if plan.overflow.shown < FILMSTRIP_MAX.min(others.len()) {53
others.sort_by_key(|tile| !model.is_recent_speaker(&tile.mri));54
}55
SpeakerSplit { focus, others, own_cells, plan }56
}57
58
pub struct StripSplit<'a> {59
pub width: f32,60
pub others: Vec<&'a Tile>,61
pub plan: Filmstrip,62
}63
64
pub fn strip_split(model: &CallModel, strip_width: f32, stage: (f32, f32)) -> StripSplit<'_> {65
let available = (stage.0 - 2. * GRID_PADDING, (stage.1 - 2. * GRID_PADDING).max(0.));66
let width = strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));67
let others: Vec<&Tile> = model68
.strip_tiles()69
.into_iter()70
.filter(|tile| !model.hidden_for_no_video(tile))71
.collect();72
let plan = share_strip(others.len(), model.own_cells(), (width, available.1), STRIP_GAP);73
StripSplit { width, others, plan }74
}75
76
const LARGE_GALLERY_TILES: usize = 4;77
78
fn want(tile: &Tile, detail: TileDetail) -> VideoWant {79
VideoWant { mri: tile.mri.clone(), detail }80
}81
82
pub fn video_wants(model: &CallModel, stage: (f32, f32), strip_width: f32) -> Vec<VideoWant> {83
if model.has_content() {84
if model.effective_layout() == CallLayout::Content {85
return Vec::new();86
}87
let split = strip_split(model, strip_width, stage);88
return split.others[..split.plan.overflow.shown]89
.iter()90
.map(|tile| want(tile, TileDetail::Small))91
.collect();92
}93
if model.effective_layout() == CallLayout::Speaker {94
let split = speaker_split(model, stage);95
let stage_person = split.focus.iter().filter(|focus| !focus.own).map(|focus| VideoWant {96
mri: focus.mri.clone(),97
detail: TileDetail::Stage,98
});99
return stage_person100
.chain(split.others[..split.plan.overflow.shown].iter().map(|tile| want(tile, TileDetail::Small)))101
.collect();102
}103
let (others, overflow) = gallery_split(model);104
let detail = if overflow.shown <= LARGE_GALLERY_TILES { TileDetail::Stage } else { TileDetail::Small };105
others[..overflow.shown].iter().map(|tile| want(tile, detail)).collect()106
}107
108
#[cfg(test)]109
mod tests {110
use std::time::Instant;111
112
use calling::{CallUpdate, RosterEntry, TileDetail, VideoWant};113
114
use super::{FILMSTRIP_TILE_MAX, GRID_PADDING, TILE_GAP, video_wants};115
use crate::model::CallModel;116
use crate::share_view::STRIP_DEFAULT_WIDTH;117
use crate::stage_layout::{GALLERY_MAX, filmstrip, split_overflow};118
use crate::view_settings::CallLayout;119
120
const STAGE: (f32, f32) = (1400., 800.);121
122
fn person(index: usize, has_video: bool) -> RosterEntry {123
RosterEntry {124
mri: format!("8:orgid:p{index}"),125
display_name: format!("P{index}"),126
muted: false,127
in_lobby: false,128
has_video,129
sharing: false,130
hand: None,131
spotlight: None,132
organizer: false,133
role: None,134
limits: Default::default(),135
}136
}137
138
fn meeting(people: Vec<RosterEntry>) -> CallModel {139
let mut model = CallModel::meeting("Standup", false);140
model.apply(CallUpdate::OwnIdentity { mri: "8:orgid:me".into() });141
model.apply(CallUpdate::Roster(people));142
model143
}144
145
fn crowd(count: usize) -> CallModel {146
meeting((0..count).map(|index| person(index, true)).collect())147
}148
149
fn details(wants: &[VideoWant]) -> Vec<TileDetail> {150
wants.iter().map(|want| want.detail).collect()151
}152
153
#[test]154
fn a_small_gallery_asks_for_large_pictures() {155
let wants = video_wants(&crowd(3), STAGE, STRIP_DEFAULT_WIDTH);156
assert_eq!(wants.len(), 3);157
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Stage));158
}159
160
#[test]161
fn a_big_gallery_asks_for_small_pictures_and_skips_the_plus_n_people() {162
let model = crowd(14);163
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);164
assert_eq!(wants.len(), split_overflow(14, 1, GALLERY_MAX).shown);165
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));166
let hidden: Vec<&str> = model.layout_tiles()[wants.len()..].iter().map(|tile| tile.mri.as_str()).collect();167
assert!(wants.iter().all(|want| !hidden.contains(&want.mri.as_str())));168
}169
170
#[test]171
fn people_hidden_for_having_no_video_get_no_picture_request() {172
let mut model = meeting(vec![person(0, true), person(1, false), person(2, false)]);173
model.view.hide_no_video = true;174
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);175
assert_eq!(wants.iter().map(|want| want.mri.as_str()).collect::<Vec<_>>(), vec!["8:orgid:p0"]);176
}177
178
#[test]179
fn the_speaker_stage_is_large_and_the_filmstrip_small() {180
let mut model = crowd(5);181
model.view.choose(CallLayout::Speaker);182
model.refresh_layout(Instant::now());183
let focus = model.speaker_focus().expect("a stage person").mri;184
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);185
assert_eq!(wants[0], VideoWant { mri: focus.clone(), detail: TileDetail::Stage });186
assert_eq!(wants.len(), 5);187
assert!(wants[1..].iter().all(|want| want.detail == TileDetail::Small && want.mri != focus));188
}189
190
#[test]191
fn the_speaker_filmstrip_drops_people_that_do_not_fit() {192
let mut model = crowd(12);193
model.view.choose(CallLayout::Speaker);194
model.refresh_layout(Instant::now());195
let wants = video_wants(&model, (500., 800.), STRIP_DEFAULT_WIDTH);196
let fitting = filmstrip(11, 1, 500. - 2. * GRID_PADDING, TILE_GAP, FILMSTRIP_TILE_MAX).overflow.shown;197
assert!(fitting < 11);198
assert_eq!(wants.len(), 1 + fitting);199
}200
201
#[test]202
fn next_to_shared_content_everybody_in_the_strip_is_small_and_content_focus_wants_nobody() {203
let mut model = crowd(3);204
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));205
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);206
assert_eq!(wants.len(), 3);207
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));208
model.view.choose(CallLayout::Content);209
assert!(video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH).is_empty());210
}211
212
#[test]213
fn a_full_share_strip_wants_video_for_every_shown_tile_and_none_behind_the_plus_tile() {214
let mut model = crowd(9);215
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));216
assert_eq!(video_wants(&model, (1400., 1100.), STRIP_DEFAULT_WIDTH).len(), 9);217
let short = video_wants(&model, (1400., 600.), STRIP_DEFAULT_WIDTH);218
assert!(short.len() >= 3 && short.len() < 9, "{} wants", short.len());219
}220
}@@ -2,3 +2,4 @@ pub const ISLAND_GAP: f32 = 6.;
2
2
pub const RAIL_ITEM_WIDTH: f32 = 48.;
3
3
pub const RAIL_WIDTH: f32 = RAIL_ITEM_WIDTH + 2. * ISLAND_GAP;
4
4
pub const SIDEBAR_WIDTH: f32 = 300.;
5
pub const ROW_PADDING: f32 = 20.;
@@ -2,3 +2,4 @@ pub const ISLAND_GAP: f32 = 6.;2
pub const RAIL_ITEM_WIDTH: f32 = 48.;2
pub const RAIL_ITEM_WIDTH: f32 = 48.;3
pub const RAIL_WIDTH: f32 = RAIL_ITEM_WIDTH + 2. * ISLAND_GAP;3
pub const RAIL_WIDTH: f32 = RAIL_ITEM_WIDTH + 2. * ISLAND_GAP;4
pub const SIDEBAR_WIDTH: f32 = 300.;4
pub const SIDEBAR_WIDTH: f32 = 300.;5
pub const ROW_PADDING: f32 = 20.;@@ -0,0 +1,83 @@
1
use teams_core::{Draft, MentionInput};
2
3
use crate::render::{Block, layout_blocks};
4
5
const BODY_PREVIEW_CHARACTERS: usize = 1200;
6
7
fn body_preview(text: &str) -> String {
8
let text = text.trim();
9
let cut: String = text.chars().take(BODY_PREVIEW_CHARACTERS).collect();
10
if cut.len() == text.len() {
11
return cut;
12
}
13
match cut.rfind('\n') {
14
Some(newline) => cut[..newline].to_owned(),
15
None => cut,
16
}
17
}
18
19
pub fn body_blocks(text: &str, mentions: &[mcp::ProposalMention]) -> Vec<Block> {
20
let inputs: Vec<MentionInput> = mentions
21
.iter()
22
.map(|mention| MentionInput::user(&mention.user_id, &mention.name))
23
.collect();
24
let preview = body_preview(text);
25
let (html, _) = teams_core::apply_mentions(&Draft::from_markdown(&preview).to_html(), &inputs);
26
layout_blocks(&teams_core::html_to_spans(&html))
27
}
28
29
#[cfg(test)]
30
mod tests {
31
use super::{BODY_PREVIEW_CHARACTERS, body_blocks, body_preview};
32
use crate::render::Block;
33
34
#[test]
35
fn the_card_body_renders_markdown_like_a_sent_message() {
36
let blocks = body_blocks("- item\n- `code`", &[]);
37
let [Block::List { items, ordered, .. }] = blocks.as_slice() else {
38
panic!("{blocks:?}");
39
};
40
assert!(!ordered);
41
assert_eq!(items.len(), 2);
42
let Block::Paragraph(inline) = &items[1][0] else {
43
panic!("{items:?}");
44
};
45
assert_eq!(inline.text, "code");
46
assert!(inline.segments.iter().any(|segment| segment.style.code));
47
}
48
49
#[test]
50
fn long_bodies_are_cut_at_the_last_line_break() {
51
let text = format!("{}\n{}", "a".repeat(1000), "b".repeat(500));
52
assert_eq!(body_preview(&text), "a".repeat(1000));
53
assert_eq!(body_preview("short"), "short");
54
}
55
56
#[test]
57
fn long_bodies_are_cut_before_layout() {
58
let long = "word ".repeat(2000);
59
let blocks = body_blocks(&long, &[]);
60
let Block::Paragraph(inline) = &blocks[0] else {
61
panic!("{blocks:?}");
62
};
63
assert!(inline.text.chars().count() <= BODY_PREVIEW_CHARACTERS);
64
}
65
66
#[test]
67
fn mentions_and_links_render_as_styled_segments() {
68
let blocks = body_blocks(
69
"**Hi** @Ada Example, see https://example.com/x",
70
&[mcp::ProposalMention {
71
user_id: "u1".to_owned(),
72
name: "Ada Example".to_owned(),
73
}],
74
);
75
let Block::Paragraph(inline) = &blocks[0] else {
76
panic!("{blocks:?}");
77
};
78
assert!(inline.segments.iter().any(|segment| segment.style.bold));
79
assert!(inline.segments.iter().any(|segment| segment.style.mention));
80
assert!(inline.segments.iter().any(|segment| segment.link.is_some()));
81
assert!(!inline.text.contains("**"));
82
}
83
}
@@ -0,0 +1,83 @@1
use teams_core::{Draft, MentionInput};2
3
use crate::render::{Block, layout_blocks};4
5
const BODY_PREVIEW_CHARACTERS: usize = 1200;6
7
fn body_preview(text: &str) -> String {8
let text = text.trim();9
let cut: String = text.chars().take(BODY_PREVIEW_CHARACTERS).collect();10
if cut.len() == text.len() {11
return cut;12
}13
match cut.rfind('\n') {14
Some(newline) => cut[..newline].to_owned(),15
None => cut,16
}17
}18
19
pub fn body_blocks(text: &str, mentions: &[mcp::ProposalMention]) -> Vec<Block> {20
let inputs: Vec<MentionInput> = mentions21
.iter()22
.map(|mention| MentionInput::user(&mention.user_id, &mention.name))23
.collect();24
let preview = body_preview(text);25
let (html, _) = teams_core::apply_mentions(&Draft::from_markdown(&preview).to_html(), &inputs);26
layout_blocks(&teams_core::html_to_spans(&html))27
}28
29
#[cfg(test)]30
mod tests {31
use super::{BODY_PREVIEW_CHARACTERS, body_blocks, body_preview};32
use crate::render::Block;33
34
#[test]35
fn the_card_body_renders_markdown_like_a_sent_message() {36
let blocks = body_blocks("- item\n- `code`", &[]);37
let [Block::List { items, ordered, .. }] = blocks.as_slice() else {38
panic!("{blocks:?}");39
};40
assert!(!ordered);41
assert_eq!(items.len(), 2);42
let Block::Paragraph(inline) = &items[1][0] else {43
panic!("{items:?}");44
};45
assert_eq!(inline.text, "code");46
assert!(inline.segments.iter().any(|segment| segment.style.code));47
}48
49
#[test]50
fn long_bodies_are_cut_at_the_last_line_break() {51
let text = format!("{}\n{}", "a".repeat(1000), "b".repeat(500));52
assert_eq!(body_preview(&text), "a".repeat(1000));53
assert_eq!(body_preview("short"), "short");54
}55
56
#[test]57
fn long_bodies_are_cut_before_layout() {58
let long = "word ".repeat(2000);59
let blocks = body_blocks(&long, &[]);60
let Block::Paragraph(inline) = &blocks[0] else {61
panic!("{blocks:?}");62
};63
assert!(inline.text.chars().count() <= BODY_PREVIEW_CHARACTERS);64
}65
66
#[test]67
fn mentions_and_links_render_as_styled_segments() {68
let blocks = body_blocks(69
"**Hi** @Ada Example, see https://example.com/x",70
&[mcp::ProposalMention {71
user_id: "u1".to_owned(),72
name: "Ada Example".to_owned(),73
}],74
);75
let Block::Paragraph(inline) = &blocks[0] else {76
panic!("{blocks:?}");77
};78
assert!(inline.segments.iter().any(|segment| segment.style.bold));79
assert!(inline.segments.iter().any(|segment| segment.style.mention));80
assert!(inline.segments.iter().any(|segment| segment.link.is_some()));81
assert!(!inline.text.contains("**"));82
}83
}@@ -11,6 +11,7 @@ use store::{MessageRecord, Store};
11
11
use teams_core::CoreEvent;
12
12
use tokio::sync::mpsc::UnboundedReceiver;
13
13
14
use super::body::body_blocks;
14
15
use super::extras::message_extras;
15
16
use super::image_scale::downscale;
16
17
use super::source::AppSource;
@@ -18,7 +19,6 @@ use super::{AgentApi, ProposalEntry, ProposalPicture, ProposalStatus, Thumbnail}
18
19
use crate::backend::Engine;
19
20
use crate::rows::reaction_glyph;
20
21
use crate::runtime;
21
use crate::views::proposal_card::body_blocks;
22
22
23
23
const PREVIEW_CHARACTERS: usize = 200;
24
24
const NEW_MESSAGE_BATCH: usize = 50;
@@ -11,6 +11,7 @@ use store::{MessageRecord, Store};11
use teams_core::CoreEvent;11
use teams_core::CoreEvent;12
use tokio::sync::mpsc::UnboundedReceiver;12
use tokio::sync::mpsc::UnboundedReceiver;13
13
14
use super::body::body_blocks;14
use super::extras::message_extras;15
use super::extras::message_extras;15
use super::image_scale::downscale;16
use super::image_scale::downscale;16
use super::source::AppSource;17
use super::source::AppSource;@@ -18,7 +19,6 @@ use super::{AgentApi, ProposalEntry, ProposalPicture, ProposalStatus, Thumbnail}18
use crate::backend::Engine;19
use crate::backend::Engine;19
use crate::rows::reaction_glyph;20
use crate::rows::reaction_glyph;20
use crate::runtime;21
use crate::runtime;21
use crate::views::proposal_card::body_blocks;22
22
23
const PREVIEW_CHARACTERS: usize = 200;23
const PREVIEW_CHARACTERS: usize = 200;24
const NEW_MESSAGE_BATCH: usize = 50;24
const NEW_MESSAGE_BATCH: usize = 50;@@ -1,4 +1,5 @@
1
1
mod bridge;
2
pub mod body;
2
3
mod source;
3
4
4
5
use std::collections::{BTreeSet, HashMap};
@@ -1,4 +1,5 @@1
mod bridge;1
mod bridge;2
pub mod body;2
mod source;3
mod source;3
4
4
use std::collections::{BTreeSet, HashMap};5
use std::collections::{BTreeSet, HashMap};@@ -52,7 +52,7 @@ impl TeamsSource for AppSource {
52
52
}
53
53
54
54
fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)> {
55
crate::views::attachment_tray::dimensions_of(bytes)
55
crate::inline_image::dimensions_of(bytes)
56
56
}
57
57
58
58
fn rendered_text(&self, markdown: &str) -> String {
@@ -52,7 +52,7 @@ impl TeamsSource for AppSource {52
}52
}53
53
54
fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)> {54
fn image_dimensions(&self, bytes: &[u8]) -> Option<(u32, u32)> {55
crate::views::attachment_tray::dimensions_of(bytes)55
crate::inline_image::dimensions_of(bytes)56
}56
}57
57
58
fn rendered_text(&self, markdown: &str) -> String {58
fn rendered_text(&self, markdown: &str) -> String {@@ -2,8 +2,7 @@ use agents::{AgentAction, MessageContext, ThreadMessage, build_prompt};
2
2
use chrono::Local;
3
3
use store::MessageRecord;
4
4
5
use crate::app_state::{AppState, Selection, selection_title};
6
use crate::notify::selection_for;
5
use crate::app_state::{AppState, Selection, selection_for, selection_title};
7
6
use crate::people::local_names;
8
7
use crate::rows::message_text;
9
8
@@ -2,8 +2,7 @@ use agents::{AgentAction, MessageContext, ThreadMessage, build_prompt};2
use chrono::Local;2
use chrono::Local;3
use store::MessageRecord;3
use store::MessageRecord;4
4
5
use crate::app_state::{AppState, Selection, selection_title};5
use crate::app_state::{AppState, Selection, selection_for, selection_title};6
use crate::notify::selection_for;7
use crate::people::local_names;6
use crate::people::local_names;8
use crate::rows::message_text;7
use crate::rows::message_text;9
8
@@ -22,10 +22,12 @@ use directories::ProjectDirs;
22
22
use gpui_kit::*;
23
23
24
24
pub use run_chip::run_chip;
25
pub use runs::{AgentRun, AgentRuns, AgentRunsEvent, AgentRunsHandle, RunState, StartOptions};
25
pub use runs::{
26
AgentRun, AgentRuns, AgentRunsEvent, AgentRunsHandle, RunState, StartOptions, StartRequest, needs_dialog,
27
};
26
28
pub use runs_popover::RunsPopover;
27
29
pub use settings_section::AgentsSettings;
28
pub use start_dialog::{StartDialog, StartDialogEvent, StartRequest};
30
pub use start_dialog::{StartDialog, StartDialogEvent};
29
31
30
32
use crate::app_state::{AppHandle, AppState};
31
33
@@ -136,7 +138,7 @@ pub fn delegate(request: StartRequest, cx: &mut App) {
136
138
return;
137
139
};
138
140
let allowed = mcp_bridge::chat_allowed(&request.conversation_id, cx);
139
if start_dialog::needs_dialog(&action, allowed) {
141
if needs_dialog(&action, allowed) {
140
142
runs.update(cx, |_, cx| cx.emit(AgentRunsEvent::StartRequested(request)));
141
143
} else {
142
144
start_run(
@@ -22,10 +22,12 @@ use directories::ProjectDirs;22
use gpui_kit::*;22
use gpui_kit::*;23
23
24
pub use run_chip::run_chip;24
pub use run_chip::run_chip;25
pub use runs::{AgentRun, AgentRuns, AgentRunsEvent, AgentRunsHandle, RunState, StartOptions};25
pub use runs::{26
AgentRun, AgentRuns, AgentRunsEvent, AgentRunsHandle, RunState, StartOptions, StartRequest, needs_dialog,27
};26
pub use runs_popover::RunsPopover;28
pub use runs_popover::RunsPopover;27
pub use settings_section::AgentsSettings;29
pub use settings_section::AgentsSettings;28
pub use start_dialog::{StartDialog, StartDialogEvent, StartRequest};30
pub use start_dialog::{StartDialog, StartDialogEvent};29
31
30
use crate::app_state::{AppHandle, AppState};32
use crate::app_state::{AppHandle, AppState};31
33
@@ -136,7 +138,7 @@ pub fn delegate(request: StartRequest, cx: &mut App) {136
return;138
return;137
};139
};138
let allowed = mcp_bridge::chat_allowed(&request.conversation_id, cx);140
let allowed = mcp_bridge::chat_allowed(&request.conversation_id, cx);139
if start_dialog::needs_dialog(&action, allowed) {141
if needs_dialog(&action, allowed) {140
runs.update(cx, |_, cx| cx.emit(AgentRunsEvent::StartRequested(request)));142
runs.update(cx, |_, cx| cx.emit(AgentRunsEvent::StartRequested(request)));141
} else {143
} else {142
start_run(144
start_run(@@ -12,7 +12,7 @@ use tokio::sync::{mpsc, oneshot};
12
12
13
13
use super::lanes::{Admit, Lanes, RestoreInfo};
14
14
use super::{
15
MCP_POLL_INTERVAL, MCP_WAIT_LIMIT, StartRequest, demo, kills, mcp_bridge, mcp_config_directory,
15
MCP_POLL_INTERVAL, MCP_WAIT_LIMIT, demo, kills, mcp_bridge, mcp_config_directory,
16
16
message_context, open_run_session, raise_notice, store as run_store,
17
17
};
18
18
use crate::app_state::AppState;
@@ -249,6 +249,17 @@ pub struct AgentRunsHandle(pub Entity<AgentRuns>);
249
249
250
250
impl Global for AgentRunsHandle {}
251
251
252
#[derive(Clone, Debug, PartialEq, Eq)]
253
pub struct StartRequest {
254
pub action_id: String,
255
pub conversation_id: String,
256
pub message_id: String,
257
}
258
259
pub fn needs_dialog(action: &AgentAction, chat_allowed: bool) -> bool {
260
action.ask_extra_instructions || !chat_allowed
261
}
262
252
263
pub enum AgentRunsEvent {
253
264
Finished(u64),
254
265
StartRequested(StartRequest),
@@ -1137,10 +1148,19 @@ pub(super) mod tests {
1137
1148
1138
1149
use super::{
1139
1150
AgentRun, AgentRuns, RunState, SessionTarget, StartOptions, Utc, api_retry_text,
1140
format_elapsed, run_store,
1151
format_elapsed, needs_dialog, run_store,
1141
1152
};
1142
1153
use crate::app_state::{AppState, Mode};
1143
1154
1155
#[test]
1156
fn the_dialog_shows_for_extra_instructions_or_a_chat_agents_cannot_see() {
1157
let quiet = AgentAction::answer_this("claude");
1158
let asking = AgentAction::build_this("claude");
1159
assert!(!needs_dialog(&quiet, true));
1160
assert!(needs_dialog(&quiet, false));
1161
assert!(needs_dialog(&asking, true));
1162
}
1163
1144
1164
pub fn finished_run(id: u64) -> AgentRun {
1145
1165
AgentRun {
1146
1166
id,
@@ -12,7 +12,7 @@ use tokio::sync::{mpsc, oneshot};12
12
13
use super::lanes::{Admit, Lanes, RestoreInfo};13
use super::lanes::{Admit, Lanes, RestoreInfo};14
use super::{14
use super::{15
MCP_POLL_INTERVAL, MCP_WAIT_LIMIT, StartRequest, demo, kills, mcp_bridge, mcp_config_directory,15
MCP_POLL_INTERVAL, MCP_WAIT_LIMIT, demo, kills, mcp_bridge, mcp_config_directory,16
message_context, open_run_session, raise_notice, store as run_store,16
message_context, open_run_session, raise_notice, store as run_store,17
};17
};18
use crate::app_state::AppState;18
use crate::app_state::AppState;@@ -249,6 +249,17 @@ pub struct AgentRunsHandle(pub Entity<AgentRuns>);249
249
250
impl Global for AgentRunsHandle {}250
impl Global for AgentRunsHandle {}251
251
252
#[derive(Clone, Debug, PartialEq, Eq)]253
pub struct StartRequest {254
pub action_id: String,255
pub conversation_id: String,256
pub message_id: String,257
}258
259
pub fn needs_dialog(action: &AgentAction, chat_allowed: bool) -> bool {260
action.ask_extra_instructions || !chat_allowed261
}262
252
pub enum AgentRunsEvent {263
pub enum AgentRunsEvent {253
Finished(u64),264
Finished(u64),254
StartRequested(StartRequest),265
StartRequested(StartRequest),@@ -1137,10 +1148,19 @@ pub(super) mod tests {1137
1148
1138
use super::{1149
use super::{1139
AgentRun, AgentRuns, RunState, SessionTarget, StartOptions, Utc, api_retry_text,1150
AgentRun, AgentRuns, RunState, SessionTarget, StartOptions, Utc, api_retry_text,1140
format_elapsed, run_store,1151
format_elapsed, needs_dialog, run_store,1141
};1152
};1142
use crate::app_state::{AppState, Mode};1153
use crate::app_state::{AppState, Mode};1143
1154
1155
#[test]1156
fn the_dialog_shows_for_extra_instructions_or_a_chat_agents_cannot_see() {1157
let quiet = AgentAction::answer_this("claude");1158
let asking = AgentAction::build_this("claude");1159
assert!(!needs_dialog(&quiet, true));1160
assert!(needs_dialog(&quiet, false));1161
assert!(needs_dialog(&asking, true));1162
}1163
1144
pub fn finished_run(id: u64) -> AgentRun {1164
pub fn finished_run(id: u64) -> AgentRun {1145
AgentRun {1165
AgentRun {1146
id,1166
id,@@ -6,8 +6,7 @@ use gpui_kit::*;
6
6
7
7
use super::runs::{AgentRun, AgentRuns, RunState};
8
8
use super::spinner::spinner;
9
use crate::app_state::AppState;
10
use crate::notify::selection_for;
9
use crate::app_state::{AppState, selection_for};
11
10
use crate::theme;
12
11
use crate::views::widgets::icon;
13
12
@@ -6,8 +6,7 @@ use gpui_kit::*;6
6
7
use super::runs::{AgentRun, AgentRuns, RunState};7
use super::runs::{AgentRun, AgentRuns, RunState};8
use super::spinner::spinner;8
use super::spinner::spinner;9
use crate::app_state::AppState;9
use crate::app_state::{AppState, selection_for};10
use crate::notify::selection_for;11
use crate::theme;10
use crate::theme;12
use crate::views::widgets::icon;11
use crate::views::widgets::icon;13
12
@@ -11,7 +11,7 @@ use gpui_kit::component::{
11
11
use gpui_kit::prelude::FluentBuilder as _;
12
12
use gpui_kit::*;
13
13
14
use super::runs::{SessionTarget, StartOptions};
14
use super::runs::{SessionTarget, StartOptions, StartRequest};
15
15
use super::session_options::{
16
16
SessionOption, default_wsl_distro, external_options, load_external, mark_live_runs, run_options,
17
17
};
@@ -39,13 +39,6 @@ const DISABLED_OPACITY: f32 = 0.5;
39
39
const DEFAULT_PLACEHOLDER: &str = "e.g. only the backend, open a PR when done";
40
40
const SESSION_PLACEHOLDER: &str = "Type the message to send";
41
41
42
#[derive(Clone, Debug, PartialEq, Eq)]
43
pub struct StartRequest {
44
pub action_id: String,
45
pub conversation_id: String,
46
pub message_id: String,
47
}
48
49
42
pub enum StartDialogEvent {
50
43
Close,
51
44
}
@@ -74,10 +67,6 @@ pub struct StartDialog {
74
67
75
68
impl EventEmitter<StartDialogEvent> for StartDialog {}
76
69
77
pub fn needs_dialog(action: &AgentAction, chat_allowed: bool) -> bool {
78
action.ask_extra_instructions || !chat_allowed
79
}
80
81
70
impl StartDialog {
82
71
pub fn new(
83
72
app: Entity<AppState>,
@@ -705,19 +694,3 @@ impl Render for StartDialog {
705
694
)
706
695
}
707
696
}
708
709
#[cfg(test)]
710
mod tests {
711
use agents::AgentAction;
712
713
use super::needs_dialog;
714
715
#[test]
716
fn the_dialog_shows_for_extra_instructions_or_a_chat_agents_cannot_see() {
717
let quiet = AgentAction::answer_this("claude");
718
let asking = AgentAction::build_this("claude");
719
assert!(!needs_dialog(&quiet, true));
720
assert!(needs_dialog(&quiet, false));
721
assert!(needs_dialog(&asking, true));
722
}
723
}
@@ -11,7 +11,7 @@ use gpui_kit::component::{11
use gpui_kit::prelude::FluentBuilder as _;11
use gpui_kit::prelude::FluentBuilder as _;12
use gpui_kit::*;12
use gpui_kit::*;13
13
14
use super::runs::{SessionTarget, StartOptions};14
use super::runs::{SessionTarget, StartOptions, StartRequest};15
use super::session_options::{15
use super::session_options::{16
SessionOption, default_wsl_distro, external_options, load_external, mark_live_runs, run_options,16
SessionOption, default_wsl_distro, external_options, load_external, mark_live_runs, run_options,17
};17
};@@ -39,13 +39,6 @@ const DISABLED_OPACITY: f32 = 0.5;39
const DEFAULT_PLACEHOLDER: &str = "e.g. only the backend, open a PR when done";39
const DEFAULT_PLACEHOLDER: &str = "e.g. only the backend, open a PR when done";40
const SESSION_PLACEHOLDER: &str = "Type the message to send";40
const SESSION_PLACEHOLDER: &str = "Type the message to send";41
41
42
#[derive(Clone, Debug, PartialEq, Eq)]43
pub struct StartRequest {44
pub action_id: String,45
pub conversation_id: String,46
pub message_id: String,47
}48
49
pub enum StartDialogEvent {42
pub enum StartDialogEvent {50
Close,43
Close,51
}44
}@@ -74,10 +67,6 @@ pub struct StartDialog {74
67
75
impl EventEmitter<StartDialogEvent> for StartDialog {}68
impl EventEmitter<StartDialogEvent> for StartDialog {}76
69
77
pub fn needs_dialog(action: &AgentAction, chat_allowed: bool) -> bool {78
action.ask_extra_instructions || !chat_allowed79
}80
81
impl StartDialog {70
impl StartDialog {82
pub fn new(71
pub fn new(83
app: Entity<AppState>,72
app: Entity<AppState>,@@ -705,19 +694,3 @@ impl Render for StartDialog {705
)694
)706
}695
}707
}696
}708
709
#[cfg(test)]710
mod tests {711
use agents::AgentAction;712
713
use super::needs_dialog;714
715
#[test]716
fn the_dialog_shows_for_extra_instructions_or_a_chat_agents_cannot_see() {717
let quiet = AgentAction::answer_this("claude");718
let asking = AgentAction::build_this("claude");719
assert!(!needs_dialog(&quiet, true));720
assert!(needs_dialog(&quiet, false));721
assert!(needs_dialog(&asking, true));722
}723
}@@ -149,8 +149,8 @@ pub struct AppState {
149
149
pub meeting_toasts: crate::call::MeetingToasts,
150
150
pub demo_meetings: Vec<chatsvc::CalendarEvent>,
151
151
pub call_backgrounds: crate::call::BackgroundLibrary,
152
pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,
153
pub transcript_panel: Option<Entity<crate::views::call_transcript::TranscriptPanel>>,
152
pub transfer_picker: Option<AnyView>,
153
pub transcript_panel: Option<AnyView>,
154
154
pub rings: Rings,
155
155
pub live_meetings: HashMap<String, LiveMeeting>,
156
156
pub live_refreshing: HashSet<String>,
@@ -164,6 +164,18 @@ impl Global for AppHandle {}
164
164
165
165
impl EventEmitter<AppEvent> for AppState {}
166
166
167
pub fn selection_for(sidebar: &Sidebar, conversation_id: &str) -> Option<Selection> {
168
if sidebar.chats.iter().any(|chat| chat.id == conversation_id) {
169
return Some(Selection::Chat(conversation_id.to_owned()));
170
}
171
sidebar
172
.teams
173
.iter()
174
.flat_map(|team| team.channels.iter())
175
.any(|channel| channel.id == conversation_id)
176
.then(|| Selection::Channel(conversation_id.to_owned()))
177
}
178
167
179
pub fn chat_title(chat: &ChatRecord) -> String {
168
180
chat.display_title()
169
181
}
@@ -944,7 +956,7 @@ mod tests {
944
956
};
945
957
use teams_core::CoreEvent;
946
958
947
use super::{AppState, Mode, Selection, chat_title, selection_title};
959
use super::{AppState, Mode, Selection, chat_title, selection_for, selection_title};
948
960
use crate::backend::BackendEvent;
949
961
use crate::data::Person;
950
962
use store::Sidebar;
@@ -962,6 +974,19 @@ mod tests {
962
974
}
963
975
}
964
976
977
#[test]
978
fn selection_kind_follows_sidebar() {
979
assert_eq!(
980
selection_for(&sidebar(), "c1"),
981
Some(Selection::Chat("c1".into()))
982
);
983
assert_eq!(
984
selection_for(&sidebar(), "ch"),
985
Some(Selection::Channel("ch".into()))
986
);
987
assert_eq!(selection_for(&sidebar(), "x"), None);
988
}
989
965
990
fn sidebar() -> Sidebar {
966
991
Sidebar {
967
992
chats: vec![chat("c1", "First", true), chat("c2", "", false)],
@@ -149,8 +149,8 @@ pub struct AppState {149
pub meeting_toasts: crate::call::MeetingToasts,149
pub meeting_toasts: crate::call::MeetingToasts,150
pub demo_meetings: Vec<chatsvc::CalendarEvent>,150
pub demo_meetings: Vec<chatsvc::CalendarEvent>,151
pub call_backgrounds: crate::call::BackgroundLibrary,151
pub call_backgrounds: crate::call::BackgroundLibrary,152
pub transfer_picker: Option<Entity<crate::views::transfer_picker::TransferPicker>>,152
pub transfer_picker: Option<AnyView>,153
pub transcript_panel: Option<Entity<crate::views::call_transcript::TranscriptPanel>>,153
pub transcript_panel: Option<AnyView>,154
pub rings: Rings,154
pub rings: Rings,155
pub live_meetings: HashMap<String, LiveMeeting>,155
pub live_meetings: HashMap<String, LiveMeeting>,156
pub live_refreshing: HashSet<String>,156
pub live_refreshing: HashSet<String>,@@ -164,6 +164,18 @@ impl Global for AppHandle {}164
164
165
impl EventEmitter<AppEvent> for AppState {}165
impl EventEmitter<AppEvent> for AppState {}166
166
167
pub fn selection_for(sidebar: &Sidebar, conversation_id: &str) -> Option<Selection> {168
if sidebar.chats.iter().any(|chat| chat.id == conversation_id) {169
return Some(Selection::Chat(conversation_id.to_owned()));170
}171
sidebar172
.teams173
.iter()174
.flat_map(|team| team.channels.iter())175
.any(|channel| channel.id == conversation_id)176
.then(|| Selection::Channel(conversation_id.to_owned()))177
}178
167
pub fn chat_title(chat: &ChatRecord) -> String {179
pub fn chat_title(chat: &ChatRecord) -> String {168
chat.display_title()180
chat.display_title()169
}181
}@@ -944,7 +956,7 @@ mod tests {944
};956
};945
use teams_core::CoreEvent;957
use teams_core::CoreEvent;946
958
947
use super::{AppState, Mode, Selection, chat_title, selection_title};959
use super::{AppState, Mode, Selection, chat_title, selection_for, selection_title};948
use crate::backend::BackendEvent;960
use crate::backend::BackendEvent;949
use crate::data::Person;961
use crate::data::Person;950
use store::Sidebar;962
use store::Sidebar;@@ -962,6 +974,19 @@ mod tests {962
}974
}963
}975
}964
976
977
#[test]978
fn selection_kind_follows_sidebar() {979
assert_eq!(980
selection_for(&sidebar(), "c1"),981
Some(Selection::Chat("c1".into()))982
);983
assert_eq!(984
selection_for(&sidebar(), "ch"),985
Some(Selection::Channel("ch".into()))986
);987
assert_eq!(selection_for(&sidebar(), "x"), None);988
}989
965
fn sidebar() -> Sidebar {990
fn sidebar() -> Sidebar {966
Sidebar {991
Sidebar {967
chats: vec![chat("c1", "First", true), chat("c2", "", false)],992
chats: vec![chat("c1", "First", true), chat("c2", "", false)],@@ -24,9 +24,8 @@ use super::report::{
24
24
};
25
25
use super::ring::{MissedCall, RingOutcome};
26
26
use super::target::{is_organizer, plan_for_chat};
27
use crate::app_state::{AppEvent, AppState, Selection, chat_title};
27
use crate::app_state::{AppEvent, AppState, Selection, chat_title, selection_for};
28
28
use crate::notice::NoticeAction;
29
use crate::notify::selection_for;
30
29
31
30
const TIMER_REFRESH: Duration = Duration::from_millis(500);
32
31
const SHARE_SOURCES_EVERY_TICKS: u32 = 10;
@@ -24,9 +24,8 @@ use super::report::{24
};24
};25
use super::ring::{MissedCall, RingOutcome};25
use super::ring::{MissedCall, RingOutcome};26
use super::target::{is_organizer, plan_for_chat};26
use super::target::{is_organizer, plan_for_chat};27
use crate::app_state::{AppEvent, AppState, Selection, chat_title};27
use crate::app_state::{AppEvent, AppState, Selection, chat_title, selection_for};28
use crate::notice::NoticeAction;28
use crate::notice::NoticeAction;29
use crate::notify::selection_for;30
29
31
const TIMER_REFRESH: Duration = Duration::from_millis(500);30
const TIMER_REFRESH: Duration = Duration::from_millis(500);32
const SHARE_SOURCES_EVERY_TICKS: u32 = 10;31
const SHARE_SOURCES_EVERY_TICKS: u32 = 10;@@ -5,8 +5,7 @@ use chrono::{DateTime, Local, Offset, Utc};
5
5
use gpui_kit::Context;
6
6
7
7
use super::agenda::{AgendaRow, demo_events};
8
use crate::app_state::{AppEvent, AppState, Selection};
9
use crate::notify::selection_for;
8
use crate::app_state::{AppEvent, AppState, Selection, selection_for};
10
9
11
10
const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";
12
11
static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();
@@ -5,8 +5,7 @@ use chrono::{DateTime, Local, Offset, Utc};5
use gpui_kit::Context;5
use gpui_kit::Context;6
6
7
use super::agenda::{AgendaRow, demo_events};7
use super::agenda::{AgendaRow, demo_events};8
use crate::app_state::{AppEvent, AppState, Selection};8
use crate::app_state::{AppEvent, AppState, Selection, selection_for};9
use crate::notify::selection_for;10
9
11
const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";10
const NO_MEETING_CHAT_NOTICE: &str = "This meeting chat is not available";12
static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();11
static DEMO_ANCHOR: OnceLock<DateTime<Utc>> = OnceLock::new();@@ -11,7 +11,6 @@ use super::recording_menu::RecordAction;
11
11
use super::target::plan_for_chat;
12
12
use crate::app_state::{AppEvent, AppState};
13
13
use crate::data::is_one_on_one;
14
use crate::views::call_transcript::TranscriptPanel;
15
14
16
15
const DEMO_ROOM_GUESTS: usize = 3;
17
16
@@ -60,7 +59,7 @@ impl AppState {
60
59
61
60
pub fn open_call_transcript(
62
61
&mut self,
63
panel: Entity<TranscriptPanel>,
62
panel: AnyView,
64
63
cx: &mut Context<Self>,
65
64
) {
66
65
self.transcript_panel = Some(panel);
@@ -215,7 +214,7 @@ impl AppState {
215
214
216
215
pub fn open_transfer_picker(
217
216
&mut self,
218
picker: Entity<crate::views::transfer_picker::TransferPicker>,
217
picker: AnyView,
219
218
cx: &mut Context<Self>,
220
219
) {
221
220
if self.can_transfer_call() {
@@ -11,7 +11,6 @@ use super::recording_menu::RecordAction;11
use super::target::plan_for_chat;11
use super::target::plan_for_chat;12
use crate::app_state::{AppEvent, AppState};12
use crate::app_state::{AppEvent, AppState};13
use crate::data::is_one_on_one;13
use crate::data::is_one_on_one;14
use crate::views::call_transcript::TranscriptPanel;15
14
16
const DEMO_ROOM_GUESTS: usize = 3;15
const DEMO_ROOM_GUESTS: usize = 3;17
16
@@ -60,7 +59,7 @@ impl AppState {60
59
61
pub fn open_call_transcript(60
pub fn open_call_transcript(62
&mut self,61
&mut self,63
panel: Entity<TranscriptPanel>,62
panel: AnyView,64
cx: &mut Context<Self>,63
cx: &mut Context<Self>,65
) {64
) {66
self.transcript_panel = Some(panel);65
self.transcript_panel = Some(panel);@@ -215,7 +214,7 @@ impl AppState {215
214
216
pub fn open_transfer_picker(215
pub fn open_transfer_picker(217
&mut self,216
&mut self,218
picker: Entity<crate::views::transfer_picker::TransferPicker>,217
picker: AnyView,219
cx: &mut Context<Self>,218
cx: &mut Context<Self>,220
) {219
) {221
if self.can_transfer_call() {220
if self.can_transfer_call() {@@ -8,8 +8,7 @@ use teams_core::{
8
8
use super::actions::{MEETING_UNAVAILABLE_NOTICE, NOT_CONNECTED_NOTICE};
9
9
use super::launcher::NOT_READY;
10
10
use super::prejoin::{DemoMeeting, MeetingJoin};
11
use crate::app_state::{AppState, selection_title};
12
use crate::notify::selection_for;
11
use crate::app_state::{AppState, selection_for, selection_title};
13
12
use crate::runtime;
14
13
15
14
const NO_LINK_NOTICE: &str = "No Teams meeting link in the clipboard";
@@ -8,8 +8,7 @@ use teams_core::{8
use super::actions::{MEETING_UNAVAILABLE_NOTICE, NOT_CONNECTED_NOTICE};8
use super::actions::{MEETING_UNAVAILABLE_NOTICE, NOT_CONNECTED_NOTICE};9
use super::launcher::NOT_READY;9
use super::launcher::NOT_READY;10
use super::prejoin::{DemoMeeting, MeetingJoin};10
use super::prejoin::{DemoMeeting, MeetingJoin};11
use crate::app_state::{AppState, selection_title};11
use crate::app_state::{AppState, selection_for, selection_title};12
use crate::notify::selection_for;13
use crate::runtime;12
use crate::runtime;14
13
15
const NO_LINK_NOTICE: &str = "No Teams meeting link in the clipboard";14
const NO_LINK_NOTICE: &str = "No Teams meeting link in the clipboard";@@ -20,7 +20,7 @@ mod view_actions;
20
20
use app_call_model::{
21
21
agenda, background, bubbles, caption_style, demo, fullscreen, health, media, mic,
22
22
model, options_dialog, people, preview, record_rights,
23
recording_menu, report, ring, share_view, stage_layout, transcript, view_settings,
23
recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,
24
24
};
25
25
26
26
pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};
@@ -57,7 +57,11 @@ pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAU
57
57
pub use preview::{CameraPreview, preview_backgrounds};
58
58
pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};
59
59
pub use ring::{MissedCall, RingEntry, Rings};
60
pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, contain_size, filmstrip, focus_stage_size, gallery_grid, share_strip, split_overflow};
60
pub use stage_split::{
61
GRID_PADDING, STRIP_GAP, SpeakerSplit, StripSplit, TILE_GAP, gallery_split,
62
measured_stage, speaker_split, strip_split, video_wants,
63
};
64
pub use stage_layout::{contain_size, focus_stage_size, gallery_grid};
61
65
pub use schedule::{FormValues, Invitee, default_window, draft_from_form};
62
66
pub use record_rights::{RecordBlock, RecordFeature};
63
67
pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};
@@ -20,7 +20,7 @@ mod view_actions;20
use app_call_model::{20
use app_call_model::{21
agenda, background, bubbles, caption_style, demo, fullscreen, health, media, mic,21
agenda, background, bubbles, caption_style, demo, fullscreen, health, media, mic,22
model, options_dialog, people, preview, record_rights,22
model, options_dialog, people, preview, record_rights,23
recording_menu, report, ring, share_view, stage_layout, transcript, view_settings,23
recording_menu, report, ring, share_view, stage_layout, stage_split, transcript, view_settings,24
};24
};25
25
26
pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};26
pub use actions::{load_camera, load_camera_effects, load_input, load_output, load_share_sound};@@ -57,7 +57,11 @@ pub use share_view::{SHARE_MOTION_META_KEY, SHARE_STANDOUT_META_KEY, STRIP_DEFAU57
pub use preview::{CameraPreview, preview_backgrounds};57
pub use preview::{CameraPreview, preview_backgrounds};58
pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};58
pub use reminder::{MeetingToasts, subtitle as meeting_subtitle};59
pub use ring::{MissedCall, RingEntry, Rings};59
pub use ring::{MissedCall, RingEntry, Rings};60
pub use stage_layout::{FILMSTRIP_MAX, Filmstrip, GALLERY_MAX, Overflow, contain_size, filmstrip, focus_stage_size, gallery_grid, share_strip, split_overflow};60
pub use stage_split::{61
GRID_PADDING, STRIP_GAP, SpeakerSplit, StripSplit, TILE_GAP, gallery_split,62
measured_stage, speaker_split, strip_split, video_wants,63
};64
pub use stage_layout::{contain_size, focus_stage_size, gallery_grid};61
pub use schedule::{FormValues, Invitee, default_window, draft_from_form};65
pub use schedule::{FormValues, Invitee, default_window, draft_from_form};62
pub use record_rights::{RecordBlock, RecordFeature};66
pub use record_rights::{RecordBlock, RecordFeature};63
pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};67
pub use recording_menu::{RecordAction, RecordingChip, record_actions, recording_chip};@@ -114,7 +114,7 @@ impl AppState {
114
114
115
115
pub fn open_invite_picker(
116
116
&mut self,
117
picker: Entity<crate::views::transfer_picker::TransferPicker>,
117
picker: AnyView,
118
118
cx: &mut Context<Self>,
119
119
) {
120
120
if self.call.as_ref().is_some_and(|call| call.model.can_invite()) {
@@ -114,7 +114,7 @@ impl AppState {114
114
115
pub fn open_invite_picker(115
pub fn open_invite_picker(116
&mut self,116
&mut self,117
picker: Entity<crate::views::transfer_picker::TransferPicker>,117
picker: AnyView,118
cx: &mut Context<Self>,118
cx: &mut Context<Self>,119
) {119
) {120
if self.call.as_ref().is_some_and(|call| call.model.can_invite()) {120
if self.call.as_ref().is_some_and(|call| call.model.can_invite()) {@@ -4,11 +4,11 @@ use calling::CallCommand;
4
4
use gpui_kit::*;
5
5
6
6
use super::caption_style::{CaptionPosition, CaptionSize};
7
use super::{measured_stage, video_wants};
7
8
use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};
8
9
use super::fullscreen::{FullscreenState, HINT_SHOWN};
9
10
use super::view_settings::{CallLayout, ViewSettings};
10
11
use crate::app_state::{AppEvent, AppState};
11
use crate::views::call_layouts::{measured_stage, video_wants};
12
12
13
13
const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);
14
14
const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);
@@ -4,11 +4,11 @@ use calling::CallCommand;4
use gpui_kit::*;4
use gpui_kit::*;5
5
6
use super::caption_style::{CaptionPosition, CaptionSize};6
use super::caption_style::{CaptionPosition, CaptionSize};7
use super::{measured_stage, video_wants};7
use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};8
use super::bubbles::{BUBBLE_SHOWN, ChatBubble, push_bubble};8
use super::fullscreen::{FullscreenState, HINT_SHOWN};9
use super::fullscreen::{FullscreenState, HINT_SHOWN};9
use super::view_settings::{CallLayout, ViewSettings};10
use super::view_settings::{CallLayout, ViewSettings};10
use crate::app_state::{AppEvent, AppState};11
use crate::app_state::{AppEvent, AppState};11
use crate::views::call_layouts::{measured_stage, video_wants};12
12
13
const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);13
const CHROME_TOUCH_THROTTLE: Duration = Duration::from_millis(250);14
const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);14
const DEMO_BUBBLE_START: Duration = Duration::from_secs(8);@@ -442,6 +442,19 @@ pub fn others(chat: &ChatRecord, me: Option<&Person>) -> Vec<(Option<String>, St
442
442
.collect()
443
443
}
444
444
445
pub fn existing_one_on_one<'chats>(
446
chats: &'chats [ChatRecord],
447
me: Option<&Person>,
448
user_id: &str,
449
) -> Option<&'chats ChatRecord> {
450
chats.iter().find(|chat| {
451
is_one_on_one(chat)
452
&& others(chat, me)
453
.iter()
454
.any(|(member_id, _)| member_id.as_deref() == Some(user_id))
455
})
456
}
457
445
458
pub fn face_members(chat: &ChatRecord, me: Option<&Person>) -> Vec<(Option<String>, String)> {
446
459
others(chat, me)
447
460
.into_iter()
@@ -442,6 +442,19 @@ pub fn others(chat: &ChatRecord, me: Option<&Person>) -> Vec<(Option<String>, St442
.collect()442
.collect()443
}443
}444
444
445
pub fn existing_one_on_one<'chats>(446
chats: &'chats [ChatRecord],447
me: Option<&Person>,448
user_id: &str,449
) -> Option<&'chats ChatRecord> {450
chats.iter().find(|chat| {451
is_one_on_one(chat)452
&& others(chat, me)453
.iter()454
.any(|(member_id, _)| member_id.as_deref() == Some(user_id))455
})456
}457
445
pub fn face_members(chat: &ChatRecord, me: Option<&Person>) -> Vec<(Option<String>, String)> {458
pub fn face_members(chat: &ChatRecord, me: Option<&Person>) -> Vec<(Option<String>, String)> {446
others(chat, me)459
others(chat, me)447
.into_iter()460
.into_iter()@@ -596,7 +596,7 @@ mod frames {
596
596
call.transcript_open = true;
597
597
state.call = Some(call);
598
598
let app_entity = cx.entity();
599
state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)));
599
state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)).into());
600
600
cx.notify();
601
601
})
602
602
});
@@ -596,7 +596,7 @@ mod frames {596
call.transcript_open = true;596
call.transcript_open = true;597
state.call = Some(call);597
state.call = Some(call);598
let app_entity = cx.entity();598
let app_entity = cx.entity();599
state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)));599
state.transcript_panel = Some(cx.new(|cx| TranscriptPanel::new(app_entity, window, cx)).into());600
cx.notify();600
cx.notify();601
})601
})602
});602
});@@ -27,6 +27,7 @@ mod message_actions;
27
27
mod notice;
28
28
mod notify;
29
29
mod outbox;
30
mod outgoing;
30
31
mod own_status;
31
32
mod pending_rows;
32
33
mod people;
@@ -48,7 +49,7 @@ pub use app_ui_kit::render;
48
49
pub use app_base::{
49
50
APP_NAME, assets, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
50
51
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,
51
image_view_math, presence_link, read_state, recap, remote_image, runtime, schedule_time,
52
image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,
52
53
single_instance, stickers, theme, translation, updater, user_activity,
53
54
};
54
55
@@ -27,6 +27,7 @@ mod message_actions;27
mod notice;27
mod notice;28
mod notify;28
mod notify;29
mod outbox;29
mod outbox;30
mod outgoing;30
mod own_status;31
mod own_status;31
mod pending_rows;32
mod pending_rows;32
mod people;33
mod people;@@ -48,7 +49,7 @@ pub use app_ui_kit::render;48
pub use app_base::{49
pub use app_base::{49
APP_NAME, assets, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,50
APP_NAME, assets, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,50
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,51
demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,51
image_view_math, presence_link, read_state, recap, remote_image, runtime, schedule_time,52
image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,52
single_instance, stickers, theme, translation, updater, user_activity,53
single_instance, stickers, theme, translation, updater, user_activity,53
};54
};54
55
@@ -5,11 +5,10 @@ use gpui_kit::*;
5
5
use store::MessageRecord;
6
6
use teams_core::{PinnedMessage, SavedMessage};
7
7
8
use crate::app_state::{AppEvent, AppState, Selection};
8
use crate::app_state::{AppEvent, AppState, Selection, selection_for};
9
9
use crate::format;
10
10
use crate::image_view_gallery::ViewerRequest;
11
11
use crate::notice::short_error;
12
use crate::notify::selection_for;
13
12
use crate::rows::{message_text, reply_excerpt};
14
13
use crate::runtime;
15
14
@@ -5,11 +5,10 @@ use gpui_kit::*;5
use store::MessageRecord;5
use store::MessageRecord;6
use teams_core::{PinnedMessage, SavedMessage};6
use teams_core::{PinnedMessage, SavedMessage};7
7
8
use crate::app_state::{AppEvent, AppState, Selection};8
use crate::app_state::{AppEvent, AppState, Selection, selection_for};9
use crate::format;9
use crate::format;10
use crate::image_view_gallery::ViewerRequest;10
use crate::image_view_gallery::ViewerRequest;11
use crate::notice::short_error;11
use crate::notice::short_error;12
use crate::notify::selection_for;13
use crate::rows::{message_text, reply_excerpt};12
use crate::rows::{message_text, reply_excerpt};14
use crate::runtime;13
use crate::runtime;15
14
@@ -23,7 +23,7 @@ use super::stack::{
23
23
use super::text::describe;
24
24
use super::toast::{PillView, ToastView};
25
25
use crate::agents::{AgentRun, AgentRunsEvent, RunState};
26
use crate::app_state::{AppEvent, AppState, Selection};
26
use crate::app_state::{AppEvent, AppState, selection_for};
27
27
use crate::call::DemoScene;
28
28
use crate::data::{self, Directory, PresenceKind};
29
29
use crate::runtime;
@@ -1173,18 +1173,6 @@ fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
1173
1173
}
1174
1174
}
1175
1175
1176
pub fn selection_for(sidebar: &Sidebar, conversation_id: &str) -> Option<Selection> {
1177
if sidebar.chats.iter().any(|chat| chat.id == conversation_id) {
1178
return Some(Selection::Chat(conversation_id.to_owned()));
1179
}
1180
sidebar
1181
.teams
1182
.iter()
1183
.flat_map(|team| team.channels.iter())
1184
.any(|channel| channel.id == conversation_id)
1185
.then(|| Selection::Channel(conversation_id.to_owned()))
1186
}
1187
1188
1176
pub fn unread_summary(
1189
1177
sidebar: &Sidebar,
1190
1178
unread_mentions: &HashSet<String>,
@@ -1284,8 +1272,7 @@ mod tests {
1284
1272
1285
1273
use std::collections::HashSet;
1286
1274
1287
use super::{preview_lines, selection_for, unread_summary};
1288
use crate::app_state::Selection;
1275
use super::{preview_lines, unread_summary};
1289
1276
use store::Sidebar;
1290
1277
1291
1278
fn sidebar() -> Sidebar {
@@ -1340,19 +1327,6 @@ mod tests {
1340
1327
assert_eq!(count, 2);
1341
1328
}
1342
1329
1343
#[test]
1344
fn selection_kind_follows_sidebar() {
1345
assert_eq!(
1346
selection_for(&sidebar(), "a"),
1347
Some(Selection::Chat("a".into()))
1348
);
1349
assert_eq!(
1350
selection_for(&sidebar(), "ch"),
1351
Some(Selection::Channel("ch".into()))
1352
);
1353
assert_eq!(selection_for(&sidebar(), "x"), None);
1354
}
1355
1356
1330
#[gpui_kit::test]
1357
1331
fn preview_lines_follow_the_wrapped_text(cx: &mut gpui_kit::TestAppContext) {
1358
1332
cx.update(|cx| {
@@ -23,7 +23,7 @@ use super::stack::{23
use super::text::describe;23
use super::text::describe;24
use super::toast::{PillView, ToastView};24
use super::toast::{PillView, ToastView};25
use crate::agents::{AgentRun, AgentRunsEvent, RunState};25
use crate::agents::{AgentRun, AgentRunsEvent, RunState};26
use crate::app_state::{AppEvent, AppState, Selection};26
use crate::app_state::{AppEvent, AppState, selection_for};27
use crate::call::DemoScene;27
use crate::call::DemoScene;28
use crate::data::{self, Directory, PresenceKind};28
use crate::data::{self, Directory, PresenceKind};29
use crate::runtime;29
use crate::runtime;@@ -1173,18 +1173,6 @@ fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {1173
}1173
}1174
}1174
}1175
1175
1176
pub fn selection_for(sidebar: &Sidebar, conversation_id: &str) -> Option<Selection> {1177
if sidebar.chats.iter().any(|chat| chat.id == conversation_id) {1178
return Some(Selection::Chat(conversation_id.to_owned()));1179
}1180
sidebar1181
.teams1182
.iter()1183
.flat_map(|team| team.channels.iter())1184
.any(|channel| channel.id == conversation_id)1185
.then(|| Selection::Channel(conversation_id.to_owned()))1186
}1187
1188
pub fn unread_summary(1176
pub fn unread_summary(1189
sidebar: &Sidebar,1177
sidebar: &Sidebar,1190
unread_mentions: &HashSet<String>,1178
unread_mentions: &HashSet<String>,@@ -1284,8 +1272,7 @@ mod tests {1284
1272
1285
use std::collections::HashSet;1273
use std::collections::HashSet;1286
1274
1287
use super::{preview_lines, selection_for, unread_summary};1275
use super::{preview_lines, unread_summary};1288
use crate::app_state::Selection;1289
use store::Sidebar;1276
use store::Sidebar;1290
1277
1291
fn sidebar() -> Sidebar {1278
fn sidebar() -> Sidebar {@@ -1340,19 +1327,6 @@ mod tests {1340
assert_eq!(count, 2);1327
assert_eq!(count, 2);1341
}1328
}1342
1329
1343
#[test]1344
fn selection_kind_follows_sidebar() {1345
assert_eq!(1346
selection_for(&sidebar(), "a"),1347
Some(Selection::Chat("a".into()))1348
);1349
assert_eq!(1350
selection_for(&sidebar(), "ch"),1351
Some(Selection::Channel("ch".into()))1352
);1353
assert_eq!(selection_for(&sidebar(), "x"), None);1354
}1355
1356
#[gpui_kit::test]1330
#[gpui_kit::test]1357
fn preview_lines_follow_the_wrapped_text(cx: &mut gpui_kit::TestAppContext) {1331
fn preview_lines_follow_the_wrapped_text(cx: &mut gpui_kit::TestAppContext) {1358
cx.update(|cx| {1332
cx.update(|cx| {@@ -13,7 +13,7 @@ mod text;
13
13
mod toast;
14
14
15
15
pub use app_base::notify::{badge, platform, ring_tone};
16
pub use center::{NotificationCenter, selection_for};
16
pub use center::NotificationCenter;
17
17
pub use incoming::{IncomingTracker, preview_of};
18
18
#[cfg(windows)]
19
19
pub use platform::native_handle;
@@ -13,7 +13,7 @@ mod text;13
mod toast;13
mod toast;14
14
15
pub use app_base::notify::{badge, platform, ring_tone};15
pub use app_base::notify::{badge, platform, ring_tone};16
pub use center::{NotificationCenter, selection_for};16
pub use center::NotificationCenter;17
pub use incoming::{IncomingTracker, preview_of};17
pub use incoming::{IncomingTracker, preview_of};18
#[cfg(windows)]18
#[cfg(windows)]19
pub use platform::native_handle;19
pub use platform::native_handle;@@ -11,7 +11,7 @@ use crate::backend::Engine;
11
11
use crate::notice::short_error;
12
12
use crate::runtime;
13
13
use crate::stored_outgoing::{decode, encode};
14
use crate::views::composer::Outgoing;
14
use crate::outgoing::Outgoing;
15
15
16
16
const RETRY_BACKOFF: [Duration; 3] = [
17
17
Duration::from_secs(2),
@@ -11,7 +11,7 @@ use crate::backend::Engine;11
use crate::notice::short_error;11
use crate::notice::short_error;12
use crate::runtime;12
use crate::runtime;13
use crate::stored_outgoing::{decode, encode};13
use crate::stored_outgoing::{decode, encode};14
use crate::views::composer::Outgoing;14
use crate::outgoing::Outgoing;15
15
16
const RETRY_BACKOFF: [Duration; 3] = [16
const RETRY_BACKOFF: [Duration; 3] = [17
Duration::from_secs(2),17
Duration::from_secs(2),@@ -0,0 +1,117 @@
1
use std::sync::Arc;
2
3
use chrono::{DateTime, Utc};
4
use gpui_kit::Image;
5
use serde::{Deserialize, Serialize};
6
use teams_core::{
7
Draft, FileKind, FileReference, HostedImage, LinkPreview, MentionInput, MessageExtras,
8
OBJECT_MARK, UploadedFile,
9
};
10
11
use crate::remote_image::RemoteImage;
12
13
#[derive(Debug, Clone, PartialEq, Eq)]
14
pub struct InlineImage {
15
pub name: String,
16
pub image: Arc<Image>,
17
pub dimensions: Option<(u32, u32)>,
18
}
19
20
/// One object in the text: uploaded bytes or a GIF or sticker the message links to.
21
#[derive(Debug, Clone, PartialEq, Eq)]
22
pub enum OutgoingImage {
23
Inline(InlineImage),
24
Remote(RemoteImage),
25
}
26
27
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28
pub struct OutgoingFile {
29
pub name: String,
30
pub size: u64,
31
pub kind: FileKind,
32
pub reference: FileReference,
33
pub uploaded: Option<UploadedFile>,
34
}
35
36
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37
pub struct ReplyPreview {
38
pub message_id: String,
39
pub author: String,
40
pub excerpt: String,
41
}
42
43
#[derive(Debug, Clone, PartialEq, Eq)]
44
pub struct EditPreview {
45
pub message_id: String,
46
pub excerpt: String,
47
pub scheduled: Option<DateTime<Utc>>,
48
}
49
50
#[derive(Debug, Clone, PartialEq, Eq)]
51
pub struct Outgoing {
52
pub draft: Draft,
53
pub subject: Option<String>,
54
pub mentions: Vec<MentionInput>,
55
pub reply: Option<ReplyPreview>,
56
pub edit: Option<EditPreview>,
57
pub images: Vec<OutgoingImage>,
58
pub files: Vec<OutgoingFile>,
59
pub link_preview: Option<LinkPreview>,
60
}
61
62
impl Outgoing {
63
/// Without list and quote markers, for previews.
64
pub fn text(&self) -> String {
65
self.draft.plain_text()
66
}
67
68
/// The body before mentions become `<at>` tags.
69
pub fn html(&self) -> String {
70
let mut html = String::new();
71
let mut objects = self.images.iter();
72
let mut uploaded = 0;
73
for character in self.draft.to_html().chars() {
74
if character != OBJECT_MARK {
75
html.push(character);
76
continue;
77
}
78
match objects.next() {
79
Some(OutgoingImage::Inline(_)) => {
80
uploaded += 1;
81
html.push_str(&format!(
82
"<img src=\"../hostedContents/{uploaded}/$value\">"
83
));
84
}
85
Some(OutgoingImage::Remote(remote)) => html.push_str(&remote.html()),
86
None => {}
87
}
88
}
89
html
90
}
91
92
pub fn has_attachments(&self) -> bool {
93
!self.images.is_empty() || !self.files.is_empty()
94
}
95
96
pub fn extras(&self) -> MessageExtras {
97
MessageExtras {
98
kept: Vec::new(),
99
images: self
100
.images
101
.iter()
102
.filter_map(|outgoing| match outgoing {
103
OutgoingImage::Inline(inline) => Some(HostedImage {
104
content_type: inline.image.format.mime_type().to_owned(),
105
bytes: Arc::new(inline.image.bytes.clone()),
106
}),
107
OutgoingImage::Remote(_) => None,
108
})
109
.collect(),
110
files: self
111
.files
112
.iter()
113
.map(|file| file.reference.clone())
114
.collect(),
115
}
116
}
117
}
@@ -0,0 +1,117 @@1
use std::sync::Arc;2
3
use chrono::{DateTime, Utc};4
use gpui_kit::Image;5
use serde::{Deserialize, Serialize};6
use teams_core::{7
Draft, FileKind, FileReference, HostedImage, LinkPreview, MentionInput, MessageExtras,8
OBJECT_MARK, UploadedFile,9
};10
11
use crate::remote_image::RemoteImage;12
13
#[derive(Debug, Clone, PartialEq, Eq)]14
pub struct InlineImage {15
pub name: String,16
pub image: Arc<Image>,17
pub dimensions: Option<(u32, u32)>,18
}19
20
/// One object in the text: uploaded bytes or a GIF or sticker the message links to.21
#[derive(Debug, Clone, PartialEq, Eq)]22
pub enum OutgoingImage {23
Inline(InlineImage),24
Remote(RemoteImage),25
}26
27
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]28
pub struct OutgoingFile {29
pub name: String,30
pub size: u64,31
pub kind: FileKind,32
pub reference: FileReference,33
pub uploaded: Option<UploadedFile>,34
}35
36
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]37
pub struct ReplyPreview {38
pub message_id: String,39
pub author: String,40
pub excerpt: String,41
}42
43
#[derive(Debug, Clone, PartialEq, Eq)]44
pub struct EditPreview {45
pub message_id: String,46
pub excerpt: String,47
pub scheduled: Option<DateTime<Utc>>,48
}49
50
#[derive(Debug, Clone, PartialEq, Eq)]51
pub struct Outgoing {52
pub draft: Draft,53
pub subject: Option<String>,54
pub mentions: Vec<MentionInput>,55
pub reply: Option<ReplyPreview>,56
pub edit: Option<EditPreview>,57
pub images: Vec<OutgoingImage>,58
pub files: Vec<OutgoingFile>,59
pub link_preview: Option<LinkPreview>,60
}61
62
impl Outgoing {63
/// Without list and quote markers, for previews.64
pub fn text(&self) -> String {65
self.draft.plain_text()66
}67
68
/// The body before mentions become `<at>` tags.69
pub fn html(&self) -> String {70
let mut html = String::new();71
let mut objects = self.images.iter();72
let mut uploaded = 0;73
for character in self.draft.to_html().chars() {74
if character != OBJECT_MARK {75
html.push(character);76
continue;77
}78
match objects.next() {79
Some(OutgoingImage::Inline(_)) => {80
uploaded += 1;81
html.push_str(&format!(82
"<img src=\"../hostedContents/{uploaded}/$value\">"83
));84
}85
Some(OutgoingImage::Remote(remote)) => html.push_str(&remote.html()),86
None => {}87
}88
}89
html90
}91
92
pub fn has_attachments(&self) -> bool {93
!self.images.is_empty() || !self.files.is_empty()94
}95
96
pub fn extras(&self) -> MessageExtras {97
MessageExtras {98
kept: Vec::new(),99
images: self100
.images101
.iter()102
.filter_map(|outgoing| match outgoing {103
OutgoingImage::Inline(inline) => Some(HostedImage {104
content_type: inline.image.format.mime_type().to_owned(),105
bytes: Arc::new(inline.image.bytes.clone()),106
}),107
OutgoingImage::Remote(_) => None,108
})109
.collect(),110
files: self111
.files112
.iter()113
.map(|file| file.reference.clone())114
.collect(),115
}116
}117
}@@ -3,8 +3,7 @@ use teams_core::{FileCard, QuoteInfo};
3
3
4
4
use crate::render::{Block, layout_blocks};
5
5
use crate::rows::{Delivery, LocalImage, MessageRow, Receipt, Series};
6
use crate::views::attachment_tray::OutgoingImage;
7
use crate::views::composer::Outgoing;
6
use crate::outgoing::{Outgoing, OutgoingImage};
8
7
9
8
fn pending_blocks(outgoing: &Outgoing) -> Vec<Block> {
10
9
let quote = outgoing.reply.as_ref().map(|reply| {
@@ -93,7 +92,7 @@ mod tests {
93
92
use teams_core::Draft;
94
93
95
94
use super::*;
96
use crate::views::composer::ReplyPreview;
95
use crate::outgoing::ReplyPreview;
97
96
98
97
#[test]
99
98
fn a_pending_reply_shows_its_quote_before_the_server_echo() {
@@ -3,8 +3,7 @@ use teams_core::{FileCard, QuoteInfo};3
3
4
use crate::render::{Block, layout_blocks};4
use crate::render::{Block, layout_blocks};5
use crate::rows::{Delivery, LocalImage, MessageRow, Receipt, Series};5
use crate::rows::{Delivery, LocalImage, MessageRow, Receipt, Series};6
use crate::views::attachment_tray::OutgoingImage;6
use crate::outgoing::{Outgoing, OutgoingImage};7
use crate::views::composer::Outgoing;8
7
9
fn pending_blocks(outgoing: &Outgoing) -> Vec<Block> {8
fn pending_blocks(outgoing: &Outgoing) -> Vec<Block> {10
let quote = outgoing.reply.as_ref().map(|reply| {9
let quote = outgoing.reply.as_ref().map(|reply| {@@ -93,7 +92,7 @@ mod tests {93
use teams_core::Draft;92
use teams_core::Draft;94
93
95
use super::*;94
use super::*;96
use crate::views::composer::ReplyPreview;95
use crate::outgoing::ReplyPreview;97
96
98
#[test]97
#[test]99
fn a_pending_reply_shows_its_quote_before_the_server_echo() {98
fn a_pending_reply_shows_its_quote_before_the_server_echo() {@@ -6,10 +6,10 @@ use gpui_kit::*;
6
6
use teams_core::PersonProfile;
7
7
8
8
use crate::app_state::{AppEvent, AppState, Selection};
9
use crate::data::existing_one_on_one;
9
10
use crate::demo_profiles;
10
11
use crate::notice::short_error;
11
12
use crate::profile_model::is_stale;
12
use crate::views::new_chat::existing_one_on_one;
13
13
14
14
#[derive(Default)]
15
15
pub struct ProfileEntry {
@@ -6,10 +6,10 @@ use gpui_kit::*;6
use teams_core::PersonProfile;6
use teams_core::PersonProfile;7
7
8
use crate::app_state::{AppEvent, AppState, Selection};8
use crate::app_state::{AppEvent, AppState, Selection};9
use crate::data::existing_one_on_one;9
use crate::demo_profiles;10
use crate::demo_profiles;10
use crate::notice::short_error;11
use crate::notice::short_error;11
use crate::profile_model::is_stale;12
use crate::profile_model::is_stale;12
use crate::views::new_chat::existing_one_on_one;13
13
14
#[derive(Default)]14
#[derive(Default)]15
pub struct ProfileEntry {15
pub struct ProfileEntry {@@ -5,7 +5,7 @@ use crate::pending_rows::pending_row;
5
5
use crate::rows::{Delivery, MessageRow, ScheduledState};
6
6
use crate::schedule_time::describe;
7
7
use crate::scheduled::{conversation_of, thread_root_of};
8
use crate::views::composer::Outgoing;
8
use crate::outgoing::Outgoing;
9
9
10
10
pub const SCHEDULED_KEY_PREFIX: &str = "scheduled-";
11
11
@@ -5,7 +5,7 @@ use crate::pending_rows::pending_row;5
use crate::rows::{Delivery, MessageRow, ScheduledState};5
use crate::rows::{Delivery, MessageRow, ScheduledState};6
use crate::schedule_time::describe;6
use crate::schedule_time::describe;7
use crate::scheduled::{conversation_of, thread_root_of};7
use crate::scheduled::{conversation_of, thread_root_of};8
use crate::views::composer::Outgoing;8
use crate::outgoing::Outgoing;9
9
10
pub const SCHEDULED_KEY_PREFIX: &str = "scheduled-";10
pub const SCHEDULED_KEY_PREFIX: &str = "scheduled-";11
11
@@ -6,8 +6,7 @@ use store::AttachmentImage;
6
6
use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};
7
7
8
8
use crate::remote_image::{RemoteImage, RemoteKind};
9
use crate::views::attachment_tray::{InlineImage, OutgoingFile, OutgoingImage};
10
use crate::views::composer::{Outgoing, ReplyPreview};
9
use crate::outgoing::{InlineImage, Outgoing, OutgoingFile, OutgoingImage, ReplyPreview};
11
10
12
11
const IMAGE_FORMATS: [ImageFormat; 9] = [
13
12
ImageFormat::Png,
@@ -6,8 +6,7 @@ use store::AttachmentImage;6
use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};6
use teams_core::{Draft, DraftLine, LinkPreview, MentionInput};7
7
8
use crate::remote_image::{RemoteImage, RemoteKind};8
use crate::remote_image::{RemoteImage, RemoteKind};9
use crate::views::attachment_tray::{InlineImage, OutgoingFile, OutgoingImage};9
use crate::outgoing::{InlineImage, Outgoing, OutgoingFile, OutgoingImage, ReplyPreview};10
use crate::views::composer::{Outgoing, ReplyPreview};11
10
12
const IMAGE_FORMATS: [ImageFormat; 9] = [11
const IMAGE_FORMATS: [ImageFormat; 9] = [13
ImageFormat::Png,12
ImageFormat::Png,@@ -0,0 +1,20 @@
1
use gpui_kit::*;
2
3
pub const COMPOSER_KEY_CONTEXT: &str = "Composer";
4
5
actions!(
6
composer,
7
[
8
ToggleBold,
9
ToggleItalic,
10
ToggleUnderline,
11
ToggleStrike,
12
ToggleSuperscript,
13
ToggleSubscript,
14
ToggleCode,
15
EditLink,
16
ScheduleSend
17
]
18
);
19
20
actions!(teams, [ReplyToHovered, OpenSwitcher, NewChat, ToggleCallMute]);
@@ -0,0 +1,20 @@1
use gpui_kit::*;2
3
pub const COMPOSER_KEY_CONTEXT: &str = "Composer";4
5
actions!(6
composer,7
[8
ToggleBold,9
ToggleItalic,10
ToggleUnderline,11
ToggleStrike,12
ToggleSuperscript,13
ToggleSubscript,14
ToggleCode,15
EditLink,16
ScheduleSend17
]18
);19
20
actions!(teams, [ReplyToHovered, OpenSwitcher, NewChat, ToggleCallMute]);@@ -7,12 +7,13 @@ use gpui_kit::assets::IconName;
7
7
use gpui_kit::component::{h_flex, v_flex};
8
8
use gpui_kit::prelude::FluentBuilder as _;
9
9
use gpui_kit::*;
10
use serde::{Deserialize, Serialize};
11
10
use teams_core::{FileKind, FileReference, UploadedFile};
12
11
13
12
use super::attachments::file_badge;
14
13
use super::widgets::icon;
15
14
use crate::format;
15
use crate::inline_image::{InlineFormat, image_dimensions, sniff_inline_format};
16
pub use crate::outgoing::{InlineImage, OutgoingFile, OutgoingImage};
16
17
use crate::remote_image::{RemoteImage, image_source};
17
18
use crate::theme;
18
19
@@ -33,58 +34,6 @@ const CHIP_REMOVE_SIZE: f32 = 28.;
33
34
const TRAY_GAP: f32 = 8.;
34
35
const PROGRESS_HEIGHT: f32 = 2.;
35
36
36
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
37
pub enum InlineFormat {
38
Png,
39
Jpeg,
40
Gif,
41
Webp,
42
}
43
44
impl InlineFormat {
45
fn image_format(self) -> ImageFormat {
46
match self {
47
InlineFormat::Png => ImageFormat::Png,
48
InlineFormat::Jpeg => ImageFormat::Jpeg,
49
InlineFormat::Gif => ImageFormat::Gif,
50
InlineFormat::Webp => ImageFormat::Webp,
51
}
52
}
53
54
fn decoder_format(self) -> Option<image::ImageFormat> {
55
match self {
56
InlineFormat::Png => Some(image::ImageFormat::Png),
57
InlineFormat::Jpeg => Some(image::ImageFormat::Jpeg),
58
InlineFormat::Webp => Some(image::ImageFormat::WebP),
59
InlineFormat::Gif => None,
60
}
61
}
62
}
63
64
pub fn sniff_inline_format(bytes: &[u8]) -> Option<InlineFormat> {
65
match bytes {
66
[0x89, b'P', b'N', b'G', ..] => Some(InlineFormat::Png),
67
[0xFF, 0xD8, 0xFF, ..] => Some(InlineFormat::Jpeg),
68
[b'G', b'I', b'F', b'8', ..] => Some(InlineFormat::Gif),
69
[
70
b'R',
71
b'I',
72
b'F',
73
b'F',
74
_,
75
_,
76
_,
77
_,
78
b'W',
79
b'E',
80
b'B',
81
b'P',
82
..,
83
] => Some(InlineFormat::Webp),
84
_ => None,
85
}
86
}
87
88
37
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
89
38
pub enum Classification {
90
39
Inline(InlineFormat),
@@ -107,25 +56,6 @@ pub fn classify(name: &str, bytes: &[u8], inline_used: u64) -> Classification {
107
56
}
108
57
}
109
58
110
fn image_dimensions(format: InlineFormat, bytes: &[u8]) -> Option<(u32, u32)> {
111
match format.decoder_format() {
112
Some(decoder) => image::ImageReader::with_format(Cursor::new(bytes), decoder)
113
.into_dimensions()
114
.ok(),
115
None => {
116
let header = bytes.get(6..10)?;
117
Some((
118
u32::from(u16::from_le_bytes([header[0], header[1]])),
119
u32::from(u16::from_le_bytes([header[2], header[3]])),
120
))
121
}
122
}
123
}
124
125
pub fn dimensions_of(bytes: &[u8]) -> Option<(u32, u32)> {
126
image_dimensions(sniff_inline_format(bytes)?, bytes)
127
}
128
129
59
pub fn inline_image(name: String, bytes: Vec<u8>) -> Option<InlineImage> {
130
60
let format = sniff_inline_format(&bytes)?;
131
61
let dimensions = image_dimensions(format, &bytes);
@@ -241,29 +171,6 @@ impl PreviewImage {
241
171
242
172
pub type RemoveImage = Rc<dyn Fn(&mut Window, &mut App)>;
243
173
244
#[derive(Debug, Clone, PartialEq, Eq)]
245
pub struct InlineImage {
246
pub name: String,
247
pub image: Arc<Image>,
248
pub dimensions: Option<(u32, u32)>,
249
}
250
251
/// One object in the text: uploaded bytes or a GIF or sticker the message links to.
252
#[derive(Debug, Clone, PartialEq, Eq)]
253
pub enum OutgoingImage {
254
Inline(InlineImage),
255
Remote(RemoteImage),
256
}
257
258
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
259
pub struct OutgoingFile {
260
pub name: String,
261
pub size: u64,
262
pub kind: FileKind,
263
pub reference: FileReference,
264
pub uploaded: Option<UploadedFile>,
265
}
266
267
174
#[derive(Debug, Clone)]
268
175
pub enum JobKind {
269
176
Upload,
@@ -7,12 +7,13 @@ use gpui_kit::assets::IconName;7
use gpui_kit::component::{h_flex, v_flex};7
use gpui_kit::component::{h_flex, v_flex};8
use gpui_kit::prelude::FluentBuilder as _;8
use gpui_kit::prelude::FluentBuilder as _;9
use gpui_kit::*;9
use gpui_kit::*;10
use serde::{Deserialize, Serialize};11
use teams_core::{FileKind, FileReference, UploadedFile};10
use teams_core::{FileKind, FileReference, UploadedFile};12
11
13
use super::attachments::file_badge;12
use super::attachments::file_badge;14
use super::widgets::icon;13
use super::widgets::icon;15
use crate::format;14
use crate::format;15
use crate::inline_image::{InlineFormat, image_dimensions, sniff_inline_format};16
pub use crate::outgoing::{InlineImage, OutgoingFile, OutgoingImage};16
use crate::remote_image::{RemoteImage, image_source};17
use crate::remote_image::{RemoteImage, image_source};17
use crate::theme;18
use crate::theme;18
19
@@ -33,58 +34,6 @@ const CHIP_REMOVE_SIZE: f32 = 28.;33
const TRAY_GAP: f32 = 8.;34
const TRAY_GAP: f32 = 8.;34
const PROGRESS_HEIGHT: f32 = 2.;35
const PROGRESS_HEIGHT: f32 = 2.;35
36
36
#[derive(Debug, Clone, Copy, PartialEq, Eq)]37
pub enum InlineFormat {38
Png,39
Jpeg,40
Gif,41
Webp,42
}43
44
impl InlineFormat {45
fn image_format(self) -> ImageFormat {46
match self {47
InlineFormat::Png => ImageFormat::Png,48
InlineFormat::Jpeg => ImageFormat::Jpeg,49
InlineFormat::Gif => ImageFormat::Gif,50
InlineFormat::Webp => ImageFormat::Webp,51
}52
}53
54
fn decoder_format(self) -> Option<image::ImageFormat> {55
match self {56
InlineFormat::Png => Some(image::ImageFormat::Png),57
InlineFormat::Jpeg => Some(image::ImageFormat::Jpeg),58
InlineFormat::Webp => Some(image::ImageFormat::WebP),59
InlineFormat::Gif => None,60
}61
}62
}63
64
pub fn sniff_inline_format(bytes: &[u8]) -> Option<InlineFormat> {65
match bytes {66
[0x89, b'P', b'N', b'G', ..] => Some(InlineFormat::Png),67
[0xFF, 0xD8, 0xFF, ..] => Some(InlineFormat::Jpeg),68
[b'G', b'I', b'F', b'8', ..] => Some(InlineFormat::Gif),69
[70
b'R',71
b'I',72
b'F',73
b'F',74
_,75
_,76
_,77
_,78
b'W',79
b'E',80
b'B',81
b'P',82
..,83
] => Some(InlineFormat::Webp),84
_ => None,85
}86
}87
88
#[derive(Debug, Clone, Copy, PartialEq, Eq)]37
#[derive(Debug, Clone, Copy, PartialEq, Eq)]89
pub enum Classification {38
pub enum Classification {90
Inline(InlineFormat),39
Inline(InlineFormat),@@ -107,25 +56,6 @@ pub fn classify(name: &str, bytes: &[u8], inline_used: u64) -> Classification {107
}56
}108
}57
}109
58
110
fn image_dimensions(format: InlineFormat, bytes: &[u8]) -> Option<(u32, u32)> {111
match format.decoder_format() {112
Some(decoder) => image::ImageReader::with_format(Cursor::new(bytes), decoder)113
.into_dimensions()114
.ok(),115
None => {116
let header = bytes.get(6..10)?;117
Some((118
u32::from(u16::from_le_bytes([header[0], header[1]])),119
u32::from(u16::from_le_bytes([header[2], header[3]])),120
))121
}122
}123
}124
125
pub fn dimensions_of(bytes: &[u8]) -> Option<(u32, u32)> {126
image_dimensions(sniff_inline_format(bytes)?, bytes)127
}128
129
pub fn inline_image(name: String, bytes: Vec<u8>) -> Option<InlineImage> {59
pub fn inline_image(name: String, bytes: Vec<u8>) -> Option<InlineImage> {130
let format = sniff_inline_format(&bytes)?;60
let format = sniff_inline_format(&bytes)?;131
let dimensions = image_dimensions(format, &bytes);61
let dimensions = image_dimensions(format, &bytes);@@ -241,29 +171,6 @@ impl PreviewImage {241
171
242
pub type RemoveImage = Rc<dyn Fn(&mut Window, &mut App)>;172
pub type RemoveImage = Rc<dyn Fn(&mut Window, &mut App)>;243
173
244
#[derive(Debug, Clone, PartialEq, Eq)]245
pub struct InlineImage {246
pub name: String,247
pub image: Arc<Image>,248
pub dimensions: Option<(u32, u32)>,249
}250
251
/// One object in the text: uploaded bytes or a GIF or sticker the message links to.252
#[derive(Debug, Clone, PartialEq, Eq)]253
pub enum OutgoingImage {254
Inline(InlineImage),255
Remote(RemoteImage),256
}257
258
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]259
pub struct OutgoingFile {260
pub name: String,261
pub size: u64,262
pub kind: FileKind,263
pub reference: FileReference,264
pub uploaded: Option<UploadedFile>,265
}266
267
#[derive(Debug, Clone)]174
#[derive(Debug, Clone)]268
pub enum JobKind {175
pub enum JobKind {269
Upload,176
Upload,@@ -302,14 +302,14 @@ pub fn open_transfer_picker(app: &Entity<AppState>, window: &mut Window, cx: &mu
302
302
let candidates = app.read(cx).transfer_candidates();
303
303
let picker_app = app.clone();
304
304
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Transfer, window, cx));
305
app.update(cx, |state, cx| state.open_transfer_picker(picker, cx));
305
app.update(cx, |state, cx| state.open_transfer_picker(picker.into(), cx));
306
306
}
307
307
308
308
pub fn open_invite_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {
309
309
let candidates = app.read(cx).invite_candidates();
310
310
let picker_app = app.clone();
311
311
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Invite, window, cx));
312
app.update(cx, |state, cx| state.open_invite_picker(picker, cx));
312
app.update(cx, |state, cx| state.open_invite_picker(picker.into(), cx));
313
313
}
314
314
315
315
#[derive(Clone)]
@@ -302,14 +302,14 @@ pub fn open_transfer_picker(app: &Entity<AppState>, window: &mut Window, cx: &mu302
let candidates = app.read(cx).transfer_candidates();302
let candidates = app.read(cx).transfer_candidates();303
let picker_app = app.clone();303
let picker_app = app.clone();304
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Transfer, window, cx));304
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Transfer, window, cx));305
app.update(cx, |state, cx| state.open_transfer_picker(picker, cx));305
app.update(cx, |state, cx| state.open_transfer_picker(picker.into(), cx));306
}306
}307
307
308
pub fn open_invite_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {308
pub fn open_invite_picker(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {309
let candidates = app.read(cx).invite_candidates();309
let candidates = app.read(cx).invite_candidates();310
let picker_app = app.clone();310
let picker_app = app.clone();311
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Invite, window, cx));311
let picker = cx.new(|cx| TransferPicker::new(picker_app, candidates, PickerMode::Invite, window, cx));312
app.update(cx, |state, cx| state.open_invite_picker(picker, cx));312
app.update(cx, |state, cx| state.open_invite_picker(picker.into(), cx));313
}313
}314
314
315
#[derive(Clone)]315
#[derive(Clone)]@@ -13,25 +13,21 @@ use gpui_kit::*;
13
13
14
14
use super::avatar::person_avatar;
15
15
use super::call_organizer::render_focus_stage;
16
use super::call_view::{
17
GRID_PADDING, STRIP_GAP, TILE_GAP, own_tile, person_tile,
18
};
16
use super::call_view::{own_tile, person_tile};
19
17
use super::widgets::icon;
20
18
use crate::app_state::AppState;
21
19
use crate::call::{
22
ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,
23
filmstrip, focus_stage_size, gallery_grid, share_strip, shown_bubbles, split_overflow,
20
ActiveCall, CallLayout, CallModel, GRID_PADDING, STRIP_GAP, SpeakerSplit,
21
StripSplit, TILE_GAP, Tile, TileSize, focus_stage_size, gallery_grid, gallery_split,
22
measured_stage, shown_bubbles, speaker_split, strip_split,
24
23
};
25
use calling::{TileDetail, VideoWant};
26
24
use crate::theme;
27
25
28
const FALLBACK_STAGE: (f32, f32) = (900., 560.);
29
26
const MEASURE_TOLERANCE: f32 = 0.5;
30
27
const OVERLAY_INSET: f32 = 16.;
31
28
const DIVIDER_LINE: f32 = 4.;
32
29
const DIVIDER_LENGTH: f32 = 48.;
33
30
const CHIP_TOP: f32 = 12.;
34
const FILMSTRIP_TILE_MAX: f32 = 220.;
35
31
const TILE_RADIUS: f32 = 12.;
36
32
const HIDDEN_LIST_WIDTH: f32 = 260.;
37
33
const HIDDEN_LIST_HEIGHT: f32 = 320.;
@@ -46,14 +42,6 @@ const BUBBLE_BACKGROUND: f32 = 0.72;
46
42
const CHIP_BACKGROUND: f32 = 0.6;
47
43
pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";
48
44
49
pub fn measured_stage(call: &ActiveCall) -> (f32, f32) {
50
let (width, height) = call.stage_size.get();
51
if width < 1. || height < 1. {
52
return FALLBACK_STAGE;
53
}
54
(width, height)
55
}
56
57
45
fn measure_stage(call: &ActiveCall) -> impl IntoElement {
58
46
let stage_size = call.stage_size.clone();
59
47
canvas(
@@ -360,12 +348,6 @@ fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {
360
348
}
361
349
}
362
350
363
fn gallery_split(model: &CallModel) -> (Vec<&Tile>, Overflow) {
364
let others = model.layout_tiles();
365
let overflow = split_overflow(others.len(), model.own_cells(), GALLERY_MAX);
366
(others, overflow)
367
}
368
369
351
fn gallery_body(
370
352
app: &Entity<AppState>,
371
353
state: &AppState,
@@ -407,35 +389,6 @@ fn gallery_body(
407
389
.into_any_element()
408
390
}
409
391
410
struct SpeakerSplit<'a> {
411
focus: Option<Focus>,
412
others: Vec<&'a Tile>,
413
own_cells: usize,
414
plan: Filmstrip,
415
}
416
417
fn speaker_split(model: &CallModel, stage: (f32, f32)) -> SpeakerSplit<'_> {
418
let focus = model.speaker_focus();
419
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());
420
let mut others: Vec<&Tile> = model
421
.layout_tiles()
422
.into_iter()
423
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)
424
.collect();
425
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));
426
let plan = filmstrip(
427
others.len(),
428
own_cells,
429
stage.0 - 2. * GRID_PADDING,
430
TILE_GAP,
431
FILMSTRIP_TILE_MAX,
432
);
433
if plan.overflow.shown < FILMSTRIP_MAX.min(others.len()) {
434
others.sort_by_key(|tile| !model.is_recent_speaker(&tile.mri));
435
}
436
SpeakerSplit { focus, others, own_cells, plan }
437
}
438
439
392
fn speaker_body(
440
393
app: &Entity<AppState>,
441
394
state: &AppState,
@@ -497,24 +450,6 @@ fn speaker_body(
497
450
.into_any_element()
498
451
}
499
452
500
struct StripSplit<'a> {
501
width: f32,
502
others: Vec<&'a Tile>,
503
plan: Filmstrip,
504
}
505
506
fn strip_split(model: &CallModel, strip_width: f32, stage: (f32, f32)) -> StripSplit<'_> {
507
let available = (stage.0 - 2. * GRID_PADDING, (stage.1 - 2. * GRID_PADDING).max(0.));
508
let width = strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));
509
let others: Vec<&Tile> = model
510
.strip_tiles()
511
.into_iter()
512
.filter(|tile| !model.hidden_for_no_video(tile))
513
.collect();
514
let plan = share_strip(others.len(), model.own_cells(), (width, available.1), STRIP_GAP);
515
StripSplit { width, others, plan }
516
}
517
518
453
fn people_strip(
519
454
app: &Entity<AppState>,
520
455
state: &AppState,
@@ -606,38 +541,6 @@ fn share_body(
606
541
.into_any_element()
607
542
}
608
543
609
const LARGE_GALLERY_TILES: usize = 4;
610
611
fn want(tile: &Tile, detail: TileDetail) -> VideoWant {
612
VideoWant { mri: tile.mri.clone(), detail }
613
}
614
615
pub fn video_wants(model: &CallModel, stage: (f32, f32), strip_width: f32) -> Vec<VideoWant> {
616
if model.has_content() {
617
if model.effective_layout() == CallLayout::Content {
618
return Vec::new();
619
}
620
let split = strip_split(model, strip_width, stage);
621
return split.others[..split.plan.overflow.shown]
622
.iter()
623
.map(|tile| want(tile, TileDetail::Small))
624
.collect();
625
}
626
if model.effective_layout() == CallLayout::Speaker {
627
let split = speaker_split(model, stage);
628
let stage_person = split.focus.iter().filter(|focus| !focus.own).map(|focus| VideoWant {
629
mri: focus.mri.clone(),
630
detail: TileDetail::Stage,
631
});
632
return stage_person
633
.chain(split.others[..split.plan.overflow.shown].iter().map(|tile| want(tile, TileDetail::Small)))
634
.collect();
635
}
636
let (others, overflow) = gallery_split(model);
637
let detail = if overflow.shown <= LARGE_GALLERY_TILES { TileDetail::Stage } else { TileDetail::Small };
638
others[..overflow.shown].iter().map(|tile| want(tile, detail)).collect()
639
}
640
641
544
pub(super) fn stage_region(
642
545
app: &Entity<AppState>,
643
546
state: &AppState,
@@ -676,117 +579,3 @@ pub(super) fn stage_region(
676
579
)
677
580
.into_any_element()
678
581
}
679
680
#[cfg(test)]
681
mod tests {
682
use std::time::Instant;
683
684
use calling::{CallUpdate, RosterEntry, TileDetail, VideoWant};
685
686
use super::{
687
CallLayout, CallModel, FILMSTRIP_TILE_MAX, GALLERY_MAX, GRID_PADDING, TILE_GAP, filmstrip, split_overflow,
688
video_wants,
689
};
690
use crate::call::STRIP_DEFAULT_WIDTH;
691
692
const STAGE: (f32, f32) = (1400., 800.);
693
694
fn person(index: usize, has_video: bool) -> RosterEntry {
695
RosterEntry {
696
mri: format!("8:orgid:p{index}"),
697
display_name: format!("P{index}"),
698
muted: false,
699
in_lobby: false,
700
has_video,
701
sharing: false,
702
hand: None,
703
spotlight: None,
704
organizer: false,
705
role: None,
706
limits: Default::default(),
707
}
708
}
709
710
fn meeting(people: Vec<RosterEntry>) -> CallModel {
711
let mut model = CallModel::meeting("Standup", false);
712
model.apply(CallUpdate::OwnIdentity { mri: "8:orgid:me".into() });
713
model.apply(CallUpdate::Roster(people));
714
model
715
}
716
717
fn crowd(count: usize) -> CallModel {
718
meeting((0..count).map(|index| person(index, true)).collect())
719
}
720
721
fn details(wants: &[VideoWant]) -> Vec<TileDetail> {
722
wants.iter().map(|want| want.detail).collect()
723
}
724
725
#[test]
726
fn a_small_gallery_asks_for_large_pictures() {
727
let wants = video_wants(&crowd(3), STAGE, STRIP_DEFAULT_WIDTH);
728
assert_eq!(wants.len(), 3);
729
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Stage));
730
}
731
732
#[test]
733
fn a_big_gallery_asks_for_small_pictures_and_skips_the_plus_n_people() {
734
let model = crowd(14);
735
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
736
assert_eq!(wants.len(), split_overflow(14, 1, GALLERY_MAX).shown);
737
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
738
let hidden: Vec<&str> = model.layout_tiles()[wants.len()..].iter().map(|tile| tile.mri.as_str()).collect();
739
assert!(wants.iter().all(|want| !hidden.contains(&want.mri.as_str())));
740
}
741
742
#[test]
743
fn people_hidden_for_having_no_video_get_no_picture_request() {
744
let mut model = meeting(vec![person(0, true), person(1, false), person(2, false)]);
745
model.view.hide_no_video = true;
746
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
747
assert_eq!(wants.iter().map(|want| want.mri.as_str()).collect::<Vec<_>>(), vec!["8:orgid:p0"]);
748
}
749
750
#[test]
751
fn the_speaker_stage_is_large_and_the_filmstrip_small() {
752
let mut model = crowd(5);
753
model.view.choose(CallLayout::Speaker);
754
model.refresh_layout(Instant::now());
755
let focus = model.speaker_focus().expect("a stage person").mri;
756
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
757
assert_eq!(wants[0], VideoWant { mri: focus.clone(), detail: TileDetail::Stage });
758
assert_eq!(wants.len(), 5);
759
assert!(wants[1..].iter().all(|want| want.detail == TileDetail::Small && want.mri != focus));
760
}
761
762
#[test]
763
fn the_speaker_filmstrip_drops_people_that_do_not_fit() {
764
let mut model = crowd(12);
765
model.view.choose(CallLayout::Speaker);
766
model.refresh_layout(Instant::now());
767
let wants = video_wants(&model, (500., 800.), STRIP_DEFAULT_WIDTH);
768
let fitting = filmstrip(11, 1, 500. - 2. * GRID_PADDING, TILE_GAP, FILMSTRIP_TILE_MAX).overflow.shown;
769
assert!(fitting < 11);
770
assert_eq!(wants.len(), 1 + fitting);
771
}
772
773
#[test]
774
fn next_to_shared_content_everybody_in_the_strip_is_small_and_content_focus_wants_nobody() {
775
let mut model = crowd(3);
776
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
777
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);
778
assert_eq!(wants.len(), 3);
779
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));
780
model.view.choose(CallLayout::Content);
781
assert!(video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH).is_empty());
782
}
783
784
#[test]
785
fn a_full_share_strip_wants_video_for_every_shown_tile_and_none_behind_the_plus_tile() {
786
let mut model = crowd(9);
787
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));
788
assert_eq!(video_wants(&model, (1400., 1100.), STRIP_DEFAULT_WIDTH).len(), 9);
789
let short = video_wants(&model, (1400., 600.), STRIP_DEFAULT_WIDTH);
790
assert!(short.len() >= 3 && short.len() < 9, "{} wants", short.len());
791
}
792
}
@@ -13,25 +13,21 @@ use gpui_kit::*;13
13
14
use super::avatar::person_avatar;14
use super::avatar::person_avatar;15
use super::call_organizer::render_focus_stage;15
use super::call_organizer::render_focus_stage;16
use super::call_view::{16
use super::call_view::{own_tile, person_tile};17
GRID_PADDING, STRIP_GAP, TILE_GAP, own_tile, person_tile,18
};19
use super::widgets::icon;17
use super::widgets::icon;20
use crate::app_state::AppState;18
use crate::app_state::AppState;21
use crate::call::{19
use crate::call::{22
ActiveCall, CallLayout, CallModel, FILMSTRIP_MAX, Filmstrip, Focus, GALLERY_MAX, Overflow, Tile, TileSize,20
ActiveCall, CallLayout, CallModel, GRID_PADDING, STRIP_GAP, SpeakerSplit,23
filmstrip, focus_stage_size, gallery_grid, share_strip, shown_bubbles, split_overflow,21
StripSplit, TILE_GAP, Tile, TileSize, focus_stage_size, gallery_grid, gallery_split,22
measured_stage, shown_bubbles, speaker_split, strip_split,24
};23
};25
use calling::{TileDetail, VideoWant};26
use crate::theme;24
use crate::theme;27
25
28
const FALLBACK_STAGE: (f32, f32) = (900., 560.);29
const MEASURE_TOLERANCE: f32 = 0.5;26
const MEASURE_TOLERANCE: f32 = 0.5;30
const OVERLAY_INSET: f32 = 16.;27
const OVERLAY_INSET: f32 = 16.;31
const DIVIDER_LINE: f32 = 4.;28
const DIVIDER_LINE: f32 = 4.;32
const DIVIDER_LENGTH: f32 = 48.;29
const DIVIDER_LENGTH: f32 = 48.;33
const CHIP_TOP: f32 = 12.;30
const CHIP_TOP: f32 = 12.;34
const FILMSTRIP_TILE_MAX: f32 = 220.;35
const TILE_RADIUS: f32 = 12.;31
const TILE_RADIUS: f32 = 12.;36
const HIDDEN_LIST_WIDTH: f32 = 260.;32
const HIDDEN_LIST_WIDTH: f32 = 260.;37
const HIDDEN_LIST_HEIGHT: f32 = 320.;33
const HIDDEN_LIST_HEIGHT: f32 = 320.;@@ -46,14 +42,6 @@ const BUBBLE_BACKGROUND: f32 = 0.72;46
const CHIP_BACKGROUND: f32 = 0.6;42
const CHIP_BACKGROUND: f32 = 0.6;47
pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";43
pub const FULLSCREEN_HINT: &str = "Press Esc to exit full screen";48
44
49
pub fn measured_stage(call: &ActiveCall) -> (f32, f32) {50
let (width, height) = call.stage_size.get();51
if width < 1. || height < 1. {52
return FALLBACK_STAGE;53
}54
(width, height)55
}56
57
fn measure_stage(call: &ActiveCall) -> impl IntoElement {45
fn measure_stage(call: &ActiveCall) -> impl IntoElement {58
let stage_size = call.stage_size.clone();46
let stage_size = call.stage_size.clone();59
canvas(47
canvas(@@ -360,12 +348,6 @@ fn rows_of(cells: Vec<AnyElement>, columns: usize) -> Vec<Div> {360
}348
}361
}349
}362
350
363
fn gallery_split(model: &CallModel) -> (Vec<&Tile>, Overflow) {364
let others = model.layout_tiles();365
let overflow = split_overflow(others.len(), model.own_cells(), GALLERY_MAX);366
(others, overflow)367
}368
369
fn gallery_body(351
fn gallery_body(370
app: &Entity<AppState>,352
app: &Entity<AppState>,371
state: &AppState,353
state: &AppState,@@ -407,35 +389,6 @@ fn gallery_body(407
.into_any_element()389
.into_any_element()408
}390
}409
391
410
struct SpeakerSplit<'a> {411
focus: Option<Focus>,412
others: Vec<&'a Tile>,413
own_cells: usize,414
plan: Filmstrip,415
}416
417
fn speaker_split(model: &CallModel, stage: (f32, f32)) -> SpeakerSplit<'_> {418
let focus = model.speaker_focus();419
let focus_mri = focus.as_ref().map(|focus| focus.mri.as_str());420
let mut others: Vec<&Tile> = model421
.layout_tiles()422
.into_iter()423
.filter(|tile| Some(tile.mri.as_str()) != focus_mri)424
.collect();425
let own_cells = usize::from(model.own_cells() > 0 && !focus.as_ref().is_some_and(|f| f.own));426
let plan = filmstrip(427
others.len(),428
own_cells,429
stage.0 - 2. * GRID_PADDING,430
TILE_GAP,431
FILMSTRIP_TILE_MAX,432
);433
if plan.overflow.shown < FILMSTRIP_MAX.min(others.len()) {434
others.sort_by_key(|tile| !model.is_recent_speaker(&tile.mri));435
}436
SpeakerSplit { focus, others, own_cells, plan }437
}438
439
fn speaker_body(392
fn speaker_body(440
app: &Entity<AppState>,393
app: &Entity<AppState>,441
state: &AppState,394
state: &AppState,@@ -497,24 +450,6 @@ fn speaker_body(497
.into_any_element()450
.into_any_element()498
}451
}499
452
500
struct StripSplit<'a> {501
width: f32,502
others: Vec<&'a Tile>,503
plan: Filmstrip,504
}505
506
fn strip_split(model: &CallModel, strip_width: f32, stage: (f32, f32)) -> StripSplit<'_> {507
let available = (stage.0 - 2. * GRID_PADDING, (stage.1 - 2. * GRID_PADDING).max(0.));508
let width = strip_width.min(((available.0 - TILE_GAP) / 2.).max(0.));509
let others: Vec<&Tile> = model510
.strip_tiles()511
.into_iter()512
.filter(|tile| !model.hidden_for_no_video(tile))513
.collect();514
let plan = share_strip(others.len(), model.own_cells(), (width, available.1), STRIP_GAP);515
StripSplit { width, others, plan }516
}517
518
fn people_strip(453
fn people_strip(519
app: &Entity<AppState>,454
app: &Entity<AppState>,520
state: &AppState,455
state: &AppState,@@ -606,38 +541,6 @@ fn share_body(606
.into_any_element()541
.into_any_element()607
}542
}608
543
609
const LARGE_GALLERY_TILES: usize = 4;610
611
fn want(tile: &Tile, detail: TileDetail) -> VideoWant {612
VideoWant { mri: tile.mri.clone(), detail }613
}614
615
pub fn video_wants(model: &CallModel, stage: (f32, f32), strip_width: f32) -> Vec<VideoWant> {616
if model.has_content() {617
if model.effective_layout() == CallLayout::Content {618
return Vec::new();619
}620
let split = strip_split(model, strip_width, stage);621
return split.others[..split.plan.overflow.shown]622
.iter()623
.map(|tile| want(tile, TileDetail::Small))624
.collect();625
}626
if model.effective_layout() == CallLayout::Speaker {627
let split = speaker_split(model, stage);628
let stage_person = split.focus.iter().filter(|focus| !focus.own).map(|focus| VideoWant {629
mri: focus.mri.clone(),630
detail: TileDetail::Stage,631
});632
return stage_person633
.chain(split.others[..split.plan.overflow.shown].iter().map(|tile| want(tile, TileDetail::Small)))634
.collect();635
}636
let (others, overflow) = gallery_split(model);637
let detail = if overflow.shown <= LARGE_GALLERY_TILES { TileDetail::Stage } else { TileDetail::Small };638
others[..overflow.shown].iter().map(|tile| want(tile, detail)).collect()639
}640
641
pub(super) fn stage_region(544
pub(super) fn stage_region(642
app: &Entity<AppState>,545
app: &Entity<AppState>,643
state: &AppState,546
state: &AppState,@@ -676,117 +579,3 @@ pub(super) fn stage_region(676
)579
)677
.into_any_element()580
.into_any_element()678
}581
}679
680
#[cfg(test)]681
mod tests {682
use std::time::Instant;683
684
use calling::{CallUpdate, RosterEntry, TileDetail, VideoWant};685
686
use super::{687
CallLayout, CallModel, FILMSTRIP_TILE_MAX, GALLERY_MAX, GRID_PADDING, TILE_GAP, filmstrip, split_overflow,688
video_wants,689
};690
use crate::call::STRIP_DEFAULT_WIDTH;691
692
const STAGE: (f32, f32) = (1400., 800.);693
694
fn person(index: usize, has_video: bool) -> RosterEntry {695
RosterEntry {696
mri: format!("8:orgid:p{index}"),697
display_name: format!("P{index}"),698
muted: false,699
in_lobby: false,700
has_video,701
sharing: false,702
hand: None,703
spotlight: None,704
organizer: false,705
role: None,706
limits: Default::default(),707
}708
}709
710
fn meeting(people: Vec<RosterEntry>) -> CallModel {711
let mut model = CallModel::meeting("Standup", false);712
model.apply(CallUpdate::OwnIdentity { mri: "8:orgid:me".into() });713
model.apply(CallUpdate::Roster(people));714
model715
}716
717
fn crowd(count: usize) -> CallModel {718
meeting((0..count).map(|index| person(index, true)).collect())719
}720
721
fn details(wants: &[VideoWant]) -> Vec<TileDetail> {722
wants.iter().map(|want| want.detail).collect()723
}724
725
#[test]726
fn a_small_gallery_asks_for_large_pictures() {727
let wants = video_wants(&crowd(3), STAGE, STRIP_DEFAULT_WIDTH);728
assert_eq!(wants.len(), 3);729
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Stage));730
}731
732
#[test]733
fn a_big_gallery_asks_for_small_pictures_and_skips_the_plus_n_people() {734
let model = crowd(14);735
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);736
assert_eq!(wants.len(), split_overflow(14, 1, GALLERY_MAX).shown);737
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));738
let hidden: Vec<&str> = model.layout_tiles()[wants.len()..].iter().map(|tile| tile.mri.as_str()).collect();739
assert!(wants.iter().all(|want| !hidden.contains(&want.mri.as_str())));740
}741
742
#[test]743
fn people_hidden_for_having_no_video_get_no_picture_request() {744
let mut model = meeting(vec![person(0, true), person(1, false), person(2, false)]);745
model.view.hide_no_video = true;746
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);747
assert_eq!(wants.iter().map(|want| want.mri.as_str()).collect::<Vec<_>>(), vec!["8:orgid:p0"]);748
}749
750
#[test]751
fn the_speaker_stage_is_large_and_the_filmstrip_small() {752
let mut model = crowd(5);753
model.view.choose(CallLayout::Speaker);754
model.refresh_layout(Instant::now());755
let focus = model.speaker_focus().expect("a stage person").mri;756
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);757
assert_eq!(wants[0], VideoWant { mri: focus.clone(), detail: TileDetail::Stage });758
assert_eq!(wants.len(), 5);759
assert!(wants[1..].iter().all(|want| want.detail == TileDetail::Small && want.mri != focus));760
}761
762
#[test]763
fn the_speaker_filmstrip_drops_people_that_do_not_fit() {764
let mut model = crowd(12);765
model.view.choose(CallLayout::Speaker);766
model.refresh_layout(Instant::now());767
let wants = video_wants(&model, (500., 800.), STRIP_DEFAULT_WIDTH);768
let fitting = filmstrip(11, 1, 500. - 2. * GRID_PADDING, TILE_GAP, FILMSTRIP_TILE_MAX).overflow.shown;769
assert!(fitting < 11);770
assert_eq!(wants.len(), 1 + fitting);771
}772
773
#[test]774
fn next_to_shared_content_everybody_in_the_strip_is_small_and_content_focus_wants_nobody() {775
let mut model = crowd(3);776
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));777
let wants = video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH);778
assert_eq!(wants.len(), 3);779
assert!(details(&wants).iter().all(|detail| *detail == TileDetail::Small));780
model.view.choose(CallLayout::Content);781
assert!(video_wants(&model, STAGE, STRIP_DEFAULT_WIDTH).is_empty());782
}783
784
#[test]785
fn a_full_share_strip_wants_video_for_every_shown_tile_and_none_behind_the_plus_tile() {786
let mut model = crowd(9);787
model.apply(CallUpdate::ScreenShare(Some("8:orgid:p1".into())));788
assert_eq!(video_wants(&model, (1400., 1100.), STRIP_DEFAULT_WIDTH).len(), 9);789
let short = video_wants(&model, (1400., 600.), STRIP_DEFAULT_WIDTH);790
assert!(short.len() >= 3 && short.len() < 9, "{} wants", short.len());791
}792
}@@ -9,11 +9,11 @@ use super::call_mini_window::{
9
9
speaker_speaking, tinted_chip,
10
10
};
11
11
use super::call_view::status_line;
12
use super::message_row::ROW_PADDING;
13
12
use super::toolbar_placement::TimelineBounds;
14
13
use super::widgets::icon;
15
14
use crate::app_state::AppState;
16
15
use crate::theme;
16
use app_ui_kit::layout::ROW_PADDING;
17
17
18
18
const MINI_WIDTH: f32 = 256.;
19
19
const MINI_HEIGHT: f32 = 144.;
@@ -9,11 +9,11 @@ use super::call_mini_window::{9
speaker_speaking, tinted_chip,9
speaker_speaking, tinted_chip,10
};10
};11
use super::call_view::status_line;11
use super::call_view::status_line;12
use super::message_row::ROW_PADDING;13
use super::toolbar_placement::TimelineBounds;12
use super::toolbar_placement::TimelineBounds;14
use super::widgets::icon;13
use super::widgets::icon;15
use crate::app_state::AppState;14
use crate::app_state::AppState;16
use crate::theme;15
use crate::theme;16
use app_ui_kit::layout::ROW_PADDING;17
17
18
const MINI_WIDTH: f32 = 256.;18
const MINI_WIDTH: f32 = 256.;19
const MINI_HEIGHT: f32 = 144.;19
const MINI_HEIGHT: f32 = 144.;@@ -130,7 +130,7 @@ pub fn transcript_and_settings_items(popup: PopupMenu, app: &Entity<AppState>) -
130
130
fn open_transcript(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {
131
131
let panel_app = app.clone();
132
132
let panel = cx.new(|cx| TranscriptPanel::new(panel_app, window, cx));
133
app.update(cx, |state, cx| state.open_call_transcript(panel, cx));
133
app.update(cx, |state, cx| state.open_call_transcript(panel.into(), cx));
134
134
}
135
135
136
136
fn choice_chip(
@@ -130,7 +130,7 @@ pub fn transcript_and_settings_items(popup: PopupMenu, app: &Entity<AppState>) -130
fn open_transcript(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {130
fn open_transcript(app: &Entity<AppState>, window: &mut Window, cx: &mut App) {131
let panel_app = app.clone();131
let panel_app = app.clone();132
let panel = cx.new(|cx| TranscriptPanel::new(panel_app, window, cx));132
let panel = cx.new(|cx| TranscriptPanel::new(panel_app, window, cx));133
app.update(cx, |state, cx| state.open_call_transcript(panel, cx));133
app.update(cx, |state, cx| state.open_call_transcript(panel.into(), cx));134
}134
}135
135
136
fn choice_chip(136
fn choice_chip(@@ -24,7 +24,8 @@ use super::call_extras::{
24
24
room_chip, whiteboard_stage,
25
25
};
26
26
use super::call_health::{health_banner, health_indicator};
27
use super::call_layouts::{measured_stage, stage_region};
27
use super::call_layouts::stage_region;
28
use crate::call::measured_stage;
28
29
use super::call_organizer::{
29
30
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,
30
31
more_button, pin_chip, spotlight_chip, with_tile_menu,
@@ -32,7 +33,6 @@ use super::call_organizer::{
32
33
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};
33
34
use super::call_stage::{StageMode, popped_placeholder, render_stage};
34
35
use super::call_view_menu::view_button;
35
use super::conversation::ConversationView;
36
36
use app_ui_kit::layout::ISLAND_GAP;
37
37
use super::widgets::{Corner, corner_badge, count_badge, icon};
38
38
use crate::app_state::AppState;
@@ -52,9 +52,6 @@ const PULSE_PERIOD: Duration = Duration::from_millis(1400);
52
52
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
53
53
const BLINK_DIMMED_OPACITY: f32 = 0.45;
54
54
pub(super) const DISABLED_OPACITY: f32 = 0.4;
55
pub(super) const TILE_GAP: f32 = 20.;
56
pub(super) const GRID_PADDING: f32 = 24.;
57
pub(super) const STRIP_GAP: f32 = 12.;
58
55
const TILE_RADIUS: f32 = 12.;
59
56
const NAME_PLATE_BACKGROUND: f32 = 0.6;
60
57
pub const CHAT_PANEL_TAG: &str = "shell/islands/main/call-chat-panel";
@@ -1133,7 +1130,7 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol
1133
1130
pub fn render_call_view(
1134
1131
app: &Entity<AppState>,
1135
1132
state: &AppState,
1136
chat: Option<Entity<ConversationView>>,
1133
chat: Option<AnyView>,
1137
1134
fullscreen: bool,
1138
1135
island_width: f32,
1139
1136
) -> Option<AnyElement> {
@@ -1339,7 +1336,7 @@ fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) ->
1339
1336
.child(content)
1340
1337
}
1341
1338
1342
fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {
1339
fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {
1343
1340
let app = app.clone();
1344
1341
side_panel(
1345
1342
"call-chat-panel",
@@ -24,7 +24,8 @@ use super::call_extras::{24
room_chip, whiteboard_stage,24
room_chip, whiteboard_stage,25
};25
};26
use super::call_health::{health_banner, health_indicator};26
use super::call_health::{health_banner, health_indicator};27
use super::call_layouts::{measured_stage, stage_region};27
use super::call_layouts::stage_region;28
use crate::call::measured_stage;28
use super::call_organizer::{29
use super::call_organizer::{29
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,30
camera_menu_button, captions_hint_chip, captions_overlay, chevron_button, lobby_banner,30
more_button, pin_chip, spotlight_chip, with_tile_menu,31
more_button, pin_chip, spotlight_chip, with_tile_menu,@@ -32,7 +33,6 @@ use super::call_organizer::{32
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};33
use super::call_people::{lock_banner, lock_chip, options_dialog, people_button, people_panel};33
use super::call_stage::{StageMode, popped_placeholder, render_stage};34
use super::call_stage::{StageMode, popped_placeholder, render_stage};34
use super::call_view_menu::view_button;35
use super::call_view_menu::view_button;35
use super::conversation::ConversationView;36
use app_ui_kit::layout::ISLAND_GAP;36
use app_ui_kit::layout::ISLAND_GAP;37
use super::widgets::{Corner, corner_badge, count_badge, icon};37
use super::widgets::{Corner, corner_badge, count_badge, icon};38
use crate::app_state::AppState;38
use crate::app_state::AppState;@@ -52,9 +52,6 @@ const PULSE_PERIOD: Duration = Duration::from_millis(1400);52
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);52
const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);53
const BLINK_DIMMED_OPACITY: f32 = 0.45;53
const BLINK_DIMMED_OPACITY: f32 = 0.45;54
pub(super) const DISABLED_OPACITY: f32 = 0.4;54
pub(super) const DISABLED_OPACITY: f32 = 0.4;55
pub(super) const TILE_GAP: f32 = 20.;56
pub(super) const GRID_PADDING: f32 = 24.;57
pub(super) const STRIP_GAP: f32 = 12.;58
const TILE_RADIUS: f32 = 12.;55
const TILE_RADIUS: f32 = 12.;59
const NAME_PLATE_BACKGROUND: f32 = 0.6;56
const NAME_PLATE_BACKGROUND: f32 = 0.6;60
pub const CHAT_PANEL_TAG: &str = "shell/islands/main/call-chat-panel";57
pub const CHAT_PANEL_TAG: &str = "shell/islands/main/call-chat-panel";@@ -1133,7 +1130,7 @@ fn folded_controls(state: &AppState, call: &ActiveCall, fullscreen: bool) -> Fol1133
pub fn render_call_view(1130
pub fn render_call_view(1134
app: &Entity<AppState>,1131
app: &Entity<AppState>,1135
state: &AppState,1132
state: &AppState,1136
chat: Option<Entity<ConversationView>>,1133
chat: Option<AnyView>,1137
fullscreen: bool,1134
fullscreen: bool,1138
island_width: f32,1135
island_width: f32,1139
) -> Option<AnyElement> {1136
) -> Option<AnyElement> {@@ -1339,7 +1336,7 @@ fn fullscreen_chrome(id: &'static str, app: &Entity<AppState>, content: Div) ->1339
.child(content)1336
.child(content)1340
}1337
}1341
1338
1342
fn chat_panel(app: &Entity<AppState>, chat: Entity<ConversationView>) -> AnyElement {1339
fn chat_panel(app: &Entity<AppState>, chat: AnyView) -> AnyElement {1343
let app = app.clone();1340
let app = app.clone();1344
side_panel(1341
side_panel(1345
"call-chat-panel",1342
"call-chat-panel",@@ -3,7 +3,6 @@ use std::collections::{HashMap, HashSet};
3
3
use std::ops::Range;
4
4
use std::path::PathBuf;
5
5
use std::rc::Rc;
6
use std::sync::Arc;
7
6
use std::time::{Duration, Instant};
8
7
9
8
use chrono::{DateTime, Utc};
@@ -23,18 +22,21 @@ use gpui_kit::component::{
23
22
};
24
23
use gpui_kit::prelude::FluentBuilder as _;
25
24
use gpui_kit::*;
26
use serde::{Deserialize, Serialize};
27
25
use teams_core::{
28
Draft, DraftLine, Edit, FileReference, FormatState, HostedImage, LineKind, LinkPreview,
29
MarkKind, MentionCandidate, MentionInput, MessageExtras, OBJECT_MARK, SizeStep, TypingStyle,
26
Draft, DraftLine, Edit, FileReference, FormatState, LineKind, LinkPreview, MarkKind,
27
MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TypingStyle,
30
28
UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
31
29
};
32
30
33
31
mod drafts;
34
32
mod schedule;
35
33
34
use super::actions::{
35
COMPOSER_KEY_CONTEXT, EditLink, OpenSwitcher, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,
36
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,
37
};
36
38
use super::attachment_tray::{
37
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS, OutgoingFile, OutgoingImage,
39
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS,
38
40
PasteAction, UploadJob, UploadResult, discard_uploaded, inline_preview, names_of, paste_action,
39
41
pasted_image_name, prepare_pasted_image, read_attachment, render_tray,
40
42
};
@@ -47,6 +49,7 @@ use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_jo
47
49
use super::widgets::{icon, symbol};
48
50
use crate::app_state::AppState;
49
51
use crate::emoji;
52
pub use crate::outgoing::{EditPreview, Outgoing, ReplyPreview};
50
53
use crate::remote_image::RemoteImage;
51
54
use crate::runtime;
52
55
use crate::scheduled_rows::scheduled_label;
@@ -70,111 +73,12 @@ const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);
70
73
const DEMO_FAILURE_STEP: u8 = 6;
71
74
const HISTORY_LIMIT: usize = 200;
72
75
const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);
73
pub(super) const KEY_CONTEXT: &str = "Composer";
74
76
const IMAGE_TOKEN_PREFIX: &str = "image-";
75
77
76
actions!(
77
composer,
78
[
79
ToggleBold,
80
ToggleItalic,
81
ToggleUnderline,
82
ToggleStrike,
83
ToggleSuperscript,
84
ToggleSubscript,
85
ToggleCode,
86
EditLink,
87
ScheduleSend
88
]
89
);
90
91
78
pub fn bind_keys(cx: &mut App) {
92
79
super::shortcuts::bind_scopes(cx, &[super::shortcuts::Scope::Composer]);
93
80
}
94
81
95
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
96
pub struct ReplyPreview {
97
pub message_id: String,
98
pub author: String,
99
pub excerpt: String,
100
}
101
102
#[derive(Debug, Clone, PartialEq, Eq)]
103
pub struct EditPreview {
104
pub message_id: String,
105
pub excerpt: String,
106
pub scheduled: Option<DateTime<Utc>>,
107
}
108
109
#[derive(Debug, Clone, PartialEq, Eq)]
110
pub struct Outgoing {
111
pub draft: Draft,
112
pub subject: Option<String>,
113
pub mentions: Vec<MentionInput>,
114
pub reply: Option<ReplyPreview>,
115
pub edit: Option<EditPreview>,
116
pub images: Vec<OutgoingImage>,
117
pub files: Vec<OutgoingFile>,
118
pub link_preview: Option<LinkPreview>,
119
}
120
121
impl Outgoing {
122
/// Without list and quote markers, for previews.
123
pub fn text(&self) -> String {
124
self.draft.plain_text()
125
}
126
127
/// The body before mentions become `<at>` tags.
128
pub fn html(&self) -> String {
129
let mut html = String::new();
130
let mut objects = self.images.iter();
131
let mut uploaded = 0;
132
for character in self.draft.to_html().chars() {
133
if character != OBJECT_MARK {
134
html.push(character);
135
continue;
136
}
137
match objects.next() {
138
Some(OutgoingImage::Inline(_)) => {
139
uploaded += 1;
140
html.push_str(&format!(
141
"<img src=\"../hostedContents/{uploaded}/$value\">"
142
));
143
}
144
Some(OutgoingImage::Remote(remote)) => html.push_str(&remote.html()),
145
None => {}
146
}
147
}
148
html
149
}
150
151
pub fn has_attachments(&self) -> bool {
152
!self.images.is_empty() || !self.files.is_empty()
153
}
154
155
pub fn extras(&self) -> MessageExtras {
156
MessageExtras {
157
kept: Vec::new(),
158
images: self
159
.images
160
.iter()
161
.filter_map(|outgoing| match outgoing {
162
OutgoingImage::Inline(inline) => Some(HostedImage {
163
content_type: inline.image.format.mime_type().to_owned(),
164
bytes: Arc::new(inline.image.bytes.clone()),
165
}),
166
OutgoingImage::Remote(_) => None,
167
})
168
.collect(),
169
files: self
170
.files
171
.iter()
172
.map(|file| file.reference.clone())
173
.collect(),
174
}
175
}
176
}
177
178
82
enum UploadEvent {
179
83
Progress(u8),
180
84
Uploaded(UploadedFile),
@@ -1027,7 +931,7 @@ impl Composer {
1027
931
return;
1028
932
}
1029
933
if self.draft.is_blank() && self.selection(cx).is_empty() {
1030
window.dispatch_action(Box::new(super::shell::OpenSwitcher), cx);
934
window.dispatch_action(Box::new(OpenSwitcher), cx);
1031
935
return;
1032
936
}
1033
937
self.open_link_editor(window, cx);
@@ -2642,7 +2546,7 @@ impl Render for Composer {
2642
2546
.px(px(inset))
2643
2547
.pt(px(top))
2644
2548
.pb(px(bottom))
2645
.key_context(KEY_CONTEXT)
2549
.key_context(COMPOSER_KEY_CONTEXT)
2646
2550
.on_action(cx.listener(|this, _: &ToggleBold, _, cx| {
2647
2551
if this.link_editor.is_none() {
2648
2552
this.toggle_mark(MarkKind::Bold, cx);
@@ -2964,7 +2868,7 @@ mod tests {
2964
2868
use teams_core::FileKind;
2965
2869
2966
2870
use super::super::attachment_tray::InlineImage;
2967
use super::{Outgoing, OutgoingFile, OutgoingImage};
2871
use crate::outgoing::{Outgoing, OutgoingFile, OutgoingImage};
2968
2872
2969
2873
let outgoing = Outgoing {
2970
2874
draft: teams_core::Draft::default(),
@@ -2997,20 +2901,20 @@ mod tests {
2997
2901
assert!(outgoing.has_attachments());
2998
2902
}
2999
2903
3000
fn placed_image(width: u32) -> super::OutgoingImage {
2904
fn placed_image(width: u32) -> crate::outgoing::OutgoingImage {
3001
2905
use std::sync::Arc;
3002
2906
3003
2907
use gpui_kit::{Image, ImageFormat};
3004
2908
3005
super::OutgoingImage::Inline(super::super::attachment_tray::InlineImage {
2909
crate::outgoing::OutgoingImage::Inline(super::super::attachment_tray::InlineImage {
3006
2910
name: "pasted-image.png".into(),
3007
2911
image: Arc::new(Image::from_bytes(ImageFormat::Png, vec![width as u8])),
3008
2912
dimensions: Some((width, width)),
3009
2913
})
3010
2914
}
3011
2915
3012
fn remote_gif(title: &str) -> super::OutgoingImage {
3013
super::OutgoingImage::Remote(super::RemoteImage {
2916
fn remote_gif(title: &str) -> crate::outgoing::OutgoingImage {
2917
crate::outgoing::OutgoingImage::Remote(super::RemoteImage {
3014
2918
kind: crate::remote_image::RemoteKind::Gif,
3015
2919
url: "https://media0.giphy.com/media/a/giphy.gif".into(),
3016
2920
title: title.into(),
@@ -3019,8 +2923,8 @@ mod tests {
3019
2923
})
3020
2924
}
3021
2925
3022
fn outgoing_with(text: &str, images: Vec<super::OutgoingImage>) -> super::Outgoing {
3023
super::Outgoing {
2926
fn outgoing_with(text: &str, images: Vec<crate::outgoing::OutgoingImage>) -> crate::outgoing::Outgoing {
2927
crate::outgoing::Outgoing {
3024
2928
draft: teams_core::Draft::plain(text),
3025
2929
subject: None,
3026
2930
mentions: Vec::new(),
@@ -3077,7 +2981,7 @@ mod tests {
3077
2981
#[test]
3078
2982
fn a_sticker_carries_the_sticker_itemtype() {
3079
2983
let sticker = super::RemoteImage::sticker(crate::stickers::popular()[0]);
3080
let outgoing = outgoing_with("\u{FFFC}", vec![super::OutgoingImage::Remote(sticker)]);
2984
let outgoing = outgoing_with("\u{FFFC}", vec![crate::outgoing::OutgoingImage::Remote(sticker)]);
3081
2985
assert!(
3082
2986
outgoing
3083
2987
.html()
@@ -3176,7 +3080,7 @@ mod tests {
3176
3080
self.cx.update(|cx| composer.read(cx).draft.clone())
3177
3081
}
3178
3082
3179
fn outgoing(&mut self) -> super::super::Outgoing {
3083
fn outgoing(&mut self) -> crate::outgoing::Outgoing {
3180
3084
let composer = self.composer.clone();
3181
3085
self.cx
3182
3086
.update(|cx| composer.read(cx).outgoing(cx))
@@ -3355,8 +3259,8 @@ mod tests {
3355
3259
.images
3356
3260
.iter()
3357
3261
.map(|image| match image {
3358
super::super::OutgoingImage::Inline(inline) => inline.dimensions,
3359
super::super::OutgoingImage::Remote(_) => None,
3262
crate::outgoing::OutgoingImage::Inline(inline) => inline.dimensions,
3263
crate::outgoing::OutgoingImage::Remote(_) => None,
3360
3264
})
3361
3265
.collect();
3362
3266
assert_eq!(dimensions, [Some((4, 4)), Some((2, 2))]);
@@ -3,7 +3,6 @@ use std::collections::{HashMap, HashSet};3
use std::ops::Range;3
use std::ops::Range;4
use std::path::PathBuf;4
use std::path::PathBuf;5
use std::rc::Rc;5
use std::rc::Rc;6
use std::sync::Arc;7
use std::time::{Duration, Instant};6
use std::time::{Duration, Instant};8
7
9
use chrono::{DateTime, Utc};8
use chrono::{DateTime, Utc};@@ -23,18 +22,21 @@ use gpui_kit::component::{23
};22
};24
use gpui_kit::prelude::FluentBuilder as _;23
use gpui_kit::prelude::FluentBuilder as _;25
use gpui_kit::*;24
use gpui_kit::*;26
use serde::{Deserialize, Serialize};27
use teams_core::{25
use teams_core::{28
Draft, DraftLine, Edit, FileReference, FormatState, HostedImage, LineKind, LinkPreview,26
Draft, DraftLine, Edit, FileReference, FormatState, LineKind, LinkPreview, MarkKind,29
MarkKind, MentionCandidate, MentionInput, MessageExtras, OBJECT_MARK, SizeStep, TypingStyle,27
MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TypingStyle,30
UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,28
UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,31
};29
};32
30
33
mod drafts;31
mod drafts;34
mod schedule;32
mod schedule;35
33
34
use super::actions::{35
COMPOSER_KEY_CONTEXT, EditLink, OpenSwitcher, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,36
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,37
};36
use super::attachment_tray::{38
use super::attachment_tray::{37
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS, OutgoingFile, OutgoingImage,39
AttachmentTray, DoneFile, JobKind, LoadedFile, MAX_ATTACHMENTS,38
PasteAction, UploadJob, UploadResult, discard_uploaded, inline_preview, names_of, paste_action,40
PasteAction, UploadJob, UploadResult, discard_uploaded, inline_preview, names_of, paste_action,39
pasted_image_name, prepare_pasted_image, read_attachment, render_tray,41
pasted_image_name, prepare_pasted_image, read_attachment, render_tray,40
};42
};@@ -47,6 +49,7 @@ use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_jo47
use super::widgets::{icon, symbol};49
use super::widgets::{icon, symbol};48
use crate::app_state::AppState;50
use crate::app_state::AppState;49
use crate::emoji;51
use crate::emoji;52
pub use crate::outgoing::{EditPreview, Outgoing, ReplyPreview};50
use crate::remote_image::RemoteImage;53
use crate::remote_image::RemoteImage;51
use crate::runtime;54
use crate::runtime;52
use crate::scheduled_rows::scheduled_label;55
use crate::scheduled_rows::scheduled_label;@@ -70,111 +73,12 @@ const DEMO_UPLOAD_STEP: Duration = Duration::from_millis(120);70
const DEMO_FAILURE_STEP: u8 = 6;73
const DEMO_FAILURE_STEP: u8 = 6;71
const HISTORY_LIMIT: usize = 200;74
const HISTORY_LIMIT: usize = 200;72
const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);75
const PASTE_HINT_DURATION: Duration = Duration::from_secs(4);73
pub(super) const KEY_CONTEXT: &str = "Composer";74
const IMAGE_TOKEN_PREFIX: &str = "image-";76
const IMAGE_TOKEN_PREFIX: &str = "image-";75
77
76
actions!(77
composer,78
[79
ToggleBold,80
ToggleItalic,81
ToggleUnderline,82
ToggleStrike,83
ToggleSuperscript,84
ToggleSubscript,85
ToggleCode,86
EditLink,87
ScheduleSend88
]89
);90
91
pub fn bind_keys(cx: &mut App) {78
pub fn bind_keys(cx: &mut App) {92
super::shortcuts::bind_scopes(cx, &[super::shortcuts::Scope::Composer]);79
super::shortcuts::bind_scopes(cx, &[super::shortcuts::Scope::Composer]);93
}80
}94
81
95
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]96
pub struct ReplyPreview {97
pub message_id: String,98
pub author: String,99
pub excerpt: String,100
}101
102
#[derive(Debug, Clone, PartialEq, Eq)]103
pub struct EditPreview {104
pub message_id: String,105
pub excerpt: String,106
pub scheduled: Option<DateTime<Utc>>,107
}108
109
#[derive(Debug, Clone, PartialEq, Eq)]110
pub struct Outgoing {111
pub draft: Draft,112
pub subject: Option<String>,113
pub mentions: Vec<MentionInput>,114
pub reply: Option<ReplyPreview>,115
pub edit: Option<EditPreview>,116
pub images: Vec<OutgoingImage>,117
pub files: Vec<OutgoingFile>,118
pub link_preview: Option<LinkPreview>,119
}120
121
impl Outgoing {122
/// Without list and quote markers, for previews.123
pub fn text(&self) -> String {124
self.draft.plain_text()125
}126
127
/// The body before mentions become `<at>` tags.128
pub fn html(&self) -> String {129
let mut html = String::new();130
let mut objects = self.images.iter();131
let mut uploaded = 0;132
for character in self.draft.to_html().chars() {133
if character != OBJECT_MARK {134
html.push(character);135
continue;136
}137
match objects.next() {138
Some(OutgoingImage::Inline(_)) => {139
uploaded += 1;140
html.push_str(&format!(141
"<img src=\"../hostedContents/{uploaded}/$value\">"142
));143
}144
Some(OutgoingImage::Remote(remote)) => html.push_str(&remote.html()),145
None => {}146
}147
}148
html149
}150
151
pub fn has_attachments(&self) -> bool {152
!self.images.is_empty() || !self.files.is_empty()153
}154
155
pub fn extras(&self) -> MessageExtras {156
MessageExtras {157
kept: Vec::new(),158
images: self159
.images160
.iter()161
.filter_map(|outgoing| match outgoing {162
OutgoingImage::Inline(inline) => Some(HostedImage {163
content_type: inline.image.format.mime_type().to_owned(),164
bytes: Arc::new(inline.image.bytes.clone()),165
}),166
OutgoingImage::Remote(_) => None,167
})168
.collect(),169
files: self170
.files171
.iter()172
.map(|file| file.reference.clone())173
.collect(),174
}175
}176
}177
178
enum UploadEvent {82
enum UploadEvent {179
Progress(u8),83
Progress(u8),180
Uploaded(UploadedFile),84
Uploaded(UploadedFile),@@ -1027,7 +931,7 @@ impl Composer {1027
return;931
return;1028
}932
}1029
if self.draft.is_blank() && self.selection(cx).is_empty() {933
if self.draft.is_blank() && self.selection(cx).is_empty() {1030
window.dispatch_action(Box::new(super::shell::OpenSwitcher), cx);934
window.dispatch_action(Box::new(OpenSwitcher), cx);1031
return;935
return;1032
}936
}1033
self.open_link_editor(window, cx);937
self.open_link_editor(window, cx);@@ -2642,7 +2546,7 @@ impl Render for Composer {2642
.px(px(inset))2546
.px(px(inset))2643
.pt(px(top))2547
.pt(px(top))2644
.pb(px(bottom))2548
.pb(px(bottom))2645
.key_context(KEY_CONTEXT)2549
.key_context(COMPOSER_KEY_CONTEXT)2646
.on_action(cx.listener(|this, _: &ToggleBold, _, cx| {2550
.on_action(cx.listener(|this, _: &ToggleBold, _, cx| {2647
if this.link_editor.is_none() {2551
if this.link_editor.is_none() {2648
this.toggle_mark(MarkKind::Bold, cx);2552
this.toggle_mark(MarkKind::Bold, cx);@@ -2964,7 +2868,7 @@ mod tests {2964
use teams_core::FileKind;2868
use teams_core::FileKind;2965
2869
2966
use super::super::attachment_tray::InlineImage;2870
use super::super::attachment_tray::InlineImage;2967
use super::{Outgoing, OutgoingFile, OutgoingImage};2871
use crate::outgoing::{Outgoing, OutgoingFile, OutgoingImage};2968
2872
2969
let outgoing = Outgoing {2873
let outgoing = Outgoing {2970
draft: teams_core::Draft::default(),2874
draft: teams_core::Draft::default(),@@ -2997,20 +2901,20 @@ mod tests {2997
assert!(outgoing.has_attachments());2901
assert!(outgoing.has_attachments());2998
}2902
}2999
2903
3000
fn placed_image(width: u32) -> super::OutgoingImage {2904
fn placed_image(width: u32) -> crate::outgoing::OutgoingImage {3001
use std::sync::Arc;2905
use std::sync::Arc;3002
2906
3003
use gpui_kit::{Image, ImageFormat};2907
use gpui_kit::{Image, ImageFormat};3004
2908
3005
super::OutgoingImage::Inline(super::super::attachment_tray::InlineImage {2909
crate::outgoing::OutgoingImage::Inline(super::super::attachment_tray::InlineImage {3006
name: "pasted-image.png".into(),2910
name: "pasted-image.png".into(),3007
image: Arc::new(Image::from_bytes(ImageFormat::Png, vec![width as u8])),2911
image: Arc::new(Image::from_bytes(ImageFormat::Png, vec![width as u8])),3008
dimensions: Some((width, width)),2912
dimensions: Some((width, width)),3009
})2913
})3010
}2914
}3011
2915
3012
fn remote_gif(title: &str) -> super::OutgoingImage {2916
fn remote_gif(title: &str) -> crate::outgoing::OutgoingImage {3013
super::OutgoingImage::Remote(super::RemoteImage {2917
crate::outgoing::OutgoingImage::Remote(super::RemoteImage {3014
kind: crate::remote_image::RemoteKind::Gif,2918
kind: crate::remote_image::RemoteKind::Gif,3015
url: "https://media0.giphy.com/media/a/giphy.gif".into(),2919
url: "https://media0.giphy.com/media/a/giphy.gif".into(),3016
title: title.into(),2920
title: title.into(),@@ -3019,8 +2923,8 @@ mod tests {3019
})2923
})3020
}2924
}3021
2925
3022
fn outgoing_with(text: &str, images: Vec<super::OutgoingImage>) -> super::Outgoing {2926
fn outgoing_with(text: &str, images: Vec<crate::outgoing::OutgoingImage>) -> crate::outgoing::Outgoing {3023
super::Outgoing {2927
crate::outgoing::Outgoing {3024
draft: teams_core::Draft::plain(text),2928
draft: teams_core::Draft::plain(text),3025
subject: None,2929
subject: None,3026
mentions: Vec::new(),2930
mentions: Vec::new(),@@ -3077,7 +2981,7 @@ mod tests {3077
#[test]2981
#[test]3078
fn a_sticker_carries_the_sticker_itemtype() {2982
fn a_sticker_carries_the_sticker_itemtype() {3079
let sticker = super::RemoteImage::sticker(crate::stickers::popular()[0]);2983
let sticker = super::RemoteImage::sticker(crate::stickers::popular()[0]);3080
let outgoing = outgoing_with("\u{FFFC}", vec![super::OutgoingImage::Remote(sticker)]);2984
let outgoing = outgoing_with("\u{FFFC}", vec![crate::outgoing::OutgoingImage::Remote(sticker)]);3081
assert!(2985
assert!(3082
outgoing2986
outgoing3083
.html()2987
.html()@@ -3176,7 +3080,7 @@ mod tests {3176
self.cx.update(|cx| composer.read(cx).draft.clone())3080
self.cx.update(|cx| composer.read(cx).draft.clone())3177
}3081
}3178
3082
3179
fn outgoing(&mut self) -> super::super::Outgoing {3083
fn outgoing(&mut self) -> crate::outgoing::Outgoing {3180
let composer = self.composer.clone();3084
let composer = self.composer.clone();3181
self.cx3085
self.cx3182
.update(|cx| composer.read(cx).outgoing(cx))3086
.update(|cx| composer.read(cx).outgoing(cx))@@ -3355,8 +3259,8 @@ mod tests {3355
.images3259
.images3356
.iter()3260
.iter()3357
.map(|image| match image {3261
.map(|image| match image {3358
super::super::OutgoingImage::Inline(inline) => inline.dimensions,3262
crate::outgoing::OutgoingImage::Inline(inline) => inline.dimensions,3359
super::super::OutgoingImage::Remote(_) => None,3263
crate::outgoing::OutgoingImage::Remote(_) => None,3360
})3264
})3361
.collect();3265
.collect();3362
assert_eq!(dimensions, [Some((4, 4)), Some((2, 2))]);3266
assert_eq!(dimensions, [Some((4, 4)), Some((2, 2))]);@@ -37,7 +37,7 @@ use super::channel_tabs::ChannelPane;
37
37
use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
38
38
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
39
39
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};
40
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};
40
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};
41
41
use super::post_card::render_post;
42
42
use super::profile_card::opens_profile;
43
43
use super::reaction_picker::{PickHandler, ReactionPicker};
@@ -49,7 +49,7 @@ use crate::app_state::{AppEvent, AppState, Selection, composer_name, selection_t
49
49
use crate::backend::Engine;
50
50
use crate::card_state::CardScope;
51
51
use crate::channel_files::DownloadSource;
52
use crate::data::{is_one_on_one, others};
52
use crate::data::{existing_one_on_one, is_one_on_one, others};
53
53
use crate::demo_library::DemoLibrary;
54
54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
55
55
use crate::emoji;
@@ -98,8 +98,6 @@ const TYPING_DOT_SIZE: f32 = 5.;
98
98
const TYPING_DOT_COUNT: usize = 3;
99
99
const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);
100
100
101
actions!(teams, [ReplyToHovered]);
102
103
101
#[derive(Clone, Copy)]
104
102
enum HoverSlot {
105
103
Row,
@@ -37,7 +37,7 @@ use super::channel_tabs::ChannelPane;37
use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};37
use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};38
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};38
use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};39
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};39
use super::message_row::{AVATAR_GAP, AVATAR_SIZE, render_message_row, render_skeleton_row};40
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};40
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder};41
use super::post_card::render_post;41
use super::post_card::render_post;42
use super::profile_card::opens_profile;42
use super::profile_card::opens_profile;43
use super::reaction_picker::{PickHandler, ReactionPicker};43
use super::reaction_picker::{PickHandler, ReactionPicker};@@ -49,7 +49,7 @@ use crate::app_state::{AppEvent, AppState, Selection, composer_name, selection_t49
use crate::backend::Engine;49
use crate::backend::Engine;50
use crate::card_state::CardScope;50
use crate::card_state::CardScope;51
use crate::channel_files::DownloadSource;51
use crate::channel_files::DownloadSource;52
use crate::data::{is_one_on_one, others};52
use crate::data::{existing_one_on_one, is_one_on_one, others};53
use crate::demo_library::DemoLibrary;53
use crate::demo_library::DemoLibrary;54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};54
use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};55
use crate::emoji;55
use crate::emoji;@@ -98,8 +98,6 @@ const TYPING_DOT_SIZE: f32 = 5.;98
const TYPING_DOT_COUNT: usize = 3;98
const TYPING_DOT_COUNT: usize = 3;99
const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);99
const TYPING_PULSE_PERIOD: Duration = Duration::from_millis(1200);100
100
101
actions!(teams, [ReplyToHovered]);102
103
#[derive(Clone, Copy)]101
#[derive(Clone, Copy)]104
enum HoverSlot {102
enum HoverSlot {105
Row,103
Row,@@ -17,7 +17,8 @@ use crate::scheduled_rows::{
17
17
draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,
18
18
};
19
19
use crate::views::composer::{EditPreview, Outgoing};
20
use crate::views::message_actions::{Action, HoverChange};
20
use crate::views::message_actions::Action;
21
use crate::views::toolbar_placement::HoverChange;
21
22
use crate::views::message_row::{DeliveryActions, RowAction};
22
23
use crate::views::scheduled_toolbar::ScheduledMenu;
23
24
use std::sync::Arc;
@@ -17,7 +17,8 @@ use crate::scheduled_rows::{17
draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,17
draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,18
};18
};19
use crate::views::composer::{EditPreview, Outgoing};19
use crate::views::composer::{EditPreview, Outgoing};20
use crate::views::message_actions::{Action, HoverChange};20
use crate::views::message_actions::Action;21
use crate::views::toolbar_placement::HoverChange;21
use crate::views::message_row::{DeliveryActions, RowAction};22
use crate::views::message_row::{DeliveryActions, RowAction};22
use crate::views::scheduled_toolbar::ScheduledMenu;23
use crate::views::scheduled_toolbar::ScheduledMenu;23
use std::sync::Arc;24
use std::sync::Arc;@@ -13,7 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _;
13
13
use gpui_kit::*;
14
14
15
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};
16
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};
16
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};
17
17
use super::widgets::icon;
18
18
use crate::rows::reaction_glyph;
19
19
use crate::theme;
@@ -27,7 +27,6 @@ pub const QUICK_REACTION_COUNT: usize = 4;
27
27
28
28
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;
29
29
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;
30
pub type HoverChange = Rc<dyn Fn(bool, &mut App)>;
31
30
32
31
#[derive(Clone)]
33
32
pub struct DelegateEntry {
@@ -13,7 +13,7 @@ use gpui_kit::prelude::FluentBuilder as _;13
use gpui_kit::*;13
use gpui_kit::*;14
14
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};16
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};16
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};17
use super::widgets::icon;17
use super::widgets::icon;18
use crate::rows::reaction_glyph;18
use crate::rows::reaction_glyph;19
use crate::theme;19
use crate::theme;@@ -27,7 +27,6 @@ pub const QUICK_REACTION_COUNT: usize = 4;27
27
28
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;28
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;29
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;29
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;30
pub type HoverChange = Rc<dyn Fn(bool, &mut App)>;31
30
32
#[derive(Clone)]31
#[derive(Clone)]33
pub struct DelegateEntry {32
pub struct DelegateEntry {@@ -9,13 +9,13 @@ use super::attachments::{FileActions, ImageOpen, attachments_view, message_body}
9
9
use super::avatar::{bot_avatar, person_avatar};
10
10
use super::call_card::{CallActions, call_card_row};
11
11
use super::link_preview::{link_preview_card, meeting_join_chip};
12
use super::message_actions::{HoverChange, MessageMenu, message_toolbar};
12
use super::message_actions::{MessageMenu, message_toolbar};
13
13
use super::profile_card::opens_profile;
14
14
use super::reaction_picker::PickHandler;
15
15
use super::reaction_pills::{ReactionControls, reaction_pills};
16
16
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
17
17
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
18
use super::toolbar_placement::{TimelineBounds, placed_toolbar};
18
use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
19
19
use super::translation_line::{TranslationActions, translation_line};
20
20
use super::widgets::{icon, symbol};
21
21
use crate::agents::{AgentRun, run_chip};
@@ -25,6 +25,7 @@ use crate::render::Block;
25
25
use crate::rows::{Delivery, MessageRow, Receipt, ScheduledState, Skeleton, bubble_corners};
26
26
use crate::sidebar_model::DELETED_PREVIEW;
27
27
use crate::theme;
28
use app_ui_kit::layout::ROW_PADDING;
28
29
29
30
pub type RowAction = Option<Box<dyn Fn(&mut App)>>;
30
31
@@ -48,7 +49,6 @@ const SERIES_START_GAP: f32 = 8.;
48
49
pub(super) const BODY_SIZE: f32 = 13.5;
49
50
const MAX_WIDTH_RATIO: f32 = 0.7;
50
51
const NARROW_BUBBLE_WIDTH: f32 = 300.;
51
pub(super) const ROW_PADDING: f32 = 20.;
52
52
const REACTION_FOOTER_HEIGHT: f32 = 24.;
53
53
const META_SIZE: f32 = 11.;
54
54
const META_CHECK_SIZE: f32 = 15.;
@@ -9,13 +9,13 @@ use super::attachments::{FileActions, ImageOpen, attachments_view, message_body}9
use super::avatar::{bot_avatar, person_avatar};9
use super::avatar::{bot_avatar, person_avatar};10
use super::call_card::{CallActions, call_card_row};10
use super::call_card::{CallActions, call_card_row};11
use super::link_preview::{link_preview_card, meeting_join_chip};11
use super::link_preview::{link_preview_card, meeting_join_chip};12
use super::message_actions::{HoverChange, MessageMenu, message_toolbar};12
use super::message_actions::{MessageMenu, message_toolbar};13
use super::profile_card::opens_profile;13
use super::profile_card::opens_profile;14
use super::reaction_picker::PickHandler;14
use super::reaction_picker::PickHandler;15
use super::reaction_pills::{ReactionControls, reaction_pills};15
use super::reaction_pills::{ReactionControls, reaction_pills};16
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};16
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};17
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};17
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};18
use super::toolbar_placement::{TimelineBounds, placed_toolbar};18
use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};19
use super::translation_line::{TranslationActions, translation_line};19
use super::translation_line::{TranslationActions, translation_line};20
use super::widgets::{icon, symbol};20
use super::widgets::{icon, symbol};21
use crate::agents::{AgentRun, run_chip};21
use crate::agents::{AgentRun, run_chip};@@ -25,6 +25,7 @@ use crate::render::Block;25
use crate::rows::{Delivery, MessageRow, Receipt, ScheduledState, Skeleton, bubble_corners};25
use crate::rows::{Delivery, MessageRow, Receipt, ScheduledState, Skeleton, bubble_corners};26
use crate::sidebar_model::DELETED_PREVIEW;26
use crate::sidebar_model::DELETED_PREVIEW;27
use crate::theme;27
use crate::theme;28
use app_ui_kit::layout::ROW_PADDING;28
29
29
pub type RowAction = Option<Box<dyn Fn(&mut App)>>;30
pub type RowAction = Option<Box<dyn Fn(&mut App)>>;30
31
@@ -48,7 +49,6 @@ const SERIES_START_GAP: f32 = 8.;48
pub(super) const BODY_SIZE: f32 = 13.5;49
pub(super) const BODY_SIZE: f32 = 13.5;49
const MAX_WIDTH_RATIO: f32 = 0.7;50
const MAX_WIDTH_RATIO: f32 = 0.7;50
const NARROW_BUBBLE_WIDTH: f32 = 300.;51
const NARROW_BUBBLE_WIDTH: f32 = 300.;51
pub(super) const ROW_PADDING: f32 = 20.;52
const REACTION_FOOTER_HEIGHT: f32 = 24.;52
const REACTION_FOOTER_HEIGHT: f32 = 24.;53
const META_SIZE: f32 = 11.;53
const META_SIZE: f32 = 11.;54
const META_CHECK_SIZE: f32 = 15.;54
const META_CHECK_SIZE: f32 = 15.;@@ -1,3 +1,4 @@
1
pub mod actions;
1
2
pub mod activity_panel;
2
3
pub mod adaptive_card;
3
4
pub mod attachment_tray;
@@ -1,3 +1,4 @@1
pub mod actions;1
pub mod activity_panel;2
pub mod activity_panel;2
pub mod adaptive_card;3
pub mod adaptive_card;3
pub mod attachment_tray;4
pub mod attachment_tray;@@ -124,19 +124,6 @@ pub fn search_results(
124
124
.collect()
125
125
}
126
126
127
pub fn existing_one_on_one<'chats>(
128
chats: &'chats [ChatRecord],
129
me: Option<&Person>,
130
user_id: &str,
131
) -> Option<&'chats ChatRecord> {
132
chats.iter().find(|chat| {
133
data::is_one_on_one(chat)
134
&& data::others(chat, me)
135
.iter()
136
.any(|(member_id, _)| member_id.as_deref() == Some(user_id))
137
})
138
}
139
140
127
pub fn composer_placeholder(chips: &[Pick], group_name: &str) -> String {
141
128
match chips {
142
129
[chip] => format!("Message {}", chip.name),
@@ -779,10 +766,9 @@ mod tests {
779
766
use store::{ChatRecord, MemberRecord};
780
767
781
768
use super::{
782
EnterAction, Pick, composer_placeholder, enter_action, existing_one_on_one, search_results,
783
suggested_people,
769
EnterAction, Pick, composer_placeholder, enter_action, search_results, suggested_people,
784
770
};
785
use crate::data::Person;
771
use crate::data::{Person, existing_one_on_one};
786
772
787
773
fn me() -> Person {
788
774
Person {
@@ -124,19 +124,6 @@ pub fn search_results(124
.collect()124
.collect()125
}125
}126
126
127
pub fn existing_one_on_one<'chats>(128
chats: &'chats [ChatRecord],129
me: Option<&Person>,130
user_id: &str,131
) -> Option<&'chats ChatRecord> {132
chats.iter().find(|chat| {133
data::is_one_on_one(chat)134
&& data::others(chat, me)135
.iter()136
.any(|(member_id, _)| member_id.as_deref() == Some(user_id))137
})138
}139
140
pub fn composer_placeholder(chips: &[Pick], group_name: &str) -> String {127
pub fn composer_placeholder(chips: &[Pick], group_name: &str) -> String {141
match chips {128
match chips {142
[chip] => format!("Message {}", chip.name),129
[chip] => format!("Message {}", chip.name),@@ -779,10 +766,9 @@ mod tests {779
use store::{ChatRecord, MemberRecord};766
use store::{ChatRecord, MemberRecord};780
767
781
use super::{768
use super::{782
EnterAction, Pick, composer_placeholder, enter_action, existing_one_on_one, search_results,769
EnterAction, Pick, composer_placeholder, enter_action, search_results, suggested_people,783
suggested_people,784
};770
};785
use crate::data::Person;771
use crate::data::{Person, existing_one_on_one};786
772
787
fn me() -> Person {773
fn me() -> Person {788
Person {774
Person {@@ -8,8 +8,10 @@ use gpui_kit::prelude::FluentBuilder as _;
8
8
use gpui_kit::*;
9
9
use teams_core::{Draft, MentionInput, OBJECT_MARK};
10
10
11
#[cfg(test)]
12
use crate::agent_api::body::body_blocks;
11
13
use crate::agent_api::{ProposalEntry, ProposalPicture, ProposalStatus, agent_label};
12
use crate::render::{Block, layout_blocks, render_blocks};
14
use crate::render::render_blocks;
13
15
use crate::theme;
14
16
use crate::views::attachment_tray::{Classification, OutgoingImage, classify, inline_image};
15
17
use crate::views::composer::{Outgoing, ReplyPreview};
@@ -25,7 +27,6 @@ const BUTTON_RADIUS: f32 = 7.;
25
27
const BODY_LINE_HEIGHT: f32 = 20.;
26
28
const BODY_MAX_LINES: f32 = 4.;
27
29
const QUOTE_BAR_WIDTH: f32 = 2.;
28
const BODY_PREVIEW_CHARACTERS: usize = 1200;
29
30
const THUMBNAIL_HEIGHT: f32 = 48.;
30
31
const THUMBNAIL_MAX_WIDTH: f32 = 120.;
31
32
const THUMBNAIL_MIN_WIDTH: f32 = 16.;
@@ -51,28 +52,6 @@ fn open_session(session_id: &str, _window: &mut Window, cx: &mut App) {
51
52
crate::agents::open_session(session_id, cx);
52
53
}
53
54
54
fn body_preview(text: &str) -> String {
55
let text = text.trim();
56
let cut: String = text.chars().take(BODY_PREVIEW_CHARACTERS).collect();
57
if cut.len() == text.len() {
58
return cut;
59
}
60
match cut.rfind('\n') {
61
Some(newline) => cut[..newline].to_owned(),
62
None => cut,
63
}
64
}
65
66
pub fn body_blocks(text: &str, mentions: &[mcp::ProposalMention]) -> Vec<Block> {
67
let inputs: Vec<MentionInput> = mentions
68
.iter()
69
.map(|mention| MentionInput::user(&mention.user_id, &mention.name))
70
.collect();
71
let preview = body_preview(text);
72
let (html, _) = teams_core::apply_mentions(&Draft::from_markdown(&preview).to_html(), &inputs);
73
layout_blocks(&teams_core::html_to_spans(&html))
74
}
75
76
55
fn inline_flags(pictures: &[ProposalPicture]) -> Vec<bool> {
77
56
let mut inline_used = 0;
78
57
pictures
@@ -420,10 +399,9 @@ mod tests {
420
399
use teams_core::MentionInput;
421
400
422
401
use super::{
423
age_label, body_blocks, needs_upload, outgoing_for, picture_files, sample_entry,
402
age_label, needs_upload, outgoing_for, picture_files, sample_entry,
424
403
sample_png, thumbnail_size,
425
404
};
426
use crate::render::Block;
427
405
use crate::views::attachment_tray::{AttachmentTray, INLINE_IMAGE_MAX_BYTES, OutgoingImage};
428
406
429
407
const TWO_MEGABYTES: usize = 2 * 1024 * 1024;
@@ -440,56 +418,6 @@ mod tests {
440
418
assert_eq!(age_label(now + Duration::minutes(5), now), "just now");
441
419
}
442
420
443
#[test]
444
fn the_card_body_renders_markdown_like_a_sent_message() {
445
let blocks = body_blocks("- item\n- `code`", &[]);
446
let [Block::List { items, ordered, .. }] = blocks.as_slice() else {
447
panic!("{blocks:?}");
448
};
449
assert!(!ordered);
450
assert_eq!(items.len(), 2);
451
let Block::Paragraph(inline) = &items[1][0] else {
452
panic!("{items:?}");
453
};
454
assert_eq!(inline.text, "code");
455
assert!(inline.segments.iter().any(|segment| segment.style.code));
456
}
457
458
#[test]
459
fn long_bodies_are_cut_at_the_last_line_break() {
460
let text = format!("{}\n{}", "a".repeat(1000), "b".repeat(500));
461
assert_eq!(super::body_preview(&text), "a".repeat(1000));
462
assert_eq!(super::body_preview("short"), "short");
463
}
464
465
#[test]
466
fn long_bodies_are_cut_before_layout() {
467
let long = "word ".repeat(2000);
468
let blocks = body_blocks(&long, &[]);
469
let crate::render::Block::Paragraph(inline) = &blocks[0] else {
470
panic!("{blocks:?}");
471
};
472
assert!(inline.text.chars().count() <= super::BODY_PREVIEW_CHARACTERS);
473
}
474
475
#[test]
476
fn mentions_and_links_render_as_styled_segments() {
477
let blocks = body_blocks(
478
"**Hi** @Ada Example, see https://example.com/x",
479
&[mcp::ProposalMention {
480
user_id: "u1".to_owned(),
481
name: "Ada Example".to_owned(),
482
}],
483
);
484
let Block::Paragraph(inline) = &blocks[0] else {
485
panic!("{blocks:?}");
486
};
487
assert!(inline.segments.iter().any(|segment| segment.style.bold));
488
assert!(inline.segments.iter().any(|segment| segment.style.mention));
489
assert!(inline.segments.iter().any(|segment| segment.link.is_some()));
490
assert!(!inline.text.contains("**"));
491
}
492
493
421
#[test]
494
422
fn thumbnails_keep_the_height_and_clamp_the_width() {
495
423
assert_eq!(thumbnail_size(Some((100, 100))), (48., 48.));
@@ -8,8 +8,10 @@ use gpui_kit::prelude::FluentBuilder as _;8
use gpui_kit::*;8
use gpui_kit::*;9
use teams_core::{Draft, MentionInput, OBJECT_MARK};9
use teams_core::{Draft, MentionInput, OBJECT_MARK};10
10
11
#[cfg(test)]12
use crate::agent_api::body::body_blocks;11
use crate::agent_api::{ProposalEntry, ProposalPicture, ProposalStatus, agent_label};13
use crate::agent_api::{ProposalEntry, ProposalPicture, ProposalStatus, agent_label};12
use crate::render::{Block, layout_blocks, render_blocks};14
use crate::render::render_blocks;13
use crate::theme;15
use crate::theme;14
use crate::views::attachment_tray::{Classification, OutgoingImage, classify, inline_image};16
use crate::views::attachment_tray::{Classification, OutgoingImage, classify, inline_image};15
use crate::views::composer::{Outgoing, ReplyPreview};17
use crate::views::composer::{Outgoing, ReplyPreview};@@ -25,7 +27,6 @@ const BUTTON_RADIUS: f32 = 7.;25
const BODY_LINE_HEIGHT: f32 = 20.;27
const BODY_LINE_HEIGHT: f32 = 20.;26
const BODY_MAX_LINES: f32 = 4.;28
const BODY_MAX_LINES: f32 = 4.;27
const QUOTE_BAR_WIDTH: f32 = 2.;29
const QUOTE_BAR_WIDTH: f32 = 2.;28
const BODY_PREVIEW_CHARACTERS: usize = 1200;29
const THUMBNAIL_HEIGHT: f32 = 48.;30
const THUMBNAIL_HEIGHT: f32 = 48.;30
const THUMBNAIL_MAX_WIDTH: f32 = 120.;31
const THUMBNAIL_MAX_WIDTH: f32 = 120.;31
const THUMBNAIL_MIN_WIDTH: f32 = 16.;32
const THUMBNAIL_MIN_WIDTH: f32 = 16.;@@ -51,28 +52,6 @@ fn open_session(session_id: &str, _window: &mut Window, cx: &mut App) {51
crate::agents::open_session(session_id, cx);52
crate::agents::open_session(session_id, cx);52
}53
}53
54
54
fn body_preview(text: &str) -> String {55
let text = text.trim();56
let cut: String = text.chars().take(BODY_PREVIEW_CHARACTERS).collect();57
if cut.len() == text.len() {58
return cut;59
}60
match cut.rfind('\n') {61
Some(newline) => cut[..newline].to_owned(),62
None => cut,63
}64
}65
66
pub fn body_blocks(text: &str, mentions: &[mcp::ProposalMention]) -> Vec<Block> {67
let inputs: Vec<MentionInput> = mentions68
.iter()69
.map(|mention| MentionInput::user(&mention.user_id, &mention.name))70
.collect();71
let preview = body_preview(text);72
let (html, _) = teams_core::apply_mentions(&Draft::from_markdown(&preview).to_html(), &inputs);73
layout_blocks(&teams_core::html_to_spans(&html))74
}75
76
fn inline_flags(pictures: &[ProposalPicture]) -> Vec<bool> {55
fn inline_flags(pictures: &[ProposalPicture]) -> Vec<bool> {77
let mut inline_used = 0;56
let mut inline_used = 0;78
pictures57
pictures@@ -420,10 +399,9 @@ mod tests {420
use teams_core::MentionInput;399
use teams_core::MentionInput;421
400
422
use super::{401
use super::{423
age_label, body_blocks, needs_upload, outgoing_for, picture_files, sample_entry,402
age_label, needs_upload, outgoing_for, picture_files, sample_entry,424
sample_png, thumbnail_size,403
sample_png, thumbnail_size,425
};404
};426
use crate::render::Block;427
use crate::views::attachment_tray::{AttachmentTray, INLINE_IMAGE_MAX_BYTES, OutgoingImage};405
use crate::views::attachment_tray::{AttachmentTray, INLINE_IMAGE_MAX_BYTES, OutgoingImage};428
406
429
const TWO_MEGABYTES: usize = 2 * 1024 * 1024;407
const TWO_MEGABYTES: usize = 2 * 1024 * 1024;@@ -440,56 +418,6 @@ mod tests {440
assert_eq!(age_label(now + Duration::minutes(5), now), "just now");418
assert_eq!(age_label(now + Duration::minutes(5), now), "just now");441
}419
}442
420
443
#[test]444
fn the_card_body_renders_markdown_like_a_sent_message() {445
let blocks = body_blocks("- item\n- `code`", &[]);446
let [Block::List { items, ordered, .. }] = blocks.as_slice() else {447
panic!("{blocks:?}");448
};449
assert!(!ordered);450
assert_eq!(items.len(), 2);451
let Block::Paragraph(inline) = &items[1][0] else {452
panic!("{items:?}");453
};454
assert_eq!(inline.text, "code");455
assert!(inline.segments.iter().any(|segment| segment.style.code));456
}457
458
#[test]459
fn long_bodies_are_cut_at_the_last_line_break() {460
let text = format!("{}\n{}", "a".repeat(1000), "b".repeat(500));461
assert_eq!(super::body_preview(&text), "a".repeat(1000));462
assert_eq!(super::body_preview("short"), "short");463
}464
465
#[test]466
fn long_bodies_are_cut_before_layout() {467
let long = "word ".repeat(2000);468
let blocks = body_blocks(&long, &[]);469
let crate::render::Block::Paragraph(inline) = &blocks[0] else {470
panic!("{blocks:?}");471
};472
assert!(inline.text.chars().count() <= super::BODY_PREVIEW_CHARACTERS);473
}474
475
#[test]476
fn mentions_and_links_render_as_styled_segments() {477
let blocks = body_blocks(478
"**Hi** @Ada Example, see https://example.com/x",479
&[mcp::ProposalMention {480
user_id: "u1".to_owned(),481
name: "Ada Example".to_owned(),482
}],483
);484
let Block::Paragraph(inline) = &blocks[0] else {485
panic!("{blocks:?}");486
};487
assert!(inline.segments.iter().any(|segment| segment.style.bold));488
assert!(inline.segments.iter().any(|segment| segment.style.mention));489
assert!(inline.segments.iter().any(|segment| segment.link.is_some()));490
assert!(!inline.text.contains("**"));491
}492
493
#[test]421
#[test]494
fn thumbnails_keep_the_height_and_clamp_the_width() {422
fn thumbnails_keep_the_height_and_clamp_the_width() {495
assert_eq!(thumbnail_size(Some((100, 100))), (48., 48.));423
assert_eq!(thumbnail_size(Some((100, 100))), (48., 48.));@@ -6,9 +6,8 @@ use teams_core::SavedMessage;
6
6
7
7
use super::avatar::person_avatar;
8
8
use super::widgets::icon;
9
use crate::app_state::{AppState, selection_title};
9
use crate::app_state::{AppState, selection_for, selection_title};
10
10
use crate::format;
11
use crate::notify::selection_for;
12
11
use crate::theme;
13
12
14
13
const AVATAR_SIZE: f32 = 32.;
@@ -6,9 +6,8 @@ use teams_core::SavedMessage;6
6
7
use super::avatar::person_avatar;7
use super::avatar::person_avatar;8
use super::widgets::icon;8
use super::widgets::icon;9
use crate::app_state::{AppState, selection_title};9
use crate::app_state::{AppState, selection_for, selection_title};10
use crate::format;10
use crate::format;11
use crate::notify::selection_for;12
use crate::theme;11
use crate::theme;13
12
14
const AVATAR_SIZE: f32 = 32.;13
const AVATAR_SIZE: f32 = 32.;@@ -3,8 +3,8 @@ use gpui_kit::base::GlobalState;
3
3
use gpui_kit::component::h_flex;
4
4
use gpui_kit::*;
5
5
6
use super::message_actions::{Action, HoverChange, bar_button};
7
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};
6
use super::message_actions::{Action, bar_button};
7
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};
8
8
use super::widgets::icon;
9
9
use crate::theme;
10
10
@@ -3,8 +3,8 @@ use gpui_kit::base::GlobalState;3
use gpui_kit::component::h_flex;3
use gpui_kit::component::h_flex;4
use gpui_kit::*;4
use gpui_kit::*;5
5
6
use super::message_actions::{Action, HoverChange, bar_button};6
use super::message_actions::{Action, bar_button};7
use super::toolbar_placement::{TOOLBAR_HEIGHT, toolbar_slot};7
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};8
use super::widgets::icon;8
use super::widgets::icon;9
use crate::theme;9
use crate::theme;10
10
@@ -7,7 +7,8 @@ use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7
7
use super::call_mini::CallMiniView;
8
8
use super::call_stage::{render_call_overlay, render_stage_overlay};
9
9
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
10
use super::conversation::{ConversationView, ReplyToHovered};
10
use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};
11
use super::conversation::ConversationView;
11
12
use super::dialog_overlay::render_task_dialog;
12
13
use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
13
14
use super::image_viewer::{ImageViewer, ImageViewerEvent};
@@ -34,17 +35,15 @@ use super::switcher::{Switcher, SwitcherEvent, candidates_from};
34
35
use super::title_bar::render_title_bar;
35
36
use crate::activity::ActivityCenter;
36
37
use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
37
use crate::app_state::{AppEvent, AppState, Selection};
38
use crate::app_state::{AppEvent, AppState, Selection, selection_for};
38
39
use crate::call::{CallMedia, CallWindows, ZoomStep};
39
40
use crate::notice::NoticeAction;
40
use crate::notify::{NotificationCenter, selection_for};
41
use crate::notify::NotificationCenter;
41
42
use crate::sidebar_model::Step;
42
43
use crate::theme;
43
44
use crate::updater::{self, IdleInputs, UpdateStatus};
44
45
use crate::user_activity::{self, UserInput};
45
46
46
actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]);
47
48
47
pub fn bind_keys(cx: &mut App) {
49
48
super::composer::bind_keys(cx);
50
49
super::shortcuts::bind_scopes(
@@ -770,7 +769,7 @@ impl Render for AppShell {
770
769
let chat_thread = self.state.read(cx).call_chat_thread();
771
770
self.sync_call_chat(chat_thread, window, cx);
772
771
self.sync_prejoin(window, cx);
773
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
772
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
774
773
let state = self.state.read(cx);
775
774
let call_fullscreen = state.call_fullscreen();
776
775
let window_width = f32::from(window.viewport_size().width);
@@ -7,7 +7,8 @@ use super::activity_panel::{ActivityPanel, ActivityPanelEvent};7
use super::call_mini::CallMiniView;7
use super::call_mini::CallMiniView;8
use super::call_stage::{render_call_overlay, render_stage_overlay};8
use super::call_stage::{render_call_overlay, render_stage_overlay};9
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};9
use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};10
use super::conversation::{ConversationView, ReplyToHovered};10
use super::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute};11
use super::conversation::ConversationView;11
use super::dialog_overlay::render_task_dialog;12
use super::dialog_overlay::render_task_dialog;12
use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};13
use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};13
use super::image_viewer::{ImageViewer, ImageViewerEvent};14
use super::image_viewer::{ImageViewer, ImageViewerEvent};@@ -34,17 +35,15 @@ use super::switcher::{Switcher, SwitcherEvent, candidates_from};34
use super::title_bar::render_title_bar;35
use super::title_bar::render_title_bar;35
use crate::activity::ActivityCenter;36
use crate::activity::ActivityCenter;36
use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};37
use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};37
use crate::app_state::{AppEvent, AppState, Selection};38
use crate::app_state::{AppEvent, AppState, Selection, selection_for};38
use crate::call::{CallMedia, CallWindows, ZoomStep};39
use crate::call::{CallMedia, CallWindows, ZoomStep};39
use crate::notice::NoticeAction;40
use crate::notice::NoticeAction;40
use crate::notify::{NotificationCenter, selection_for};41
use crate::notify::NotificationCenter;41
use crate::sidebar_model::Step;42
use crate::sidebar_model::Step;42
use crate::theme;43
use crate::theme;43
use crate::updater::{self, IdleInputs, UpdateStatus};44
use crate::updater::{self, IdleInputs, UpdateStatus};44
use crate::user_activity::{self, UserInput};45
use crate::user_activity::{self, UserInput};45
46
46
actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]);47
48
pub fn bind_keys(cx: &mut App) {47
pub fn bind_keys(cx: &mut App) {49
super::composer::bind_keys(cx);48
super::composer::bind_keys(cx);50
super::shortcuts::bind_scopes(49
super::shortcuts::bind_scopes(@@ -770,7 +769,7 @@ impl Render for AppShell {770
let chat_thread = self.state.read(cx).call_chat_thread();769
let chat_thread = self.state.read(cx).call_chat_thread();771
self.sync_call_chat(chat_thread, window, cx);770
self.sync_call_chat(chat_thread, window, cx);772
self.sync_prejoin(window, cx);771
self.sync_prejoin(window, cx);773
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());772
let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());774
let state = self.state.read(cx);773
let state = self.state.read(cx);775
let call_fullscreen = state.call_fullscreen();774
let call_fullscreen = state.call_fullscreen();776
let window_width = f32::from(window.viewport_size().width);775
let window_width = f32::from(window.viewport_size().width);@@ -1,11 +1,10 @@
1
1
use gpui_kit::*;
2
2
3
use super::composer::{
4
EditLink, KEY_CONTEXT as COMPOSER_CONTEXT, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,
5
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,
3
use super::actions::{
4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, NewChat, OpenSwitcher, ReplyToHovered,
5
ScheduleSend, ToggleBold, ToggleCode, ToggleItalic, ToggleStrike, ToggleSubscript,
6
ToggleSuperscript, ToggleUnderline, ToggleCallMute,
6
7
};
7
use super::conversation::ReplyToHovered;
8
use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};
9
8
10
9
const TEXT_FIELD_CONTEXT: &str = "Input";
11
10
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";
@@ -1,11 +1,10 @@1
use gpui_kit::*;1
use gpui_kit::*;2
2
3
use super::composer::{3
use super::actions::{4
EditLink, KEY_CONTEXT as COMPOSER_CONTEXT, ScheduleSend, ToggleBold, ToggleCode, ToggleItalic,4
COMPOSER_KEY_CONTEXT as COMPOSER_CONTEXT, EditLink, NewChat, OpenSwitcher, ReplyToHovered,5
ToggleStrike, ToggleSubscript, ToggleSuperscript, ToggleUnderline,5
ScheduleSend, ToggleBold, ToggleCode, ToggleItalic, ToggleStrike, ToggleSubscript,6
ToggleSuperscript, ToggleUnderline, ToggleCallMute,6
};7
};7
use super::conversation::ReplyToHovered;8
use super::shell::{NewChat, OpenSwitcher, ToggleCallMute};9
8
10
const TEXT_FIELD_CONTEXT: &str = "Input";9
const TEXT_FIELD_CONTEXT: &str = "Input";11
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";10
const OUTSIDE_COMPOSER_CONTEXT: &str = "!Composer";@@ -65,7 +65,7 @@ pub fn render_title_bar(
65
65
.text_size(px(13.))
66
66
.font_weight(FontWeight::SEMIBOLD)
67
67
.text_color(theme::text())
68
.child(crate::APP_NAME),
68
.child(app_base::APP_NAME),
69
69
)
70
70
.child(div().flex_1().flex().justify_center().child(search))
71
71
.children(own)
@@ -65,7 +65,7 @@ pub fn render_title_bar(65
.text_size(px(13.))65
.text_size(px(13.))66
.font_weight(FontWeight::SEMIBOLD)66
.font_weight(FontWeight::SEMIBOLD)67
.text_color(theme::text())67
.text_color(theme::text())68
.child(crate::APP_NAME),68
.child(app_base::APP_NAME),69
)69
)70
.child(div().flex_1().flex().justify_center().child(search))70
.child(div().flex_1().flex().justify_center().child(search))71
.children(own)71
.children(own)@@ -3,8 +3,7 @@ use std::rc::Rc;
3
3
4
4
use gpui_kit::*;
5
5
6
use super::message_actions::HoverChange;
7
6
pub type HoverChange = Rc<dyn Fn(bool, &mut App)>;
8
7
pub type TimelineBounds = Rc<Cell<Option<Bounds<Pixels>>>>;
9
8
10
9
pub const TOOLBAR_HEIGHT: f32 = 36.;
@@ -3,8 +3,7 @@ use std::rc::Rc;3
3
4
use gpui_kit::*;4
use gpui_kit::*;5
5
6
use super::message_actions::HoverChange;6
pub type HoverChange = Rc<dyn Fn(bool, &mut App)>;7
8
pub type TimelineBounds = Rc<Cell<Option<Bounds<Pixels>>>>;7
pub type TimelineBounds = Rc<Cell<Option<Bounds<Pixels>>>>;9
8
10
pub const TOOLBAR_HEIGHT: f32 = 36.;9
pub const TOOLBAR_HEIGHT: f32 = 36.;