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(whatsapp): show owners as their Macro user and group subjects as text (#9036)
Wolf Mermelsteina1f77ccdae0c
diff --git a/apps/web/src/features/external-chat/AGENTS.md b/apps/web/src/features/external-chat/AGENTS.mdindex 1fbdbca26c..8f6068fd8b 100644--- a/apps/web/src/features/external-chat/AGENTS.md+++ b/apps/web/src/features/external-chat/AGENTS.md@@ -112,7 +112,9 @@ belong to `features/external-view`. Architecture:menu lists the members (ids are JIDs, minus the sender) and nothing else;`composerMentions` turns the chips into `@<digits>` plus `mentions` on thetext send.-- Senders show their provider name (`imported_author`), Macro users included.+- Macro users (senders and system-line people with a `userId`) show their+ Macro name and avatar; everyone else shows their provider name+ (`imported_author`).- Spans are `external_chat.*` with `external_chat.id`; provider accountoperations stay `whatsapp.*` in `lib/queries/whatsapp-linked`.- Use backend limits for text, files, edits and deletes.diff --git a/apps/web/src/features/external-chat/components/system-line.tsx b/apps/web/src/features/external-chat/components/system-line.tsxindex 8de8a82835..844b64ce0c 100644--- a/apps/web/src/features/external-chat/components/system-line.tsx+++ b/apps/web/src/features/external-chat/components/system-line.tsx@@ -1,4 +1,5 @@import { SystemActivityLine } from '@channel/components/SystemActivityRow';+import { getDisplayName, tryMacroId } from '@core/user';import ImageIcon from '@phosphor/image.svg';import PencilIcon from '@phosphor/pencil-simple.svg';import PushPinIcon from '@phosphor/push-pin.svg';@@ -8,6 +9,7 @@ import UserPlusIcon from '@phosphor/user-plus.svg';import PhoneIcon from '@phosphor-fill/phone-fill.svg';import {describeSystemLine,+ type Person,type SystemLine,type SystemLineText,systemLineSentence,@@ -23,6 +25,12 @@ const ICONS = {timer: TimerIcon,} satisfies Record<SystemLineText['icon'], typeof PencilIcon>;+/** Macro users go by their Macro name, as their messages do. */+function named(person: Person): Person {+ const id = person.userId ? tryMacroId(person.userId) : undefined;+ return id ? { ...person, name: getDisplayName(id) } : person;+}+/** A provider event in the chat, drawn like Chat's system activity rows. */export function ExternalChatSystemLine(props: {id: string;@@ -30,7 +38,15 @@ export function ExternalChatSystemLine(props: {chat: 'group' | 'direct';occurredAt: string;}) {- const text = () => describeSystemLine(props.line, props.chat);+ const text = () =>+ describeSystemLine(+ {+ ...props.line,+ actor: props.line.actor && named(props.line.actor),+ participants: props.line.participants.map(named),+ },+ props.chat+ );return (<SystemActivityLineid={props.id}diff --git a/apps/web/src/features/external-chat/core/message-data.test.ts b/apps/web/src/features/external-chat/core/message-data.test.tsnew file mode 100644index 0000000000..f36e9c6bf8--- /dev/null+++ b/apps/web/src/features/external-chat/core/message-data.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest';+import type { ChatMessage } from './chat';+import { chatMessageData } from './message-data';++const message: ChatMessage = {+ id: 'message-1',+ kind: 'message',+ sender: { name: 'WhatsApp participant', userId: 'macro|[email protected]' },+ mentions: [],+ forwarded: false,+ body: 'Sent from my phone',+ sentAt: '2026-10-22T15:41:58Z',+ edited: false,+ deleted: false,+ reactions: [],+ attachments: [],+};++describe('chat message senders', () => {+ it('shows a Macro user as themselves, whatever WhatsApp called them', () => {+ const row = chatMessageData(message, undefined, (body) => body);++ expect(row.sender_id).toBe('macro|[email protected]');+ expect(row.imported_author).toBeNull();+ });++ it('shows anyone else by their WhatsApp name', () => {+ const row = chatMessageData(+ { ...message, sender: { name: 'Ana Ruiz' } },+ undefined,+ (body) => body+ );++ expect(row.sender_id).toBe('');+ expect(row.imported_author).toEqual({ name: 'Ana Ruiz' });+ });+});diff --git a/apps/web/src/features/external-chat/core/message-data.ts b/apps/web/src/features/external-chat/core/message-data.tsindex f2666f13f1..16c874afab 100644--- a/apps/web/src/features/external-chat/core/message-data.ts+++ b/apps/web/src/features/external-chat/core/message-data.ts@@ -3,8 +3,9 @@ import type { ChatProvider } from '../providers';import type { ChatMessage } from './chat';/**- * A chat message in the shape the shared channel rows render. Senders show- * their provider name; Macro users keep their Macro avatar.+ * A chat message in the shape the shared channel rows render. Macro users+ * show as themselves (Macro name and avatar); everyone else by their+ * provider name.*/export function chatMessageData(message: ChatMessage,@@ -16,11 +17,10 @@ export function chatMessageData(id: message.id,content: message.deleted ? '' : toMarkdown(message.body, message.mentions),sender_id: message.sender.userId ?? '',- // The provider's name for everyone, Macro users included: a Macro profile- // without a name would otherwise show its email.- imported_author: message.sender.name.trim()- ? { name: message.sender.name }- : null,+ imported_author:+ !message.sender.userId && message.sender.name.trim()+ ? { name: message.sender.name }+ : null,created_at: message.sentAt,updated_at: message.sentAt,edited_at: message.edited ? message.sentAt : null,diff --git a/crates/external_chat/src/domain/rich.rs b/crates/external_chat/src/domain/rich.rsindex f79dde2826..32e176fc0f 100644--- a/crates/external_chat/src/domain/rich.rs+++ b/crates/external_chat/src/domain/rich.rs@@ -239,5 +239,21 @@ pub fn web_link(value: &str) -> Option<String> {.then(|| value.to_owned())}+/// The subject a group-created line names. Older phones give the subject;+/// newer ones give the group's creation metadata as a JSON object, whose+/// `subject` may be null. Lines stored before this was read hold the+/// metadata itself, so the timeline reads them through this again.+pub fn created_subject(value: &str) -> Option<String> {+ let subject = match serde_json::from_str(value) {+ Ok(serde_json::Value::Object(metadata)) => metadata+ .get("subject")+ .and_then(serde_json::Value::as_str)?+ .to_owned(),+ _ => value.to_owned(),+ };+ let subject = subject.trim();+ (!subject.is_empty()).then(|| subject.to_owned())+}+#[cfg(test)]mod test;diff --git a/crates/external_chat/src/domain/rich/test.rs b/crates/external_chat/src/domain/rich/test.rsindex c9f75092bb..60375d16c8 100644--- a/crates/external_chat/src/domain/rich/test.rs+++ b/crates/external_chat/src/domain/rich/test.rs@@ -24,3 +24,15 @@ fn only_http_and_https_links_are_kept() {None);}++#[test]+fn a_group_created_line_names_the_subject_never_the_creation_metadata() {+ let metadata = r#"{"reason":0,"parent_group_jid":null,"is_open_group":true,"subject":null,"author":"123456789@lid","is_initially_empty":false}"#;+ let named = r#"{"reason":0,"subject":"Launch","author":"123456789@lid"}"#;++ assert_eq!(created_subject(metadata), None);+ assert_eq!(created_subject(named).as_deref(), Some("Launch"));+ assert_eq!(created_subject(" Launch ").as_deref(), Some("Launch"));+ assert_eq!(created_subject("2026").as_deref(), Some("2026"));+ assert_eq!(created_subject(" "), None);+}diff --git a/crates/external_chat/src/domain/timeline/view.rs b/crates/external_chat/src/domain/timeline/view.rsindex 242eb5af16..d8d2dd3c1b 100644--- a/crates/external_chat/src/domain/timeline/view.rs+++ b/crates/external_chat/src/domain/timeline/view.rs@@ -2,7 +2,9 @@//! ids become people's names, votes become tallies.use super::*;-use crate::domain::rich::{Event, Location, PollOption, RichContent, SystemLine, web_link};+use crate::domain::rich::{+ Event, Location, PollOption, RichContent, SystemAction, SystemLine, created_subject, web_link,+};use std::collections::HashMap;#[cfg(test)]@@ -108,7 +110,10 @@ fn system_view(.iter().map(|jid| people.get(jid)).collect(),- value: line.value,+ value: match line.action {+ SystemAction::GroupCreated => line.value.as_deref().and_then(created_subject),+ _ => line.value,+ },call: line.call,}}diff --git a/crates/external_chat/src/domain/timeline/view/test.rs b/crates/external_chat/src/domain/timeline/view/test.rsindex 6df3d6e547..91c1cd8a57 100644--- a/crates/external_chat/src/domain/timeline/view/test.rs+++ b/crates/external_chat/src/domain/timeline/view/test.rs@@ -198,3 +198,29 @@ fn a_poll_vote_is_never_shown_on_its_own() {None);}++#[test]+fn a_stored_group_created_line_holding_creation_metadata_names_no_subject() {+ let created = RichContent::System(SystemLine {+ action: SystemAction::GroupCreated,+ participants: vec![],+ value: Some(+ r#"{"reason":0,"parent_group_jid":null,"is_open_group":true,"subject":null}"#+ .to_owned(),+ ),+ call: None,+ by_whatsapp: false,+ });+ let ana = person("Ana", Some("macro|[email protected]"));++ assert_eq!(+ rich_view(created, &ana, &[], "viewer", &People::default()),+ Some(ExternalChatRichContent::System(ExternalChatSystemLine {+ action: SystemAction::GroupCreated,+ actor: Some(ana.clone()),+ participants: vec![],+ value: None,+ call: None,+ }))+ );+}diff --git a/services/whatsapp_session_service/src/outbound/whatsapp/events/rich.rs b/services/whatsapp_session_service/src/outbound/whatsapp/events/rich.rsindex f998b3ff2e..7423fd6c06 100644--- a/services/whatsapp_session_service/src/outbound/whatsapp/events/rich.rs+++ b/services/whatsapp_session_service/src/outbound/whatsapp/events/rich.rs@@ -6,7 +6,7 @@use chrono::{DateTime, Utc};use external_chat::domain::rich::{Call, CallOutcome, ContactCard, Contacts, Event, Location, Poll, PollOption, PollVote,- RichContent, SystemAction, SystemLine, web_link,+ RichContent, SystemAction, SystemLine, created_subject, web_link,};use nom::Parser;use nom::bytes::complete::{take_till, take_while1};@@ -382,7 +382,10 @@ pub(super) fn stub_line(web: &WebMessageInfo) -> Option<SystemLine> {};Some(match stub {StubType::GroupCreate => SystemLine {- value: first(),+ value: parameters+ .first()+ .map(String::as_str)+ .and_then(created_subject),..line(SystemAction::GroupCreated)},StubType::GroupChangeSubject => SystemLine {diff --git a/services/whatsapp_session_service/src/outbound/whatsapp/events/rich/test.rs b/services/whatsapp_session_service/src/outbound/whatsapp/events/rich/test.rsindex a4d4deab2c..9d4ddc9ea0 100644--- a/services/whatsapp_session_service/src/outbound/whatsapp/events/rich/test.rs+++ b/services/whatsapp_session_service/src/outbound/whatsapp/events/rich/test.rs@@ -11,3 +11,30 @@ fn a_vcard_gives_its_name_and_phone_numbers() {assert_eq!(name.as_deref(), Some("Ada Lovelace"));assert_eq!(phones, vec!["+1 555-000-1111", "+44 20 7946 0000"]);}++/// Newer phones give a created group's metadata as JSON, not its subject.+#[test]+fn a_history_group_create_stub_names_the_subject_not_the_metadata() {+ let created = |parameter: &str| {+ super::stub_line(&whatsmeow::proto::wa_web::WebMessageInfo {+ message_stub_type: Some(+ whatsmeow::proto::wa_web::web_message_info::StubType::GroupCreate as i32,+ ),+ message_stub_parameters: vec![parameter.to_owned()],+ ..Default::default()+ })+ .unwrap()+ };++ let metadata = created(+ r#"{"reason":0,"parent_group_jid":null,"is_open_group":true,"subject":null,"author":"123456789@lid"}"#,+ );+ let subject = created("Launch");++ assert_eq!(+ metadata.action,+ external_chat::domain::rich::SystemAction::GroupCreated+ );+ assert_eq!(metadata.value, None);+ assert_eq!(subject.value.as_deref(), Some("Launch"));+}