feat(channel): announcement drafts, audience hint and Teams banner size
- post drafts keep subject, headline and banner color across channel switches and reopen the post card - "N people will see your message." above the card in announcement mode (Graph channel members) - composer banner 240 px, centered 32 px headline, placeholder "Type a headline" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -185,7 +185,7 @@ mod frames {
185
185
use crate::views::composer::{
186
186
COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
187
187
COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,
188
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
188
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_AUDIENCE_TAG, POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
189
189
POST_CARD_SUBJECT_TAG,
190
190
};
191
191
use crate::views::conversation::{
@@ -2153,6 +2153,8 @@ mod frames {
2153
2153
let banner = bounds_of(POST_ANNOUNCEMENT_TAG);
2154
2154
let subject = bounds_of(POST_CARD_SUBJECT_TAG);
2155
2155
assert!(header.bottom() <= banner.top() && banner.bottom() <= subject.top());
2156
let audience = bounds_of(POST_AUDIENCE_TAG);
2157
assert!(audience.bottom() <= card.top(), "audience hint not above the card");
2156
2158
let left = f32::from(banner.left() - card.left());
2157
2159
let right = f32::from(card.right() - banner.right());
2158
2160
assert!((left - right).abs() < TOLERANCE, "banner insets: left {left}, right {right}");
@@ -185,7 +185,7 @@ mod frames {185
use crate::views::composer::{185
use crate::views::composer::{186
COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,186
COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,187
COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,187
COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,188
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,188
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_AUDIENCE_TAG, POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,189
POST_CARD_SUBJECT_TAG,189
POST_CARD_SUBJECT_TAG,190
};190
};191
use crate::views::conversation::{191
use crate::views::conversation::{@@ -2153,6 +2153,8 @@ mod frames {2153
let banner = bounds_of(POST_ANNOUNCEMENT_TAG);2153
let banner = bounds_of(POST_ANNOUNCEMENT_TAG);2154
let subject = bounds_of(POST_CARD_SUBJECT_TAG);2154
let subject = bounds_of(POST_CARD_SUBJECT_TAG);2155
assert!(header.bottom() <= banner.top() && banner.bottom() <= subject.top());2155
assert!(header.bottom() <= banner.top() && banner.bottom() <= subject.top());2156
let audience = bounds_of(POST_AUDIENCE_TAG);2157
assert!(audience.bottom() <= card.top(), "audience hint not above the card");2156
let left = f32::from(banner.left() - card.left());2158
let left = f32::from(banner.left() - card.left());2157
let right = f32::from(card.right() - banner.right());2159
let right = f32::from(card.right() - banner.right());2158
assert!((left - right).abs() < TOLERANCE, "banner insets: left {left}, right {right}");2160
assert!((left - right).abs() < TOLERANCE, "banner insets: left {left}, right {right}");@@ -35,9 +35,9 @@ mod drafts;
35
35
mod format_menus;
36
36
mod post;
37
37
pub use post::{
38
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG,
39
POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
40
POST_CARD_SUBJECT_TAG, SUBJECT_PLACEHOLDER,
38
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_AUDIENCE_TAG, POST_CARD_DIVIDER_TAG,
39
POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG, POST_CARD_SUBJECT_TAG,
40
SUBJECT_PLACEHOLDER,
41
41
};
42
42
mod rule;
43
43
mod schedule;
@@ -141,6 +141,7 @@ pub enum ComposerEvent {
141
141
Typing(bool),
142
142
Edited,
143
143
ClosePost,
144
RestorePost(Option<String>),
144
145
}
145
146
146
147
struct MentionPopup {
@@ -249,6 +250,7 @@ pub struct Composer {
249
250
format_bar: HashSet<String>,
250
251
post_subject: Option<Entity<InputState>>,
251
252
announcement: Option<post::AnnouncementDraft>,
253
audience: Option<(String, usize)>,
252
254
active_cell: Option<(String, teams_core::Cell)>,
253
255
caret_before_table: usize,
254
256
caret_text: String,
@@ -519,6 +521,7 @@ impl Composer {
519
521
format_bar: HashSet::new(),
520
522
post_subject: None,
521
523
announcement: None,
524
audience: None,
522
525
active_cell: None,
523
526
caret_before_table: 0,
524
527
caret_text: String::new(),
@@ -1873,7 +1876,7 @@ impl Composer {
1873
1876
}
1874
1877
Outgoing {
1875
1878
draft,
1876
subject: None,
1879
subject: self.post_subject_text(cx),
1877
1880
mentions,
1878
1881
reply: self.reply.clone(),
1879
1882
edit: self.editing.clone(),
@@ -2422,6 +2425,9 @@ impl Composer {
2422
2425
self.link.restore(outgoing.link_preview.clone());
2423
2426
if outgoing.edit.is_none() {
2424
2427
self.restore_announcement(outgoing.banner.as_ref(), window, cx);
2428
if !self.inline && (outgoing.subject.is_some() || outgoing.banner.is_some()) {
2429
cx.emit(ComposerEvent::RestorePost(outgoing.subject.clone()));
2430
}
2425
2431
}
2426
2432
self.close_popup();
2427
2433
self.schedule_draft_save(cx);
@@ -3394,6 +3400,7 @@ impl Render for Composer {
3394
3400
.children(self.render_reply_strip(cx))
3395
3401
.children(self.render_edit_strip(cx))
3396
3402
.children(self.render_urgent_banner(cx))
3403
.children(self.render_audience_hint())
3397
3404
.children(self.render_meeting_chip())
3398
3405
.children(self.render_link_preview(cx))
3399
3406
.child(
@@ -5278,6 +5285,49 @@ mod tests {
5278
5285
});
5279
5286
}
5280
5287
5288
#[gpui_kit::test]
5289
fn a_post_draft_keeps_subject_and_banner_across_a_channel_switch(cx: &mut TestAppContext) {
5290
use std::cell::RefCell;
5291
use std::rc::Rc;
5292
5293
use gpui_kit::component::input::InputState;
5294
5295
use super::super::ComposerEvent;
5296
5297
let (handle, composer) = demo_composer(cx);
5298
let restored = Rc::new(RefCell::new(Vec::new()));
5299
cx.update_window(handle, |_, window, cx| {
5300
let seen = restored.clone();
5301
cx.subscribe(&composer, move |_, event: &ComposerEvent, _| {
5302
if let ComposerEvent::RestorePost(subject) = event {
5303
seen.borrow_mut().push(subject.clone());
5304
}
5305
})
5306
.detach();
5307
let subject = cx.new(|cx| InputState::new(window, cx));
5308
subject.update(cx, |input, cx| input.set_value("Code freeze", window, cx));
5309
composer.update(cx, |composer, cx| {
5310
composer.set_conversation("channel-a", "A", window, cx);
5311
composer.set_post_layout(Some(subject), cx);
5312
composer.toggle_announcement(window, cx);
5313
let headline = composer.announcement.as_ref().unwrap().headline.clone();
5314
headline.update(cx, |input, cx| input.set_value("Release 43", window, cx));
5315
composer.leave_conversation("channel-b", cx);
5316
composer.set_post_layout(None, cx);
5317
composer.set_conversation("channel-b", "B", window, cx);
5318
composer.set_conversation("channel-a", "A", window, cx);
5319
});
5320
})
5321
.unwrap();
5322
cx.run_until_parked();
5323
cx.update(|cx| {
5324
let composer = composer.read(cx);
5325
let draft = composer.announcement.as_ref().unwrap();
5326
assert_eq!(draft.headline.read(cx).value().as_ref(), "Release 43");
5327
assert_eq!(*restored.borrow(), vec![Some("Code freeze".to_owned())]);
5328
});
5329
}
5330
5281
5331
#[gpui_kit::test]
5282
5332
fn sending_clears_the_stored_draft_and_a_blank_composer_deletes_it(
5283
5333
cx: &mut TestAppContext,
@@ -35,9 +35,9 @@ mod drafts;35
mod format_menus;35
mod format_menus;36
mod post;36
mod post;37
pub use post::{37
pub use post::{38
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG,38
POST_ANNOUNCEMENT_TAG, POST_ANNOUNCEMENT_TOGGLE_TAG, POST_AUDIENCE_TAG, POST_CARD_DIVIDER_TAG,39
POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,39
POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG, POST_CARD_SUBJECT_TAG,40
POST_CARD_SUBJECT_TAG, SUBJECT_PLACEHOLDER,40
SUBJECT_PLACEHOLDER,41
};41
};42
mod rule;42
mod rule;43
mod schedule;43
mod schedule;@@ -141,6 +141,7 @@ pub enum ComposerEvent {141
Typing(bool),141
Typing(bool),142
Edited,142
Edited,143
ClosePost,143
ClosePost,144
RestorePost(Option<String>),144
}145
}145
146
146
struct MentionPopup {147
struct MentionPopup {@@ -249,6 +250,7 @@ pub struct Composer {249
format_bar: HashSet<String>,250
format_bar: HashSet<String>,250
post_subject: Option<Entity<InputState>>,251
post_subject: Option<Entity<InputState>>,251
announcement: Option<post::AnnouncementDraft>,252
announcement: Option<post::AnnouncementDraft>,253
audience: Option<(String, usize)>,252
active_cell: Option<(String, teams_core::Cell)>,254
active_cell: Option<(String, teams_core::Cell)>,253
caret_before_table: usize,255
caret_before_table: usize,254
caret_text: String,256
caret_text: String,@@ -519,6 +521,7 @@ impl Composer {519
format_bar: HashSet::new(),521
format_bar: HashSet::new(),520
post_subject: None,522
post_subject: None,521
announcement: None,523
announcement: None,524
audience: None,522
active_cell: None,525
active_cell: None,523
caret_before_table: 0,526
caret_before_table: 0,524
caret_text: String::new(),527
caret_text: String::new(),@@ -1873,7 +1876,7 @@ impl Composer {1873
}1876
}1874
Outgoing {1877
Outgoing {1875
draft,1878
draft,1876
subject: None,1879
subject: self.post_subject_text(cx),1877
mentions,1880
mentions,1878
reply: self.reply.clone(),1881
reply: self.reply.clone(),1879
edit: self.editing.clone(),1882
edit: self.editing.clone(),@@ -2422,6 +2425,9 @@ impl Composer {2422
self.link.restore(outgoing.link_preview.clone());2425
self.link.restore(outgoing.link_preview.clone());2423
if outgoing.edit.is_none() {2426
if outgoing.edit.is_none() {2424
self.restore_announcement(outgoing.banner.as_ref(), window, cx);2427
self.restore_announcement(outgoing.banner.as_ref(), window, cx);2428
if !self.inline && (outgoing.subject.is_some() || outgoing.banner.is_some()) {2429
cx.emit(ComposerEvent::RestorePost(outgoing.subject.clone()));2430
}2425
}2431
}2426
self.close_popup();2432
self.close_popup();2427
self.schedule_draft_save(cx);2433
self.schedule_draft_save(cx);@@ -3394,6 +3400,7 @@ impl Render for Composer {3394
.children(self.render_reply_strip(cx))3400
.children(self.render_reply_strip(cx))3395
.children(self.render_edit_strip(cx))3401
.children(self.render_edit_strip(cx))3396
.children(self.render_urgent_banner(cx))3402
.children(self.render_urgent_banner(cx))3403
.children(self.render_audience_hint())3397
.children(self.render_meeting_chip())3404
.children(self.render_meeting_chip())3398
.children(self.render_link_preview(cx))3405
.children(self.render_link_preview(cx))3399
.child(3406
.child(@@ -5278,6 +5285,49 @@ mod tests {5278
});5285
});5279
}5286
}5280
5287
5288
#[gpui_kit::test]5289
fn a_post_draft_keeps_subject_and_banner_across_a_channel_switch(cx: &mut TestAppContext) {5290
use std::cell::RefCell;5291
use std::rc::Rc;5292
5293
use gpui_kit::component::input::InputState;5294
5295
use super::super::ComposerEvent;5296
5297
let (handle, composer) = demo_composer(cx);5298
let restored = Rc::new(RefCell::new(Vec::new()));5299
cx.update_window(handle, |_, window, cx| {5300
let seen = restored.clone();5301
cx.subscribe(&composer, move |_, event: &ComposerEvent, _| {5302
if let ComposerEvent::RestorePost(subject) = event {5303
seen.borrow_mut().push(subject.clone());5304
}5305
})5306
.detach();5307
let subject = cx.new(|cx| InputState::new(window, cx));5308
subject.update(cx, |input, cx| input.set_value("Code freeze", window, cx));5309
composer.update(cx, |composer, cx| {5310
composer.set_conversation("channel-a", "A", window, cx);5311
composer.set_post_layout(Some(subject), cx);5312
composer.toggle_announcement(window, cx);5313
let headline = composer.announcement.as_ref().unwrap().headline.clone();5314
headline.update(cx, |input, cx| input.set_value("Release 43", window, cx));5315
composer.leave_conversation("channel-b", cx);5316
composer.set_post_layout(None, cx);5317
composer.set_conversation("channel-b", "B", window, cx);5318
composer.set_conversation("channel-a", "A", window, cx);5319
});5320
})5321
.unwrap();5322
cx.run_until_parked();5323
cx.update(|cx| {5324
let composer = composer.read(cx);5325
let draft = composer.announcement.as_ref().unwrap();5326
assert_eq!(draft.headline.read(cx).value().as_ref(), "Release 43");5327
assert_eq!(*restored.borrow(), vec![Some("Code freeze".to_owned())]);5328
});5329
}5330
5281
#[gpui_kit::test]5331
#[gpui_kit::test]5282
fn sending_clears_the_stored_draft_and_a_blank_composer_deletes_it(5332
fn sending_clears_the_stored_draft_and_a_blank_composer_deletes_it(5283
cx: &mut TestAppContext,5333
cx: &mut TestAppContext,@@ -38,9 +38,13 @@ fn draft_preview(outgoing: &Outgoing) -> String {
38
38
.split_whitespace()
39
39
.collect::<Vec<_>>()
40
40
.join(" ");
41
if text.is_empty() {
41
let text = Some(text)
42
.filter(|text| !text.is_empty())
43
.or_else(|| outgoing.subject.clone())
44
.or_else(|| outgoing.banner.as_ref().map(|banner| banner.title.clone()));
45
let Some(text) = text else {
42
46
return IMAGE_ONLY_PREVIEW.to_owned();
43
}
47
};
44
48
truncated(&text, DRAFT_PREVIEW_CHARS)
45
49
}
46
50
@@ -99,7 +103,7 @@ impl DraftWrites {
99
103
}
100
104
101
105
impl Composer {
102
pub(super) fn schedule_draft_save(&mut self, cx: &mut Context<Self>) {
106
pub fn schedule_draft_save(&mut self, cx: &mut Context<Self>) {
103
107
self.draft_save = Some(cx.spawn(async move |this, cx| {
104
108
cx.background_executor().timer(DRAFT_SAVE_DELAY).await;
105
109
let Ok(Some((write, fingerprint, store, landed, sequence))) =
@@ -150,7 +154,11 @@ impl Composer {
150
154
fn storable_draft(&self, cx: &App) -> Option<Outgoing> {
151
155
let mut outgoing = self.compose(cx);
152
156
outgoing.files.clear();
153
(!outgoing.draft.is_blank() || !outgoing.images.is_empty()).then_some(outgoing)
157
(!outgoing.draft.is_blank()
158
|| !outgoing.images.is_empty()
159
|| outgoing.subject.is_some()
160
|| outgoing.banner.is_some())
161
.then_some(outgoing)
154
162
}
155
163
156
164
fn pending_draft_write(&self, cx: &App) -> Option<(DraftWrite, Option<ImageFingerprint>)> {
@@ -38,9 +38,13 @@ fn draft_preview(outgoing: &Outgoing) -> String {38
.split_whitespace()38
.split_whitespace()39
.collect::<Vec<_>>()39
.collect::<Vec<_>>()40
.join(" ");40
.join(" ");41
if text.is_empty() {41
let text = Some(text)42
.filter(|text| !text.is_empty())43
.or_else(|| outgoing.subject.clone())44
.or_else(|| outgoing.banner.as_ref().map(|banner| banner.title.clone()));45
let Some(text) = text else {42
return IMAGE_ONLY_PREVIEW.to_owned();46
return IMAGE_ONLY_PREVIEW.to_owned();43
}47
};44
truncated(&text, DRAFT_PREVIEW_CHARS)48
truncated(&text, DRAFT_PREVIEW_CHARS)45
}49
}46
50
@@ -99,7 +103,7 @@ impl DraftWrites {99
}103
}100
104
101
impl Composer {105
impl Composer {102
pub(super) fn schedule_draft_save(&mut self, cx: &mut Context<Self>) {106
pub fn schedule_draft_save(&mut self, cx: &mut Context<Self>) {103
self.draft_save = Some(cx.spawn(async move |this, cx| {107
self.draft_save = Some(cx.spawn(async move |this, cx| {104
cx.background_executor().timer(DRAFT_SAVE_DELAY).await;108
cx.background_executor().timer(DRAFT_SAVE_DELAY).await;105
let Ok(Some((write, fingerprint, store, landed, sequence))) =109
let Ok(Some((write, fingerprint, store, landed, sequence))) =@@ -150,7 +154,11 @@ impl Composer {150
fn storable_draft(&self, cx: &App) -> Option<Outgoing> {154
fn storable_draft(&self, cx: &App) -> Option<Outgoing> {151
let mut outgoing = self.compose(cx);155
let mut outgoing = self.compose(cx);152
outgoing.files.clear();156
outgoing.files.clear();153
(!outgoing.draft.is_blank() || !outgoing.images.is_empty()).then_some(outgoing)157
(!outgoing.draft.is_blank()158
|| !outgoing.images.is_empty()159
|| outgoing.subject.is_some()160
|| outgoing.banner.is_some())161
.then_some(outgoing)154
}162
}155
163
156
fn pending_draft_write(&self, cx: &App) -> Option<(DraftWrite, Option<ImageFingerprint>)> {164
fn pending_draft_write(&self, cx: &App) -> Option<(DraftWrite, Option<ImageFingerprint>)> {@@ -1,4 +1,4 @@
1
use gpui_kit::component::input::{Input, InputState};
1
use gpui_kit::component::input::{Input, InputEvent, InputState};
2
2
use gpui_kit::component::tooltip::Tooltip;
3
3
use gpui_kit::component::{Sizable as _, Size, h_flex, v_flex};
4
4
use gpui_kit::prelude::FluentBuilder as _;
@@ -7,6 +7,7 @@ use gpui_kit::*;
7
7
use teams_core::{AnnouncementBanner, BannerBackground};
8
8
9
9
use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer, ComposerEvent};
10
use crate::runtime;
10
11
use crate::theme;
11
12
use crate::views::announcement_banner::{
12
13
BANNER_COLORS, banner_fill, banner_frame, color_label, headline_style,
@@ -21,11 +22,16 @@ pub const POST_CARD_FOOTER_TAG: &str = "composer/post/footer";
21
22
pub const POST_CARD_SEND_TAG: &str = "composer/post/send";
22
23
pub const POST_ANNOUNCEMENT_TAG: &str = "composer/post/announcement";
23
24
pub const POST_ANNOUNCEMENT_TOGGLE_TAG: &str = "composer/post/announcement-toggle";
25
pub const POST_AUDIENCE_TAG: &str = "composer/post/audience";
26
const DEMO_AUDIENCE: usize = 24;
27
const AUDIENCE_HEIGHT: f32 = 32.;
24
28
const ANNOUNCEMENT_TOOLTIP: &str = "Announcement";
25
const HEADLINE_PLACEHOLDER: &str = "Add a headline";
29
const HEADLINE_PLACEHOLDER: &str = "Type a headline";
26
30
pub const SUBJECT_PLACEHOLDER: &str = "Add a subject";
27
31
const SUBHEADING_PLACEHOLDER: &str = "Add a subheading";
28
const HEADLINE_SIZE: f32 = 24.;
32
const HEADLINE_SIZE: f32 = 32.;
33
const COMPOSER_BANNER_HEIGHT: f32 = 240.;
34
const HEADLINE_LINE: f32 = 1.25;
29
35
const SWATCH_SIZE: f32 = 18.;
30
36
const SWATCH_RING: f32 = 2.;
31
37
const SWATCH_GAP: f32 = 6.;
@@ -40,8 +46,16 @@ const SUBJECT_INSET: f32 = 8.;
40
46
const TEXT_INSET: f32 = 16.;
41
47
42
48
pub(super) struct AnnouncementDraft {
43
headline: Entity<InputState>,
49
pub(super) headline: Entity<InputState>,
44
50
color: &'static str,
51
_changes: Subscription,
52
}
53
54
pub fn audience_hint(count: usize) -> String {
55
match count {
56
1 => "1 person will see your message.".to_owned(),
57
count => format!("{count} people will see your message."),
58
}
45
59
}
46
60
47
61
impl Composer {
@@ -54,6 +68,7 @@ impl Composer {
54
68
self.announcement = None;
55
69
}
56
70
if changed {
71
self.schedule_draft_save(cx);
57
72
cx.notify();
58
73
}
59
74
}
@@ -62,6 +77,20 @@ impl Composer {
62
77
self.post_subject.is_some() && self.editing.is_none()
63
78
}
64
79
80
pub(super) fn post_subject_text(&self, cx: &App) -> Option<String> {
81
let subject = self.post_subject.as_ref().filter(|_| self.post_layout())?;
82
let text = subject.read(cx).value().trim().to_owned();
83
(!text.is_empty()).then_some(text)
84
}
85
86
/// Saves the draft with its post subject and banner before the post card closes.
87
pub fn leave_conversation(&mut self, next_conversation_id: &str, cx: &mut Context<Self>) {
88
if self.conversation_id.as_deref() != Some(next_conversation_id) {
89
self.save_draft_now(cx);
90
self.conversation_id = None;
91
}
92
}
93
65
94
pub(super) fn announcement_banner(&self, cx: &App) -> Option<AnnouncementBanner> {
66
95
let draft = self.announcement.as_ref().filter(|_| self.post_layout())?;
67
96
let title = draft.headline.read(cx).value().trim().to_owned();
@@ -98,7 +127,7 @@ impl Composer {
98
127
}
99
128
}
100
129
101
fn toggle_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {
130
pub(super) fn toggle_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {
102
131
if self.announcement.is_some() {
103
132
self.close_announcement(window, cx);
104
133
self.focus(window, cx);
@@ -119,18 +148,94 @@ impl Composer {
119
148
cx: &mut Context<Self>,
120
149
) {
121
150
let headline = cx.new(|cx| InputState::new(window, cx).placeholder(HEADLINE_PLACEHOLDER));
122
self.announcement = Some(AnnouncementDraft { headline, color });
151
let changes = cx.subscribe(&headline, |this, _, event: &InputEvent, cx| {
152
if matches!(event, InputEvent::Change) {
153
this.schedule_draft_save(cx);
154
}
155
});
156
self.announcement = Some(AnnouncementDraft {
157
headline,
158
color,
159
_changes: changes,
160
});
123
161
self.set_subject_placeholder(SUBHEADING_PLACEHOLDER, window, cx);
162
self.load_audience(cx);
163
self.schedule_draft_save(cx);
124
164
cx.notify();
125
165
}
126
166
127
167
pub(super) fn close_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {
128
168
if self.announcement.take().is_some() {
129
169
self.set_subject_placeholder(SUBJECT_PLACEHOLDER, window, cx);
170
self.schedule_draft_save(cx);
130
171
cx.notify();
131
172
}
132
173
}
133
174
175
fn load_audience(&mut self, cx: &mut Context<Self>) {
176
let Some(channel_id) = self.conversation_id.clone() else {
177
return;
178
};
179
if self
180
.audience
181
.as_ref()
182
.is_some_and(|(id, _)| *id == channel_id)
183
{
184
return;
185
}
186
let state = self.app.read(cx);
187
if state.mode.demo {
188
self.audience = Some((channel_id, DEMO_AUDIENCE));
189
return;
190
}
191
let Some(engine) = state.engine.clone() else {
192
return;
193
};
194
let lookup = channel_id.clone();
195
let receiver = runtime::spawn(async move { engine.channel_member_count(&lookup).await });
196
cx.spawn(async move |this, cx| {
197
let Ok(Ok(count)) = receiver.await else {
198
return;
199
};
200
this.update(cx, |this, cx| {
201
if this.conversation_id.as_deref() == Some(channel_id.as_str()) {
202
this.audience = Some((channel_id, count));
203
cx.notify();
204
}
205
})
206
.ok();
207
})
208
.detach();
209
}
210
211
pub(super) fn render_audience_hint(&self) -> Option<Div> {
212
self.announcement.as_ref().filter(|_| self.post_layout())?;
213
let (channel_id, count) = self.audience.as_ref()?;
214
(self.conversation_id.as_ref() == Some(channel_id)).then(|| {
215
h_flex()
216
.debug_selector(|| POST_AUDIENCE_TAG.into())
217
.w_full()
218
.h(px(AUDIENCE_HEIGHT))
219
.mb(px(8.))
220
.px(px(CARD_INSET))
221
.items_center()
222
.rounded(px(10.))
223
.bg(theme::surface_raised())
224
.text_size(px(12.))
225
.text_color(theme::text_muted())
226
.child(audience_hint(*count))
227
})
228
}
229
230
pub fn sync_subject_placeholder(&self, window: &mut Window, cx: &mut Context<Self>) {
231
let placeholder = if self.announcement.is_some() {
232
SUBHEADING_PLACEHOLDER
233
} else {
234
SUBJECT_PLACEHOLDER
235
};
236
self.set_subject_placeholder(placeholder, window, cx);
237
}
238
134
239
fn set_subject_placeholder(
135
240
&self,
136
241
placeholder: &'static str,
@@ -209,6 +314,7 @@ impl Composer {
209
314
.on_click(cx.listener(move |this, _, _, cx| {
210
315
if let Some(draft) = this.announcement.as_mut() {
211
316
draft.color = color;
317
this.schedule_draft_save(cx);
212
318
cx.notify();
213
319
}
214
320
}))
@@ -221,11 +327,15 @@ impl Composer {
221
327
.pt(px(CARD_INSET))
222
328
.child(
223
329
banner_frame(&BannerBackground::Color(draft.color.to_owned()), directory)
330
.h(px(COMPOSER_BANNER_HEIGHT))
224
331
.child(
225
332
headline_style(div().w_full()).child(
226
333
Input::new(&draft.headline)
227
334
.appearance(false)
228
335
.bordered(false)
336
.text_center()
337
.h(px(HEADLINE_SIZE * HEADLINE_LINE))
338
.line_height(px(HEADLINE_SIZE * HEADLINE_LINE))
229
339
.with_size(Size::Size(px(HEADLINE_SIZE / INPUT_TEXT_SCALE))),
230
340
),
231
341
)
@@ -1,4 +1,4 @@1
use gpui_kit::component::input::{Input, InputState};1
use gpui_kit::component::input::{Input, InputEvent, InputState};2
use gpui_kit::component::tooltip::Tooltip;2
use gpui_kit::component::tooltip::Tooltip;3
use gpui_kit::component::{Sizable as _, Size, h_flex, v_flex};3
use gpui_kit::component::{Sizable as _, Size, h_flex, v_flex};4
use gpui_kit::prelude::FluentBuilder as _;4
use gpui_kit::prelude::FluentBuilder as _;@@ -7,6 +7,7 @@ use gpui_kit::*;7
use teams_core::{AnnouncementBanner, BannerBackground};7
use teams_core::{AnnouncementBanner, BannerBackground};8
8
9
use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer, ComposerEvent};9
use super::{COMPOSER_BUTTON_SIZE, COMPOSER_ICON_SIZE, Composer, ComposerEvent};10
use crate::runtime;10
use crate::theme;11
use crate::theme;11
use crate::views::announcement_banner::{12
use crate::views::announcement_banner::{12
BANNER_COLORS, banner_fill, banner_frame, color_label, headline_style,13
BANNER_COLORS, banner_fill, banner_frame, color_label, headline_style,@@ -21,11 +22,16 @@ pub const POST_CARD_FOOTER_TAG: &str = "composer/post/footer";21
pub const POST_CARD_SEND_TAG: &str = "composer/post/send";22
pub const POST_CARD_SEND_TAG: &str = "composer/post/send";22
pub const POST_ANNOUNCEMENT_TAG: &str = "composer/post/announcement";23
pub const POST_ANNOUNCEMENT_TAG: &str = "composer/post/announcement";23
pub const POST_ANNOUNCEMENT_TOGGLE_TAG: &str = "composer/post/announcement-toggle";24
pub const POST_ANNOUNCEMENT_TOGGLE_TAG: &str = "composer/post/announcement-toggle";25
pub const POST_AUDIENCE_TAG: &str = "composer/post/audience";26
const DEMO_AUDIENCE: usize = 24;27
const AUDIENCE_HEIGHT: f32 = 32.;24
const ANNOUNCEMENT_TOOLTIP: &str = "Announcement";28
const ANNOUNCEMENT_TOOLTIP: &str = "Announcement";25
const HEADLINE_PLACEHOLDER: &str = "Add a headline";29
const HEADLINE_PLACEHOLDER: &str = "Type a headline";26
pub const SUBJECT_PLACEHOLDER: &str = "Add a subject";30
pub const SUBJECT_PLACEHOLDER: &str = "Add a subject";27
const SUBHEADING_PLACEHOLDER: &str = "Add a subheading";31
const SUBHEADING_PLACEHOLDER: &str = "Add a subheading";28
const HEADLINE_SIZE: f32 = 24.;32
const HEADLINE_SIZE: f32 = 32.;33
const COMPOSER_BANNER_HEIGHT: f32 = 240.;34
const HEADLINE_LINE: f32 = 1.25;29
const SWATCH_SIZE: f32 = 18.;35
const SWATCH_SIZE: f32 = 18.;30
const SWATCH_RING: f32 = 2.;36
const SWATCH_RING: f32 = 2.;31
const SWATCH_GAP: f32 = 6.;37
const SWATCH_GAP: f32 = 6.;@@ -40,8 +46,16 @@ const SUBJECT_INSET: f32 = 8.;40
const TEXT_INSET: f32 = 16.;46
const TEXT_INSET: f32 = 16.;41
47
42
pub(super) struct AnnouncementDraft {48
pub(super) struct AnnouncementDraft {43
headline: Entity<InputState>,49
pub(super) headline: Entity<InputState>,44
color: &'static str,50
color: &'static str,51
_changes: Subscription,52
}53
54
pub fn audience_hint(count: usize) -> String {55
match count {56
1 => "1 person will see your message.".to_owned(),57
count => format!("{count} people will see your message."),58
}45
}59
}46
60
47
impl Composer {61
impl Composer {@@ -54,6 +68,7 @@ impl Composer {54
self.announcement = None;68
self.announcement = None;55
}69
}56
if changed {70
if changed {71
self.schedule_draft_save(cx);57
cx.notify();72
cx.notify();58
}73
}59
}74
}@@ -62,6 +77,20 @@ impl Composer {62
self.post_subject.is_some() && self.editing.is_none()77
self.post_subject.is_some() && self.editing.is_none()63
}78
}64
79
80
pub(super) fn post_subject_text(&self, cx: &App) -> Option<String> {81
let subject = self.post_subject.as_ref().filter(|_| self.post_layout())?;82
let text = subject.read(cx).value().trim().to_owned();83
(!text.is_empty()).then_some(text)84
}85
86
/// Saves the draft with its post subject and banner before the post card closes.87
pub fn leave_conversation(&mut self, next_conversation_id: &str, cx: &mut Context<Self>) {88
if self.conversation_id.as_deref() != Some(next_conversation_id) {89
self.save_draft_now(cx);90
self.conversation_id = None;91
}92
}93
65
pub(super) fn announcement_banner(&self, cx: &App) -> Option<AnnouncementBanner> {94
pub(super) fn announcement_banner(&self, cx: &App) -> Option<AnnouncementBanner> {66
let draft = self.announcement.as_ref().filter(|_| self.post_layout())?;95
let draft = self.announcement.as_ref().filter(|_| self.post_layout())?;67
let title = draft.headline.read(cx).value().trim().to_owned();96
let title = draft.headline.read(cx).value().trim().to_owned();@@ -98,7 +127,7 @@ impl Composer {98
}127
}99
}128
}100
129
101
fn toggle_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {130
pub(super) fn toggle_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {102
if self.announcement.is_some() {131
if self.announcement.is_some() {103
self.close_announcement(window, cx);132
self.close_announcement(window, cx);104
self.focus(window, cx);133
self.focus(window, cx);@@ -119,18 +148,94 @@ impl Composer {119
cx: &mut Context<Self>,148
cx: &mut Context<Self>,120
) {149
) {121
let headline = cx.new(|cx| InputState::new(window, cx).placeholder(HEADLINE_PLACEHOLDER));150
let headline = cx.new(|cx| InputState::new(window, cx).placeholder(HEADLINE_PLACEHOLDER));122
self.announcement = Some(AnnouncementDraft { headline, color });151
let changes = cx.subscribe(&headline, |this, _, event: &InputEvent, cx| {152
if matches!(event, InputEvent::Change) {153
this.schedule_draft_save(cx);154
}155
});156
self.announcement = Some(AnnouncementDraft {157
headline,158
color,159
_changes: changes,160
});123
self.set_subject_placeholder(SUBHEADING_PLACEHOLDER, window, cx);161
self.set_subject_placeholder(SUBHEADING_PLACEHOLDER, window, cx);162
self.load_audience(cx);163
self.schedule_draft_save(cx);124
cx.notify();164
cx.notify();125
}165
}126
166
127
pub(super) fn close_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {167
pub(super) fn close_announcement(&mut self, window: &mut Window, cx: &mut Context<Self>) {128
if self.announcement.take().is_some() {168
if self.announcement.take().is_some() {129
self.set_subject_placeholder(SUBJECT_PLACEHOLDER, window, cx);169
self.set_subject_placeholder(SUBJECT_PLACEHOLDER, window, cx);170
self.schedule_draft_save(cx);130
cx.notify();171
cx.notify();131
}172
}132
}173
}133
174
175
fn load_audience(&mut self, cx: &mut Context<Self>) {176
let Some(channel_id) = self.conversation_id.clone() else {177
return;178
};179
if self180
.audience181
.as_ref()182
.is_some_and(|(id, _)| *id == channel_id)183
{184
return;185
}186
let state = self.app.read(cx);187
if state.mode.demo {188
self.audience = Some((channel_id, DEMO_AUDIENCE));189
return;190
}191
let Some(engine) = state.engine.clone() else {192
return;193
};194
let lookup = channel_id.clone();195
let receiver = runtime::spawn(async move { engine.channel_member_count(&lookup).await });196
cx.spawn(async move |this, cx| {197
let Ok(Ok(count)) = receiver.await else {198
return;199
};200
this.update(cx, |this, cx| {201
if this.conversation_id.as_deref() == Some(channel_id.as_str()) {202
this.audience = Some((channel_id, count));203
cx.notify();204
}205
})206
.ok();207
})208
.detach();209
}210
211
pub(super) fn render_audience_hint(&self) -> Option<Div> {212
self.announcement.as_ref().filter(|_| self.post_layout())?;213
let (channel_id, count) = self.audience.as_ref()?;214
(self.conversation_id.as_ref() == Some(channel_id)).then(|| {215
h_flex()216
.debug_selector(|| POST_AUDIENCE_TAG.into())217
.w_full()218
.h(px(AUDIENCE_HEIGHT))219
.mb(px(8.))220
.px(px(CARD_INSET))221
.items_center()222
.rounded(px(10.))223
.bg(theme::surface_raised())224
.text_size(px(12.))225
.text_color(theme::text_muted())226
.child(audience_hint(*count))227
})228
}229
230
pub fn sync_subject_placeholder(&self, window: &mut Window, cx: &mut Context<Self>) {231
let placeholder = if self.announcement.is_some() {232
SUBHEADING_PLACEHOLDER233
} else {234
SUBJECT_PLACEHOLDER235
};236
self.set_subject_placeholder(placeholder, window, cx);237
}238
134
fn set_subject_placeholder(239
fn set_subject_placeholder(135
&self,240
&self,136
placeholder: &'static str,241
placeholder: &'static str,@@ -209,6 +314,7 @@ impl Composer {209
.on_click(cx.listener(move |this, _, _, cx| {314
.on_click(cx.listener(move |this, _, _, cx| {210
if let Some(draft) = this.announcement.as_mut() {315
if let Some(draft) = this.announcement.as_mut() {211
draft.color = color;316
draft.color = color;317
this.schedule_draft_save(cx);212
cx.notify();318
cx.notify();213
}319
}214
}))320
}))@@ -221,11 +327,15 @@ impl Composer {221
.pt(px(CARD_INSET))327
.pt(px(CARD_INSET))222
.child(328
.child(223
banner_frame(&BannerBackground::Color(draft.color.to_owned()), directory)329
banner_frame(&BannerBackground::Color(draft.color.to_owned()), directory)330
.h(px(COMPOSER_BANNER_HEIGHT))224
.child(331
.child(225
headline_style(div().w_full()).child(332
headline_style(div().w_full()).child(226
Input::new(&draft.headline)333
Input::new(&draft.headline)227
.appearance(false)334
.appearance(false)228
.bordered(false)335
.bordered(false)336
.text_center()337
.h(px(HEADLINE_SIZE * HEADLINE_LINE))338
.line_height(px(HEADLINE_SIZE * HEADLINE_LINE))229
.with_size(Size::Size(px(HEADLINE_SIZE / INPUT_TEXT_SCALE))),339
.with_size(Size::Size(px(HEADLINE_SIZE / INPUT_TEXT_SCALE))),230
),340
),231
)341
)@@ -790,6 +790,9 @@ impl ConversationView {
790
790
ComposerEvent::Typing(active) => self.send_typing(*active, cx),
791
791
ComposerEvent::Edited => {}
792
792
ComposerEvent::ClosePost => self.cancel_new_post(window, cx),
793
ComposerEvent::RestorePost(subject) => {
794
self.restore_new_post(subject.clone(), window, cx)
795
}
793
796
}
794
797
}
795
798
@@ -915,6 +918,10 @@ impl ConversationView {
915
918
}
916
919
self.stop_typing(cx);
917
920
self.stop_reply_typing(cx);
921
let next_conversation_id = selection.conversation_id().to_owned();
922
self.composer.update(cx, |composer, cx| {
923
composer.leave_conversation(&next_conversation_id, cx)
924
});
918
925
self.close_new_post(cx);
919
926
self.feed_stash = None;
920
927
self.feed_at_top = true;
@@ -790,6 +790,9 @@ impl ConversationView {790
ComposerEvent::Typing(active) => self.send_typing(*active, cx),790
ComposerEvent::Typing(active) => self.send_typing(*active, cx),791
ComposerEvent::Edited => {}791
ComposerEvent::Edited => {}792
ComposerEvent::ClosePost => self.cancel_new_post(window, cx),792
ComposerEvent::ClosePost => self.cancel_new_post(window, cx),793
ComposerEvent::RestorePost(subject) => {794
self.restore_new_post(subject.clone(), window, cx)795
}793
}796
}794
}797
}795
798
@@ -915,6 +918,10 @@ impl ConversationView {915
}918
}916
self.stop_typing(cx);919
self.stop_typing(cx);917
self.stop_reply_typing(cx);920
self.stop_reply_typing(cx);921
let next_conversation_id = selection.conversation_id().to_owned();922
self.composer.update(cx, |composer, cx| {923
composer.leave_conversation(&next_conversation_id, cx)924
});918
self.close_new_post(cx);925
self.close_new_post(cx);919
self.feed_stash = None;926
self.feed_stash = None;920
self.feed_at_top = true;927
self.feed_at_top = true;@@ -51,11 +51,28 @@ impl ConversationView {
51
51
fn mark_new_post_open(&mut self, cx: &mut Context<Self>) {
52
52
self.new_post_open = true;
53
53
let subject = self.subject.clone();
54
self.composer
55
.update(cx, |composer, cx| composer.set_post_layout(Some(subject), cx));
54
self.composer.update(cx, |composer, cx| {
55
composer.set_post_layout(Some(subject), cx)
56
});
56
57
cx.notify();
57
58
}
58
59
60
pub(super) fn restore_new_post(
61
&mut self,
62
subject: Option<String>,
63
window: &mut Window,
64
cx: &mut Context<Self>,
65
) {
66
if !self.in_feed() {
67
return;
68
}
69
self.restore_subject(subject.as_deref(), window, cx);
70
self.mark_new_post_open(cx);
71
self.composer.update(cx, |composer, cx| {
72
composer.sync_subject_placeholder(window, cx)
73
});
74
}
75
59
76
pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {
60
77
self.composer
61
78
.update(cx, |composer, cx| composer.set_post_layout(None, cx));
@@ -98,9 +115,14 @@ impl ConversationView {
98
115
window: &mut Window,
99
116
cx: &mut Context<Self>,
100
117
) {
101
if matches!(event, InputEvent::PressEnter { .. }) {
102
self.composer
103
.update(cx, |composer, cx| composer.focus(window, cx));
118
match event {
119
InputEvent::PressEnter { .. } => self
120
.composer
121
.update(cx, |composer, cx| composer.focus(window, cx)),
122
InputEvent::Change => self
123
.composer
124
.update(cx, |composer, cx| composer.schedule_draft_save(cx)),
125
_ => {}
104
126
}
105
127
}
106
128
@@ -220,7 +242,8 @@ impl ConversationView {
220
242
ComposerEvent::Schedule { .. }
221
243
| ComposerEvent::EditLast
222
244
| ComposerEvent::FocusMessages
223
| ComposerEvent::ClosePost => {}
245
| ComposerEvent::ClosePost
246
| ComposerEvent::RestorePost(_) => {}
224
247
}
225
248
}
226
249
@@ -51,11 +51,28 @@ impl ConversationView {51
fn mark_new_post_open(&mut self, cx: &mut Context<Self>) {51
fn mark_new_post_open(&mut self, cx: &mut Context<Self>) {52
self.new_post_open = true;52
self.new_post_open = true;53
let subject = self.subject.clone();53
let subject = self.subject.clone();54
self.composer54
self.composer.update(cx, |composer, cx| {55
.update(cx, |composer, cx| composer.set_post_layout(Some(subject), cx));55
composer.set_post_layout(Some(subject), cx)56
});56
cx.notify();57
cx.notify();57
}58
}58
59
60
pub(super) fn restore_new_post(61
&mut self,62
subject: Option<String>,63
window: &mut Window,64
cx: &mut Context<Self>,65
) {66
if !self.in_feed() {67
return;68
}69
self.restore_subject(subject.as_deref(), window, cx);70
self.mark_new_post_open(cx);71
self.composer.update(cx, |composer, cx| {72
composer.sync_subject_placeholder(window, cx)73
});74
}75
59
pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {76
pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {60
self.composer77
self.composer61
.update(cx, |composer, cx| composer.set_post_layout(None, cx));78
.update(cx, |composer, cx| composer.set_post_layout(None, cx));@@ -98,9 +115,14 @@ impl ConversationView {98
window: &mut Window,115
window: &mut Window,99
cx: &mut Context<Self>,116
cx: &mut Context<Self>,100
) {117
) {101
if matches!(event, InputEvent::PressEnter { .. }) {118
match event {102
self.composer119
InputEvent::PressEnter { .. } => self103
.update(cx, |composer, cx| composer.focus(window, cx));120
.composer121
.update(cx, |composer, cx| composer.focus(window, cx)),122
InputEvent::Change => self123
.composer124
.update(cx, |composer, cx| composer.schedule_draft_save(cx)),125
_ => {}104
}126
}105
}127
}106
128
@@ -220,7 +242,8 @@ impl ConversationView {220
ComposerEvent::Schedule { .. }242
ComposerEvent::Schedule { .. }221
| ComposerEvent::EditLast243
| ComposerEvent::EditLast222
| ComposerEvent::FocusMessages244
| ComposerEvent::FocusMessages223
| ComposerEvent::ClosePost => {}245
| ComposerEvent::ClosePost246
| ComposerEvent::RestorePost(_) => {}224
}247
}225
}248
}226
249
@@ -25,6 +25,13 @@ impl<R: Remote> SyncEngine<R> {
25
25
.await
26
26
}
27
27
28
pub async fn channel_member_count(&self, channel_id: &str) -> Result<usize> {
29
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
30
return Err(Error::Unsupported("a member count for a chat"));
31
};
32
self.remote.channel_member_count(&team_id, channel_id).await
33
}
34
28
35
pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
29
36
self.remote.list_children(folder).await
30
37
}
@@ -25,6 +25,13 @@ impl<R: Remote> SyncEngine<R> {25
.await25
.await26
}26
}27
27
28
pub async fn channel_member_count(&self, channel_id: &str) -> Result<usize> {29
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {30
return Err(Error::Unsupported("a member count for a chat"));31
};32
self.remote.channel_member_count(&team_id, channel_id).await33
}34
28
pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {35
pub async fn library_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {29
self.remote.list_children(folder).await36
self.remote.list_children(folder).await30
}37
}@@ -222,6 +222,10 @@ pub trait Remote {
222
222
Err(Error::Unsupported("a channel tab link"))
223
223
}
224
224
225
async fn channel_member_count(&self, _team_id: &str, _channel_id: &str) -> Result<usize> {
226
Err(Error::Unsupported("a channel member count"))
227
}
228
225
229
async fn list_children(&self, _folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
226
230
Err(Error::Unsupported("a folder listing"))
227
231
}
@@ -1007,6 +1011,10 @@ impl Remote for Graph {
1007
1011
Ok(Graph::channel_tab_web_url(self, team_id, channel_id, tab_id).await?)
1008
1012
}
1009
1013
1014
async fn channel_member_count(&self, team_id: &str, channel_id: &str) -> Result<usize> {
1015
Ok(Graph::channel_member_count(self, team_id, channel_id).await?)
1016
}
1017
1010
1018
async fn list_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {
1011
1019
Ok(Graph::list_children(self, folder).await?)
1012
1020
}
@@ -222,6 +222,10 @@ pub trait Remote {222
Err(Error::Unsupported("a channel tab link"))222
Err(Error::Unsupported("a channel tab link"))223
}223
}224
224
225
async fn channel_member_count(&self, _team_id: &str, _channel_id: &str) -> Result<usize> {226
Err(Error::Unsupported("a channel member count"))227
}228
225
async fn list_children(&self, _folder: &DriveFolder) -> Result<Vec<DriveEntry>> {229
async fn list_children(&self, _folder: &DriveFolder) -> Result<Vec<DriveEntry>> {226
Err(Error::Unsupported("a folder listing"))230
Err(Error::Unsupported("a folder listing"))227
}231
}@@ -1007,6 +1011,10 @@ impl Remote for Graph {1007
Ok(Graph::channel_tab_web_url(self, team_id, channel_id, tab_id).await?)1011
Ok(Graph::channel_tab_web_url(self, team_id, channel_id, tab_id).await?)1008
}1012
}1009
1013
1014
async fn channel_member_count(&self, team_id: &str, channel_id: &str) -> Result<usize> {1015
Ok(Graph::channel_member_count(self, team_id, channel_id).await?)1016
}1017
1010
async fn list_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {1018
async fn list_children(&self, folder: &DriveFolder) -> Result<Vec<DriveEntry>> {1011
Ok(Graph::list_children(self, folder).await?)1019
Ok(Graph::list_children(self, folder).await?)1012
}1020
}@@ -6,6 +6,7 @@ use crate::error::Result;
6
6
use crate::urls;
7
7
8
8
const TABS_SCOPE: &str = "TeamsTab.ReadWrite.All";
9
const MEMBERS_SCOPE: &str = "ChannelMember.Read.All";
9
10
10
11
fn web_url(tab: &Value) -> Option<String> {
11
12
tab.get("webUrl")
@@ -29,6 +30,16 @@ impl Graph {
29
30
.await?;
30
31
Ok(web_url(&tab))
31
32
}
33
34
pub async fn channel_member_count(&self, team_id: &str, channel_id: &str) -> Result<usize> {
35
let members: Vec<Value> = self
36
.get_all(
37
&urls::channel_members(team_id, channel_id),
38
Scope::graph(MEMBERS_SCOPE),
39
)
40
.await?;
41
Ok(members.len())
42
}
32
43
}
33
44
34
45
#[cfg(test)]
@@ -6,6 +6,7 @@ use crate::error::Result;6
use crate::urls;6
use crate::urls;7
7
8
const TABS_SCOPE: &str = "TeamsTab.ReadWrite.All";8
const TABS_SCOPE: &str = "TeamsTab.ReadWrite.All";9
const MEMBERS_SCOPE: &str = "ChannelMember.Read.All";9
10
10
fn web_url(tab: &Value) -> Option<String> {11
fn web_url(tab: &Value) -> Option<String> {11
tab.get("webUrl")12
tab.get("webUrl")@@ -29,6 +30,16 @@ impl Graph {29
.await?;30
.await?;30
Ok(web_url(&tab))31
Ok(web_url(&tab))31
}32
}33
34
pub async fn channel_member_count(&self, team_id: &str, channel_id: &str) -> Result<usize> {35
let members: Vec<Value> = self36
.get_all(37
&urls::channel_members(team_id, channel_id),38
Scope::graph(MEMBERS_SCOPE),39
)40
.await?;41
Ok(members.len())42
}32
}43
}33
44
34
#[cfg(test)]45
#[cfg(test)]@@ -184,6 +184,14 @@ pub fn channel_files_folder(team_id: &str, channel_id: &str) -> String {
184
184
)
185
185
}
186
186
187
pub fn channel_members(team_id: &str, channel_id: &str) -> String {
188
format!(
189
"{GRAPH}/v1.0/teams/{}/channels/{}/members?$select=id&$top=999",
190
segment(team_id),
191
segment(channel_id)
192
)
193
}
194
187
195
pub fn channel_tab(team_id: &str, channel_id: &str, tab_id: &str) -> String {
188
196
format!(
189
197
"{GRAPH}/v1.0/teams/{}/channels/{}/tabs/{}",
@@ -365,6 +373,16 @@ mod tests {
365
373
366
374
use super::*;
367
375
376
#[test]
377
fn channel_members_ask_for_ids_only_in_large_pages() {
378
assert_eq!(
379
channel_members("t 1", "19:c@thread.tacv2"),
380
format!(
381
"{GRAPH}/v1.0/teams/t%201/channels/19%3Ac%40thread.tacv2/members?$select=id&$top=999"
382
)
383
);
384
}
385
368
386
#[test]
369
387
fn photos_ask_for_the_240_rendition_then_the_original() {
370
388
assert_eq!(
@@ -184,6 +184,14 @@ pub fn channel_files_folder(team_id: &str, channel_id: &str) -> String {184
)184
)185
}185
}186
186
187
pub fn channel_members(team_id: &str, channel_id: &str) -> String {188
format!(189
"{GRAPH}/v1.0/teams/{}/channels/{}/members?$select=id&$top=999",190
segment(team_id),191
segment(channel_id)192
)193
}194
187
pub fn channel_tab(team_id: &str, channel_id: &str, tab_id: &str) -> String {195
pub fn channel_tab(team_id: &str, channel_id: &str, tab_id: &str) -> String {188
format!(196
format!(189
"{GRAPH}/v1.0/teams/{}/channels/{}/tabs/{}",197
"{GRAPH}/v1.0/teams/{}/channels/{}/tabs/{}",@@ -365,6 +373,16 @@ mod tests {365
373
366
use super::*;374
use super::*;367
375
376
#[test]377
fn channel_members_ask_for_ids_only_in_large_pages() {378
assert_eq!(379
channel_members("t 1", "19:c@thread.tacv2"),380
format!(381
"{GRAPH}/v1.0/teams/t%201/channels/19%3Ac%40thread.tacv2/members?$select=id&$top=999"382
)383
);384
}385
368
#[test]386
#[test]369
fn photos_ask_for_the_240_rendition_then_the_original() {387
fn photos_ask_for_the_240_rendition_then_the_original() {370
assert_eq!(388
assert_eq!(