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(github): rollback browser and push notifs (#3711)

Will Hutchinsonea31407bfcac
diff --git a/js/app/packages/notifications/notification-platform.ts b/js/app/packages/notifications/notification-platform.ts
index 9462ba7694..1a52c064bf 100644
--- a/js/app/packages/notifications/notification-platform.ts
+++ b/js/app/packages/notifications/notification-platform.ts
@@ -81,8 +81,13 @@ export async function maybeHandlePlatformNotification(
notificationInterface: PlatformNotificationState,
splitLayoutManager: SplitManager
) {
- // Ignore notification types that should not show as browser notifications
- if (notification.notification_metadata.tag === 'document_mention') {
+ // Ignore notification types that should not show as browser notifications.
+ // GitHub PR notifications should remain visible in-app, but should not
+ // render as browser/system popups.
+ if (
+ notification.notification_metadata.tag === 'document_mention' ||
+ notification.notification_metadata.tag === 'github_pr_event'
+ ) {
return;
}
diff --git a/js/app/packages/notifications/tests/notification-platform.test.ts b/js/app/packages/notifications/tests/notification-platform.test.ts
new file mode 100644
index 0000000000..9f44721f7f
--- /dev/null
+++ b/js/app/packages/notifications/tests/notification-platform.test.ts
@@ -0,0 +1,151 @@
+import type { SplitManager } from '@app/component/split-layout/layoutManager';
+import { describe, expect, it, vi } from 'vitest';
+import type { PlatformNotificationState } from '../components/PlatformNotificationProvider';
+import type { PlatformNotificationHandle } from '../notification-platform';
+import type { UnifiedNotification } from '../types';
+
+vi.mock('@app/util/favicon', () => ({
+ getFaviconUrl: () => 'favicon.ico',
+}));
+
+vi.mock('@lexical-core', () => ({
+ markdownToPlainText: (content: string) => content,
+}));
+
+vi.mock('../../theme/signals/themeReactive', () => ({
+ themeReactive: {
+ a0: {
+ l: [() => '0.8'],
+ c: [() => '0.1'],
+ h: [() => '100'],
+ },
+ },
+}));
+
+vi.mock('../notification-navigation', () => ({
+ openNotification: vi.fn(),
+}));
+
+vi.mock('../notification-resolvers', () => ({
+ DefaultDocumentNameResolver: vi.fn(async () => undefined),
+ DefaultUserNameResolver: vi.fn(async () => undefined),
+}));
+
+import { maybeHandlePlatformNotification } from '../notification-platform';
+
+function baseNotification(
+ overrides: Partial<UnifiedNotification>
+): UnifiedNotification {
+ const now = new Date().toISOString();
+
+ return {
+ id: 'notification-1',
+ entity_id: 'entity-1',
+ entity_type: 'channel',
+ created_at: now,
+ updated_at: now,
+ viewed_at: null,
+ deleted_at: null,
+ done: false,
+ sent: true,
+ sender_id: null,
+ ...overrides,
+ } as UnifiedNotification;
+}
+
+function createChannelInviteNotification(): UnifiedNotification {
+ return baseNotification({
+ notification_event_type: 'channel_invite',
+ notification_metadata: {
+ tag: 'channel_invite',
+ content: {
+ channelName: 'General',
+ invitedBy: 'user-1',
+ },
+ },
+ });
+}
+
+function createGithubPrNotification(): UnifiedNotification {
+ return baseNotification({
+ entity_id: '123e4567-e89b-12d3-a456-426614174000',
+ entity_type: 'foreign_entity',
+ notification_event_type: 'github_pr_event',
+ notification_metadata: {
+ tag: 'github_pr_event',
+ content: {
+ action: 'opened',
+ displayName: 'macro/macro#42',
+ foreignEntityId: '123e4567-e89b-12d3-a456-426614174000',
+ githubKey: 'macro/macro/pull/42',
+ number: 42,
+ owner: 'macro',
+ repo: 'macro',
+ status: 'open',
+ title: 'Add notification support',
+ url: 'https://github.com/macro/macro/pull/42',
+ },
+ },
+ });
+}
+
+function createNotificationInterface(
+ showNotification: PlatformNotificationState['showNotification']
+): PlatformNotificationState {
+ return {
+ permission: () => 'granted',
+ requestPermission: async () => 'granted',
+ unregisterNotification: async () => undefined,
+ showNotification,
+ };
+}
+
+function createNotificationHandle(): PlatformNotificationHandle {
+ return {
+ onClick: vi.fn(),
+ onDismiss: vi.fn(),
+ close: vi.fn(),
+ };
+}
+
+describe('maybeHandlePlatformNotification', () => {
+ it('skips GitHub PR events so they do not render as browser notifications', async () => {
+ const showNotification = vi.fn<
+ PlatformNotificationState['showNotification']
+ >(async () => 'not-granted');
+ const notificationInterface = createNotificationInterface(showNotification);
+
+ await maybeHandlePlatformNotification(
+ createGithubPrNotification(),
+ notificationInterface,
+ {} as SplitManager
+ );
+
+ expect(showNotification).not.toHaveBeenCalled();
+ });
+
+ it('still renders non-GitHub browser notifications', async () => {
+ const handle = createNotificationHandle();
+ const showNotification = vi.fn<
+ PlatformNotificationState['showNotification']
+ >(async () => handle);
+ const notificationInterface = createNotificationInterface(showNotification);
+
+ await maybeHandlePlatformNotification(
+ createChannelInviteNotification(),
+ notificationInterface,
+ {} as SplitManager
+ );
+
+ expect(showNotification).toHaveBeenCalledOnce();
+ expect(showNotification).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: 'Someone <General>',
+ options: expect.objectContaining({
+ body: 'invited you to',
+ }),
+ })
+ );
+ expect(handle.onClick).toHaveBeenCalledOnce();
+ });
+});
diff --git a/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs b/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
index 8643a30597..467195143c 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/notify_pr.rs
@@ -82,7 +82,6 @@ impl<
recipient_ids,
}
.into_request()
- .with_apns()
.with_conn_gateway();
if let Err(error) = self.notification_ingress.send_notification(request).await {
diff --git a/rust/cloud-storage/github/src/domain/service/sync/test.rs b/rust/cloud-storage/github/src/domain/service/sync/test.rs
index 8cef48ca70..bf0fbde229 100644
--- a/rust/cloud-storage/github/src/domain/service/sync/test.rs
+++ b/rust/cloud-storage/github/src/domain/service/sync/test.rs
@@ -995,7 +995,7 @@ fn notification_request_recipients(request: &serde_json::Value) -> Vec<String> {
recipient_ids
}
-fn assert_github_pr_notification_delivery_enabled(request: &serde_json::Value) {
+fn assert_github_pr_notification_realtime_enabled_apns_disabled(request: &serde_json::Value) {
assert_eq!(
request
.pointer("/req/notification/tag")
@@ -1009,11 +1009,10 @@ fn assert_github_pr_notification_delivery_enabled(request: &serde_json::Value) {
Some(true)
);
assert!(
- !request
+ request
.pointer("/build_apns")
- .expect("build_apns field")
- .is_null(),
- "GitHub PR notifications should include APNS payloads"
+ .is_none_or(serde_json::Value::is_null),
+ "GitHub PR notifications should not include APNS payloads"
);
}
@@ -1960,7 +1959,7 @@ async fn github_pr_event_opened_team_source_notifies_team_members() {
assert_eq!(requests.len(), 1);
let request = &requests[0];
- assert_github_pr_notification_delivery_enabled(request);
+ assert_github_pr_notification_realtime_enabled_apns_disabled(request);
assert_eq!(
request
.pointer("/req/notification_entity/entity_type")
@@ -2099,7 +2098,7 @@ async fn github_pr_event_merged_user_source_notifies_user() {
assert_eq!(requests.len(), 1);
let request = &requests[0];
- assert_github_pr_notification_delivery_enabled(request);
+ assert_github_pr_notification_realtime_enabled_apns_disabled(request);
assert_eq!(
notification_request_recipients(request),
vec!["macro|[email protected]".to_string()]
@@ -2239,7 +2238,10 @@ async fn github_pr_event_send_failure_does_not_fail_webhook_processing() {
assert!(result.is_ok());
assert_eq!(service.foreign_entity_service.foreign_entities().len(), 1);
- assert_eq!(service.notification_ingress.requests().len(), 1);
+
+ let requests = service.notification_ingress.requests();
+ assert_eq!(requests.len(), 1);
+ assert_github_pr_notification_realtime_enabled_apns_disabled(&requests[0]);
}
#[tokio::test]
diff --git a/rust/cloud-storage/model_notifications/src/metadata.rs b/rust/cloud-storage/model_notifications/src/metadata.rs
index 3261ba9282..92ecb0676e 100644
--- a/rust/cloud-storage/model_notifications/src/metadata.rs
+++ b/rust/cloud-storage/model_notifications/src/metadata.rs
@@ -149,25 +149,6 @@ impl NotificationTitle for GithubPrEvent {
}
}
-impl NotificationExtIos for GithubPrEvent {
- type NotifData = ::notification::domain::models::apple::PushNotificationData;
-
- fn collapse_key(&self, entity: &Entity<'_>) -> NotifCollapseKey {
- let entity_type: &'static str = entity.entity_type.into();
- NotifCollapseKey::new(entity_type).append(&entity.entity_id)
- }
-
- fn as_apns<'a>(
- &self,
- sender_id: Option<MacroUserIdStr<'a>>,
- _entity: &Entity<'_>,
- notification_id: Uuid,
- ) -> Option<APNSPushNotification<Self::NotifData>> {
- let avatar_url = self.sender_github_avatar_url.clone();
- alert_apns(self, sender_id, notification_id, avatar_url).ok()
- }
-}
-
#[derive(Debug, Clone, Copy, ToSchema, Doppleganger, Serialize, Deserialize)]
#[dg(backward = models_comms::channel::ChannelType)]
#[serde(rename_all = "camelCase")]
diff --git a/rust/cloud-storage/model_notifications/src/metadata/test.rs b/rust/cloud-storage/model_notifications/src/metadata/test.rs
index 0dbf9f948f..36e36445c9 100644
--- a/rust/cloud-storage/model_notifications/src/metadata/test.rs
+++ b/rust/cloud-storage/model_notifications/src/metadata/test.rs
@@ -117,25 +117,30 @@ fn github_pr_event_title_falls_back_to_display_name() {
}
#[test]
-fn github_pr_event_uses_foreign_entity_for_collapse_key_and_apns() {
- let event = github_pr_event();
- let entity = EntityType::ForeignEntity.with_entity_string(event.foreign_entity_id.to_string());
- let entity_type: &'static str = EntityType::ForeignEntity.into();
- let expected_collapse_key = NotifCollapseKey::new(entity_type)
- .append(&event.foreign_entity_id.to_string())
- .into_hashed()
- .into_inner();
+fn github_pr_event_notif_event_deserializes_and_renders_in_app() {
+ let expected = github_pr_event();
+ let value = serde_json::json!({
+ "tag": "github_pr_event",
+ "content": serde_json::to_value(&expected).unwrap(),
+ });
- let collapse_key = event.collapse_key(&entity).into_hashed().into_inner();
- let apns = event.as_apns(None, &entity, Uuid::nil()).unwrap();
+ let event: crate::NotifEvent = serde_json::from_value(value).unwrap();
- assert_eq!(collapse_key, expected_collapse_key);
assert_eq!(
- apns.push_notification_data
- .sender_profile_picture_url
- .as_deref(),
- Some("https://avatars.githubusercontent.com/u/12345?v=4")
+ event
+ .format_title(Some(uid("macro|[email protected]")))
+ .unwrap(),
+ "pr.sender merged a pull request"
+ );
+ assert_eq!(
+ event.format_body(None).unwrap(),
+ "macro/app#42: Add GitHub PR notifications"
);
+
+ let crate::NotifEvent::GithubPrEvent(actual) = event else {
+ panic!("expected github_pr_event variant");
+ };
+ assert_eq!(actual, expected);
}
#[test]