Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(calendar): match an Outlook meeting copy to its Google copies (#8745)

gbirman4704e09033e3
diff --git a/.sqlx/query-f4ac6711db74208d4ab2c909150dacef6abdc5ce1db574cbda8bd488cd91c6b5.json b/.sqlx/query-41c9b8b64954e28433337d9dcd878574dd0f831c81b7c5110b5f17fdb5cdca41.json
similarity index 62%
rename from .sqlx/query-f4ac6711db74208d4ab2c909150dacef6abdc5ce1db574cbda8bd488cd91c6b5.json
rename to .sqlx/query-41c9b8b64954e28433337d9dcd878574dd0f831c81b7c5110b5f17fdb5cdca41.json
index c715a4e37a..3e9658ce69 100644
--- a/.sqlx/query-f4ac6711db74208d4ab2c909150dacef6abdc5ce1db574cbda8bd488cd91c6b5.json
+++ b/.sqlx/query-41c9b8b64954e28433337d9dcd878574dd0f831c81b7c5110b5f17fdb5cdca41.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n (mentioned.id IS NOT NULL) AS \"mention_exists!\",\n viewer_event.id AS \"resolved_event_id?\",\n viewer_event.is_channel_shared AS \"is_channel_shared?\",\n viewer_event.is_snapshot AS \"is_snapshot?\",\n viewer_event.inbox_organizes AS \"inbox_organizes?\",\n viewer_event.inbox_attends AS \"inbox_attends?\",\n COALESCE(occurrence_override.title, viewer_event.title) AS \"title?\",\n left(\n COALESCE(occurrence_override.description, viewer_event.description),\n $5\n ) AS \"description?\",\n COALESCE(occurrence_override.location, viewer_event.location) AS \"location?\",\n viewer_event.organizer_email AS \"organizer_email?\",\n viewer_event.organizer_name AS \"organizer_name?\",\n viewer_event.recurrence_lines AS \"recurrence_lines?\",\n viewer_event.starts_at AS \"event_starts_at?\",\n viewer_event.ends_at AS \"event_ends_at?\",\n viewer_event.start_date AS \"event_start_date?\",\n viewer_event.end_date AS \"event_end_date?\",\n viewer_event.time_zone AS \"time_zone?\",\n viewer_event.updated_at AS \"updated_at?\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\",\n attendees.attendee_count AS \"attendee_count?\"\n FROM unnest($2::uuid[], $3::text[])\n WITH ORDINALITY AS requested(event_id, occurrence_key, ord)\n LEFT JOIN calendar_events mentioned\n ON mentioned.id = requested.event_id\n AND mentioned.status <> 'cancelled'\n LEFT JOIN LATERAL (\n SELECT resolved.*\n FROM (\n SELECT\n candidate.id,\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = mentioned.id) AS is_mentioned,\n candidate.is_snapshot,\n -- The copy's own inbox decides how the requester\n -- holds it, as it decides their capabilities: an\n -- inbox they own that organizes it or is on it.\n COALESCE(\n lower(copy_inbox.email_address) = lower(candidate.organizer_email)\n OR EXISTS (\n SELECT 1\n FROM calendar_event_attendees organizer\n WHERE organizer.event_id = candidate.id\n AND organizer.is_organizer\n AND lower(organizer.email) = lower(copy_inbox.email_address)\n ),\n false\n ) AS inbox_organizes,\n EXISTS (\n SELECT 1\n FROM calendar_event_attendees guest\n WHERE guest.event_id = candidate.id\n AND lower(guest.email) = lower(copy_inbox.email_address)\n ) AS inbox_attends,\n candidate.title,\n candidate.description,\n candidate.location,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.recurrence_lines,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.updated_at\n FROM calendar_events candidate\n LEFT JOIN email_links copy_inbox\n ON copy_inbox.id = candidate.source_link_id\n AND copy_inbox.macro_id = $1\n WHERE candidate.ical_uid = mentioned.ical_uid\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n mentioned.id,\n true,\n false,\n true,\n false,\n false,\n false,\n mentioned.title,\n mentioned.description,\n mentioned.location,\n mentioned.organizer_email,\n mentioned.organizer_name,\n mentioned.recurrence_lines,\n mentioned.starts_at,\n mentioned.ends_at,\n mentioned.start_date,\n mentioned.end_date,\n mentioned.time_zone,\n mentioned.updated_at\n WHERE mentioned.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = mentioned.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ) resolved\n ORDER BY\n resolved.is_channel_shared,\n resolved.is_owned DESC,\n resolved.is_mentioned DESC,\n resolved.updated_at DESC,\n resolved.id\n LIMIT 1\n ) viewer_event ON true\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.recurrence_id,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = viewer_event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance.occurrence_key\n IS NOT DISTINCT FROM requested.occurrence_key) DESC,\n (instance_start.at >= $4) DESC,\n CASE WHEN instance_start.at >= $4 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n -- An exception's content replaces the series content for the\n -- previewed occurrence alone, as it does in the event view.\n LEFT JOIN calendar_event_overrides occurrence_override\n ON occurrence_override.event_id = viewer_event.id\n AND occurrence_override.recurrence_id = occurrence.recurrence_id\n LEFT JOIN LATERAL (\n SELECT count(*) AS attendee_count\n FROM calendar_event_attendees attendee\n WHERE attendee.event_id = viewer_event.id\n ) attendees ON true\n ORDER BY requested.ord\n ",
+ "query": "\n SELECT\n (mentioned.id IS NOT NULL) AS \"mention_exists!\",\n viewer_event.id AS \"resolved_event_id?\",\n viewer_event.is_channel_shared AS \"is_channel_shared?\",\n viewer_event.is_snapshot AS \"is_snapshot?\",\n viewer_event.inbox_organizes AS \"inbox_organizes?\",\n viewer_event.inbox_attends AS \"inbox_attends?\",\n COALESCE(occurrence_override.title, viewer_event.title) AS \"title?\",\n left(\n COALESCE(occurrence_override.description, viewer_event.description),\n $5\n ) AS \"description?\",\n COALESCE(occurrence_override.location, viewer_event.location) AS \"location?\",\n viewer_event.organizer_email AS \"organizer_email?\",\n viewer_event.organizer_name AS \"organizer_name?\",\n viewer_event.recurrence_lines AS \"recurrence_lines?\",\n viewer_event.starts_at AS \"event_starts_at?\",\n viewer_event.ends_at AS \"event_ends_at?\",\n viewer_event.start_date AS \"event_start_date?\",\n viewer_event.end_date AS \"event_end_date?\",\n viewer_event.time_zone AS \"time_zone?\",\n viewer_event.updated_at AS \"updated_at?\",\n occurrence.occurrence_key AS \"occurrence_key?\",\n occurrence.starts_at AS \"occurrence_starts_at?\",\n occurrence.ends_at AS \"occurrence_ends_at?\",\n occurrence.start_date AS \"occurrence_start_date?\",\n occurrence.end_date AS \"occurrence_end_date?\",\n attendees.attendee_count AS \"attendee_count?\"\n FROM unnest($2::uuid[], $3::text[])\n WITH ORDINALITY AS requested(event_id, occurrence_key, ord)\n LEFT JOIN calendar_events mentioned\n ON mentioned.id = requested.event_id\n AND mentioned.status <> 'cancelled'\n LEFT JOIN LATERAL (\n SELECT resolved.*\n FROM (\n SELECT\n candidate.id,\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = mentioned.id) AS is_mentioned,\n candidate.is_snapshot,\n -- The copy's own inbox decides how the requester\n -- holds it, as it decides their capabilities: an\n -- inbox they own that organizes it or is on it.\n COALESCE(\n lower(copy_inbox.email_address) = lower(candidate.organizer_email)\n OR EXISTS (\n SELECT 1\n FROM calendar_event_attendees organizer\n WHERE organizer.event_id = candidate.id\n AND organizer.is_organizer\n AND lower(organizer.email) = lower(copy_inbox.email_address)\n ),\n false\n ) AS inbox_organizes,\n EXISTS (\n SELECT 1\n FROM calendar_event_attendees guest\n WHERE guest.event_id = candidate.id\n AND lower(guest.email) = lower(copy_inbox.email_address)\n ) AS inbox_attends,\n candidate.title,\n candidate.description,\n candidate.location,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.recurrence_lines,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.updated_at\n FROM calendar_events candidate\n LEFT JOIN email_links copy_inbox\n ON copy_inbox.id = candidate.source_link_id\n AND copy_inbox.macro_id = $1\n WHERE calendar_meeting_uid(candidate.ical_uid)\n = calendar_meeting_uid(mentioned.ical_uid)\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n mentioned.id,\n true,\n false,\n true,\n false,\n false,\n false,\n mentioned.title,\n mentioned.description,\n mentioned.location,\n mentioned.organizer_email,\n mentioned.organizer_name,\n mentioned.recurrence_lines,\n mentioned.starts_at,\n mentioned.ends_at,\n mentioned.start_date,\n mentioned.end_date,\n mentioned.time_zone,\n mentioned.updated_at\n WHERE mentioned.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = mentioned.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ) resolved\n ORDER BY\n resolved.is_channel_shared,\n resolved.is_owned DESC,\n resolved.is_mentioned DESC,\n resolved.updated_at DESC,\n resolved.id\n LIMIT 1\n ) viewer_event ON true\n LEFT JOIN LATERAL (\n SELECT\n instance.occurrence_key,\n instance.recurrence_id,\n instance.starts_at,\n instance.ends_at,\n instance.start_date,\n instance.end_date\n FROM calendar_event_occurrences instance\n CROSS JOIN LATERAL (\n SELECT COALESCE(\n instance.starts_at,\n instance.start_date::timestamp AT TIME ZONE 'UTC'\n ) AS at\n ) instance_start\n WHERE instance.event_id = viewer_event.id\n AND NOT instance.is_cancelled\n ORDER BY\n (instance.occurrence_key\n IS NOT DISTINCT FROM requested.occurrence_key) DESC,\n (instance_start.at >= $4) DESC,\n CASE WHEN instance_start.at >= $4 THEN instance_start.at END ASC,\n instance_start.at DESC,\n instance.occurrence_key\n LIMIT 1\n ) occurrence ON true\n -- An exception's content replaces the series content for the\n -- previewed occurrence alone, as it does in the event view.\n LEFT JOIN calendar_event_overrides occurrence_override\n ON occurrence_override.event_id = viewer_event.id\n AND occurrence_override.recurrence_id = occurrence.recurrence_id\n LEFT JOIN LATERAL (\n SELECT count(*) AS attendee_count\n FROM calendar_event_attendees attendee\n WHERE attendee.event_id = viewer_event.id\n ) attendees ON true\n ORDER BY requested.ord\n ",
"describe": {
"columns": [
{
@@ -160,5 +160,5 @@
null
]
},
- "hash": "f4ac6711db74208d4ab2c909150dacef6abdc5ce1db574cbda8bd488cd91c6b5"
+ "hash": "41c9b8b64954e28433337d9dcd878574dd0f831c81b7c5110b5f17fdb5cdca41"
}
diff --git a/.sqlx/query-62680e48f82df42e0c3c78b0053a4c8eb1f112ae5a395733aa67d1476fc86e53.json b/.sqlx/query-62680e48f82df42e0c3c78b0053a4c8eb1f112ae5a395733aa67d1476fc86e53.json
deleted file mode 100644
index ee333628b6..0000000000
--- a/.sqlx/query-62680e48f82df42e0c3c78b0053a4c8eb1f112ae5a395733aa67d1476fc86e53.json
+++ /dev/null
@@ -1,119 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT\n resolved.is_channel_shared AS \"is_channel_shared!\",\n resolved.owner_id AS \"owner_id!\",\n resolved.event_type AS \"event_type!\",\n resolved.ical_uid AS \"ical_uid!\",\n resolved.sequence AS \"sequence!\",\n resolved.title AS \"title!\",\n resolved.description,\n resolved.location,\n resolved.starts_at,\n resolved.ends_at,\n resolved.start_date,\n resolved.end_date,\n resolved.time_zone,\n resolved.recurrence_lines AS \"recurrence_lines!\",\n resolved.organizer_email,\n resolved.organizer_name,\n resolved.updated_at AS \"updated_at!\"\n FROM calendar_events requested\n CROSS JOIN LATERAL (\n SELECT\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = requested.id) AS is_requested,\n candidate.id,\n candidate.owner_id,\n candidate.event_type,\n candidate.ical_uid,\n candidate.sequence,\n candidate.title,\n candidate.description,\n candidate.location,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.recurrence_lines,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.updated_at\n FROM calendar_events candidate\n WHERE candidate.ical_uid = requested.ical_uid\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n true,\n false,\n true,\n requested.id,\n requested.owner_id,\n requested.event_type,\n requested.ical_uid,\n requested.sequence,\n requested.title,\n requested.description,\n requested.location,\n requested.starts_at,\n requested.ends_at,\n requested.start_date,\n requested.end_date,\n requested.time_zone,\n requested.recurrence_lines,\n requested.organizer_email,\n requested.organizer_name,\n requested.updated_at\n WHERE requested.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = requested.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ORDER BY\n is_channel_shared,\n is_owned DESC,\n is_requested DESC,\n updated_at DESC,\n id\n LIMIT 1\n ) resolved\n WHERE requested.id = $2\n AND requested.status <> 'cancelled'\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "is_channel_shared!",
- "type_info": "Bool"
- },
- {
- "ordinal": 1,
- "name": "owner_id!",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "event_type!",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "ical_uid!",
- "type_info": "Text"
- },
- {
- "ordinal": 4,
- "name": "sequence!",
- "type_info": "Int4"
- },
- {
- "ordinal": 5,
- "name": "title!",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "description",
- "type_info": "Text"
- },
- {
- "ordinal": 7,
- "name": "location",
- "type_info": "Text"
- },
- {
- "ordinal": 8,
- "name": "starts_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 9,
- "name": "ends_at",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 10,
- "name": "start_date",
- "type_info": "Date"
- },
- {
- "ordinal": 11,
- "name": "end_date",
- "type_info": "Date"
- },
- {
- "ordinal": 12,
- "name": "time_zone",
- "type_info": "Text"
- },
- {
- "ordinal": 13,
- "name": "recurrence_lines!",
- "type_info": "TextArray"
- },
- {
- "ordinal": 14,
- "name": "organizer_email",
- "type_info": "Text"
- },
- {
- "ordinal": 15,
- "name": "organizer_name",
- "type_info": "Text"
- },
- {
- "ordinal": 16,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Uuid"
- ]
- },
- "nullable": [
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null,
- null
- ]
- },
- "hash": "62680e48f82df42e0c3c78b0053a4c8eb1f112ae5a395733aa67d1476fc86e53"
-}
diff --git a/.sqlx/query-e873aa50b615d723e90e515711af09709d153881c0f81b54854c1aac88755c8b.json b/.sqlx/query-6a3169c9f261fe5c96f383935a87309bf4ee6dffc35917ec7110dd286a33c174.json
similarity index 73%
rename from .sqlx/query-e873aa50b615d723e90e515711af09709d153881c0f81b54854c1aac88755c8b.json
rename to .sqlx/query-6a3169c9f261fe5c96f383935a87309bf4ee6dffc35917ec7110dd286a33c174.json
index e8eb360ad0..eb11fa0a40 100644
--- a/.sqlx/query-e873aa50b615d723e90e515711af09709d153881c0f81b54854c1aac88755c8b.json
+++ b/.sqlx/query-6a3169c9f261fe5c96f383935a87309bf4ee6dffc35917ec7110dd286a33c174.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT\n candidate.id AS \"event_id!\",\n copy_inbox.email_address AS \"inbox!\",\n COALESCE(\n lower(copy_inbox.email_address) = lower(candidate.organizer_email)\n OR EXISTS (\n SELECT 1\n FROM calendar_event_attendees organizer\n WHERE organizer.event_id = candidate.id\n AND organizer.is_organizer\n AND lower(organizer.email) = lower(copy_inbox.email_address)\n ),\n false\n ) AS \"organizes!\",\n EXISTS (\n SELECT 1\n FROM calendar_event_attendees guest\n WHERE guest.event_id = candidate.id\n AND lower(guest.email) = lower(copy_inbox.email_address)\n ) AS \"attends!\"\n FROM calendar_events addressed\n JOIN calendar_events candidate\n ON candidate.ical_uid = addressed.ical_uid\n JOIN email_links copy_inbox\n ON copy_inbox.id = candidate.source_link_id\n AND copy_inbox.macro_id = $1\n WHERE addressed.id = $2\n AND candidate.owner_id = $1\n AND candidate.status <> 'cancelled'\n ORDER BY lower(copy_inbox.email_address), candidate.id\n ",
+ "query": "\n SELECT\n candidate.id AS \"event_id!\",\n copy_inbox.email_address AS \"inbox!\",\n COALESCE(\n lower(copy_inbox.email_address) = lower(candidate.organizer_email)\n OR EXISTS (\n SELECT 1\n FROM calendar_event_attendees organizer\n WHERE organizer.event_id = candidate.id\n AND organizer.is_organizer\n AND lower(organizer.email) = lower(copy_inbox.email_address)\n ),\n false\n ) AS \"organizes!\",\n EXISTS (\n SELECT 1\n FROM calendar_event_attendees guest\n WHERE guest.event_id = candidate.id\n AND lower(guest.email) = lower(copy_inbox.email_address)\n ) AS \"attends!\"\n FROM calendar_events addressed\n JOIN calendar_events candidate\n ON calendar_meeting_uid(candidate.ical_uid)\n = calendar_meeting_uid(addressed.ical_uid)\n JOIN email_links copy_inbox\n ON copy_inbox.id = candidate.source_link_id\n AND copy_inbox.macro_id = $1\n WHERE addressed.id = $2\n AND candidate.owner_id = $1\n AND candidate.status <> 'cancelled'\n ORDER BY lower(copy_inbox.email_address), candidate.id\n ",
"describe": {
"columns": [
{
@@ -37,5 +37,5 @@
null
]
},
- "hash": "e873aa50b615d723e90e515711af09709d153881c0f81b54854c1aac88755c8b"
+ "hash": "6a3169c9f261fe5c96f383935a87309bf4ee6dffc35917ec7110dd286a33c174"
}
diff --git a/.sqlx/query-d0d877520021390a1782954063024b077caea0f63ea4fdd2e1708762a4c05063.json b/.sqlx/query-d0d877520021390a1782954063024b077caea0f63ea4fdd2e1708762a4c05063.json
new file mode 100644
index 0000000000..697ca05c7c
--- /dev/null
+++ b/.sqlx/query-d0d877520021390a1782954063024b077caea0f63ea4fdd2e1708762a4c05063.json
@@ -0,0 +1,119 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n resolved.is_channel_shared AS \"is_channel_shared!\",\n resolved.owner_id AS \"owner_id!\",\n resolved.event_type AS \"event_type!\",\n -- The meeting's UID, not an Outlook copy's Exchange wrapper of it:\n -- an .ics or a snapshot carries it to other calendars.\n calendar_meeting_uid(resolved.ical_uid) AS \"ical_uid!\",\n resolved.sequence AS \"sequence!\",\n resolved.title AS \"title!\",\n resolved.description,\n resolved.location,\n resolved.starts_at,\n resolved.ends_at,\n resolved.start_date,\n resolved.end_date,\n resolved.time_zone,\n resolved.recurrence_lines AS \"recurrence_lines!\",\n resolved.organizer_email,\n resolved.organizer_name,\n resolved.updated_at AS \"updated_at!\"\n FROM calendar_events requested\n CROSS JOIN LATERAL (\n SELECT\n false AS is_channel_shared,\n (candidate.owner_id = $1) AS is_owned,\n (candidate.id = requested.id) AS is_requested,\n candidate.id,\n candidate.owner_id,\n candidate.event_type,\n candidate.ical_uid,\n candidate.sequence,\n candidate.title,\n candidate.description,\n candidate.location,\n candidate.starts_at,\n candidate.ends_at,\n candidate.start_date,\n candidate.end_date,\n candidate.time_zone,\n candidate.recurrence_lines,\n candidate.organizer_email,\n candidate.organizer_name,\n candidate.updated_at\n FROM calendar_events candidate\n WHERE calendar_meeting_uid(candidate.ical_uid)\n = calendar_meeting_uid(requested.ical_uid)\n AND candidate.status <> 'cancelled'\n AND (\n candidate.owner_id = $1\n OR EXISTS (\n SELECT 1\n FROM macro_user_links link\n WHERE link.link_id = candidate.source_link_id\n AND link.primary_macro_id = $1\n )\n )\n UNION ALL\n SELECT\n true,\n false,\n true,\n requested.id,\n requested.owner_id,\n requested.event_type,\n requested.ical_uid,\n requested.sequence,\n requested.title,\n requested.description,\n requested.location,\n requested.starts_at,\n requested.ends_at,\n requested.start_date,\n requested.end_date,\n requested.time_zone,\n requested.recurrence_lines,\n requested.organizer_email,\n requested.organizer_name,\n requested.updated_at\n WHERE requested.visibility IN ('default', 'public')\n AND EXISTS (\n SELECT 1\n FROM entity_access grant_row\n JOIN comms_channel_participants participant\n ON participant.channel_id::text = grant_row.source_id\n AND participant.user_id = $1\n AND participant.left_at IS NULL\n WHERE grant_row.entity_id = requested.id\n AND grant_row.entity_type = 'calendar_event'\n AND grant_row.source_type = 'channel'\n )\n ORDER BY\n is_channel_shared,\n is_owned DESC,\n is_requested DESC,\n updated_at DESC,\n id\n LIMIT 1\n ) resolved\n WHERE requested.id = $2\n AND requested.status <> 'cancelled'\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "is_channel_shared!",
+ "type_info": "Bool"
+ },
+ {
+ "ordinal": 1,
+ "name": "owner_id!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "event_type!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "ical_uid!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 4,
+ "name": "sequence!",
+ "type_info": "Int4"
+ },
+ {
+ "ordinal": 5,
+ "name": "title!",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "description",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 7,
+ "name": "location",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 8,
+ "name": "starts_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 9,
+ "name": "ends_at",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 10,
+ "name": "start_date",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 11,
+ "name": "end_date",
+ "type_info": "Date"
+ },
+ {
+ "ordinal": 12,
+ "name": "time_zone",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 13,
+ "name": "recurrence_lines!",
+ "type_info": "TextArray"
+ },
+ {
+ "ordinal": 14,
+ "name": "organizer_email",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 15,
+ "name": "organizer_name",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 16,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Uuid"
+ ]
+ },
+ "nullable": [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null
+ ]
+ },
+ "hash": "d0d877520021390a1782954063024b077caea0f63ea4fdd2e1708762a4c05063"
+}
diff --git a/crates/calendar_events/AGENTS.md b/crates/calendar_events/AGENTS.md
index 772330edc1..239afe27d9 100644
--- a/crates/calendar_events/AGENTS.md
+++ b/crates/calendar_events/AGENTS.md
@@ -165,18 +165,23 @@ reminder dispatch, team availability, and provider/Postgres persistence.
the reason, or the agent asks, and guests are added from the copy the user
organizes. `domain::copies::check_copy` enforces it: such a change on a
meeting the user holds through several of their own inboxes
- (`meeting_copies`, matched by iCalendar UID) is refused, listing each copy,
- until `inbox` names the addressed copy's inbox. UpdateCalendarEvent and
- DeleteCalendarEvent check every call; the update, invite-guests and delete
- routes check agent runs and any request naming `inbox` through
- `CalendarCopyConfirmation`, answering 409 `copy_choice_required`. An agent
- run is a token with `agent_id` (in-app code mode) or a request carrying
- `x-macro-code-execution`, which `code_execution`'s bootstrap sets on every
- code-mode program's SDK requests, public MCP clients' included. Code-mode
- agents never see the calendar tools (`agent_code_mode::covered_by_code_sdk`),
- so the routes and the SDK docs are what reach them; the web, which opens one
- copy, sends no `inbox` and is not checked. An Outlook copy of a Google
- meeting carries Exchange's UID, so it is not matched.
+ (`meeting_copies`) is refused, listing each copy, until `inbox` names the
+ addressed copy's inbox. UpdateCalendarEvent and DeleteCalendarEvent check
+ every call; the update, invite-guests and delete routes check agent runs and
+ any request naming `inbox` through `CalendarCopyConfirmation`, answering 409
+ `copy_choice_required`. An agent run is a token with `agent_id` (in-app code
+ mode) or a request carrying `x-macro-code-execution`, which
+ `code_execution`'s bootstrap sets on every code-mode program's SDK requests,
+ public MCP clients' included. Code-mode agents never see the calendar tools
+ (`agent_code_mode::covered_by_code_sdk`), so the routes and the SDK docs are
+ what reach them; the web, which opens one copy, sends no `inbox` and is not
+ checked.
+- Copies of one meeting pair by `calendar_meeting_uid(ical_uid)`, not the raw
+ UID: Exchange gives a meeting it imports from an invitation its own UID that
+ wraps the original after `vCal-Uid`, and the SQL function unwraps it, so an
+ Outlook copy of a Google meeting pairs with its Google copies in
+ `meeting_copies`, the mention preview and `event_export`. Email invitation
+ matching (`pg/invitations.rs`) still compares the raw UID.
- Preserve the conservative OOO refresh hint on write outcomes and sync reports;
its contract is in [team sharing](../../docs/design/calendar-team-sharing.md).
- The team out-of-office overlay (`src/outbound/pg_team/ooo.rs`) starts from
diff --git a/crates/calendar_events/src/outbound/pg.rs b/crates/calendar_events/src/outbound/pg.rs
index 921b1f819b..ee9ae43a29 100644
--- a/crates/calendar_events/src/outbound/pg.rs
+++ b/crates/calendar_events/src/outbound/pg.rs
@@ -1375,7 +1375,8 @@ impl CalendarRepository for PgCalendarRepository {
LEFT JOIN email_links copy_inbox
ON copy_inbox.id = candidate.source_link_id
AND copy_inbox.macro_id = $1
- WHERE candidate.ical_uid = mentioned.ical_uid
+ WHERE calendar_meeting_uid(candidate.ical_uid)
+ = calendar_meeting_uid(mentioned.ical_uid)
AND candidate.status <> 'cancelled'
AND (
candidate.owner_id = $1
@@ -1511,7 +1512,8 @@ impl CalendarRepository for PgCalendarRepository {
) AS "attends!"
FROM calendar_events addressed
JOIN calendar_events candidate
- ON candidate.ical_uid = addressed.ical_uid
+ ON calendar_meeting_uid(candidate.ical_uid)
+ = calendar_meeting_uid(addressed.ical_uid)
JOIN email_links copy_inbox
ON copy_inbox.id = candidate.source_link_id
AND copy_inbox.macro_id = $1
diff --git a/crates/calendar_events/src/outbound/pg/export.rs b/crates/calendar_events/src/outbound/pg/export.rs
index 6f74b6b3c5..65021b5154 100644
--- a/crates/calendar_events/src/outbound/pg/export.rs
+++ b/crates/calendar_events/src/outbound/pg/export.rs
@@ -39,7 +39,9 @@ pub(super) async fn event_export(
resolved.is_channel_shared AS "is_channel_shared!",
resolved.owner_id AS "owner_id!",
resolved.event_type AS "event_type!",
- resolved.ical_uid AS "ical_uid!",
+ -- The meeting's UID, not an Outlook copy's Exchange wrapper of it:
+ -- an .ics or a snapshot carries it to other calendars.
+ calendar_meeting_uid(resolved.ical_uid) AS "ical_uid!",
resolved.sequence AS "sequence!",
resolved.title AS "title!",
resolved.description,
@@ -77,7 +79,8 @@ pub(super) async fn event_export(
candidate.organizer_name,
candidate.updated_at
FROM calendar_events candidate
- WHERE candidate.ical_uid = requested.ical_uid
+ WHERE calendar_meeting_uid(candidate.ical_uid)
+ = calendar_meeting_uid(requested.ical_uid)
AND candidate.status <> 'cancelled'
AND (
candidate.owner_id = $1
diff --git a/crates/calendar_events/src/outbound/pg/test.rs b/crates/calendar_events/src/outbound/pg/test.rs
index d4df3b374f..f3a8c0d99a 100644
--- a/crates/calendar_events/src/outbound/pg/test.rs
+++ b/crates/calendar_events/src/outbound/pg/test.rs
@@ -7263,6 +7263,7 @@ mod export;
mod invitations;
mod join_requests;
mod meeting_copies;
+mod meeting_uid;
#[cfg(feature = "notes")]
mod notes;
mod source_access;
diff --git a/crates/calendar_events/src/outbound/pg/test/meeting_uid.rs b/crates/calendar_events/src/outbound/pg/test/meeting_uid.rs
new file mode 100644
index 0000000000..03c0c035c7
--- /dev/null
+++ b/crates/calendar_events/src/outbound/pg/test/meeting_uid.rs
@@ -0,0 +1,152 @@
+use super::*;
+use crate::domain::ics::CalendarEventExportAccess;
+
+/// The UID Exchange gives a meeting it imports from an invitation carrying
+/// `uid`: a GlobalObjectId whose data wraps `uid` after "vCal-Uid".
+fn exchange_uid(uid: &str) -> String {
+ let mut data = b"vCal-Uid".to_vec();
+ data.extend_from_slice(&[1, 0, 0, 0]);
+ data.extend_from_slice(uid.as_bytes());
+ data.push(0);
+ let size = u32::try_from(data.len()).unwrap().to_le_bytes();
+ let hex = |bytes: &[u8]| {
+ bytes
+ .iter()
+ .map(|byte| format!("{byte:02X}"))
+ .collect::<String>()
+ };
+ format!(
+ "040000008200E00074C5B7101A82E008{}{}{}",
+ "00".repeat(20),
+ hex(&size),
+ hex(&data)
+ )
+}
+
+async fn meeting_uid(pool: &PgPool, uid: &str) -> String {
+ sqlx::query_scalar!(r#"SELECT calendar_meeting_uid($1) AS "uid!""#, uid)
+ .fetch_one(pool)
+ .await
+ .unwrap()
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn the_meeting_uid_unwraps_only_an_imported_exchange_uid(pool: PgPool) {
+ // As Graph reported it on dev for a Google meeting.
+ assert_eq!(
+ meeting_uid(
+ &pool,
+ "040000008200E00074C5B7101A82E0080000000000000000000000000000000000000000320000007643616C2D55696401000000736A696236727237306F3535397269336633336F6D373662386F40676F6F676C652E636F6D00",
+ )
+ .await,
+ );
+ assert_eq!(
+ meeting_uid(&pool, &exchange_uid("[email protected]").to_lowercase()).await,
+ );
+ // A meeting Exchange organized wraps no foreign UID, so its UID stays.
+ let native = "040000008200E00074C5B7101A82E00800000000E0F2A5D1C3E9DA01000000000000000010000000F9DC1CC4E5A0EB4DA9F5C4E7BBA0CDB2";
+ assert_eq!(meeting_uid(&pool, native).await, native);
+ assert_eq!(
+ meeting_uid(&pool, "[email protected]").await,
+ );
+ // A wrapped UID that is not printable ASCII, or that the escape encoding
+ // would not reproduce exactly, is left alone.
+ let backslash = exchange_uid("a\\[email protected]");
+ assert_eq!(meeting_uid(&pool, &backslash).await, backslash);
+ let delete = exchange_uid("a\[email protected]");
+ assert_eq!(meeting_uid(&pool, &delete).await, delete);
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn an_outlook_copy_pairs_with_the_meetings_google_copies(pool: PgPool) {
+ let author_id = "macro|[email protected]";
+ let viewer_id = "macro|[email protected]";
+ let author_link = insert_link(&pool, author_id).await;
+ let google_link = insert_link(&pool, viewer_id).await;
+ let outlook_link = insert_link(&pool, viewer_id).await;
+ let repo = PgCalendarRepository::new(pool.clone());
+
+ let authored = timed_upsert(
+ author_id,
+ author_link,
+ provider_ids(&repo, author_link).await,
+ "Planning",
+ 1,
+ );
+ let authored_id = authored.event.id;
+ repo.upsert_event_fixture(authored).await.unwrap();
+ let google_copy = timed_upsert(
+ viewer_id,
+ google_link,
+ provider_ids(&repo, google_link).await,
+ "Planning",
+ 1,
+ );
+ let google_id = google_copy.event.id;
+ repo.upsert_event_fixture(google_copy).await.unwrap();
+ let outlook_copy = timed_upsert(
+ viewer_id,
+ outlook_link,
+ provider_ids(&repo, outlook_link).await,
+ &exchange_uid("[email protected]"),
+ "Planning",
+ 1,
+ );
+ let outlook_id = outlook_copy.event.id;
+ repo.upsert_event_fixture(outlook_copy).await.unwrap();
+
+ let mut copies: Vec<Uuid> = repo
+ .meeting_copies(viewer_id, outlook_id)
+ .await
+ .unwrap()
+ .into_iter()
+ .map(|copy| copy.event_id)
+ .collect();
+ copies.sort();
+ let mut expected = vec![google_id, outlook_id];
+ expected.sort();
+ assert_eq!(copies, expected);
+
+ // Someone holding only an Outlook copy of the author's Google meeting
+ // sees it as their own: the mention and the export resolve to that copy.
+ let outlook_only_id = "macro|[email protected]";
+ let outlook_only_link = insert_link(&pool, outlook_only_id).await;
+ let lone_copy = timed_upsert(
+ outlook_only_id,
+ outlook_only_link,
+ provider_ids(&repo, outlook_only_link).await,
+ &exchange_uid("[email protected]"),
+ "Planning",
+ 1,
+ );
+ let lone_id = lone_copy.event.id;
+ repo.upsert_event_fixture(lone_copy).await.unwrap();
+ let previews = repo
+ .mention_previews(
+ outlook_only_id,
+ vec![CalendarMentionRequestItem {
+ event_id: authored_id,
+ occurrence_key: None,
+ }],
+ Utc.with_ymd_and_hms(2026, 7, 23, 0, 0, 0).unwrap(),
+ )
+ .await
+ .unwrap();
+ let CalendarMentionPreview::Accessible(preview) = &previews[0] else {
+ panic!("an Outlook copy is the viewer's own: {:?}", previews[0]);
+ };
+ assert_eq!(preview.viewer_event_id, Some(lone_id));
+ let export = repo
+ .event_export(outlook_only_id, authored_id)
+ .await
+ .unwrap()
+ .expect("an Outlook copy is the viewer's own");
+ assert_eq!(export.access, CalendarEventExportAccess::OwnCopy);
+ assert_eq!(export.owner_id, outlook_only_id);
+ assert_eq!(export.ical_uid, "[email protected]");
+}
diff --git a/crates/macro_db_client/migrations/20261024082129_calendar_meeting_uid.sql b/crates/macro_db_client/migrations/20261024082129_calendar_meeting_uid.sql
new file mode 100644
index 0000000000..17042cd52f
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261024082129_calendar_meeting_uid.sql
@@ -0,0 +1,14 @@
+-- Exchange gives a meeting it imports from an iCalendar invitation its own UID:
+-- a hex GlobalObjectId whose data wraps the original UID after "vCal-Uid" and a
+-- version word, NUL-terminated. Unwrapping it pairs an Outlook copy of a Google
+-- meeting with that meeting's Google copies. Only printable ASCII other than a
+-- backslash is unwrapped, so the escape encoding returns the UID unchanged.
+CREATE OR REPLACE FUNCTION calendar_meeting_uid(uid text) RETURNS text
+ LANGUAGE sql IMMUTABLE STRICT PARALLEL SAFE
+ AS $$
+ SELECT CASE
+ WHEN uid ~* '^040000008200E00074C5B7101A82E008[0-9A-F]{48}7643616C2D55696401000000([2-46][0-9A-F]|5[0-9ABD-F]|7[0-9A-E])+00$'
+ THEN encode(decode(substr(uid, 105, length(uid) - 106), 'hex'), 'escape')
+ ELSE uid
+ END
+ $$;
diff --git a/crates/macro_db_client/migrations/20261024082141_calendar_events_meeting_uid_idx.sql b/crates/macro_db_client/migrations/20261024082141_calendar_events_meeting_uid_idx.sql
new file mode 100644
index 0000000000..2284d4e85f
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261024082141_calendar_events_meeting_uid_idx.sql
@@ -0,0 +1,9 @@
+-- no-transaction
+-- Copies of one meeting are paired by `calendar_meeting_uid(ical_uid)`, which an
+-- index on the raw UID cannot serve.
+-- Must stay a single statement: sqlx sends no-transaction migrations as one
+-- batch, and CONCURRENTLY cannot run inside a transaction. No IF NOT EXISTS:
+-- an interrupted concurrent build leaves an invalid index that a retry must
+-- not accept (see docs/design/outlook-email-support.md).
+CREATE INDEX CONCURRENTLY calendar_events_meeting_uid_idx
+ ON calendar_events (calendar_meeting_uid(ical_uid));