Simplify wait screen

main
Bob Mottram 2020-09-28 17:33:39 +01:00
parent bb391c8f98
commit 6111170dfe
1 changed files with 7 additions and 204 deletions

211
daemon.py
View File

@ -9133,62 +9133,6 @@ class PubServer(BaseHTTPRequestHandler):
self._set_headers_head(mediaFileType, fileLength, self._set_headers_head(mediaFileType, fileLength,
etag, callingDomain) etag, callingDomain)
def _showSendingScreen(self, authorized: bool, callingDomain: str) -> None:
"""Shows a 'sending post' wait screen
"""
if self.server.defaultTimeline != 'inbox':
return
if not self._requestHTTP():
return
# make a copy of the headers
currHeaders = self.headers.items()
# show a sending post screen
msg = \
htmlSendingPost(self.server.baseDir,
self.server.translate).encode('utf-8')
self._login_headers('text/html', len(msg), callingDomain)
self._write(msg)
self.wfile.flush()
# restore headers
for headerField in currHeaders:
fieldName = headerField[0]
fieldValue = headerField[1]
self.headers[fieldName] = fieldValue
def _clearSendingScreen(self, authorized: bool,
boxName: str, path: str,
callingDomain: str, cookie: str) -> None:
"""Redirects to the given box
"""
if boxName != 'inbox':
return
if not self._requestHTTP():
return
self._showInbox(authorized,
callingDomain, self.path,
self.server.baseDir,
self.server.httpPrefix,
self.server.domain,
self.server.domainFull,
self.server.port,
self.server.onionDomain,
self.server.i2pDomain,
None, None,
self.server.proxyType,
cookie, self.server.debug,
self.server.recentPostsCache,
self.server.session,
self.server.defaultTimeline,
self.server.maxRecentPosts,
self.server.translate,
self.server.cachedWebfingers,
self.server.personCache,
self.server.allowDeletion,
self.server.projectVersion,
self.server.YTReplacementDomain)
def _receiveNewPostProcess(self, postType: str, path: str, headers: {}, def _receiveNewPostProcess(self, postType: str, path: str, headers: {},
length: int, postBytes, boundary: str, length: int, postBytes, boundary: str,
callingDomain: str, cookie: str, callingDomain: str, cookie: str,
@ -9334,12 +9278,6 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
privateEvent = True privateEvent = True
# self._showSendingScreen(authorized, callingDomain)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
if postType == 'newpost': if postType == 'newpost':
messageJson = \ messageJson = \
createPublicPost(self.server.baseDir, createPublicPost(self.server.baseDir,
@ -9358,10 +9296,6 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
@ -9371,16 +9305,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, messageJson,
self.server.maxReplies, self.server.maxReplies,
self.server.debug) self.server.debug)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newblog': elif postType == 'newblog':
messageJson = \ messageJson = \
@ -9398,10 +9324,6 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
populateReplies(self.server.baseDir, populateReplies(self.server.baseDir,
@ -9410,16 +9332,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, messageJson,
self.server.maxReplies, self.server.maxReplies,
self.server.debug) self.server.debug)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'editblogpost': elif postType == 'editblogpost':
print('Edited blog post received') print('Edited blog post received')
@ -9488,10 +9402,6 @@ class PubServer(BaseHTTPRequestHandler):
self.server.YTReplacementDomain) self.server.YTReplacementDomain)
saveJson(postJsonObject, postFilename) saveJson(postJsonObject, postFilename)
print('Edited blog post, resaved ' + postFilename) print('Edited blog post, resaved ' + postFilename)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
print('Edited blog post, unable to load json for ' + print('Edited blog post, unable to load json for ' +
@ -9499,9 +9409,6 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
print('Edited blog post not found ' + print('Edited blog post not found ' +
str(fields['postUrl'])) str(fields['postUrl']))
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
elif postType == 'newunlisted': elif postType == 'newunlisted':
messageJson = \ messageJson = \
@ -9523,10 +9430,6 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
populateReplies(self.server.baseDir, populateReplies(self.server.baseDir,
@ -9535,16 +9438,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, messageJson,
self.server.maxReplies, self.server.maxReplies,
self.server.debug) self.server.debug)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newfollowers': elif postType == 'newfollowers':
messageJson = \ messageJson = \
@ -9568,10 +9463,6 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
populateReplies(self.server.baseDir, populateReplies(self.server.baseDir,
@ -9580,16 +9471,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, messageJson,
self.server.maxReplies, self.server.maxReplies,
self.server.debug) self.server.debug)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newevent': elif postType == 'newevent':
# A Mobilizon-type event is posted # A Mobilizon-type event is posted
@ -9640,22 +9523,10 @@ class PubServer(BaseHTTPRequestHandler):
fields['ticketUrl']) fields['ticketUrl'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newdm': elif postType == 'newdm':
messageJson = None messageJson = None
@ -9683,10 +9554,6 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
print('Sending new DM to ' + print('Sending new DM to ' +
str(messageJson['object']['to'])) str(messageJson['object']['to']))
@ -9697,16 +9564,8 @@ class PubServer(BaseHTTPRequestHandler):
messageJson, messageJson,
self.server.maxReplies, self.server.maxReplies,
self.server.debug) self.server.debug)
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newreminder': elif postType == 'newreminder':
messageJson = None messageJson = None
@ -9733,32 +9592,16 @@ class PubServer(BaseHTTPRequestHandler):
fields['location']) fields['location'])
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
print('DEBUG: new reminder to ' + print('DEBUG: new reminder to ' +
str(messageJson['object']['to'])) str(messageJson['object']['to']))
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newreport': elif postType == 'newreport':
if attachmentMediaType: if attachmentMediaType:
if attachmentMediaType != 'image': if attachmentMediaType != 'image':
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
# So as to be sure that this only goes to moderators # So as to be sure that this only goes to moderators
# and not accounts being reported we disable any # and not accounts being reported we disable any
@ -9777,28 +9620,13 @@ class PubServer(BaseHTTPRequestHandler):
self.server.debug, fields['subject']) self.server.debug, fields['subject'])
if messageJson: if messageJson:
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
else: else:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
elif postType == 'newquestion': elif postType == 'newquestion':
if not fields.get('duration'): if not fields.get('duration'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
if not fields.get('message'): if not fields.get('message'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
# questionStr = fields['message'] # questionStr = fields['message']
qOptions = [] qOptions = []
@ -9807,9 +9635,6 @@ class PubServer(BaseHTTPRequestHandler):
qOptions.append(fields['questionOption' + qOptions.append(fields['questionOption' +
str(questionCtr)]) str(questionCtr)])
if not qOptions: if not qOptions:
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
messageJson = \ messageJson = \
createQuestionPost(self.server.baseDir, createQuestionPost(self.server.baseDir,
@ -9829,42 +9654,19 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug: if self.server.debug:
print('DEBUG: new Question') print('DEBUG: new Question')
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return 1 return 1
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
elif postType == 'newshare': elif postType == 'newshare':
if not fields.get('itemType'): if not fields.get('itemType'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
if not fields.get('category'): if not fields.get('category'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
if not fields.get('location'): if not fields.get('location'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
if not fields.get('duration'): if not fields.get('duration'):
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
if attachmentMediaType: if attachmentMediaType:
if attachmentMediaType != 'image': if attachmentMediaType != 'image':
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain,
cookie)
return -1 return -1
durationStr = fields['duration'] durationStr = fields['duration']
if durationStr: if durationStr:
@ -9886,13 +9688,7 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(filename): if os.path.isfile(filename):
os.remove(filename) os.remove(filename)
self.postToNickname = nickname self.postToNickname = nickname
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return 1 return 1
self._clearSendingScreen(authorized,
self.server.defaultTimeline,
self.path, callingDomain, cookie)
return -1 return -1
def _receiveNewPost(self, postType: str, path: str, def _receiveNewPost(self, postType: str, path: str,
@ -9915,6 +9711,13 @@ class PubServer(BaseHTTPRequestHandler):
print('New post begins: ' + postType + ' ' + path) print('New post begins: ' + postType + ' ' + path)
msg = \
htmlSendingPost(self.server.baseDir,
self.server.translate).encode('utf-8')
self._login_headers('text/html', len(msg), callingDomain)
self._write(msg)
self.wfile.flush()
if '?page=' in path: if '?page=' in path:
pageNumberStr = path.split('?page=')[1] pageNumberStr = path.split('?page=')[1]
if '?' in pageNumberStr: if '?' in pageNumberStr: