Check that an account can receive calendar events from the actor

main
Bob Mottram 2020-07-03 19:49:00 +01:00
parent 5a7a235cbb
commit ebd681d11a
2 changed files with 18 additions and 0 deletions

View File

@ -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:

View File

@ -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