From ebd681d11adf850130ad401136c328776d0ad371 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 3 Jul 2020 19:49:00 +0100 Subject: [PATCH] Check that an account can receive calendar events from the actor --- calendar.py | 6 ++++++ inbox.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/calendar.py b/calendar.py index 87b8f770..50d18b24 100644 --- a/calendar.py +++ b/calendar.py @@ -50,6 +50,12 @@ def receiveCalendarEvents(baseDir: str, nickname: str, domain: str, if os.path.isfile(calendarFilename): with open(calendarFilename, 'r') as calendarFile: followingHandles = calendarFile.read() + else: + # create a new calendar file from the following file + with open(followingFilename, 'r') as followingFile: + followingHandles = followingFile.read() + with open(calendarFilename, 'w') as fp: + fp.write(followingHandles) # already in the calendar file? if handle + '\n' in followingHandles: diff --git a/inbox.py b/inbox.py index 24006d54..ee179e7b 100644 --- a/inbox.py +++ b/inbox.py @@ -62,6 +62,7 @@ from question import questionUpdateVotes from media import replaceYouTube from git import isGitPatch from git import receiveGitPatch +from calendar import receivingCalendarEvents def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: @@ -1844,6 +1845,8 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None: and if so saves the post id to a file in the calendar directory for the account """ + if not postJsonObject.get('actor'): + return if not postJsonObject.get('object'): return if not isinstance(postJsonObject['object'], dict): @@ -1857,6 +1860,15 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None: if not os.path.isdir(calendarPath): os.mkdir(calendarPath) + actor = postJsonObject['actor'] + actorNickname = getNicknameFromActor(actor) + actorDomain, actorPort = getDomainFromActor(actor) + if not receivingCalendarEvents(baseDir, + handle.split('@')[0], + handle.split('@')[1], + actorNickname, + actorDomain): + return for tagDict in postJsonObject['object']['tag']: if tagDict['type'] != 'Event': continue