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
feat(call): share with team toggle (#2787)
Will Hutchinson8f43fe442066
diff --git a/js/app/packages/app/vite.base.ts b/js/app/packages/app/vite.base.tsindex b3fbf5f6db..2e3d6feb98 100644--- a/js/app/packages/app/vite.base.ts+++ b/js/app/packages/app/vite.base.ts@@ -12,7 +12,15 @@ import tsconfigpaths from 'vite-tsconfig-paths';// @ts-ignoreimport { version } from './package.json';-const shortSha = execSync('git rev-parse --short HEAD').toString().trim();+function readShortSha(): string {+ try {+ return execSync('git rev-parse --short HEAD').toString().trim();+ } catch {+ return 'unknown';+ }+}++const shortSha = readShortSha();const appVersion = `${version}+${shortSha}`;function readGitBranch(): string {diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsxindex 0aa4c8721e..2bb0381fb0 100644--- a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx@@ -33,6 +33,7 @@ import { ChannelAttachmentsTab } from '@channel/Attachments/ChannelAttachmentsTaimport { ChannelParticipantsTab } from '@channel/Participants/ChannelParticipantsTab';import {CallAudioSink,+ CallEventSync,CallProvider,ChannelCallAutoJoin,ChannelCallButton,@@ -212,6 +213,7 @@ export function NewChannelBlockAdapter(props: BlockChannelProps) {return (<EntityPermissionsGate entityType="channel" entityId={channelId}><CallProvider>+ <CallEventSync /><ChannelTabProvider activeTab={activeTab} setActiveTab={setActiveTab}><ChannelCallAutoJoinchannelId={channelId}diff --git a/js/app/packages/channel/Call/CallContext.tsx b/js/app/packages/channel/Call/CallContext.tsxindex 77e6d028fd..85b5d3fbb5 100644--- a/js/app/packages/channel/Call/CallContext.tsx+++ b/js/app/packages/channel/Call/CallContext.tsx@@ -37,6 +37,7 @@ export type MediaDeviceInfo = {type CallStoreState = {connectionState: ConnectionState;activeChannelId: string | null;+ activeCallId: string | null;remoteParticipants: Map<string, RemoteParticipant>;isAudioMuted: boolean;isVideoMuted: boolean;@@ -50,11 +51,16 @@ type CallStoreState = {activeAudioOutputDeviceId: string | null;activeVideoInputDeviceId: string | null;isNoiseSuppressed: boolean;+ // Mirrors the call's `share_with_team` flag. Defaults to true to match the+ // server-side default for newly-created calls; synced from the toggle+ // endpoint's response on each flip.+ isSharedWithTeam: boolean;};const initialState: CallStoreState = {connectionState: ConnectionState.Disconnected,activeChannelId: null,+ activeCallId: null,remoteParticipants: new Map(),isAudioMuted: false,isVideoMuted: true,@@ -68,6 +74,7 @@ const initialState: CallStoreState = {activeAudioOutputDeviceId: null,activeVideoInputDeviceId: null,isNoiseSuppressed: false,+ isSharedWithTeam: true,};export type CallState = {@@ -79,6 +86,8 @@ export type CallState = {isInCall: () => boolean;/** Channel ID of the active call */activeChannelId: () => string | null;+ /** Call ID of the active call (from CallTokenResponse) */+ activeCallId: () => string | null;/** Remote participants in the call */remoteParticipants: () => Map<string, RemoteParticipant>;/** Incremented when track subscription/mute state changes */@@ -125,6 +134,10 @@ export type CallState = {isNoiseSuppressed: () => boolean;/** Toggle Krisp noise suppression on/off */toggleNoiseSuppression: () => Promise<void>;+ /** Whether the call is currently shared with the creator's team */+ isSharedWithTeam: () => boolean;+ /** Update the locally-cached share-with-team flag (call after a toggle RPC) */+ setSharedWithTeam: (value: boolean) => void;};const CallContext = createContext<CallState>();@@ -408,6 +421,8 @@ function createCallState() {}setStore('activeChannelId', tokenResponse.channelId);+ setStore('activeCallId', tokenResponse.callId);+ setStore('isSharedWithTeam', true);try {await targetRoom.connect(tokenResponse.serverUrl, tokenResponse.token);@@ -519,6 +534,10 @@ function createCallState() {}}+ function setSharedWithTeam(value: boolean) {+ setStore('isSharedWithTeam', value);+ }+async function toggleNoiseSuppression() {const krisp = krispFilter();if (!krisp) return;@@ -562,6 +581,7 @@ function createCallState() {connectionState: () => store.connectionState,isInCall: () => store.connectionState === ConnectionState.Connected,activeChannelId: () => store.activeChannelId,+ activeCallId: () => store.activeCallId,remoteParticipants: () => store.remoteParticipants,trackVersion: () => store.trackVersion,isLocalSpeaking: () => {@@ -595,6 +615,8 @@ function createCallState() {switchVideoInput,isNoiseSuppressed: () => store.isNoiseSuppressed,toggleNoiseSuppression,+ isSharedWithTeam: () => store.isSharedWithTeam,+ setSharedWithTeam,};return state;diff --git a/js/app/packages/channel/Call/CallEventSync.tsx b/js/app/packages/channel/Call/CallEventSync.tsxnew file mode 100644index 0000000000..4d5a7ac457--- /dev/null+++ b/js/app/packages/channel/Call/CallEventSync.tsx@@ -0,0 +1,40 @@+import { createConnectionWebsocketEffect } from '@service-connection/websocket';+import { match } from 'ts-pattern';+import { useCallContext } from './CallContext';++type CallShareWithTeamToggledPayload = {+ call_id: string;+ channel_id: string;+ share_with_team: boolean;+ toggled_by: string | null;+};++/**+ * Applies connection-gateway events that mutate active-call state held in+ * `CallContext`. Must be rendered inside `<CallProvider />`.+ *+ * Handled events:+ * - `call_share_with_team_toggled` — keeps `isSharedWithTeam` in sync when+ * the flag is flipped by another participant (or by the same user on a+ * different device). Skipped when the payload's `call_id` does not match+ * the currently active call, since the flag is only tracked while the+ * user is in that call.+ */+export function CallEventSync() {+ const callCtx = useCallContext();++ createConnectionWebsocketEffect((data) => {+ const payload =+ typeof data.data === 'string' ? JSON.parse(data.data) : data.data;++ match(data)+ .with({ type: 'call_share_with_team_toggled' }, () => {+ const typed = payload as CallShareWithTeamToggledPayload;+ if (typed.call_id !== callCtx.activeCallId()) return;+ callCtx.setSharedWithTeam(typed.share_with_team);+ })+ .otherwise(() => {});+ });++ return null;+}diff --git a/js/app/packages/channel/Call/CallOverlay.tsx b/js/app/packages/channel/Call/CallOverlay.tsxindex e58c126ae3..19d518f48c 100644--- a/js/app/packages/channel/Call/CallOverlay.tsx+++ b/js/app/packages/channel/Call/CallOverlay.tsx@@ -7,7 +7,9 @@ import MicrophoneSlash from '@icon/regular/microphone-slash.svg';import VideoCamera from '@icon/regular/video-camera.svg';import VideoCameraSlash from '@icon/regular/video-camera-slash.svg';import Screencast from '@icon/regular/screencast.svg';+import Users from '@icon/regular/users.svg';import CaretDown from '@icon/regular/caret-down.svg';+import { useToggleShareWithTeamMutation } from '@queries/call/call';import { DropdownMenu } from '@kobalte/core/dropdown-menu';import {DropdownMenuContent,@@ -209,6 +211,14 @@ function ScreenShareTile(props: { participant: RemoteParticipant }) {export function CallOverlay(props: { onLeave: () => void }) {const callCtx = useCallContext();+ const toggleShareWithTeam = useToggleShareWithTeamMutation();++ const handleToggleShareWithTeam = async () => {+ const callId = callCtx.activeCallId();+ if (!callId) return;+ const newValue = await toggleShareWithTeam.mutateAsync(callId);+ callCtx.setSharedWithTeam(newValue);+ };const participants = () =>Array.from(callCtx.remoteParticipants().values()).filter((p) => !p.isAgent);@@ -362,6 +372,21 @@ export function CallOverlay(props: { onLeave: () => void }) {<Screencast class="w-5 h-5" /></ControlButton>+ <div+ title={+ callCtx.isSharedWithTeam()+ ? 'Shared with team — click to make private'+ : 'Not shared — click to share with team'+ }+ >+ <ControlButton+ onClick={handleToggleShareWithTeam}+ active={callCtx.isSharedWithTeam()}+ >+ <Users class="w-5 h-5" />+ </ControlButton>+ </div>+<ControlButton onClick={props.onLeave} danger><PhoneDisconnect class="w-5 h-5" /></ControlButton>diff --git a/js/app/packages/channel/Call/index.ts b/js/app/packages/channel/Call/index.tsindex 92b65b2ab8..d904f0593e 100644--- a/js/app/packages/channel/Call/index.ts+++ b/js/app/packages/channel/Call/index.ts@@ -10,3 +10,4 @@ export { CallAudioSink } from './CallAudioSink';export { ChannelCallButton } from './ChannelCallButton';export { ChannelCallTab } from './ChannelCallTab';export { ChannelCallAutoJoin } from './ChannelCallAutoJoin';+export { CallEventSync } from './CallEventSync';diff --git a/js/app/packages/queries/call/call.ts b/js/app/packages/queries/call/call.tsindex d4f37c17c4..fb8eebc873 100644--- a/js/app/packages/queries/call/call.ts+++ b/js/app/packages/queries/call/call.ts@@ -48,3 +48,14 @@ export function useCallRecordQuery(callId: Accessor<string>) {await throwOnErr(() => callServiceClient.getCallRecord(callId())),}));}++export function useToggleShareWithTeamMutation() {+ return useMutation(() => ({+ gcTime: 0,+ mutationFn: (callId: string) =>+ throwOnErr(() => callServiceClient.toggleShareWithTeam(callId)),+ onError(error: Error) {+ console.error('failed to toggle share with team', error);+ },+ }));+}diff --git a/js/app/packages/service-clients/service-call/client.ts b/js/app/packages/service-clients/service-call/client.tsindex 60b27779df..2480731a0c 100644--- a/js/app/packages/service-clients/service-call/client.ts+++ b/js/app/packages/service-clients/service-call/client.ts@@ -62,4 +62,15 @@ export const callServiceClient = {() => undefined);},++ async toggleShareWithTeam(callId: string) {+ // fetchWithToken requires T extends ObjectLike, but this endpoint returns a+ // primitive JSON boolean. response.json() parses it correctly at runtime;+ // we only need to satisfy the generic constraint.+ const result = await fetchWithToken<Record<string, never>>(+ `${host}/call/record/${callId}/share-with-team/toggle`,+ { method: 'POST' }+ );+ return mapOk(result, (r) => r as unknown as boolean);+ },};diff --git a/rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.json b/rust/cloud-storage/call/.sqlx/query-77fae7a910ecfe9c5eeaf4c37a334398757d8e7959cd237df7e4947fb75aa56f.jsonsimilarity index 61%rename from rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.jsonrename to rust/cloud-storage/call/.sqlx/query-77fae7a910ecfe9c5eeaf4c37a334398757d8e7959cd237df7e4947fb75aa56f.jsonindex dd2f916e5e..5226fe888d 100644--- a/rust/cloud-storage/call/.sqlx/query-d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19.json+++ b/rust/cloud-storage/call/.sqlx/query-77fae7a910ecfe9c5eeaf4c37a334398757d8e7959cd237df7e4947fb75aa56f.json@@ -1,12 +1,17 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE calls\n SET share_with_team = NOT share_with_team\n WHERE id = $1\n RETURNING share_with_team\n ",+ "query": "\n UPDATE calls\n SET share_with_team = NOT share_with_team\n WHERE id = $1\n RETURNING share_with_team, channel_id\n ","describe": {"columns": [{"ordinal": 0,"name": "share_with_team","type_info": "Bool"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"}],"parameters": {@@ -15,8 +20,9 @@]},"nullable": [+ false,false]},- "hash": "d913bcfef1a7d318743aca5d1db542ffe191451bf3b578cb3aaedaf754a46a19"+ "hash": "77fae7a910ecfe9c5eeaf4c37a334398757d8e7959cd237df7e4947fb75aa56f"}diff --git a/rust/cloud-storage/call/src/domain/ports.rs b/rust/cloud-storage/call/src/domain/ports.rsindex 0a2117b143..70456b2f05 100644--- a/rust/cloud-storage/call/src/domain/ports.rs+++ b/rust/cloud-storage/call/src/domain/ports.rs@@ -96,11 +96,12 @@ pub trait CallRepository: Send + Sync + 'static {egress_id: &str,) -> impl Future<Output = Result<(), Self::Err>> + Send;- /// Flip the `share_with_team` flag on an active call. Returns the new value.+ /// Flip the `share_with_team` flag on an active call. Returns the new+ /// value along with the call's `channel_id`.fn toggle_share_with_team(&self,call_id: &Uuid,- ) -> impl Future<Output = Result<bool, Self::Err>> + Send;+ ) -> impl Future<Output = Result<(bool, Uuid), Self::Err>> + Send;/// Archive an active call to the permanent `call_records` and/// `call_record_participants` tables, then delete the ephemeral rows.diff --git a/rust/cloud-storage/call/src/domain/service.rs b/rust/cloud-storage/call/src/domain/service.rsindex e777a6f4a0..f009730142 100644--- a/rust/cloud-storage/call/src/domain/service.rs+++ b/rust/cloud-storage/call/src/domain/service.rs@@ -136,6 +136,41 @@ impl<.await.inspect_err(|e| tracing::error!(error=?e, message_type, "failed to send call event"));}++ /// Send an event to the active participants of a call (best-effort).+ ///+ /// Unlike [`Self::send_call_event`], which fans out to every member of+ /// the channel, this targets only users currently in the call — rows in+ /// `call_participants` with `left_at IS NULL`.+ async fn send_call_participant_event(+ &self,+ call_id: &Uuid,+ message_type: &str,+ message: &serde_json::Value,+ ) {+ let participants = match self.repo.get_participants(call_id).await {+ Ok(p) => p,+ Err(e) => {+ tracing::error!(error=?e, "failed to fetch call participants for event");+ return;+ }+ };++ let users: Vec<MacroUserIdStr<'static>> = participants+ .into_iter()+ .filter_map(|p| {+ MacroUserIdStr::parse_from_str(&p.user_id)+ .map(CowLike::into_owned)+ .ok()+ })+ .collect();++ let _ = self+ .connection_service+ .send_channel_message(&users, message_type, message.clone())+ .await+ .inspect_err(|e| tracing::error!(error=?e, message_type, "failed to send call participant event"));+ }}#[derive(Serialize, Deserialize, Clone)]@@ -757,10 +792,25 @@ impl<let call_id = macro_uuid::string_to_uuid(&entity.entity_id).map_err(|_| CallError::Internal(anyhow::anyhow!("invalid call entity receipt")))?;- self.repo+ let (new_value, channel_id) = self+ .repo.toggle_share_with_team(&call_id).await- .map_err(|e| CallError::Internal(e.into()))+ .map_err(|e| CallError::Internal(e.into()))?;++ self.send_call_participant_event(+ &call_id,+ "call_share_with_team_toggled",+ &serde_json::json!({+ "call_id": call_id,+ "channel_id": channel_id,+ "share_with_team": new_value,+ "toggled_by": receipt.get_authenticated_user().ok(),+ }),+ )+ .await;++ Ok(new_value)}}diff --git a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs b/rust/cloud-storage/call/src/outbound/pg_call_repo.rsindex ee779aefee..d0dd9e4432 100644--- a/rust/cloud-storage/call/src/outbound/pg_call_repo.rs+++ b/rust/cloud-storage/call/src/outbound/pg_call_repo.rs@@ -399,19 +399,19 @@ impl CallRepository for PgCallRepo {}#[tracing::instrument(err, skip(self))]- async fn toggle_share_with_team(&self, call_id: &Uuid) -> Result<bool, Self::Err> {+ async fn toggle_share_with_team(&self, call_id: &Uuid) -> Result<(bool, Uuid), Self::Err> {let row = sqlx::query!(r#"UPDATE callsSET share_with_team = NOT share_with_teamWHERE id = $1- RETURNING share_with_team+ RETURNING share_with_team, channel_id"#,call_id,).fetch_one(&self.pool).await?;- Ok(row.share_with_team)+ Ok((row.share_with_team, row.channel_id))}#[tracing::instrument(err, skip(self))]