forked from indymedia/epicyon
Add endpoint for new event
parent
fa0434ca9c
commit
43d8fc1863
38
daemon.py
38
daemon.py
|
@ -69,6 +69,7 @@ from posts import createBlogPost
|
||||||
from posts import createReportPost
|
from posts import createReportPost
|
||||||
from posts import createUnlistedPost
|
from posts import createUnlistedPost
|
||||||
from posts import createFollowersOnlyPost
|
from posts import createFollowersOnlyPost
|
||||||
|
from posts import createEventPost
|
||||||
from posts import createDirectMessagePost
|
from posts import createDirectMessagePost
|
||||||
from posts import populateRepliesJson
|
from posts import populateRepliesJson
|
||||||
from posts import addToField
|
from posts import addToField
|
||||||
|
@ -3619,6 +3620,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.path.endswith('/newfollowers') or
|
self.path.endswith('/newfollowers') or
|
||||||
self.path.endswith('/newdm') or
|
self.path.endswith('/newdm') or
|
||||||
self.path.endswith('/newreminder') or
|
self.path.endswith('/newreminder') or
|
||||||
|
self.path.endswith('/newevent') or
|
||||||
self.path.endswith('/newreport') or
|
self.path.endswith('/newreport') or
|
||||||
self.path.endswith('/newquestion') or
|
self.path.endswith('/newquestion') or
|
||||||
self.path.endswith('/newshare'))):
|
self.path.endswith('/newshare'))):
|
||||||
|
@ -5709,6 +5711,42 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
elif postType == 'newevent':
|
||||||
|
# A Mobilizon-type event is posted
|
||||||
|
|
||||||
|
# if there is no image dscription then make it the same
|
||||||
|
# as the event title
|
||||||
|
if not fields.get('imageDescription'):
|
||||||
|
fields['imageDescription'] = fields['subject']
|
||||||
|
# Events are public by default, with opt-in
|
||||||
|
# followers only status
|
||||||
|
if not fields.get('followersOnlyEvent'):
|
||||||
|
fields['followersOnlyEvent'] = False
|
||||||
|
|
||||||
|
messageJson = \
|
||||||
|
createEventPost(self.server.baseDir,
|
||||||
|
nickname,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.port,
|
||||||
|
self.server.httpPrefix,
|
||||||
|
mentionsStr + fields['message'],
|
||||||
|
fields['followersOnlyEvent'],
|
||||||
|
False, False,
|
||||||
|
filename, attachmentMediaType,
|
||||||
|
fields['imageDescription'],
|
||||||
|
self.server.useBlurHash,
|
||||||
|
fields['subject'],
|
||||||
|
fields['schedulePost'],
|
||||||
|
fields['eventDate'],
|
||||||
|
fields['eventTime'],
|
||||||
|
fields['location'])
|
||||||
|
if messageJson:
|
||||||
|
if fields['schedulePost']:
|
||||||
|
return 1
|
||||||
|
if self._postToOutbox(messageJson, __version__, nickname):
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return -1
|
||||||
elif postType == 'newdm':
|
elif postType == 'newdm':
|
||||||
messageJson = None
|
messageJson = None
|
||||||
print('A DM was posted')
|
print('A DM was posted')
|
||||||
|
|
71
posts.py
71
posts.py
|
@ -13,6 +13,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import uuid
|
||||||
from socket import error as SocketError
|
from socket import error as SocketError
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
@ -614,7 +615,8 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
useBlurhash: bool, isModerationReport: bool,
|
useBlurhash: bool, isModerationReport: bool,
|
||||||
isArticle: bool, inReplyTo=None,
|
isArticle: bool, inReplyTo=None,
|
||||||
inReplyToAtomUri=None, subject=None, schedulePost=False,
|
inReplyToAtomUri=None, subject=None, schedulePost=False,
|
||||||
eventDate=None, eventTime=None, location=None) -> {}:
|
eventDate=None, eventTime=None, location=None,
|
||||||
|
eventUUID=None) -> {}:
|
||||||
"""Creates a message
|
"""Creates a message
|
||||||
"""
|
"""
|
||||||
mentionedRecipients = \
|
mentionedRecipients = \
|
||||||
|
@ -755,6 +757,11 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
for ccRemoval in removeFromCC:
|
for ccRemoval in removeFromCC:
|
||||||
toCC.remove(ccRemoval)
|
toCC.remove(ccRemoval)
|
||||||
|
|
||||||
|
# the type of post to be made
|
||||||
|
postObjectType = 'Note'
|
||||||
|
if eventUUID:
|
||||||
|
postObjectType = 'Event'
|
||||||
|
|
||||||
if not clientToServer:
|
if not clientToServer:
|
||||||
actorUrl = httpPrefix + '://' + domain + '/users/' + nickname
|
actorUrl = httpPrefix + '://' + domain + '/users/' + nickname
|
||||||
|
|
||||||
|
@ -783,7 +790,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
'cc': toCC,
|
'cc': toCC,
|
||||||
'object': {
|
'object': {
|
||||||
'id': newPostId,
|
'id': newPostId,
|
||||||
'type': 'Note',
|
'type': postObjectType,
|
||||||
'summary': summary,
|
'summary': summary,
|
||||||
'inReplyTo': inReplyTo,
|
'inReplyTo': inReplyTo,
|
||||||
'published': published,
|
'published': published,
|
||||||
|
@ -824,7 +831,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
|
||||||
newPost = {
|
newPost = {
|
||||||
"@context": postContext,
|
"@context": postContext,
|
||||||
'id': newPostId,
|
'id': newPostId,
|
||||||
'type': 'Note',
|
'type': postObjectType,
|
||||||
'summary': summary,
|
'summary': summary,
|
||||||
'inReplyTo': inReplyTo,
|
'inReplyTo': inReplyTo,
|
||||||
'published': published,
|
'published': published,
|
||||||
|
@ -1028,7 +1035,7 @@ def createPublicPost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, False, inReplyTo, inReplyToAtomUri, subject,
|
False, False, inReplyTo, inReplyToAtomUri, subject,
|
||||||
schedulePost, eventDate, eventTime, location)
|
schedulePost, eventDate, eventTime, location, None)
|
||||||
|
|
||||||
|
|
||||||
def createBlogPost(baseDir: str,
|
def createBlogPost(baseDir: str,
|
||||||
|
@ -1079,7 +1086,7 @@ def createQuestionPost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, False, None, None, subject,
|
False, False, None, None, subject,
|
||||||
False, None, None, None)
|
False, None, None, None, None)
|
||||||
messageJson['object']['type'] = 'Question'
|
messageJson['object']['type'] = 'Question'
|
||||||
messageJson['object']['oneOf'] = []
|
messageJson['object']['oneOf'] = []
|
||||||
messageJson['object']['votersCount'] = 0
|
messageJson['object']['votersCount'] = 0
|
||||||
|
@ -1126,7 +1133,7 @@ def createUnlistedPost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, False, inReplyTo, inReplyToAtomUri, subject,
|
False, False, inReplyTo, inReplyToAtomUri, subject,
|
||||||
schedulePost, eventDate, eventTime, location)
|
schedulePost, eventDate, eventTime, location, None)
|
||||||
|
|
||||||
|
|
||||||
def createFollowersOnlyPost(baseDir: str,
|
def createFollowersOnlyPost(baseDir: str,
|
||||||
|
@ -1157,7 +1164,48 @@ def createFollowersOnlyPost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, False, inReplyTo, inReplyToAtomUri, subject,
|
False, False, inReplyTo, inReplyToAtomUri, subject,
|
||||||
schedulePost, eventDate, eventTime, location)
|
schedulePost, eventDate, eventTime, location, None)
|
||||||
|
|
||||||
|
|
||||||
|
def createEventPost(baseDir: str,
|
||||||
|
nickname: str, domain: str, port: int,
|
||||||
|
httpPrefix: str,
|
||||||
|
content: str, followersOnly: bool,
|
||||||
|
saveToFile: bool,
|
||||||
|
clientToServer: bool,
|
||||||
|
attachImageFilename: str, mediaType: str,
|
||||||
|
imageDescription: str, useBlurhash: bool,
|
||||||
|
subject=None, schedulePost=False,
|
||||||
|
eventDate=None, eventTime=None,
|
||||||
|
location=None) -> {}:
|
||||||
|
"""Mobilizon-type Event post
|
||||||
|
"""
|
||||||
|
if not attachImageFilename:
|
||||||
|
return None
|
||||||
|
domainFull = domain
|
||||||
|
if port:
|
||||||
|
if port != 80 and port != 443:
|
||||||
|
if ':' not in domain:
|
||||||
|
domainFull = domain + ':' + str(port)
|
||||||
|
|
||||||
|
# create event uuid
|
||||||
|
eventUUID = str(uuid.uuid1())
|
||||||
|
|
||||||
|
toStr1 = 'https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
toStr2 = httpPrefix + '://' + domainFull + '/users/' + \
|
||||||
|
nickname + '/followers',
|
||||||
|
if followersOnly:
|
||||||
|
toStr1 = toStr2
|
||||||
|
toStr2 = None
|
||||||
|
return createPostBase(baseDir, nickname, domain, port,
|
||||||
|
toStr1, toStr2,
|
||||||
|
httpPrefix, content, followersOnly, saveToFile,
|
||||||
|
clientToServer,
|
||||||
|
attachImageFilename, mediaType,
|
||||||
|
imageDescription, useBlurhash,
|
||||||
|
False, False, None, None, subject,
|
||||||
|
schedulePost, eventDate, eventTime, location,
|
||||||
|
eventUUID)
|
||||||
|
|
||||||
|
|
||||||
def getMentionedPeople(baseDir: str, httpPrefix: str,
|
def getMentionedPeople(baseDir: str, httpPrefix: str,
|
||||||
|
@ -1226,7 +1274,7 @@ def createDirectMessagePost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, False, inReplyTo, inReplyToAtomUri, subject,
|
False, False, inReplyTo, inReplyToAtomUri, subject,
|
||||||
schedulePost, eventDate, eventTime, location)
|
schedulePost, eventDate, eventTime, location, None)
|
||||||
# mentioned recipients go into To rather than Cc
|
# mentioned recipients go into To rather than Cc
|
||||||
messageJson['to'] = messageJson['object']['cc']
|
messageJson['to'] = messageJson['object']['cc']
|
||||||
messageJson['object']['to'] = messageJson['to']
|
messageJson['object']['to'] = messageJson['to']
|
||||||
|
@ -1318,7 +1366,7 @@ def createReportPost(baseDir: str,
|
||||||
attachImageFilename, mediaType,
|
attachImageFilename, mediaType,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
True, False, None, None, subject,
|
True, False, None, None, subject,
|
||||||
False, None, None, None)
|
False, None, None, None, None)
|
||||||
if not postJsonObject:
|
if not postJsonObject:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1474,7 +1522,7 @@ def sendPost(projectVersion: str,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, isArticle, inReplyTo,
|
False, isArticle, inReplyTo,
|
||||||
inReplyToAtomUri, subject,
|
inReplyToAtomUri, subject,
|
||||||
False, None, None, None)
|
False, None, None, None, None)
|
||||||
|
|
||||||
# get the senders private key
|
# get the senders private key
|
||||||
privateKeyPem = getPersonKey(nickname, domain, baseDir, 'private')
|
privateKeyPem = getPersonKey(nickname, domain, baseDir, 'private')
|
||||||
|
@ -1618,7 +1666,7 @@ def sendPostViaServer(projectVersion: str,
|
||||||
imageDescription, useBlurhash,
|
imageDescription, useBlurhash,
|
||||||
False, isArticle, inReplyTo,
|
False, isArticle, inReplyTo,
|
||||||
inReplyToAtomUri, subject,
|
inReplyToAtomUri, subject,
|
||||||
False, None, None, None)
|
False, None, None, None, None)
|
||||||
|
|
||||||
authHeader = createBasicAuthHeader(fromNickname, password)
|
authHeader = createBasicAuthHeader(fromNickname, password)
|
||||||
|
|
||||||
|
@ -2441,6 +2489,7 @@ def isImageMedia(session, baseDir: str, httpPrefix: str,
|
||||||
if postJsonObject['object'].get('moderationStatus'):
|
if postJsonObject['object'].get('moderationStatus'):
|
||||||
return False
|
return False
|
||||||
if postJsonObject['object']['type'] != 'Note' and \
|
if postJsonObject['object']['type'] != 'Note' and \
|
||||||
|
postJsonObject['object']['type'] != 'Event' and \
|
||||||
postJsonObject['object']['type'] != 'Article':
|
postJsonObject['object']['type'] != 'Article':
|
||||||
return False
|
return False
|
||||||
if not postJsonObject['object'].get('attachment'):
|
if not postJsonObject['object'].get('attachment'):
|
||||||
|
|
Loading…
Reference in New Issue