Receiving event posts

main
Bob Mottram 2020-08-20 17:51:48 +01:00
parent a771ce3041
commit f263cef884
3 changed files with 74 additions and 5 deletions

View File

@ -43,8 +43,8 @@ def removeEventFromTimeline(eventId: str, tlEventsFilename: str) -> None:
pass
def saveEvent(baseDir: str, handle: str, postId: str,
eventJson: {}) -> bool:
def saveEventPost(baseDir: str, handle: str, postId: str,
eventJson: {}) -> bool:
"""Saves an event to the calendar and/or the events timeline
If an event has extra fields, as per Mobilizon,
Then it is saved as a separate entity and added to the
@ -71,6 +71,7 @@ def saveEvent(baseDir: str, handle: str, postId: str,
eventJson.get('uuid') and eventJson.get('content'):
if not validUuid(eventJson['uuid']):
return False
print('Mobilizon type event')
# if this is a full description of an event then save it
# as a separate json file
eventsPath = baseDir + '/accounts/' + handle + '/events'

View File

@ -64,7 +64,7 @@ from git import isGitPatch
from git import receiveGitPatch
from followingCalendar import receivingCalendarEvents
from content import dangerousMarkup
from happening import saveEvent
from happening import saveEventPost
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
@ -770,6 +770,56 @@ def receiveUndo(session, baseDir: str, httpPrefix: str,
return False
def isEventPost(messageJson: {}) -> bool:
"""Is the given post a mobilizon-type event activity?
"""
if not messageJson.get('id'):
return False
if not messageJson.get('actor'):
return False
if not messageJson.get('object'):
return False
if not isinstance(messageJson['object'], dict):
return False
if not messageJson['object'].get('type'):
return False
if messageJson['object']['type'] != 'Event':
return False
if not messageJson['object'].get('startTime'):
return False
if not messageJson['object'].get('actor'):
return False
if not messageJson['object'].get('content'):
return False
if not messageJson['object'].get('name'):
return False
if not messageJson['object'].get('uuid'):
return False
return True
def receiveEventPost(recentPostsCache: {}, session, baseDir: str,
httpPrefix: str, domain: str, port: int,
sendThreads: [], postLog: [], cachedWebfingers: {},
personCache: {}, messageJson: {}, federationList: [],
nickname: str, debug: bool) -> bool:
"""Receive a mobilizon-type event activity
"""
if not isEventPost(messageJson):
return
print('Receiving event: ' + str(messageJson['object']))
handle = nickname + '@' + domain
if port:
if port != 80 and port != 443:
handle += ':' + str(port)
postId = \
messageJson['id'].replace('/activity', '').replace('/', '#')
postId = postId.replace('/event', '')
saveEventPost(baseDir, handle, postId, messageJson['object'])
def personReceiveUpdate(baseDir: str,
domain: str, port: int,
updateNickname: str, updateDomain: str,
@ -1991,7 +2041,7 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
continue
if not tagDict.get('startTime'):
continue
saveEvent(baseDir, handle, postId, tagDict)
saveEventPost(baseDir, handle, postId, tagDict)
def inboxUpdateIndex(boxname: str, baseDir: str, handle: str,
@ -2715,6 +2765,23 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
queue.pop(0)
continue
if receiveEventPost(recentPostsCache, session,
baseDir, httpPrefix,
domain, port,
sendThreads, postLog,
cachedWebfingers,
personCache,
queueJson['post'],
federationList,
queueJson['postNickname'],
debug):
print('Queue: Event activity accepted from ' + keyId)
if os.path.isfile(queueFilename):
os.remove(queueFilename)
if len(queue) > 0:
queue.pop(0)
continue
if receiveUpdate(recentPostsCache, session,
baseDir, httpPrefix,
domain, port,

View File

@ -152,7 +152,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
permittedOutboxTypes = ('Create', 'Announce', 'Like', 'Follow', 'Undo',
'Update', 'Add', 'Remove', 'Block', 'Delete',
'Delegate', 'Skill', 'Bookmark')
'Delegate', 'Skill', 'Bookmark', 'Event')
if messageJson['type'] not in permittedOutboxTypes:
if debug:
print('DEBUG: POST to outbox - ' + messageJson['type'] +
@ -191,6 +191,7 @@ def postMessageToOutbox(messageJson: {}, postToNickname: str,
messageJson['type'] == 'Note' or \
messageJson['type'] == 'EncryptedMessage' or \
messageJson['type'] == 'Article' or \
messageJson['type'] == 'Event' or \
messageJson['type'] == 'Patch' or \
messageJson['type'] == 'Announce':
indexes = [outboxName, "inbox"]