Skip to content

Commit 46a4e4d

Browse files
committed
Fix created date for cancelled events
1 parent d015b8f commit 46a4e4d

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

tools/google-calendar/src/google-calendar.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,15 @@ export class GoogleCalendar
362362
let resolvedCalendarId = calendarId;
363363
if (authToken) {
364364
try {
365-
resolvedCalendarId = await this.resolveCalendarId(authToken, calendarId);
365+
resolvedCalendarId = await this.resolveCalendarId(
366+
authToken,
367+
calendarId
368+
);
366369
} catch (error) {
367-
console.warn("Failed to resolve calendar ID, using provided value", error);
370+
console.warn(
371+
"Failed to resolve calendar ID, using provided value",
372+
error
373+
);
368374
}
369375
}
370376

@@ -473,7 +479,6 @@ export class GoogleCalendar
473479
*/
474480
private async renewCalendarWatch(calendarId: string): Promise<void> {
475481
try {
476-
477482
// Get auth token
478483
const authToken = await this.get<string>(`auth_token_${calendarId}`);
479484
if (!authToken) {
@@ -502,7 +507,6 @@ export class GoogleCalendar
502507

503508
// Create new watch (reuses existing webhook URL and callback)
504509
await this.setupCalendarWatch(authToken, calendarId, authToken);
505-
506510
} catch (error) {
507511
console.error(`Failed to renew watch for calendar ${calendarId}:`, error);
508512
// Don't throw - let reactive checking handle it as fallback
@@ -583,9 +587,11 @@ export class GoogleCalendar
583587
const syncLock = await this.get<boolean>(`sync_lock_${calendarId}`);
584588
if (!syncLock) {
585589
// Both state and lock are cleared - sync completed normally, this is a stale callback
586-
} else {
590+
} else {
587591
// State missing but lock still set - sync may have been superseded
588-
console.warn(`No sync state found for calendar ${calendarId}, sync may have been superseded`);
592+
console.warn(
593+
`No sync state found for calendar ${calendarId}, sync may have been superseded`
594+
);
589595
await this.clear(`sync_lock_${calendarId}`);
590596
}
591597
return;
@@ -678,7 +684,12 @@ export class GoogleCalendar
678684

679685
// Check if this is a recurring event instance (exception)
680686
if (event.recurringEventId && event.originalStartTime) {
681-
await this.processEventInstance(event, calendarId, initialSync, callbackToken);
687+
await this.processEventInstance(
688+
event,
689+
calendarId,
690+
initialSync,
691+
callbackToken
692+
);
682693
} else {
683694
// Regular or master recurring event
684695
const activityData = transformGoogleEvent(event, calendarId);
@@ -700,14 +711,13 @@ export class GoogleCalendar
700711
// Convert to Note type with blocked tag and cancellation note
701712
const activity: NewActivityWithNotes = {
702713
source: canonicalUrl,
714+
created: event.created ? new Date(event.created) : undefined,
703715
type: ActivityType.Note,
704-
title: activityData.title || "",
716+
title: activityData.title,
717+
preview: "Cancelled",
705718
start: activityData.start || null,
706719
end: activityData.end || null,
707720
meta: activityData.meta ?? null,
708-
tags: {
709-
[Tag.Blocked]: [], // Toggle tag, empty actor array
710-
},
711721
notes: [cancelNote],
712722
...(initialSync ? { unread: false } : {}), // false for initial sync, omit for incremental updates
713723
...(initialSync ? { archived: false } : {}), // unarchive on initial sync only
@@ -1087,7 +1097,10 @@ export class GoogleCalendar
10871097
// Trigger contacts sync with the same authorization
10881098
// This happens automatically when calendar auth succeeds
10891099
try {
1090-
const token = await this.tools.integrations.get(authResult.provider, authResult.actor.id);
1100+
const token = await this.tools.integrations.get(
1101+
authResult.provider,
1102+
authResult.actor.id
1103+
);
10911104
if (token) {
10921105
await this.tools.googleContacts.syncWithAuth(
10931106
authResult,

tools/outlook-calendar/src/outlook-calendar.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ export class OutlookCalendar
153153
extends Tool<OutlookCalendar>
154154
implements CalendarTool
155155
{
156-
static readonly SCOPES = [
157-
"https://graph.microsoft.com/calendars.readwrite",
158-
];
156+
static readonly SCOPES = ["https://graph.microsoft.com/calendars.readwrite"];
159157

160158
build(build: ToolBuilder) {
161159
return {
@@ -198,7 +196,10 @@ export class OutlookCalendar
198196

199197
private async getApi(authToken: string): Promise<GraphApi> {
200198
// Try new flow: authToken is an ActorId, look up directly
201-
let token = await this.tools.integrations.get(AuthProvider.Microsoft, authToken as ActorId);
199+
let token = await this.tools.integrations.get(
200+
AuthProvider.Microsoft,
201+
authToken as ActorId
202+
);
202203

203204
// Fall back to legacy flow: authToken is opaque UUID mapped to stored authorization
204205
if (!token) {
@@ -209,7 +210,10 @@ export class OutlookCalendar
209210
throw new Error("Authorization no longer available");
210211
}
211212

212-
token = await this.tools.integrations.get(authorization.provider, authorization.actor.id);
213+
token = await this.tools.integrations.get(
214+
authorization.provider,
215+
authorization.actor.id
216+
);
213217
if (!token) {
214218
throw new Error("Authorization no longer available");
215219
}
@@ -488,10 +492,11 @@ export class OutlookCalendar
488492
// Convert to Note type with blocked tag and cancellation note
489493
const activity: NewActivityWithNotes = {
490494
type: ActivityType.Note,
495+
created: outlookEvent.createdDateTime
496+
? new Date(outlookEvent.createdDateTime)
497+
: new Date(),
498+
preview: "Cancelled",
491499
source,
492-
tags: {
493-
[Tag.Blocked]: [], // Toggle tag, empty actor array
494-
},
495500
notes: [cancelNote],
496501
...(initialSync ? { unread: false } : {}), // false for initial sync, omit for incremental updates
497502
...(initialSync ? { archived: false } : {}), // unarchive on initial sync only
@@ -792,7 +797,6 @@ export class OutlookCalendar
792797
calendarId: string,
793798
authToken: string
794799
): Promise<void> {
795-
796800
try {
797801
await this.getApi(authToken);
798802
} catch (error) {

0 commit comments

Comments
 (0)