Skip to content

Commit

Permalink
Issue #32 bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaccarini-Lorenzo committed Nov 15, 2023
1 parent bc4700a commit f188010
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/controllers/calendarViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CalendarViewController {
for (let i=0; i<codeComponents.length; i++){
const codeComponent = codeComponents[i];
const eventList = await calendarViewController.getEventList(codeComponent);
if (!eventList) return;
eventList.forEach((cloudEvent) => calendarViewController.cloudEventUUIDMap.set(cloudEvent.cloudEventUUID, cloudEvent));
const calendarViewData = new CalendarViewData(new DateRange(new Date(codeComponent.from), new Date(codeComponent.to)), eventList);
if (!codeComponent.codeBlock) return null;
Expand Down
26 changes: 14 additions & 12 deletions src/controllers/googleCalendarController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {SettingInterface} from "../plugin/appSetting";
import {GoogleAuthenticator} from "./googleAuthenticator";
import {Misc} from "../misc/misc";
import calendarViewController from "./calendarViewController";
import {calendar} from "googleapis/build/src/apis/calendar";

export class GoogleCalendarController implements CloudController {
private _pluginPath: string;
private readonly _scopes: string[];
private _calendarEndpoint: APIEndpoint;
private _calendars: GoogleCalendar[];
private _currentCalendarName: string;
private _currentCalendarId: string;
private _settings: SettingInterface;
private _channelId: string;

Expand All @@ -40,7 +42,7 @@ export class GoogleCalendarController implements CloudController {
}

async updateEvent(cloudEvent: CloudEvent): Promise<boolean>{
const googleEventInsertResponse = await this._calendarEndpoint.events.patch({
const googleEventInsertResponse = await this._calendarEndpoint.events.patch({
calendarId: this._currentCalendarName,
eventId: (cloudEvent as GoogleCalendarEvent).id,
resource: cloudEvent as GoogleCalendarEvent
Expand All @@ -50,8 +52,8 @@ export class GoogleCalendarController implements CloudController {
}

async getEvents(missedDateRange: DateRange): Promise<CloudEvent[]> {
const googleEventResponse = await this._calendarEndpoint.events.list({
calendarId: this._currentCalendarName,
const googleEventResponse = await this._calendarEndpoint.events.list({
calendarId: this._currentCalendarId,
orderBy: "startTime",
singleEvents: true,
timeMax: missedDateRange.end.toISOString(),
Expand All @@ -61,10 +63,13 @@ export class GoogleCalendarController implements CloudController {
const googleEvents = googleEventResponse.data.items as GoogleCalendarEvent[];

googleEvents.forEach(googleEvent => {
const cloudEventStartDate = googleEvent.start.dateTime ? new Date(googleEvent.start.dateTime) : new Date(googleEvent.start.date + " 00:00");
const cloudEventEndDate = googleEvent.end.dateTime ? new Date(googleEvent.end.dateTime) : new Date(googleEvent.end.date + " 23:59");

googleEvent.cloudEventUUID = googleEvent.id;
googleEvent.cloudEventTitle = googleEvent.summary;
googleEvent.cloudEventStartDate = new Date(googleEvent.start.dateTime);
googleEvent.cloudEventEndDate = new Date(googleEvent.end.dateTime);
googleEvent.cloudEventStartDate = cloudEventStartDate
googleEvent.cloudEventEndDate = cloudEventEndDate
})

return googleEvents;
Expand All @@ -78,24 +83,19 @@ export class GoogleCalendarController implements CloudController {
this._settings = settings;
if (this._calendars.length == 0){
this._currentCalendarName = this._settings.calendar;
return;
return;
}
this._currentCalendarName = this._calendars.filter(calendar => {
return calendar.summary == this._settings.calendar;
}).first().summary;
this._currentCalendarId = this._calendars.filter(calendar => calendar.summary == this._currentCalendarName).first().id;
}

async tryAuthentication(auth: Map<string,string>): Promise<CloudStatus> {
//await this._calendarEndpoint.events.watch();
if (auth){
return await this.manageTokenValidity(auth);
}
/*
const oAuth2Client = await authenticate({
scopes: this._scopes,
keyfilePath: this._credentialsPath,
});
*/
const googleAuthenticator = new GoogleAuthenticator(this._scopes);
const oAuth2Client = await googleAuthenticator.authenticate();
if (oAuth2Client.credentials) {
Expand All @@ -116,6 +116,8 @@ export class GoogleCalendarController implements CloudController {
async preloadData() {
const calendarResponse = await this._calendarEndpoint.calendarList.list();
this._calendars = calendarResponse.data.items as GoogleCalendar[];
if (!this._currentCalendarName) return;
this._currentCalendarId = this._calendars.filter(calendar => calendar.summary == this._currentCalendarName).first().id;
}

getCalendarNames() {
Expand Down
4 changes: 2 additions & 2 deletions src/model/events/googleCalendarEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class GoogleCalendarEvent extends CloudEvent {
summary: string
creator: { email: string, self: boolean };
organizer: { email: string, self: boolean };
start: { dateTime: string, timeZone: string };
end: { dateTime: string, timeZone: string };
start: { date?: string, dateTime?: string, timeZone: string };
end: { date?:string, dateTime?: string, timeZone: string };
magicCalendarUID: string;
sequence: number;
reminders: { useDefault: boolean };
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class MagicCalendar extends Plugin implements PluginValue{
private manageRegistrations(){
this.registerEditorExtension(nlpPlugin)
this.registerMarkdownPostProcessor(calendarViewController.getMarkdownPostProcessor);
this.addRibbonIcon("calendar-clock", "magicCalendarSync", () => {
this.addRibbonIcon("calendar-clock", "MagicCalendar", () => {
this._statusModal.open();
});
}
Expand Down

0 comments on commit f188010

Please sign in to comment.