Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(calendar): strip Macro call links from exported .ics files (#8571)
gbirman6d9fff7a1581
diff --git a/crates/calendar_events/src/domain/ics.rs b/crates/calendar_events/src/domain/ics.rsindex 6d80809c99..6016b2725c 100644--- a/crates/calendar_events/src/domain/ics.rs+++ b/crates/calendar_events/src/domain/ics.rs@@ -7,7 +7,10 @@ mod test;use chrono::{DateTime, NaiveDate, Utc};use chrono_tz::Tz;-use super::models::EventTime;+use super::{+ meeting_links::{first_macro_call_url, strip_macro_call},+ models::EventTime,+};/// Longest content line, in octets, before RFC 5545 folding.const MAX_LINE_OCTETS: usize = 75;@@ -17,7 +20,8 @@ const MAX_LINE_OCTETS: usize = 75;////// Attendees and the conference link are deliberately absent: a channel/// share exposes the meeting, not its guest list or join link, and the export-/// has one shape however the requester sees the event.+/// has one shape however the requester sees the event. A Macro call travels+/// in the description and location instead, so the renderer strips it there.#[derive(Clone, Debug, PartialEq, Eq)]pub struct CalendarEventExport {/// RFC 5545 UID shared by every projection of the meeting.@@ -80,16 +84,22 @@ pub fn render_event_ics(event: &CalendarEventExport) -> String {lines.extend(time_lines(&event.time, !recurrence_lines.is_empty()));lines.extend(recurrence_lines.into_iter().map(str::to_string));lines.push(format!("SUMMARY:{}", escape_text(&event.title)));- if let Some(description) = event+ let description = event.description.as_deref().and_then(plain_text)- .filter(|text| !text.is_empty())- {+ .unwrap_or_default();+ let location = event.location.clone().unwrap_or_default();+ let (description, location) =+ match first_macro_call_url(event.location.as_deref(), event.description.as_deref()) {+ Some(url) => strip_macro_call(&description, &location, &url),+ None => (description, location),+ };+ if !description.is_empty() {lines.push(format!("DESCRIPTION:{}", escape_text(&description)));}- if let Some(location) = event.location.as_deref().filter(|value| !value.is_empty()) {- lines.push(format!("LOCATION:{}", escape_text(location)));+ if !location.is_empty() {+ lines.push(format!("LOCATION:{}", escape_text(&location)));}if let Some(email) = event.organizer_email.as_deref() {let name = eventdiff --git a/crates/calendar_events/src/domain/ics/test.rs b/crates/calendar_events/src/domain/ics/test.rsindex 7265d0d5d0..4216fd8302 100644--- a/crates/calendar_events/src/domain/ics/test.rs+++ b/crates/calendar_events/src/domain/ics/test.rs@@ -1,7 +1,9 @@use chrono::{NaiveDate, TimeZone, Utc};use super::{CalendarEventExport, render_event_ics};-use crate::domain::models::EventTime;+use crate::domain::{meeting_links::attach_macro_call, models::EventTime};++const CALL_URL: &str = "https://macro.com/app/meet/join/0123456789abcdef0123456789abcdef";fn export(time: EventTime) -> CalendarEventExport {CalendarEventExport {@@ -122,6 +124,66 @@ fn plain_text_description_keeps_its_line_breaks() {assert!(lines.contains(&"DESCRIPTION:Dial in first\\nthen share your screen".to_string()));}+#[test]+fn a_macro_call_leaves_neither_its_join_line_nor_its_link_as_the_location() {+ let mut event = export(all_day());+ let (description, location) =+ attach_macro_call(Some("<p>Bring the budget draft</p>"), None, CALL_URL);+ event.description = Some(description);+ event.location = Some(location);++ let document = render_event_ics(&event);+ let lines = unfolded(&document);++ assert!(+ lines.contains(&"DESCRIPTION:Bring the budget draft".to_string()),+ "{lines:?}"+ );+ assert!(+ !lines.iter().any(|line| line.starts_with("LOCATION")),+ "{lines:?}"+ );+ assert!(!document.contains("/meet/join/"), "{lines:?}");+}++#[test]+fn a_macro_call_keeps_a_physical_location_and_drops_an_empty_description() {+ let mut event = export(all_day());+ let (description, location) = attach_macro_call(None, Some("Room 4"), CALL_URL);+ event.description = Some(description);+ event.location = Some(location);++ let lines = unfolded(&render_event_ics(&event));++ assert!(lines.contains(&"LOCATION:Room 4".to_string()), "{lines:?}");+ assert!(+ !lines.iter().any(|line| line.starts_with("DESCRIPTION")),+ "{lines:?}"+ );+}++#[test]+fn the_join_line_goes_even_when_an_earlier_call_link_is_found_first() {+ let earlier = "https://macro.com/app/meet/join/fedcba9876543210fedcba9876543210";+ let mut event = export(all_day());+ let (description, location) = attach_macro_call(+ Some(&format!("<p>Last week: {earlier}</p>")),+ Some("Room 4"),+ CALL_URL,+ );+ event.description = Some(description);+ event.location = Some(location);++ let document = render_event_ics(&event);+ let lines = unfolded(&document);++ assert!(+ lines.contains(&format!("DESCRIPTION:Last week: {earlier}")),+ "{lines:?}"+ );+ assert!(!document.contains(CALL_URL), "{lines:?}");+}+#[test]fn stored_line_breaks_cannot_start_a_new_property() {let mut event = export(EventTime::Timed {diff --git a/crates/calendar_events/src/domain/meeting_links.rs b/crates/calendar_events/src/domain/meeting_links.rsindex 682a67179b..0d7cb60203 100644--- a/crates/calendar_events/src/domain/meeting_links.rs+++ b/crates/calendar_events/src/domain/meeting_links.rs@@ -3,8 +3,9 @@//! A Macro call is not provider conferencing: Google knows nothing about it,//! so the link travels in the event's ordinary location and description//! fields, in the exact shape the calendar UI recognizes and can later-//! strip or replace. This module owns that shape and the create flow that-//! mints a meeting and writes the event carrying it.+//! strip or replace. This module owns that shape, finding and stripping it+//! again, and the create flow that mints a meeting and writes the event+//! carrying it.use chrono::{DateTime, Utc};use uuid::Uuid;@@ -116,6 +117,56 @@ pub fn attach_macro_call((description, location)}+/// The join link already written into an event, including inside the+/// generated HTML paragraph.+pub fn first_macro_call_url(location: Option<&str>, description: Option<&str>) -> Option<String> {+ for text in [location, description].into_iter().flatten() {+ for token in text.split(|character: char| {+ character.is_whitespace() || matches!(character, '"' | '\'' | '<' | '>' | '&')+ }) {+ let token = token.trim_end_matches(|character: char| {+ matches!(character, '.' | ',' | ')' | ']' | ';')+ });+ if token.starts_with("http") && token.contains("/meet/join/") {+ return Some(token.to_string());+ }+ }+ }+ None+}++/// Take back out what [`attach_macro_call`] wrote, as the calendar UI does+/// before showing an event: the join line of a description already reduced+/// to plain text, whichever call it names, and a location that is only the+/// event's call link `url`. Everything the user wrote stays, including a+/// link written anywhere else. The text may show the link in brackets, as+/// html2text writes links.+pub fn strip_macro_call(description_text: &str, location: &str, url: &str) -> (String, String) {+ let description = description_text+ .lines()+ .filter(|line| !is_join_line(&line.trim().replace(['[', ']'], "")))+ .collect::<Vec<_>>()+ .join("\n");+ let location = if location.trim() == url {+ String::new()+ } else {+ location.to_string()+ };+ (description.trim().to_string(), location)+}++/// Whether `line` is the generated join line: the label alone, or the label+/// followed by a Macro call link.+fn is_join_line(line: &str) -> bool {+ match line.strip_prefix(JOIN_LINE_LABEL) {+ Some("") => true,+ Some(rest) => rest+ .strip_prefix(": ")+ .is_some_and(|link| first_macro_call_url(Some(link), None).as_deref() == Some(link)),+ None => false,+ }+}+/// Create an event that carries a Macro call.////// The meeting is minted first so the single invitation attendees receivediff --git a/crates/calendar_scheduling/src/outbound/macro_services.rs b/crates/calendar_scheduling/src/outbound/macro_services.rsindex 45068c9893..32e73ff65b 100644--- a/crates/calendar_scheduling/src/outbound/macro_services.rs+++ b/crates/calendar_scheduling/src/outbound/macro_services.rs@@ -4,7 +4,7 @@ use crate::domain::{ports::{Calendars, Directory},};use calendar_events::domain::{- meeting_links::create_event_with_macro_call,+ meeting_links::{create_event_with_macro_call, first_macro_call_url},models::{CalendarAttendeeInput, CalendarEventDraft, CalendarSyncStatus, ConferenceChange, EventTime,EventTransparency, OccurrenceRange,@@ -444,23 +444,5 @@ fn carries_url(location: Option<&str>, description: Option<&str>, url: &str) ->|| description.is_some_and(|value| value.contains(url))}-/// The join link already written into an event, including inside the-/// generated HTML paragraph.-fn first_macro_call_url(location: Option<&str>, description: Option<&str>) -> Option<String> {- for text in [location, description].into_iter().flatten() {- for token in text.split(|character: char| {- character.is_whitespace() || matches!(character, '"' | '\'' | '<' | '>' | '&')- }) {- let token = token.trim_end_matches(|character: char| {- matches!(character, '.' | ',' | ')' | ']' | ';')- });- if token.starts_with("http") && token.contains("/meet/join/") {- return Some(token.to_string());- }- }- }- None-}-#[cfg(test)]mod test;diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.mdindex c5d4684f78..02c8fb43b8 100644--- a/docs/agent-guide/calendar.md+++ b/docs/agent-guide/calendar.md@@ -462,7 +462,9 @@ explanation; an Outlook organizer adds guests like a Google one.The details header's `Download .ics` icon button, beside `Copy event`, saves the event as aniCalendar file named after its title, so it can be passed on or added to another calendar. Thefile holds the series (its repeat rule, in the event's original time zone), title, description-as plain text, location and organizer, never the guest list or join link. Like `Copy event`, it+as plain text, location and organizer, never the guest list or join link. A Macro call's+`Join Macro call` line and a location that is only its link are left out too, as event details+leave them out. Like `Copy event`, itis absent from teammates' out-of-office chips. Its endpoint, document storage's`GET /calendar-events/{event_id}/ics`, also exports an event shared with a channel the viewerbelongs to.