Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,18 @@
}
return new Date(min);
},
getChannelIds() {
const channelIds = [];
getCalendarIdForChannelId(incomingChannelId) {
for (const calendarId of this.calendarIds) {
const channelId = this.db.get(`${calendarId}.channelId`);
channelIds.push(channelId);
if (this.db.get(`${calendarId}.channelId`) === incomingChannelId) {
return calendarId;
}
}
return channelIds;
return null;
},
},
async run(event) {
let calendarId = null; // calendar ID matching incoming channel ID

// refresh watch
if (event.interval_seconds) {
// get time
Expand All @@ -224,9 +226,9 @@
}
} else {
// Verify channel ID
const channelIds = this.getChannelIds();
const incomingChannelId = event?.headers?.["x-goog-channel-id"];
if (!channelIds.includes(incomingChannelId)) {
calendarId = this.getCalendarIdForChannelId(incomingChannelId);
if (!calendarId) {
console.log(
`Unexpected channel ID ${incomingChannelId}. This likely means there are multiple, older subscriptions active.`,
);
Expand All @@ -252,7 +254,10 @@
}

// Fetch and emit events
for (const calendarId of this.calendarIds) {
const checkCalendarIds = calendarId
? [calendarId]

Check failure on line 258 in components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required after '['

Check failure on line 258 in components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

A linebreak is required before ']'
: this.calendarIds;
for (const calendarId of checkCalendarIds) {
const syncToken = this.getNextSyncToken(calendarId);
let nextSyncToken = null;
let nextPageToken = null;
Expand All @@ -266,10 +271,11 @@
syncToken,
pageToken: nextPageToken,
maxResults: 2500,
validateStatus: (status) => (status >= 200 && (status < 300 || status == 410)),
});
if (syncStatus === 410) {
console.log("Sync token invalid, resyncing");
nextSyncToken = await this.googleCalendar.fullSync(this.calendarId);
nextSyncToken = await this.googleCalendar.fullSync(calendarId);
break;
}
nextPageToken = syncData.nextPageToken;
Expand Down
Loading