mirror of https://gitlab.com/bashrc2/epicyon
Creating question activity
parent
67bb0850f1
commit
08811ffcf8
31
daemon.py
31
daemon.py
|
@ -39,6 +39,7 @@ from person import removeAccount
|
|||
from person import canRemovePost
|
||||
from person import personSnooze
|
||||
from person import personUnsnooze
|
||||
from posts import createQuestionPost
|
||||
from posts import outboxMessageCreateWrap
|
||||
from posts import savePostToBox
|
||||
from posts import sendToFollowersThread
|
||||
|
@ -2150,6 +2151,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.path.endswith('/newfollowers') or \
|
||||
self.path.endswith('/newdm') or \
|
||||
self.path.endswith('/newreport') or \
|
||||
self.path.endswith('/newquestion') or \
|
||||
self.path.endswith('/newshare')):
|
||||
msg=htmlNewPost(self.server.translate, \
|
||||
self.server.baseDir, \
|
||||
|
@ -3564,6 +3566,35 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
return 1
|
||||
else:
|
||||
return -1
|
||||
elif postType=='newquestion':
|
||||
if not fields.get('duration'):
|
||||
return -1
|
||||
if not fields.get('message'):
|
||||
return -1
|
||||
questionStr=fields['message']
|
||||
qOptions=[]
|
||||
for questionCtr in range(6):
|
||||
if fields.get('questionOption'+str(questionCtr)):
|
||||
qOptions.append(fields['questionOption'+str(questionCtr)])
|
||||
if not qOptions:
|
||||
return -1
|
||||
messageJson= \
|
||||
createQuestionPost(self.server.baseDir, \
|
||||
nickname, \
|
||||
self.server.domain,self.server.port, \
|
||||
self.server.httpPrefix, \
|
||||
fields['message'],qOptions, \
|
||||
False,False,False, \
|
||||
filename,attachmentMediaType, \
|
||||
fields['imageDescription'],True, \
|
||||
fields['subject'],int(fields['duration']))
|
||||
if messageJson:
|
||||
self.postToNickname=nickname
|
||||
if self.server.debug:
|
||||
print('DEBUG: new Question')
|
||||
if self._postToOutbox(messageJson,__version__):
|
||||
return 1
|
||||
return -1
|
||||
elif postType=='newshare':
|
||||
if not fields.get('itemType'):
|
||||
return -1
|
||||
|
|
43
posts.py
43
posts.py
|
@ -821,6 +821,49 @@ def createPublicPost(baseDir: str,
|
|||
False,inReplyTo,inReplyToAtomUri,subject, \
|
||||
eventDate,eventTime,location)
|
||||
|
||||
def createQuestionPost(baseDir: str,
|
||||
nickname: str,domain: str,port: int,httpPrefix: str, \
|
||||
content: str,qOptions: [], \
|
||||
followersOnly: bool,saveToFile: bool,
|
||||
clientToServer: bool,\
|
||||
attachImageFilename: str,mediaType: str, \
|
||||
imageDescription: str,useBlurhash: bool, \
|
||||
subject: str,durationDays: int) -> {}:
|
||||
"""Question post with multiple choice options
|
||||
"""
|
||||
domainFull=domain
|
||||
if port:
|
||||
if port!=80 and port!=443:
|
||||
if ':' not in domain:
|
||||
domainFull=domain+':'+str(port)
|
||||
messageJson= \
|
||||
createPostBase(baseDir,nickname,domain,port, \
|
||||
'https://www.w3.org/ns/activitystreams#Public', \
|
||||
httpPrefix+'://'+domainFull+'/users/'+nickname+'/followers', \
|
||||
httpPrefix,content,followersOnly,saveToFile, \
|
||||
clientToServer, \
|
||||
attachImageFilename,mediaType, \
|
||||
imageDescription,useBlurhash, \
|
||||
False,None,None,subject, \
|
||||
None,None,None)
|
||||
messageJson['object']['type']='Question'
|
||||
messageJson['object']['oneof']=[]
|
||||
messageJson['object']['votersCount']=0
|
||||
currTime=datetime.datetime.utcnow()
|
||||
daysSinceEpoch=int((currTime - datetime.datetime(1970,1,1)).days + durationDays)
|
||||
endTime=datetime.datetime(1970,1,1) + datetime.timedelta(daysSinceEpoch)
|
||||
messageJson['object']['endTime']=endTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
for questionOption in qOptions:
|
||||
messageJson['object']['oneof'].append({
|
||||
"type": "Note",
|
||||
"name": questionOption,
|
||||
"replies": {
|
||||
"type": "Collection",
|
||||
"totalItems": 0
|
||||
}
|
||||
})
|
||||
return messageJson
|
||||
|
||||
def createUnlistedPost(baseDir: str,
|
||||
nickname: str,domain: str,port: int,httpPrefix: str, \
|
||||
content: str,followersOnly: bool,saveToFile: bool,
|
||||
|
|
Loading…
Reference in New Issue