mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
d5bc7b989e
22
inbox.py
22
inbox.py
|
@ -913,7 +913,6 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {},
|
|||
except BaseException:
|
||||
print('EX: _receiveUpdateToQuestion unable to delete ' +
|
||||
cachedPostFilename)
|
||||
pass
|
||||
# remove from memory cache
|
||||
removePostFromCache(messageJson, recentPostsCache)
|
||||
|
||||
|
@ -2789,9 +2788,24 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
|||
maxReplies, debug)
|
||||
|
||||
# if this is a reply to a question then update the votes
|
||||
questionJson = questionUpdateVotes(baseDir, nickname, domain,
|
||||
postJsonObject)
|
||||
if questionJson:
|
||||
questionJson, questionPostFilename = \
|
||||
questionUpdateVotes(baseDir, nickname, domain, postJsonObject)
|
||||
if questionJson and questionPostFilename:
|
||||
removePostFromCache(questionJson, recentPostsCache)
|
||||
# add id to inbox index
|
||||
inboxUpdateIndex('inbox', baseDir, handle,
|
||||
questionPostFilename, debug)
|
||||
# ensure that the cached post is removed if it exists, so
|
||||
# that it then will be recreated
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(baseDir, nickname, domain, questionJson)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
os.remove(cachedPostFilename)
|
||||
except BaseException:
|
||||
print('EX: replytoQuestion unable to delete ' +
|
||||
cachedPostFilename)
|
||||
# Is this a question created by this instance?
|
||||
idPrefix = httpPrefix + '://' + domain
|
||||
if questionJson['object']['id'].startswith(idPrefix):
|
||||
|
|
38
question.py
38
question.py
|
@ -15,42 +15,42 @@ from utils import hasObjectDict
|
|||
|
||||
|
||||
def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
||||
replyJson: {}) -> {}:
|
||||
replyJson: {}) -> ({}, str):
|
||||
""" For a given reply update the votes on a question
|
||||
Returns the question json object if the vote totals were changed
|
||||
"""
|
||||
if not hasObjectDict(replyJson):
|
||||
return None
|
||||
return None, None
|
||||
if not replyJson['object'].get('inReplyTo'):
|
||||
return None
|
||||
return None, None
|
||||
if not replyJson['object']['inReplyTo']:
|
||||
return None
|
||||
return None, None
|
||||
if not isinstance(replyJson['object']['inReplyTo'], str):
|
||||
return None
|
||||
return None, None
|
||||
if not replyJson['object'].get('name'):
|
||||
return None
|
||||
return None, None
|
||||
inReplyTo = replyJson['object']['inReplyTo']
|
||||
questionPostFilename = locatePost(baseDir, nickname, domain, inReplyTo)
|
||||
if not questionPostFilename:
|
||||
return None
|
||||
return None, None
|
||||
questionJson = loadJson(questionPostFilename)
|
||||
if not questionJson:
|
||||
return None
|
||||
return None, None
|
||||
if not hasObjectDict(questionJson):
|
||||
return None
|
||||
return None, None
|
||||
if not questionJson['object'].get('type'):
|
||||
return None
|
||||
return None, None
|
||||
if questionJson['type'] != 'Question':
|
||||
return None
|
||||
return None, None
|
||||
if not questionJson['object'].get('oneOf'):
|
||||
return None
|
||||
return None, None
|
||||
if not isinstance(questionJson['object']['oneOf'], list):
|
||||
return None
|
||||
return None, None
|
||||
if not questionJson['object'].get('content'):
|
||||
return None
|
||||
return None, None
|
||||
replyVote = replyJson['object']['name']
|
||||
# does the reply name field match any possible question option?
|
||||
foundAnswer = None
|
||||
foundAnswer = None, None
|
||||
for possibleAnswer in questionJson['object']['oneOf']:
|
||||
if not possibleAnswer.get('name'):
|
||||
continue
|
||||
|
@ -58,7 +58,7 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
|||
foundAnswer = possibleAnswer
|
||||
break
|
||||
if not foundAnswer:
|
||||
return None
|
||||
return None, None
|
||||
# update the voters file
|
||||
votersFileSeparator = ';;;'
|
||||
votersFilename = questionPostFilename.replace('.json', '.voters')
|
||||
|
@ -97,7 +97,7 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
|||
for voteLine in newlines:
|
||||
votersFile.write(voteLine)
|
||||
else:
|
||||
return None
|
||||
return None, None
|
||||
# update the vote counts
|
||||
questionTotalsChanged = False
|
||||
for possibleAnswer in questionJson['object']['oneOf']:
|
||||
|
@ -114,10 +114,10 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str,
|
|||
possibleAnswer['replies']['totalItems'] = totalItems
|
||||
questionTotalsChanged = True
|
||||
if not questionTotalsChanged:
|
||||
return None
|
||||
return None, None
|
||||
# save the question with altered totals
|
||||
saveJson(questionJson, questionPostFilename)
|
||||
return questionJson
|
||||
return questionJson, questionPostFilename
|
||||
|
||||
|
||||
def isQuestion(postObjectJson: {}) -> bool:
|
||||
|
|
Loading…
Reference in New Issue