mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
9e6b069ab4
commit
4479027aef
16
announce.py
16
announce.py
|
@ -33,22 +33,22 @@ from webfinger import webfingerHandle
|
|||
from auth import createBasicAuthHeader
|
||||
|
||||
|
||||
def isSelfAnnounce(postJsonObject: {}) -> bool:
|
||||
def isSelfAnnounce(post_json_object: {}) -> bool:
|
||||
"""Is the given post a self announce?
|
||||
"""
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return False
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return False
|
||||
if postJsonObject['type'] != 'Announce':
|
||||
if post_json_object['type'] != 'Announce':
|
||||
return False
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['actor'], str):
|
||||
if not isinstance(post_json_object['actor'], str):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object'], str):
|
||||
if not isinstance(post_json_object['object'], str):
|
||||
return False
|
||||
return postJsonObject['actor'] in postJsonObject['object']
|
||||
return post_json_object['actor'] in post_json_object['object']
|
||||
|
||||
|
||||
def outboxAnnounce(recentPostsCache: {},
|
||||
|
|
60
blocking.py
60
blocking.py
|
@ -529,19 +529,19 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
if not postFilename:
|
||||
print('mutePost: file not found ' + postId)
|
||||
return
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
print('mutePost: object not loaded ' + postId)
|
||||
return
|
||||
print('mutePost: ' + str(postJsonObject))
|
||||
print('mutePost: ' + str(post_json_object))
|
||||
|
||||
postJsonObj = postJsonObject
|
||||
postJsonObj = post_json_object
|
||||
alsoUpdatePostId = None
|
||||
if hasObjectDict(postJsonObject):
|
||||
postJsonObj = postJsonObject['object']
|
||||
if hasObjectDict(post_json_object):
|
||||
postJsonObj = post_json_object['object']
|
||||
else:
|
||||
if hasObjectString(postJsonObject, debug):
|
||||
alsoUpdatePostId = removeIdEnding(postJsonObject['object'])
|
||||
if hasObjectString(post_json_object, debug):
|
||||
alsoUpdatePostId = removeIdEnding(post_json_object['object'])
|
||||
|
||||
domainFull = getFullDomain(domain, port)
|
||||
actor = localActorUrl(http_prefix, nickname, domainFull)
|
||||
|
@ -581,13 +581,13 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
itemsList.append(newIgnore)
|
||||
postJsonObj['ignores']['totalItems'] = igIt
|
||||
postJsonObj['muted'] = True
|
||||
if saveJson(postJsonObject, postFilename):
|
||||
if saveJson(post_json_object, postFilename):
|
||||
print('mutePost: saved ' + postFilename)
|
||||
|
||||
# remove cached post so that the muted version gets recreated
|
||||
# without its content text and/or image
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, postJsonObject)
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -611,11 +611,11 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
# if the post is in the recent posts cache then mark it as muted
|
||||
if recentPostsCache.get('index'):
|
||||
postId = \
|
||||
removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||
removeIdEnding(post_json_object['id']).replace('/', '#')
|
||||
if postId in recentPostsCache['index']:
|
||||
print('MUTE: ' + postId + ' is in recent posts cache')
|
||||
if recentPostsCache.get('json'):
|
||||
recentPostsCache['json'][postId] = json.dumps(postJsonObject)
|
||||
recentPostsCache['json'][postId] = json.dumps(post_json_object)
|
||||
print('MUTE: ' + postId +
|
||||
' marked as muted in recent posts memory cache')
|
||||
if recentPostsCache.get('html'):
|
||||
|
@ -660,8 +660,8 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
postFilename = locatePost(base_dir, nickname, domain, postId)
|
||||
if not postFilename:
|
||||
return
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
muteFilename = postFilename + '.muted'
|
||||
|
@ -674,13 +674,13 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
str(muteFilename))
|
||||
print('UNMUTE: ' + muteFilename + ' file removed')
|
||||
|
||||
postJsonObj = postJsonObject
|
||||
postJsonObj = post_json_object
|
||||
alsoUpdatePostId = None
|
||||
if hasObjectDict(postJsonObject):
|
||||
postJsonObj = postJsonObject['object']
|
||||
if hasObjectDict(post_json_object):
|
||||
postJsonObj = post_json_object['object']
|
||||
else:
|
||||
if hasObjectString(postJsonObject, debug):
|
||||
alsoUpdatePostId = removeIdEnding(postJsonObject['object'])
|
||||
if hasObjectString(post_json_object, debug):
|
||||
alsoUpdatePostId = removeIdEnding(post_json_object['object'])
|
||||
|
||||
if postJsonObj.get('conversation'):
|
||||
unmuteConversation(base_dir, nickname, domain,
|
||||
|
@ -708,12 +708,12 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
igItLen = len(postJsonObj['ignores']['items'])
|
||||
postJsonObj['ignores']['totalItems'] = igItLen
|
||||
postJsonObj['muted'] = False
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
# remove cached post so that the muted version gets recreated
|
||||
# with its content text and/or image
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, postJsonObject)
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -726,11 +726,11 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
|
|||
# if the post is in the recent posts cache then mark it as unmuted
|
||||
if recentPostsCache.get('index'):
|
||||
postId = \
|
||||
removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||
removeIdEnding(post_json_object['id']).replace('/', '#')
|
||||
if postId in recentPostsCache['index']:
|
||||
print('UNMUTE: ' + postId + ' is in recent posts cache')
|
||||
if recentPostsCache.get('json'):
|
||||
recentPostsCache['json'][postId] = json.dumps(postJsonObject)
|
||||
recentPostsCache['json'][postId] = json.dumps(post_json_object)
|
||||
print('UNMUTE: ' + postId +
|
||||
' marked as unmuted in recent posts cache')
|
||||
if recentPostsCache.get('html'):
|
||||
|
@ -1006,20 +1006,20 @@ def loadCWLists(base_dir: str, verbose: bool) -> {}:
|
|||
return result
|
||||
|
||||
|
||||
def addCWfromLists(postJsonObject: {}, CWlists: {}, translate: {},
|
||||
def addCWfromLists(post_json_object: {}, CWlists: {}, translate: {},
|
||||
lists_enabled: str) -> None:
|
||||
"""Adds content warnings by matching the post content
|
||||
against domains or keywords
|
||||
"""
|
||||
if not lists_enabled:
|
||||
return
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return
|
||||
cw = ''
|
||||
if postJsonObject['object'].get('summary'):
|
||||
cw = postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('summary'):
|
||||
cw = post_json_object['object']['summary']
|
||||
|
||||
content = postJsonObject['object']['content']
|
||||
content = post_json_object['object']['content']
|
||||
for name, item in CWlists.items():
|
||||
if name not in lists_enabled:
|
||||
continue
|
||||
|
@ -1061,8 +1061,8 @@ def addCWfromLists(postJsonObject: {}, CWlists: {}, translate: {},
|
|||
cw = warning
|
||||
break
|
||||
if cw:
|
||||
postJsonObject['object']['summary'] = cw
|
||||
postJsonObject['object']['sensitive'] = True
|
||||
post_json_object['object']['summary'] = cw
|
||||
post_json_object['object']['sensitive'] = True
|
||||
|
||||
|
||||
def getCWlistVariable(listName: str) -> str:
|
||||
|
|
109
blog.py
109
blog.py
|
@ -188,7 +188,7 @@ def _getBlogReplies(base_dir: str, http_prefix: str, translate: {},
|
|||
def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
||||
base_dir: str, http_prefix: str, translate: {},
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
handle: str, restrictToDomain: bool,
|
||||
peertubeInstances: [],
|
||||
systemLanguage: str,
|
||||
|
@ -200,21 +200,22 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
actor = ''
|
||||
blogStr = ''
|
||||
messageLink = ''
|
||||
if postJsonObject['object'].get('id'):
|
||||
messageLink = postJsonObject['object']['id'].replace('/statuses/', '/')
|
||||
if post_json_object['object'].get('id'):
|
||||
messageLink = \
|
||||
post_json_object['object']['id'].replace('/statuses/', '/')
|
||||
titleStr = ''
|
||||
articleAdded = False
|
||||
if postJsonObject['object'].get('summary'):
|
||||
titleStr = postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('summary'):
|
||||
titleStr = post_json_object['object']['summary']
|
||||
blogStr += '<article><h1><a href="' + messageLink + '">' + \
|
||||
titleStr + '</a></h1>\n'
|
||||
articleAdded = True
|
||||
|
||||
# get the handle of the author
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
if post_json_object['object'].get('attributedTo'):
|
||||
authorNickname = None
|
||||
if isinstance(postJsonObject['object']['attributedTo'], str):
|
||||
actor = postJsonObject['object']['attributedTo']
|
||||
if isinstance(post_json_object['object']['attributedTo'], str):
|
||||
actor = post_json_object['object']['attributedTo']
|
||||
authorNickname = getNicknameFromActor(actor)
|
||||
if authorNickname:
|
||||
authorDomain, authorPort = getDomainFromActor(actor)
|
||||
|
@ -228,10 +229,10 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
if restrictToDomain:
|
||||
return ''
|
||||
|
||||
if postJsonObject['object'].get('published'):
|
||||
if 'T' in postJsonObject['object']['published']:
|
||||
if post_json_object['object'].get('published'):
|
||||
if 'T' in post_json_object['object']['published']:
|
||||
blogStr += '<h3>' + \
|
||||
postJsonObject['object']['published'].split('T')[0]
|
||||
post_json_object['object']['published'].split('T')[0]
|
||||
if handle:
|
||||
if handle.startswith(nickname + '@' + domain):
|
||||
blogStr += ' <a href="' + http_prefix + '://' + \
|
||||
|
@ -255,7 +256,7 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
deleteStr = ''
|
||||
muteStr = ''
|
||||
isMuted = False
|
||||
attachmentStr, galleryStr = getPostAttachmentsAsHtml(postJsonObject,
|
||||
attachmentStr, galleryStr = getPostAttachmentsAsHtml(post_json_object,
|
||||
'tlblogs', translate,
|
||||
isMuted, avatarLink,
|
||||
replyStr, announceStr,
|
||||
|
@ -270,14 +271,15 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
languagesUnderstood = []
|
||||
if actorJson:
|
||||
languagesUnderstood = getActorLanguagesList(actorJson)
|
||||
jsonContent = getContentFromPost(postJsonObject, systemLanguage,
|
||||
jsonContent = getContentFromPost(post_json_object, systemLanguage,
|
||||
languagesUnderstood)
|
||||
if jsonContent:
|
||||
contentStr = addEmbeddedElements(translate, jsonContent,
|
||||
peertubeInstances)
|
||||
if postJsonObject['object'].get('tag'):
|
||||
if post_json_object['object'].get('tag'):
|
||||
post_json_object_tags = post_json_object['object']['tag']
|
||||
contentStr = replaceEmojiFromTags(session, base_dir, contentStr,
|
||||
postJsonObject['object']['tag'],
|
||||
post_json_object_tags,
|
||||
'content', debug)
|
||||
if articleAdded:
|
||||
blogStr += '<br>' + contentStr + '</article>\n'
|
||||
|
@ -285,8 +287,8 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
blogStr += '<br><article>' + contentStr + '</article>\n'
|
||||
|
||||
citationsStr = ''
|
||||
if postJsonObject['object'].get('tag'):
|
||||
for tagJson in postJsonObject['object']['tag']:
|
||||
if post_json_object['object'].get('tag'):
|
||||
for tagJson in post_json_object['object']['tag']:
|
||||
if not isinstance(tagJson, dict):
|
||||
continue
|
||||
if not tagJson.get('type'):
|
||||
|
@ -315,7 +317,7 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
|
||||
replies = _noOfBlogReplies(base_dir, http_prefix, translate,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject['object']['id'])
|
||||
post_json_object['object']['id'])
|
||||
|
||||
# separator between blogs should be centered
|
||||
if '<center>' not in blogSeparator:
|
||||
|
@ -334,11 +336,11 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
if not titleStr:
|
||||
blogStr += _getBlogReplies(base_dir, http_prefix, translate,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject['object']['id'])
|
||||
post_json_object['object']['id'])
|
||||
else:
|
||||
blogRepliesStr = _getBlogReplies(base_dir, http_prefix, translate,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject['object']['id'])
|
||||
post_json_object['object']['id'])
|
||||
blogStr += blogRepliesStr.replace('>' + titleStr + '<', '')
|
||||
|
||||
return blogStr
|
||||
|
@ -347,25 +349,26 @@ def _htmlBlogPostContent(debug: bool, session, authorized: bool,
|
|||
def _htmlBlogPostRSS2(authorized: bool,
|
||||
base_dir: str, http_prefix: str, translate: {},
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
handle: str, restrictToDomain: bool,
|
||||
systemLanguage: str) -> str:
|
||||
"""Returns the RSS version 2 feed for a single blog post
|
||||
"""
|
||||
rssStr = ''
|
||||
messageLink = ''
|
||||
if postJsonObject['object'].get('id'):
|
||||
messageLink = postJsonObject['object']['id'].replace('/statuses/', '/')
|
||||
if post_json_object['object'].get('id'):
|
||||
messageLink = \
|
||||
post_json_object['object']['id'].replace('/statuses/', '/')
|
||||
if not restrictToDomain or \
|
||||
(restrictToDomain and '/' + domain in messageLink):
|
||||
if postJsonObject['object'].get('summary') and \
|
||||
postJsonObject['object'].get('published'):
|
||||
published = postJsonObject['object']['published']
|
||||
if post_json_object['object'].get('summary') and \
|
||||
post_json_object['object'].get('published'):
|
||||
published = post_json_object['object']['published']
|
||||
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
||||
titleStr = postJsonObject['object']['summary']
|
||||
titleStr = post_json_object['object']['summary']
|
||||
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
|
||||
content = \
|
||||
getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
description = firstParagraphFromString(content)
|
||||
rssStr = ' <item>'
|
||||
rssStr += ' <title>' + titleStr + '</title>'
|
||||
|
@ -380,25 +383,26 @@ def _htmlBlogPostRSS2(authorized: bool,
|
|||
def _htmlBlogPostRSS3(authorized: bool,
|
||||
base_dir: str, http_prefix: str, translate: {},
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
handle: str, restrictToDomain: bool,
|
||||
systemLanguage: str) -> str:
|
||||
"""Returns the RSS version 3 feed for a single blog post
|
||||
"""
|
||||
rssStr = ''
|
||||
messageLink = ''
|
||||
if postJsonObject['object'].get('id'):
|
||||
messageLink = postJsonObject['object']['id'].replace('/statuses/', '/')
|
||||
if post_json_object['object'].get('id'):
|
||||
messageLink = \
|
||||
post_json_object['object']['id'].replace('/statuses/', '/')
|
||||
if not restrictToDomain or \
|
||||
(restrictToDomain and '/' + domain in messageLink):
|
||||
if postJsonObject['object'].get('summary') and \
|
||||
postJsonObject['object'].get('published'):
|
||||
published = postJsonObject['object']['published']
|
||||
if post_json_object['object'].get('summary') and \
|
||||
post_json_object['object'].get('published'):
|
||||
published = post_json_object['object']['published']
|
||||
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
||||
titleStr = postJsonObject['object']['summary']
|
||||
titleStr = post_json_object['object']['summary']
|
||||
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
|
||||
content = \
|
||||
getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
description = firstParagraphFromString(content)
|
||||
rssStr = 'title: ' + titleStr + '\n'
|
||||
rssStr += 'link: ' + messageLink + '\n'
|
||||
|
@ -419,10 +423,11 @@ def _htmlBlogRemoveCwButton(blogStr: str, translate: {}) -> str:
|
|||
return blogStr
|
||||
|
||||
|
||||
def _getSnippetFromBlogContent(postJsonObject: {}, systemLanguage: str) -> str:
|
||||
def _getSnippetFromBlogContent(post_json_object: {},
|
||||
systemLanguage: str) -> str:
|
||||
"""Returns a snippet of text from the blog post as a preview
|
||||
"""
|
||||
content = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
content = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if '<p>' in content:
|
||||
content = content.split('<p>', 1)[1]
|
||||
if '</p>' in content:
|
||||
|
@ -438,7 +443,7 @@ def _getSnippetFromBlogContent(postJsonObject: {}, systemLanguage: str) -> str:
|
|||
def htmlBlogPost(session, authorized: bool,
|
||||
base_dir: str, http_prefix: str, translate: {},
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
peertubeInstances: [],
|
||||
systemLanguage: str, personCache: {},
|
||||
debug: bool, content_license_url: str) -> str:
|
||||
|
@ -451,15 +456,15 @@ def htmlBlogPost(session, authorized: bool,
|
|||
cssFilename = base_dir + '/blog.css'
|
||||
instanceTitle = \
|
||||
getConfigParam(base_dir, 'instanceTitle')
|
||||
published = postJsonObject['object']['published']
|
||||
published = post_json_object['object']['published']
|
||||
modified = published
|
||||
if postJsonObject['object'].get('updated'):
|
||||
modified = postJsonObject['object']['updated']
|
||||
title = postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('updated'):
|
||||
modified = post_json_object['object']['updated']
|
||||
title = post_json_object['object']['summary']
|
||||
url = ''
|
||||
if postJsonObject['object'].get('url'):
|
||||
url = postJsonObject['object']['url']
|
||||
snippet = _getSnippetFromBlogContent(postJsonObject, systemLanguage)
|
||||
if post_json_object['object'].get('url'):
|
||||
url = post_json_object['object']['url']
|
||||
snippet = _getSnippetFromBlogContent(post_json_object, systemLanguage)
|
||||
blogStr = htmlHeaderWithBlogMarkup(cssFilename, instanceTitle,
|
||||
http_prefix, domainFull, nickname,
|
||||
systemLanguage, published, modified,
|
||||
|
@ -470,7 +475,7 @@ def htmlBlogPost(session, authorized: bool,
|
|||
blogStr += _htmlBlogPostContent(debug, session, authorized, base_dir,
|
||||
http_prefix, translate,
|
||||
nickname, domain,
|
||||
domainFull, postJsonObject,
|
||||
domainFull, post_json_object,
|
||||
None, False,
|
||||
peertubeInstances, systemLanguage,
|
||||
personCache)
|
||||
|
@ -778,8 +783,8 @@ def htmlEditBlog(media_instance: bool, translate: {},
|
|||
print('Edit blog: Filename not found for ' + postUrl)
|
||||
return None
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
print('Edit blog: json not loaded for ' + postFilename)
|
||||
return None
|
||||
|
||||
|
@ -883,15 +888,15 @@ def htmlEditBlog(media_instance: bool, translate: {},
|
|||
editBlogForm += \
|
||||
' <label class="labels">' + placeholderSubject + '</label><br>'
|
||||
titleStr = ''
|
||||
if postJsonObject['object'].get('summary'):
|
||||
titleStr = postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('summary'):
|
||||
titleStr = post_json_object['object']['summary']
|
||||
editBlogForm += \
|
||||
' <input type="text" name="subject" value="' + titleStr + '">'
|
||||
editBlogForm += ''
|
||||
editBlogForm += ' <br>'
|
||||
messageBoxHeight = 800
|
||||
|
||||
contentStr = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
contentStr = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
contentStr = contentStr.replace('<p>', '').replace('</p>', '\n')
|
||||
|
||||
editBlogForm += \
|
||||
|
|
94
bookmarks.py
94
bookmarks.py
|
@ -38,15 +38,15 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
|||
actor: str, domain: str, debug: bool) -> None:
|
||||
"""Undoes a bookmark for a particular actor
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
# remove any cached version of this post so that the
|
||||
# bookmark icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -56,7 +56,7 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
|||
print('EX: undoBookmarksCollectionEntry ' +
|
||||
'unable to delete cached post file ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
# remove from the index
|
||||
bookmarksIndexFilename = \
|
||||
|
@ -83,32 +83,32 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
|||
except OSError:
|
||||
print('EX: unable to write bookmarks index ' +
|
||||
bookmarksIndexFilename)
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
if debug:
|
||||
print('DEBUG: bookmarked post has no object ' +
|
||||
str(postJsonObject))
|
||||
str(post_json_object))
|
||||
return
|
||||
if not postJsonObject['object'].get('bookmarks'):
|
||||
if not post_json_object['object'].get('bookmarks'):
|
||||
return
|
||||
if not isinstance(postJsonObject['object']['bookmarks'], dict):
|
||||
if not isinstance(post_json_object['object']['bookmarks'], dict):
|
||||
return
|
||||
if not postJsonObject['object']['bookmarks'].get('items'):
|
||||
if not post_json_object['object']['bookmarks'].get('items'):
|
||||
return
|
||||
totalItems = 0
|
||||
if postJsonObject['object']['bookmarks'].get('totalItems'):
|
||||
totalItems = postJsonObject['object']['bookmarks']['totalItems']
|
||||
if post_json_object['object']['bookmarks'].get('totalItems'):
|
||||
totalItems = post_json_object['object']['bookmarks']['totalItems']
|
||||
itemFound = False
|
||||
for bookmarkItem in postJsonObject['object']['bookmarks']['items']:
|
||||
for bookmarkItem in post_json_object['object']['bookmarks']['items']:
|
||||
if bookmarkItem.get('actor'):
|
||||
if bookmarkItem['actor'] == actor:
|
||||
if debug:
|
||||
print('DEBUG: bookmark was removed for ' + actor)
|
||||
bmIt = bookmarkItem
|
||||
postJsonObject['object']['bookmarks']['items'].remove(bmIt)
|
||||
post_json_object['object']['bookmarks']['items'].remove(bmIt)
|
||||
itemFound = True
|
||||
break
|
||||
|
||||
|
@ -118,38 +118,39 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
|
|||
if totalItems == 1:
|
||||
if debug:
|
||||
print('DEBUG: bookmarks was removed from post')
|
||||
del postJsonObject['object']['bookmarks']
|
||||
del post_json_object['object']['bookmarks']
|
||||
else:
|
||||
bmItLen = len(postJsonObject['object']['bookmarks']['items'])
|
||||
postJsonObject['object']['bookmarks']['totalItems'] = bmItLen
|
||||
saveJson(postJsonObject, postFilename)
|
||||
bmItLen = len(post_json_object['object']['bookmarks']['items'])
|
||||
post_json_object['object']['bookmarks']['totalItems'] = bmItLen
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def bookmarkedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
|
||||
def bookmarkedByPerson(post_json_object: {},
|
||||
nickname: str, domain: str) -> bool:
|
||||
"""Returns True if the given post is bookmarked by the given person
|
||||
"""
|
||||
if _noOfBookmarks(postJsonObject) == 0:
|
||||
if _noOfBookmarks(post_json_object) == 0:
|
||||
return False
|
||||
actorMatch = domain + '/users/' + nickname
|
||||
for item in postJsonObject['object']['bookmarks']['items']:
|
||||
for item in post_json_object['object']['bookmarks']['items']:
|
||||
if item['actor'].endswith(actorMatch):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _noOfBookmarks(postJsonObject: {}) -> int:
|
||||
def _noOfBookmarks(post_json_object: {}) -> int:
|
||||
"""Returns the number of bookmarks ona given post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return 0
|
||||
if not postJsonObject['object'].get('bookmarks'):
|
||||
if not post_json_object['object'].get('bookmarks'):
|
||||
return 0
|
||||
if not isinstance(postJsonObject['object']['bookmarks'], dict):
|
||||
if not isinstance(post_json_object['object']['bookmarks'], dict):
|
||||
return 0
|
||||
if not postJsonObject['object']['bookmarks'].get('items'):
|
||||
postJsonObject['object']['bookmarks']['items'] = []
|
||||
postJsonObject['object']['bookmarks']['totalItems'] = 0
|
||||
return len(postJsonObject['object']['bookmarks']['items'])
|
||||
if not post_json_object['object']['bookmarks'].get('items'):
|
||||
post_json_object['object']['bookmarks']['items'] = []
|
||||
post_json_object['object']['bookmarks']['totalItems'] = 0
|
||||
return len(post_json_object['object']['bookmarks']['items'])
|
||||
|
||||
|
||||
def updateBookmarksCollection(recentPostsCache: {},
|
||||
|
@ -158,13 +159,13 @@ def updateBookmarksCollection(recentPostsCache: {},
|
|||
actor: str, domain: str, debug: bool) -> None:
|
||||
"""Updates the bookmarks collection within a post
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
# remove any cached version of this post so that the
|
||||
# bookmark icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -174,17 +175,17 @@ def updateBookmarksCollection(recentPostsCache: {},
|
|||
print('EX: updateBookmarksCollection ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
if debug:
|
||||
print('DEBUG: no object in bookmarked post ' +
|
||||
str(postJsonObject))
|
||||
str(post_json_object))
|
||||
return
|
||||
if not objectUrl.endswith('/bookmarks'):
|
||||
objectUrl = objectUrl + '/bookmarks'
|
||||
# does this post have bookmarks on it from differenent actors?
|
||||
if not postJsonObject['object'].get('bookmarks'):
|
||||
if not post_json_object['object'].get('bookmarks'):
|
||||
if debug:
|
||||
print('DEBUG: Adding initial bookmarks to ' + objectUrl)
|
||||
bookmarksJson = {
|
||||
|
@ -197,11 +198,12 @@ def updateBookmarksCollection(recentPostsCache: {},
|
|||
'actor': actor
|
||||
}]
|
||||
}
|
||||
postJsonObject['object']['bookmarks'] = bookmarksJson
|
||||
post_json_object['object']['bookmarks'] = bookmarksJson
|
||||
else:
|
||||
if not postJsonObject['object']['bookmarks'].get('items'):
|
||||
postJsonObject['object']['bookmarks']['items'] = []
|
||||
for bookmarkItem in postJsonObject['object']['bookmarks']['items']:
|
||||
if not post_json_object['object']['bookmarks'].get('items'):
|
||||
post_json_object['object']['bookmarks']['items'] = []
|
||||
bm_items = post_json_object['object']['bookmarks']['items']
|
||||
for bookmarkItem in bm_items:
|
||||
if bookmarkItem.get('actor'):
|
||||
if bookmarkItem['actor'] == actor:
|
||||
return
|
||||
|
@ -210,15 +212,15 @@ def updateBookmarksCollection(recentPostsCache: {},
|
|||
'actor': actor
|
||||
}
|
||||
nb = newBookmark
|
||||
bmIt = len(postJsonObject['object']['bookmarks']['items'])
|
||||
postJsonObject['object']['bookmarks']['items'].append(nb)
|
||||
postJsonObject['object']['bookmarks']['totalItems'] = bmIt
|
||||
bmIt = len(post_json_object['object']['bookmarks']['items'])
|
||||
post_json_object['object']['bookmarks']['items'].append(nb)
|
||||
post_json_object['object']['bookmarks']['totalItems'] = bmIt
|
||||
|
||||
if debug:
|
||||
print('DEBUG: saving post with bookmarks added')
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
# prepend to the index
|
||||
bookmarksIndexFilename = \
|
||||
|
|
12
context.py
12
context.py
|
@ -38,13 +38,13 @@ def getIndividualPostContext() -> []:
|
|||
]
|
||||
|
||||
|
||||
def hasValidContext(postJsonObject: {}) -> bool:
|
||||
def hasValidContext(post_json_object: {}) -> bool:
|
||||
"""Are the links within the @context of a post recognised?
|
||||
"""
|
||||
if not postJsonObject.get('@context'):
|
||||
if not post_json_object.get('@context'):
|
||||
return False
|
||||
if isinstance(postJsonObject['@context'], list):
|
||||
for url in postJsonObject['@context']:
|
||||
if isinstance(post_json_object['@context'], list):
|
||||
for url in post_json_object['@context']:
|
||||
if not isinstance(url, str):
|
||||
continue
|
||||
if url not in validContexts:
|
||||
|
@ -58,8 +58,8 @@ def hasValidContext(postJsonObject: {}) -> bool:
|
|||
if not wildcardFound:
|
||||
print('Unrecognized @context: ' + url)
|
||||
return False
|
||||
elif isinstance(postJsonObject['@context'], str):
|
||||
url = postJsonObject['@context']
|
||||
elif isinstance(post_json_object['@context'], str):
|
||||
url = post_json_object['@context']
|
||||
if url not in validContexts:
|
||||
wildcardFound = False
|
||||
for c in validContexts:
|
||||
|
|
|
@ -14,32 +14,32 @@ from utils import removeIdEnding
|
|||
|
||||
|
||||
def _getConversationFilename(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> str:
|
||||
post_json_object: {}) -> str:
|
||||
"""Returns the conversation filename
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return None
|
||||
if not postJsonObject['object'].get('conversation'):
|
||||
if not post_json_object['object'].get('conversation'):
|
||||
return None
|
||||
if not postJsonObject['object'].get('id'):
|
||||
if not post_json_object['object'].get('id'):
|
||||
return None
|
||||
conversationDir = acctDir(base_dir, nickname, domain) + '/conversation'
|
||||
if not os.path.isdir(conversationDir):
|
||||
os.mkdir(conversationDir)
|
||||
conversationId = postJsonObject['object']['conversation']
|
||||
conversationId = post_json_object['object']['conversation']
|
||||
conversationId = conversationId.replace('/', '#')
|
||||
return conversationDir + '/' + conversationId
|
||||
|
||||
|
||||
def updateConversation(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> bool:
|
||||
post_json_object: {}) -> bool:
|
||||
"""Ads a post to a conversation index in the /conversation subdirectory
|
||||
"""
|
||||
conversationFilename = \
|
||||
_getConversationFilename(base_dir, nickname, domain, postJsonObject)
|
||||
_getConversationFilename(base_dir, nickname, domain, post_json_object)
|
||||
if not conversationFilename:
|
||||
return False
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
if not os.path.isfile(conversationFilename):
|
||||
try:
|
||||
with open(conversationFilename, 'w+') as fp:
|
||||
|
|
86
daemon.py
86
daemon.py
|
@ -528,12 +528,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
locatePost(self.server.base_dir, nickname,
|
||||
self.server.domain, messageId)
|
||||
if postFilename:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
populateReplies(self.server.base_dir,
|
||||
self.server.http_prefix,
|
||||
self.server.domainFull,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
self.server.max_replies,
|
||||
self.server.debug)
|
||||
# record the vote
|
||||
|
@ -550,7 +550,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
getCachedPostFilename(self.server.base_dir,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
postJsonObject)
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -560,7 +560,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'unable to delete ' +
|
||||
cachedPostFilename)
|
||||
# remove from memory cache
|
||||
removePostFromCache(postJsonObject,
|
||||
removePostFromCache(post_json_object,
|
||||
self.server.recentPostsCache)
|
||||
else:
|
||||
print('ERROR: unable to post vote to outbox')
|
||||
|
@ -4626,16 +4626,16 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
locatePost(base_dir, nickname, domain,
|
||||
newsPostUrl)
|
||||
if postFilename:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
post_json_object = loadJson(postFilename)
|
||||
# update the content and title
|
||||
postJsonObject['object']['summary'] = \
|
||||
post_json_object['object']['summary'] = \
|
||||
newsPostTitle
|
||||
postJsonObject['object']['content'] = \
|
||||
post_json_object['object']['content'] = \
|
||||
newsPostContent
|
||||
contentMap = postJsonObject['object']['contentMap']
|
||||
contentMap = post_json_object['object']['contentMap']
|
||||
contentMap[self.server.systemLanguage] = newsPostContent
|
||||
# update newswire
|
||||
pubDate = postJsonObject['object']['published']
|
||||
pubDate = post_json_object['object']['published']
|
||||
publishedDate = \
|
||||
datetime.datetime.strptime(pubDate,
|
||||
"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
@ -4654,13 +4654,13 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
print('ERROR: saving newswire state, ' + str(ex))
|
||||
|
||||
# remove any previous cached news posts
|
||||
newsId = removeIdEnding(postJsonObject['object']['id'])
|
||||
newsId = removeIdEnding(post_json_object['object']['id'])
|
||||
newsId = newsId.replace('/', '#')
|
||||
clearFromPostCaches(base_dir, self.server.recentPostsCache,
|
||||
newsId)
|
||||
|
||||
# save the news post
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
# redirect back to the default timeline
|
||||
if self.server.news_instance:
|
||||
|
@ -8798,13 +8798,13 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self._redirect_headers(actorPathStr, cookie, callingDomain)
|
||||
return
|
||||
|
||||
postJsonObject = None
|
||||
post_json_object = None
|
||||
reactionPostFilename = \
|
||||
locatePost(self.server.base_dir,
|
||||
self.postToNickname, domain, reactionUrl)
|
||||
if reactionPostFilename:
|
||||
postJsonObject = loadJson(reactionPostFilename)
|
||||
if not reactionPostFilename or not postJsonObject:
|
||||
post_json_object = loadJson(reactionPostFilename)
|
||||
if not reactionPostFilename or not post_json_object:
|
||||
print('WARN: unable to locate reaction post ' + reactionUrl)
|
||||
actorAbsolute = self._getInstanceUrl(callingDomain) + actor
|
||||
actorPathStr = \
|
||||
|
@ -8823,7 +8823,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.cachedWebfingers,
|
||||
self.server.personCache,
|
||||
self.postToNickname,
|
||||
domain, port, postJsonObject,
|
||||
domain, port, post_json_object,
|
||||
self.server.http_prefix,
|
||||
self.server.project_version,
|
||||
self.server.yt_replace_domain,
|
||||
|
@ -9960,8 +9960,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.GETbusy = False
|
||||
return True
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
self.send_response(429)
|
||||
self.end_headers()
|
||||
self.server.GETbusy = False
|
||||
|
@ -9970,7 +9970,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# Only authorized viewers get to see likes on posts
|
||||
# Otherwize marketers could gain more social graph info
|
||||
if not authorized:
|
||||
pjo = postJsonObject
|
||||
pjo = post_json_object
|
||||
if not isPublicPost(pjo):
|
||||
self._404()
|
||||
self.server.GETbusy = False
|
||||
|
@ -9988,7 +9988,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.personCache,
|
||||
nickname, domain, port,
|
||||
authorized,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
http_prefix,
|
||||
self.server.project_version,
|
||||
likedBy, reactBy, reactEmoji,
|
||||
|
@ -10014,15 +10014,15 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
else:
|
||||
if self._secure_mode():
|
||||
if not includeCreateWrapper and \
|
||||
postJsonObject['type'] == 'Create' and \
|
||||
hasObjectDict(postJsonObject):
|
||||
unwrappedJson = postJsonObject['object']
|
||||
post_json_object['type'] == 'Create' and \
|
||||
hasObjectDict(post_json_object):
|
||||
unwrappedJson = post_json_object['object']
|
||||
unwrappedJson['@context'] = \
|
||||
getIndividualPostContext()
|
||||
msg = json.dumps(unwrappedJson,
|
||||
ensure_ascii=False)
|
||||
else:
|
||||
msg = json.dumps(postJsonObject,
|
||||
msg = json.dumps(post_json_object,
|
||||
ensure_ascii=False)
|
||||
msg = msg.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -12957,12 +12957,12 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
|
||||
customSubmitText = getConfigParam(base_dir, 'customSubmitText')
|
||||
|
||||
postJsonObject = None
|
||||
post_json_object = None
|
||||
if inReplyToUrl:
|
||||
replyPostFilename = \
|
||||
locatePost(base_dir, nickname, domain, inReplyToUrl)
|
||||
if replyPostFilename:
|
||||
postJsonObject = loadJson(replyPostFilename)
|
||||
post_json_object = loadJson(replyPostFilename)
|
||||
|
||||
msg = htmlNewPost(self.server.cssCache,
|
||||
media_instance,
|
||||
|
@ -12988,7 +12988,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.cachedWebfingers,
|
||||
self.server.personCache,
|
||||
self.server.port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
self.server.project_version,
|
||||
self.server.yt_replace_domain,
|
||||
self.server.twitter_replacement_domain,
|
||||
|
@ -14154,8 +14154,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.domainFull,
|
||||
self.path)
|
||||
if blogFilename and nickname:
|
||||
postJsonObject = loadJson(blogFilename)
|
||||
if isBlogPost(postJsonObject):
|
||||
post_json_object = loadJson(blogFilename)
|
||||
if isBlogPost(post_json_object):
|
||||
msg = htmlBlogPost(self.server.session,
|
||||
authorized,
|
||||
self.server.base_dir,
|
||||
|
@ -14163,7 +14163,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.translate,
|
||||
nickname, self.server.domain,
|
||||
self.server.domainFull,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
self.server.peertubeInstances,
|
||||
self.server.systemLanguage,
|
||||
self.server.personCache,
|
||||
|
@ -16741,8 +16741,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
nickname, self.server.domain,
|
||||
fields['postUrl'])
|
||||
if os.path.isfile(postFilename):
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
cachedFilename = \
|
||||
acctDir(self.server.base_dir,
|
||||
nickname, self.server.domain) + \
|
||||
|
@ -16756,10 +16756,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
print('EX: _receiveNewPostProcess ' +
|
||||
'unable to delete ' + cachedFilename)
|
||||
# remove from memory cache
|
||||
removePostFromCache(postJsonObject,
|
||||
removePostFromCache(post_json_object,
|
||||
self.server.recentPostsCache)
|
||||
# change the blog post title
|
||||
postJsonObject['object']['summary'] = fields['subject']
|
||||
post_json_object['object']['summary'] = \
|
||||
fields['subject']
|
||||
# format message
|
||||
tags = []
|
||||
hashtagsDict = {}
|
||||
|
@ -16783,8 +16784,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
tags, 'content',
|
||||
self.server.debug)
|
||||
|
||||
postJsonObject['object']['content'] = fields['message']
|
||||
contentMap = postJsonObject['object']['contentMap']
|
||||
post_json_object['object']['content'] = \
|
||||
fields['message']
|
||||
contentMap = post_json_object['object']['contentMap']
|
||||
contentMap[self.server.systemLanguage] = \
|
||||
fields['message']
|
||||
|
||||
|
@ -16797,13 +16799,13 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.base_dir,
|
||||
nickname,
|
||||
self.server.domain)
|
||||
postJsonObject['object'] = \
|
||||
post_json_object['object'] = \
|
||||
attachMedia(self.server.base_dir,
|
||||
self.server.http_prefix,
|
||||
nickname,
|
||||
self.server.domain,
|
||||
self.server.port,
|
||||
postJsonObject['object'],
|
||||
post_json_object['object'],
|
||||
filename,
|
||||
attachmentMediaType,
|
||||
imgDescription,
|
||||
|
@ -16811,20 +16813,20 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.low_bandwidth,
|
||||
self.server.content_license_url)
|
||||
|
||||
replaceYouTube(postJsonObject,
|
||||
replaceYouTube(post_json_object,
|
||||
self.server.yt_replace_domain,
|
||||
self.server.systemLanguage)
|
||||
replaceTwitter(postJsonObject,
|
||||
replaceTwitter(post_json_object,
|
||||
self.server.twitter_replacement_domain,
|
||||
self.server.systemLanguage)
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
# also save to the news actor
|
||||
if nickname != 'news':
|
||||
postFilename = \
|
||||
postFilename.replace('#users#' +
|
||||
nickname + '#',
|
||||
'#users#news#')
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
print('Edited blog post, resaved ' + postFilename)
|
||||
return 1
|
||||
else:
|
||||
|
|
|
@ -200,22 +200,22 @@ def _hasReadPost(actor: str, postId: str, postCategory: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _postIsToYou(actor: str, postJsonObject: {}) -> bool:
|
||||
def _postIsToYou(actor: str, post_json_object: {}) -> bool:
|
||||
"""Returns true if the post is to the actor
|
||||
"""
|
||||
toYourActor = False
|
||||
if postJsonObject.get('to'):
|
||||
if actor in postJsonObject['to']:
|
||||
if post_json_object.get('to'):
|
||||
if actor in post_json_object['to']:
|
||||
toYourActor = True
|
||||
if not toYourActor and postJsonObject.get('cc'):
|
||||
if actor in postJsonObject['cc']:
|
||||
if not toYourActor and post_json_object.get('cc'):
|
||||
if actor in post_json_object['cc']:
|
||||
toYourActor = True
|
||||
if not toYourActor and hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('to'):
|
||||
if actor in postJsonObject['object']['to']:
|
||||
if not toYourActor and hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('to'):
|
||||
if actor in post_json_object['object']['to']:
|
||||
toYourActor = True
|
||||
if not toYourActor and postJsonObject['object'].get('cc'):
|
||||
if actor in postJsonObject['object']['cc']:
|
||||
if not toYourActor and post_json_object['object'].get('cc'):
|
||||
if actor in post_json_object['object']['cc']:
|
||||
toYourActor = True
|
||||
return toYourActor
|
||||
|
||||
|
@ -232,42 +232,43 @@ def _newDesktopNotifications(actor: str, inboxJson: {},
|
|||
return
|
||||
DMdone = False
|
||||
replyDone = False
|
||||
for postJsonObject in inboxJson['orderedItems']:
|
||||
if not postJsonObject.get('id'):
|
||||
for post_json_object in inboxJson['orderedItems']:
|
||||
if not post_json_object.get('id'):
|
||||
continue
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
continue
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
if post_json_object['type'] == 'Announce':
|
||||
continue
|
||||
if not _postIsToYou(actor, postJsonObject):
|
||||
if not _postIsToYou(actor, post_json_object):
|
||||
continue
|
||||
if isDM(postJsonObject):
|
||||
if isDM(post_json_object):
|
||||
if not DMdone:
|
||||
if not _hasReadPost(actor, postJsonObject['id'], 'dm'):
|
||||
if not _hasReadPost(actor, post_json_object['id'], 'dm'):
|
||||
changed = False
|
||||
if not notifyJson.get('dmPostId'):
|
||||
changed = True
|
||||
else:
|
||||
if notifyJson['dmPostId'] != postJsonObject['id']:
|
||||
if notifyJson['dmPostId'] != post_json_object['id']:
|
||||
changed = True
|
||||
if changed:
|
||||
notifyJson['dmNotify'] = True
|
||||
notifyJson['dmNotifyChanged'] = True
|
||||
notifyJson['dmPostId'] = postJsonObject['id']
|
||||
notifyJson['dmPostId'] = post_json_object['id']
|
||||
DMdone = True
|
||||
else:
|
||||
if not replyDone:
|
||||
if not _hasReadPost(actor, postJsonObject['id'], 'replies'):
|
||||
if not _hasReadPost(actor, post_json_object['id'], 'replies'):
|
||||
changed = False
|
||||
if not notifyJson.get('repliesPostId'):
|
||||
changed = True
|
||||
else:
|
||||
if notifyJson['repliesPostId'] != postJsonObject['id']:
|
||||
if notifyJson['repliesPostId'] != \
|
||||
post_json_object['id']:
|
||||
changed = True
|
||||
if changed:
|
||||
notifyJson['repliesNotify'] = True
|
||||
notifyJson['repliesNotifyChanged'] = True
|
||||
notifyJson['repliesPostId'] = postJsonObject['id']
|
||||
notifyJson['repliesPostId'] = post_json_object['id']
|
||||
replyDone = True
|
||||
|
||||
|
||||
|
@ -588,14 +589,14 @@ def _textOnlyContent(content: str) -> str:
|
|||
return removeHtml(content)
|
||||
|
||||
|
||||
def _getImageDescription(postJsonObject: {}) -> str:
|
||||
def _getImageDescription(post_json_object: {}) -> str:
|
||||
"""Returns a image description/s on a post
|
||||
"""
|
||||
imageDescription = ''
|
||||
if not postJsonObject['object'].get('attachment'):
|
||||
if not post_json_object['object'].get('attachment'):
|
||||
return imageDescription
|
||||
|
||||
attachList = postJsonObject['object']['attachment']
|
||||
attachList = post_json_object['object']['attachment']
|
||||
if not isinstance(attachList, list):
|
||||
return imageDescription
|
||||
|
||||
|
@ -617,14 +618,14 @@ def _getImageDescription(postJsonObject: {}) -> str:
|
|||
return imageDescription
|
||||
|
||||
|
||||
def _showLikesOnPost(postJsonObject: {}, maxLikes: int) -> None:
|
||||
def _showLikesOnPost(post_json_object: {}, maxLikes: int) -> None:
|
||||
"""Shows the likes on a post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('likes'):
|
||||
if not post_json_object['object'].get('likes'):
|
||||
return
|
||||
objectLikes = postJsonObject['object']['likes']
|
||||
objectLikes = post_json_object['object']['likes']
|
||||
if not isinstance(objectLikes, dict):
|
||||
return
|
||||
if not objectLikes.get('items'):
|
||||
|
@ -640,14 +641,14 @@ def _showLikesOnPost(postJsonObject: {}, maxLikes: int) -> None:
|
|||
break
|
||||
|
||||
|
||||
def _showRepliesOnPost(postJsonObject: {}, max_replies: int) -> None:
|
||||
def _showRepliesOnPost(post_json_object: {}, max_replies: int) -> None:
|
||||
"""Shows the replies on a post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('replies'):
|
||||
if not post_json_object['object'].get('replies'):
|
||||
return
|
||||
objectReplies = postJsonObject['object']['replies']
|
||||
objectReplies = post_json_object['object']['replies']
|
||||
if not isinstance(objectReplies, dict):
|
||||
return
|
||||
if not objectReplies.get('items'):
|
||||
|
@ -678,8 +679,8 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
if _timelineIsEmpty(boxJson):
|
||||
return {}
|
||||
|
||||
postJsonObject = _desktopGetBoxPostObject(boxJson, index)
|
||||
if not postJsonObject:
|
||||
post_json_object = _desktopGetBoxPostObject(boxJson, index)
|
||||
if not post_json_object:
|
||||
return {}
|
||||
gender = 'They/Them'
|
||||
|
||||
|
@ -692,18 +693,18 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
_sayCommand(sayStr, sayStr2, screenreader, systemLanguage, espeak)
|
||||
print('')
|
||||
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
actor = postJsonObject['actor']
|
||||
if post_json_object['type'] == 'Announce':
|
||||
actor = post_json_object['actor']
|
||||
nameStr = getNicknameFromActor(actor)
|
||||
recentPostsCache = {}
|
||||
allow_local_network_access = False
|
||||
yt_replace_domain = None
|
||||
twitter_replacement_domain = None
|
||||
postJsonObject2 = \
|
||||
post_json_object2 = \
|
||||
downloadAnnounce(session, base_dir,
|
||||
http_prefix,
|
||||
nickname, domain,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
__version__, translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
|
@ -713,13 +714,14 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
domainFull, personCache,
|
||||
signingPrivateKeyPem,
|
||||
blockedCache)
|
||||
if postJsonObject2:
|
||||
if hasObjectDict(postJsonObject2):
|
||||
if postJsonObject2['object'].get('attributedTo') and \
|
||||
postJsonObject2['object'].get('content'):
|
||||
attributedTo = postJsonObject2['object']['attributedTo']
|
||||
if post_json_object2:
|
||||
if hasObjectDict(post_json_object2):
|
||||
if post_json_object2['object'].get('attributedTo') and \
|
||||
post_json_object2['object'].get('content'):
|
||||
attributedTo = post_json_object2['object']['attributedTo']
|
||||
content = \
|
||||
getBaseContentFromPost(postJsonObject2, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object2,
|
||||
systemLanguage)
|
||||
if isinstance(attributedTo, str) and content:
|
||||
actor = attributedTo
|
||||
nameStr += ' ' + translate['announces'] + ' ' + \
|
||||
|
@ -732,26 +734,26 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
time.sleep(2)
|
||||
content = \
|
||||
_textOnlyContent(content)
|
||||
content += _getImageDescription(postJsonObject2)
|
||||
content += _getImageDescription(post_json_object2)
|
||||
messageStr, detectedLinks = \
|
||||
speakableText(base_dir, content, translate)
|
||||
sayStr = content
|
||||
_sayCommand(sayStr, messageStr, screenreader,
|
||||
systemLanguage, espeak)
|
||||
return postJsonObject2
|
||||
return post_json_object2
|
||||
return {}
|
||||
|
||||
attributedTo = postJsonObject['object']['attributedTo']
|
||||
attributedTo = post_json_object['object']['attributedTo']
|
||||
if not attributedTo:
|
||||
return {}
|
||||
content = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
content = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if not isinstance(attributedTo, str) or \
|
||||
not isinstance(content, str):
|
||||
return {}
|
||||
actor = attributedTo
|
||||
nameStr = getNicknameFromActor(actor)
|
||||
content = _textOnlyContent(content)
|
||||
content += _getImageDescription(postJsonObject)
|
||||
content += _getImageDescription(post_json_object)
|
||||
|
||||
if isPGPEncrypted(content):
|
||||
sayStr = 'Encrypted message. Please enter your passphrase.'
|
||||
|
@ -773,8 +775,8 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
systemLanguage, espeak, nameStr, gender)
|
||||
print('')
|
||||
|
||||
if postJsonObject['object'].get('inReplyTo'):
|
||||
print('Replying to ' + postJsonObject['object']['inReplyTo'] + '\n')
|
||||
if post_json_object['object'].get('inReplyTo'):
|
||||
print('Replying to ' + post_json_object['object']['inReplyTo'] + '\n')
|
||||
|
||||
if screenreader:
|
||||
time.sleep(2)
|
||||
|
@ -783,17 +785,17 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
|
|||
_sayCommand(content, messageStr, screenreader,
|
||||
systemLanguage, espeak, nameStr, gender)
|
||||
|
||||
_showLikesOnPost(postJsonObject, 10)
|
||||
_showRepliesOnPost(postJsonObject, 10)
|
||||
_showLikesOnPost(post_json_object, 10)
|
||||
_showRepliesOnPost(post_json_object, 10)
|
||||
|
||||
# if the post is addressed to you then mark it as read
|
||||
if _postIsToYou(yourActor, postJsonObject):
|
||||
if isDM(postJsonObject):
|
||||
_markPostAsRead(yourActor, postJsonObject['id'], 'dm')
|
||||
if _postIsToYou(yourActor, post_json_object):
|
||||
if isDM(post_json_object):
|
||||
_markPostAsRead(yourActor, post_json_object['id'], 'dm')
|
||||
else:
|
||||
_markPostAsRead(yourActor, postJsonObject['id'], 'replies')
|
||||
_markPostAsRead(yourActor, post_json_object['id'], 'replies')
|
||||
|
||||
return postJsonObject
|
||||
return post_json_object
|
||||
|
||||
|
||||
def _desktopShowActor(base_dir: str, actorJson: {}, translate: {},
|
||||
|
@ -837,29 +839,29 @@ def _desktopShowProfile(session, nickname: str, domain: str,
|
|||
systemLanguage: str,
|
||||
screenreader: str, espeak,
|
||||
translate: {}, yourActor: str,
|
||||
postJsonObject: {}, signingPrivateKeyPem: str) -> {}:
|
||||
post_json_object: {}, signingPrivateKeyPem: str) -> {}:
|
||||
"""Shows the profile of the actor for the given post
|
||||
Returns the actor json
|
||||
"""
|
||||
if _timelineIsEmpty(boxJson):
|
||||
return {}
|
||||
|
||||
if not postJsonObject:
|
||||
postJsonObject = _desktopGetBoxPostObject(boxJson, index)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
post_json_object = _desktopGetBoxPostObject(boxJson, index)
|
||||
if not post_json_object:
|
||||
return {}
|
||||
|
||||
actor = None
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
nickname = getNicknameFromActor(postJsonObject['object'])
|
||||
if post_json_object['type'] == 'Announce':
|
||||
nickname = getNicknameFromActor(post_json_object['object'])
|
||||
if nickname:
|
||||
nickStr = '/' + nickname + '/'
|
||||
if nickStr in postJsonObject['object']:
|
||||
if nickStr in post_json_object['object']:
|
||||
actor = \
|
||||
postJsonObject['object'].split(nickStr)[0] + \
|
||||
post_json_object['object'].split(nickStr)[0] + \
|
||||
'/' + nickname
|
||||
else:
|
||||
actor = postJsonObject['object']['attributedTo']
|
||||
actor = post_json_object['object']['attributedTo']
|
||||
|
||||
if not actor:
|
||||
return {}
|
||||
|
@ -883,7 +885,7 @@ def _desktopShowProfileFromHandle(session, nickname: str, domain: str,
|
|||
systemLanguage: str,
|
||||
screenreader: str, espeak,
|
||||
translate: {}, yourActor: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
signingPrivateKeyPem: str) -> {}:
|
||||
"""Shows the profile for a handle
|
||||
Returns the actor json
|
||||
|
@ -902,27 +904,27 @@ def _desktopGetBoxPostObject(boxJson: {}, index: int) -> {}:
|
|||
"""Gets the post with the given index from the timeline
|
||||
"""
|
||||
ctr = 0
|
||||
for postJsonObject in boxJson['orderedItems']:
|
||||
if not postJsonObject.get('type'):
|
||||
for post_json_object in boxJson['orderedItems']:
|
||||
if not post_json_object.get('type'):
|
||||
continue
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
continue
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
if not isinstance(postJsonObject['object'], str):
|
||||
if post_json_object['type'] == 'Announce':
|
||||
if not isinstance(post_json_object['object'], str):
|
||||
continue
|
||||
ctr += 1
|
||||
if ctr == index:
|
||||
return postJsonObject
|
||||
return post_json_object
|
||||
continue
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
continue
|
||||
if not postJsonObject['object'].get('published'):
|
||||
if not post_json_object['object'].get('published'):
|
||||
continue
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
continue
|
||||
ctr += 1
|
||||
if ctr == index:
|
||||
return postJsonObject
|
||||
return post_json_object
|
||||
return None
|
||||
|
||||
|
||||
|
@ -1000,23 +1002,23 @@ def _desktopShowBox(indent: str,
|
|||
return False
|
||||
|
||||
ctr = 1
|
||||
for postJsonObject in boxJson['orderedItems']:
|
||||
if not postJsonObject.get('type'):
|
||||
for post_json_object in boxJson['orderedItems']:
|
||||
if not post_json_object.get('type'):
|
||||
continue
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
if postJsonObject.get('actor') and \
|
||||
postJsonObject.get('object'):
|
||||
if isinstance(postJsonObject['object'], str):
|
||||
authorActor = postJsonObject['actor']
|
||||
if post_json_object['type'] == 'Announce':
|
||||
if post_json_object.get('actor') and \
|
||||
post_json_object.get('object'):
|
||||
if isinstance(post_json_object['object'], str):
|
||||
authorActor = post_json_object['actor']
|
||||
name = getNicknameFromActor(authorActor) + ' ⮌'
|
||||
name = _padToWidth(name, nameWidth)
|
||||
ctrStr = str(ctr)
|
||||
posStr = _padToWidth(ctrStr, numberWidth)
|
||||
published = _formatPublished(postJsonObject['published'])
|
||||
published = _formatPublished(post_json_object['published'])
|
||||
announcedNickname = \
|
||||
getNicknameFromActor(postJsonObject['object'])
|
||||
getNicknameFromActor(post_json_object['object'])
|
||||
announcedDomain, announcedPort = \
|
||||
getDomainFromActor(postJsonObject['object'])
|
||||
getDomainFromActor(post_json_object['object'])
|
||||
announcedHandle = announcedNickname + '@' + announcedDomain
|
||||
lineStr = \
|
||||
indent + str(posStr) + ' | ' + name + ' | ' + \
|
||||
|
@ -1026,39 +1028,39 @@ def _desktopShowBox(indent: str,
|
|||
ctr += 1
|
||||
continue
|
||||
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
continue
|
||||
if not postJsonObject['object'].get('published'):
|
||||
if not post_json_object['object'].get('published'):
|
||||
continue
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
continue
|
||||
ctrStr = str(ctr)
|
||||
posStr = _padToWidth(ctrStr, numberWidth)
|
||||
|
||||
authorActor = postJsonObject['object']['attributedTo']
|
||||
authorActor = post_json_object['object']['attributedTo']
|
||||
contentWarning = None
|
||||
if postJsonObject['object'].get('summary'):
|
||||
if post_json_object['object'].get('summary'):
|
||||
contentWarning = '⚡' + \
|
||||
_padToWidth(postJsonObject['object']['summary'],
|
||||
_padToWidth(post_json_object['object']['summary'],
|
||||
contentWidth)
|
||||
name = getNicknameFromActor(authorActor)
|
||||
|
||||
# append icons to the end of the name
|
||||
spaceAdded = False
|
||||
if postJsonObject['object'].get('inReplyTo'):
|
||||
if post_json_object['object'].get('inReplyTo'):
|
||||
if not spaceAdded:
|
||||
spaceAdded = True
|
||||
name += ' '
|
||||
name += '↲'
|
||||
if postJsonObject['object'].get('replies'):
|
||||
repliesList = postJsonObject['object']['replies']
|
||||
if post_json_object['object'].get('replies'):
|
||||
repliesList = post_json_object['object']['replies']
|
||||
if repliesList.get('items'):
|
||||
items = repliesList['items']
|
||||
for i in range(int(items)):
|
||||
name += '↰'
|
||||
if i > 10:
|
||||
break
|
||||
likesCount = noOfLikes(postJsonObject)
|
||||
likesCount = noOfLikes(post_json_object)
|
||||
if likesCount > 10:
|
||||
likesCount = 10
|
||||
for like in range(likesCount):
|
||||
|
@ -1068,12 +1070,12 @@ def _desktopShowBox(indent: str,
|
|||
name += '❤'
|
||||
name = _padToWidth(name, nameWidth)
|
||||
|
||||
published = _formatPublished(postJsonObject['published'])
|
||||
published = _formatPublished(post_json_object['published'])
|
||||
|
||||
contentStr = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
contentStr = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
content = _textOnlyContent(contentStr)
|
||||
if boxName != 'dm':
|
||||
if isDM(postJsonObject):
|
||||
if isDM(post_json_object):
|
||||
content = '📧' + content
|
||||
if not contentWarning:
|
||||
if isPGPEncrypted(content):
|
||||
|
@ -1090,18 +1092,18 @@ def _desktopShowBox(indent: str,
|
|||
content = '🔗' + contentWarning
|
||||
else:
|
||||
content = contentWarning
|
||||
if postJsonObject['object'].get('ignores'):
|
||||
if post_json_object['object'].get('ignores'):
|
||||
content = '🔇'
|
||||
if postJsonObject['object'].get('bookmarks'):
|
||||
if post_json_object['object'].get('bookmarks'):
|
||||
content = '🔖' + content
|
||||
if '\n' in content:
|
||||
content = content.replace('\n', ' ')
|
||||
lineStr = indent + str(posStr) + ' | ' + name + ' | ' + \
|
||||
published + ' | ' + content
|
||||
if boxName == 'inbox' and \
|
||||
_postIsToYou(yourActor, postJsonObject):
|
||||
if not _hasReadPost(yourActor, postJsonObject['id'], 'dm'):
|
||||
if not _hasReadPost(yourActor, postJsonObject['id'],
|
||||
_postIsToYou(yourActor, post_json_object):
|
||||
if not _hasReadPost(yourActor, post_json_object['id'], 'dm'):
|
||||
if not _hasReadPost(yourActor, post_json_object['id'],
|
||||
'replies'):
|
||||
lineStr = _highlightText(lineStr)
|
||||
print(lineStr)
|
||||
|
@ -1366,7 +1368,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
currTimeline = 'inbox'
|
||||
pageNumber = 1
|
||||
|
||||
postJsonObject = {}
|
||||
post_json_object = {}
|
||||
originalScreenReader = screenreader
|
||||
soundsDir = 'theme/default/sounds/'
|
||||
# prevSay = ''
|
||||
|
@ -1635,7 +1637,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
_desktopClearScreen()
|
||||
_desktopShowBanner()
|
||||
postIndex = int(postIndexStr)
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_readLocalBoxPost(session, nickname, domain,
|
||||
http_prefix, base_dir, currTimeline,
|
||||
pageNumber, postIndex, boxJson,
|
||||
|
@ -1656,7 +1658,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
elif commandStr.startswith('profile ') or commandStr == 'profile':
|
||||
actorJson = None
|
||||
if commandStr == 'profile':
|
||||
if postJsonObject:
|
||||
if post_json_object:
|
||||
actorJson = \
|
||||
_desktopShowProfile(session, nickname, domain,
|
||||
http_prefix, base_dir,
|
||||
|
@ -1665,7 +1667,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
boxJson,
|
||||
systemLanguage, screenreader,
|
||||
espeak, translate, yourActor,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
signingPrivateKeyPem)
|
||||
else:
|
||||
postIndexStr = '1'
|
||||
|
@ -1711,16 +1713,16 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
refreshTimeline = True
|
||||
print('')
|
||||
elif commandStr == 'reply' or commandStr == 'r':
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
postId = postJsonObject['id']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
postId = post_json_object['id']
|
||||
subject = None
|
||||
if postJsonObject['object'].get('summary'):
|
||||
subject = postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('summary'):
|
||||
subject = post_json_object['object']['summary']
|
||||
conversationId = None
|
||||
if postJsonObject['object'].get('conversation'):
|
||||
if post_json_object['object'].get('conversation'):
|
||||
conversationId = \
|
||||
postJsonObject['object']['conversation']
|
||||
post_json_object['object']['conversation']
|
||||
sessionReply = createSession(proxy_type)
|
||||
_desktopReplyToPost(sessionReply, postId,
|
||||
base_dir, nickname, password,
|
||||
|
@ -1789,11 +1791,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
likeActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
likeActor = post_json_object['object']['attributedTo']
|
||||
sayStr = 'Liking post by ' + \
|
||||
getNicknameFromActor(likeActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -1803,7 +1805,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
sendLikeViaServer(base_dir, sessionLike,
|
||||
nickname, password,
|
||||
domain, port, http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers, personCache,
|
||||
False, __version__,
|
||||
signingPrivateKeyPem)
|
||||
|
@ -1828,11 +1830,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
muteActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
muteActor = post_json_object['object']['attributedTo']
|
||||
sayStr = 'Unmuting post by ' + \
|
||||
getNicknameFromActor(muteActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -1843,7 +1845,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
nickname, password,
|
||||
domain, port,
|
||||
http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers,
|
||||
personCache,
|
||||
False, __version__,
|
||||
|
@ -1860,11 +1862,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
muteActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
muteActor = post_json_object['object']['attributedTo']
|
||||
sayStr = 'Muting post by ' + \
|
||||
getNicknameFromActor(muteActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -1874,7 +1876,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
sendMuteViaServer(base_dir, sessionMute,
|
||||
nickname, password,
|
||||
domain, port,
|
||||
http_prefix, postJsonObject['id'],
|
||||
http_prefix, post_json_object['id'],
|
||||
cachedWebfingers, personCache,
|
||||
False, __version__,
|
||||
signingPrivateKeyPem)
|
||||
|
@ -1901,11 +1903,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
bmActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
bmActor = post_json_object['object']['attributedTo']
|
||||
sayStr = 'Unbookmarking post by ' + \
|
||||
getNicknameFromActor(bmActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -1915,7 +1917,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
sendUndoBookmarkViaServer(base_dir, sessionbm,
|
||||
nickname, password,
|
||||
domain, port, http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers,
|
||||
personCache,
|
||||
False, __version__,
|
||||
|
@ -1932,11 +1934,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
bmActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
bmActor = post_json_object['object']['attributedTo']
|
||||
sayStr = 'Bookmarking post by ' + \
|
||||
getNicknameFromActor(bmActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -1946,7 +1948,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
sendBookmarkViaServer(base_dir, sessionbm,
|
||||
nickname, password,
|
||||
domain, port, http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers, personCache,
|
||||
False, __version__,
|
||||
signingPrivateKeyPem)
|
||||
|
@ -1962,15 +1964,15 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id') and \
|
||||
postJsonObject.get('object'):
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
if post_json_object:
|
||||
if post_json_object.get('id') and \
|
||||
post_json_object.get('object'):
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('attributedTo'):
|
||||
blockActor = \
|
||||
postJsonObject['object']['attributedTo']
|
||||
post_json_object['object']['attributedTo']
|
||||
sayStr = 'Unblocking ' + \
|
||||
getNicknameFromActor(blockActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -2007,15 +2009,15 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
localActorUrl(http_prefix,
|
||||
blockNickname, blockDomain)
|
||||
if currIndex > 0 and boxJson and not blockActor:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject and not blockActor:
|
||||
if postJsonObject.get('id') and \
|
||||
postJsonObject.get('object'):
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
if post_json_object and not blockActor:
|
||||
if post_json_object.get('id') and \
|
||||
post_json_object.get('object'):
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('attributedTo'):
|
||||
blockActor = \
|
||||
postJsonObject['object']['attributedTo']
|
||||
post_json_object['object']['attributedTo']
|
||||
if blockActor:
|
||||
sayStr = 'Blocking ' + \
|
||||
getNicknameFromActor(blockActor)
|
||||
|
@ -2041,11 +2043,12 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
unlikeActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
unlikeActor = \
|
||||
post_json_object['object']['attributedTo']
|
||||
sayStr = \
|
||||
'Undoing like of post by ' + \
|
||||
getNicknameFromActor(unlikeActor)
|
||||
|
@ -2056,7 +2059,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
sendUndoLikeViaServer(base_dir, sessionUnlike,
|
||||
nickname, password,
|
||||
domain, port, http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers, personCache,
|
||||
False, __version__,
|
||||
signingPrivateKeyPem)
|
||||
|
@ -2071,13 +2074,13 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
postId = postJsonObject['id']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
postId = post_json_object['id']
|
||||
announceActor = \
|
||||
postJsonObject['object']['attributedTo']
|
||||
post_json_object['object']['attributedTo']
|
||||
sayStr = 'Announcing post by ' + \
|
||||
getNicknameFromActor(announceActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -2104,13 +2107,13 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
postId = postJsonObject['id']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
postId = post_json_object['id']
|
||||
announceActor = \
|
||||
postJsonObject['object']['attributedTo']
|
||||
post_json_object['object']['attributedTo']
|
||||
sayStr = 'Undoing announce post by ' + \
|
||||
getNicknameFromActor(announceActor)
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -2118,7 +2121,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
systemLanguage, espeak)
|
||||
sessionAnnounce = createSession(proxy_type)
|
||||
sendUndoAnnounceViaServer(base_dir, sessionAnnounce,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
nickname, password,
|
||||
domain, port,
|
||||
http_prefix, postId,
|
||||
|
@ -2389,19 +2392,19 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
if post_json_object:
|
||||
if post_json_object['type'] == 'Announce':
|
||||
recentPostsCache = {}
|
||||
allow_local_network_access = False
|
||||
yt_replace_domain = None
|
||||
twitter_replacement_domain = None
|
||||
postJsonObject2 = \
|
||||
post_json_object2 = \
|
||||
downloadAnnounce(session, base_dir,
|
||||
http_prefix,
|
||||
nickname, domain,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
__version__, translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
|
@ -2411,11 +2414,12 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
domainFull, personCache,
|
||||
signingPrivateKeyPem,
|
||||
blockedCache)
|
||||
if postJsonObject2:
|
||||
postJsonObject = postJsonObject2
|
||||
if postJsonObject:
|
||||
if post_json_object2:
|
||||
post_json_object = post_json_object2
|
||||
if post_json_object:
|
||||
content = \
|
||||
getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object,
|
||||
systemLanguage)
|
||||
messageStr, detectedLinks = \
|
||||
speakableText(base_dir, content, translate)
|
||||
linkOpened = False
|
||||
|
@ -2457,11 +2461,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
if postIndex.isdigit():
|
||||
currIndex = int(postIndex)
|
||||
if currIndex > 0 and boxJson:
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_desktopGetBoxPostObject(boxJson, currIndex)
|
||||
if postJsonObject:
|
||||
if postJsonObject.get('id'):
|
||||
rmActor = postJsonObject['object']['attributedTo']
|
||||
if post_json_object:
|
||||
if post_json_object.get('id'):
|
||||
rmActor = post_json_object['object']['attributedTo']
|
||||
if rmActor != yourActor:
|
||||
sayStr = 'You can only delete your own posts'
|
||||
_sayCommand(sayStr, sayStr,
|
||||
|
@ -2469,10 +2473,11 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
systemLanguage, espeak)
|
||||
else:
|
||||
print('')
|
||||
if postJsonObject['object'].get('summary'):
|
||||
print(postJsonObject['object']['summary'])
|
||||
contentStr = getBaseContentFromPost(postJsonObject,
|
||||
systemLanguage)
|
||||
if post_json_object['object'].get('summary'):
|
||||
print(post_json_object['object']['summary'])
|
||||
contentStr = \
|
||||
getBaseContentFromPost(post_json_object,
|
||||
systemLanguage)
|
||||
print(contentStr)
|
||||
print('')
|
||||
sayStr = 'Confirm delete, yes or no?'
|
||||
|
@ -2489,7 +2494,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
nickname, password,
|
||||
domain, port,
|
||||
http_prefix,
|
||||
postJsonObject['id'],
|
||||
post_json_object['id'],
|
||||
cachedWebfingers,
|
||||
personCache,
|
||||
False, __version__,
|
||||
|
|
38
git.py
38
git.py
|
@ -112,45 +112,45 @@ def _getPatchDescription(patchStr: str) -> str:
|
|||
|
||||
|
||||
def convertPostToPatch(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> bool:
|
||||
post_json_object: {}) -> bool:
|
||||
"""Detects whether the given post contains a patch
|
||||
and if so then converts it to a Patch ActivityPub type
|
||||
"""
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
if not hasObjectStringType(post_json_object, False):
|
||||
return False
|
||||
if postJsonObject['object']['type'] == 'Patch':
|
||||
if post_json_object['object']['type'] == 'Patch':
|
||||
return True
|
||||
if not postJsonObject['object'].get('summary'):
|
||||
if not post_json_object['object'].get('summary'):
|
||||
return False
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return False
|
||||
if not postJsonObject['object'].get('attributedTo'):
|
||||
if not post_json_object['object'].get('attributedTo'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object']['attributedTo'], str):
|
||||
if not isinstance(post_json_object['object']['attributedTo'], str):
|
||||
return False
|
||||
if not isGitPatch(base_dir, nickname, domain,
|
||||
postJsonObject['object']['type'],
|
||||
postJsonObject['object']['summary'],
|
||||
postJsonObject['object']['content'],
|
||||
post_json_object['object']['type'],
|
||||
post_json_object['object']['summary'],
|
||||
post_json_object['object']['content'],
|
||||
False):
|
||||
return False
|
||||
patchStr = _gitFormatContent(postJsonObject['object']['content'])
|
||||
patchStr = _gitFormatContent(post_json_object['object']['content'])
|
||||
commitHash = _getGitHash(patchStr)
|
||||
if not commitHash:
|
||||
return False
|
||||
postJsonObject['object']['type'] = 'Patch'
|
||||
post_json_object['object']['type'] = 'Patch'
|
||||
# add a commitedBy parameter
|
||||
if not postJsonObject['object'].get('committedBy'):
|
||||
postJsonObject['object']['committedBy'] = \
|
||||
postJsonObject['object']['attributedTo']
|
||||
postJsonObject['object']['hash'] = commitHash
|
||||
postJsonObject['object']['description'] = {
|
||||
if not post_json_object['object'].get('committedBy'):
|
||||
post_json_object['object']['committedBy'] = \
|
||||
post_json_object['object']['attributedTo']
|
||||
post_json_object['object']['hash'] = commitHash
|
||||
post_json_object['object']['description'] = {
|
||||
"mediaType": "text/plain",
|
||||
"content": _getPatchDescription(patchStr)
|
||||
}
|
||||
# remove content map
|
||||
if postJsonObject['object'].get('contentMap'):
|
||||
del postJsonObject['object']['contentMap']
|
||||
if post_json_object['object'].get('contentMap'):
|
||||
del post_json_object['object']['contentMap']
|
||||
print('Converted post to Patch ActivityPub type')
|
||||
return True
|
||||
|
||||
|
|
34
happening.py
34
happening.py
|
@ -161,14 +161,14 @@ def _isHappeningEvent(tag: {}) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def _isHappeningPost(postJsonObject: {}) -> bool:
|
||||
def _isHappeningPost(post_json_object: {}) -> bool:
|
||||
"""Is this a post with tags?
|
||||
"""
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('tag'):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -210,15 +210,15 @@ def getTodaysEvents(base_dir: str, nickname: str, domain: str,
|
|||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not _isHappeningPost(postJsonObject):
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
publicEvent = isPublicPost(postJsonObject)
|
||||
publicEvent = isPublicPost(post_json_object)
|
||||
|
||||
postEvent = []
|
||||
dayOfMonth = None
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not _isHappeningEvent(tag):
|
||||
continue
|
||||
# this tag is an event or a place
|
||||
|
@ -284,11 +284,11 @@ def dayEventsCheck(base_dir: str, nickname: str, domain: str,
|
|||
if not postFilename:
|
||||
continue
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not _isHappeningPost(postJsonObject):
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not _isHappeningEvent(tag):
|
||||
continue
|
||||
# this tag is an event or a place
|
||||
|
@ -341,13 +341,13 @@ def getThisWeeksEvents(base_dir: str, nickname: str, domain: str) -> {}:
|
|||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not _isHappeningPost(postJsonObject):
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
postEvent = []
|
||||
weekDayIndex = None
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not _isHappeningEvent(tag):
|
||||
continue
|
||||
# this tag is an event or a place
|
||||
|
@ -406,13 +406,13 @@ def getCalendarEvents(base_dir: str, nickname: str, domain: str,
|
|||
recreateEventsFile = True
|
||||
continue
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not _isHappeningPost(postJsonObject):
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not _isHappeningPost(post_json_object):
|
||||
continue
|
||||
|
||||
postEvent = []
|
||||
dayOfMonth = None
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not _isHappeningEvent(tag):
|
||||
continue
|
||||
# this tag is an event or a place
|
||||
|
|
375
inbox.py
375
inbox.py
|
@ -125,7 +125,7 @@ from person import validSendingActor
|
|||
|
||||
|
||||
def _storeLastPostId(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> None:
|
||||
post_json_object: {}) -> None:
|
||||
"""Stores the id of the last post made by an actor
|
||||
When a new post arrives this allows it to be compared against the last
|
||||
to see if it is an edited post.
|
||||
|
@ -133,14 +133,14 @@ def _storeLastPostId(base_dir: str, nickname: str, domain: str,
|
|||
source but we don't live in that ideal world.
|
||||
"""
|
||||
actor = postId = None
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
if isinstance(postJsonObject['object']['attributedTo'], str):
|
||||
actor = postJsonObject['object']['attributedTo']
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('attributedTo'):
|
||||
if isinstance(post_json_object['object']['attributedTo'], str):
|
||||
actor = post_json_object['object']['attributedTo']
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
if not actor:
|
||||
actor = postJsonObject['actor']
|
||||
postId = removeIdEnding(postJsonObject['id'])
|
||||
actor = post_json_object['actor']
|
||||
postId = removeIdEnding(post_json_object['id'])
|
||||
if not actor:
|
||||
return
|
||||
lastpostDir = acctDir(base_dir, nickname, domain) + '/lastpost'
|
||||
|
@ -201,19 +201,19 @@ def _updateCachedHashtagSwarm(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
def storeHashTags(base_dir: str, nickname: str, domain: str,
|
||||
http_prefix: str, domainFull: str,
|
||||
postJsonObject: {}, translate: {}) -> None:
|
||||
post_json_object: {}, translate: {}) -> None:
|
||||
"""Extracts hashtags from an incoming post and updates the
|
||||
relevant tags files.
|
||||
"""
|
||||
if not isPublicPost(postJsonObject):
|
||||
if not isPublicPost(post_json_object):
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('tag'):
|
||||
return
|
||||
if not postJsonObject.get('id'):
|
||||
if not post_json_object.get('id'):
|
||||
return
|
||||
if not isinstance(postJsonObject['object']['tag'], list):
|
||||
if not isinstance(post_json_object['object']['tag'], list):
|
||||
return
|
||||
tagsDir = base_dir + '/tags'
|
||||
|
||||
|
@ -225,7 +225,7 @@ def storeHashTags(base_dir: str, nickname: str, domain: str,
|
|||
hashtagCategories = getHashtagCategories(base_dir)
|
||||
|
||||
hashtagsCtr = 0
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not tag.get('type'):
|
||||
continue
|
||||
if not isinstance(tag['type'], str):
|
||||
|
@ -238,7 +238,7 @@ def storeHashTags(base_dir: str, nickname: str, domain: str,
|
|||
if not validHashTag(tagName):
|
||||
continue
|
||||
tagsFilename = tagsDir + '/' + tagName + '.txt'
|
||||
postUrl = removeIdEnding(postJsonObject['id'])
|
||||
postUrl = removeIdEnding(post_json_object['id'])
|
||||
postUrl = postUrl.replace('/', '#')
|
||||
daysDiff = datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)
|
||||
daysSinceEpoch = daysDiff.days
|
||||
|
@ -283,7 +283,7 @@ def _inboxStorePostToHtmlCache(recentPostsCache: {}, max_recent_posts: int,
|
|||
base_dir: str, http_prefix: str,
|
||||
session, cachedWebfingers: {}, personCache: {},
|
||||
nickname: str, domain: str, port: int,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
allow_deletion: bool, boxname: str,
|
||||
show_published_date_only: bool,
|
||||
peertubeInstances: [],
|
||||
|
@ -301,7 +301,7 @@ def _inboxStorePostToHtmlCache(recentPostsCache: {}, max_recent_posts: int,
|
|||
if boxname != 'outbox':
|
||||
boxname = 'inbox'
|
||||
|
||||
notDM = not isDM(postJsonObject)
|
||||
notDM = not isDM(post_json_object)
|
||||
yt_replace_domain = getConfigParam(base_dir, 'youtubedomain')
|
||||
twitter_replacement_domain = getConfigParam(base_dir, 'twitterdomain')
|
||||
individualPostAsHtml(signingPrivateKeyPem,
|
||||
|
@ -309,7 +309,7 @@ def _inboxStorePostToHtmlCache(recentPostsCache: {}, max_recent_posts: int,
|
|||
translate, pageNumber,
|
||||
base_dir, session, cachedWebfingers,
|
||||
personCache,
|
||||
nickname, domain, port, postJsonObject,
|
||||
nickname, domain, port, post_json_object,
|
||||
avatarUrl, True, allow_deletion,
|
||||
http_prefix, __version__, boxname,
|
||||
yt_replace_domain, twitter_replacement_domain,
|
||||
|
@ -450,7 +450,7 @@ def inboxPermittedMessage(domain: str, messageJson: {},
|
|||
|
||||
def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
originalPostJsonObject: {},
|
||||
messageBytes: str,
|
||||
httpHeaders: {},
|
||||
|
@ -471,18 +471,18 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
|||
postNickname = None
|
||||
postDomain = None
|
||||
actor = None
|
||||
if postJsonObject.get('actor'):
|
||||
if not isinstance(postJsonObject['actor'], str):
|
||||
if post_json_object.get('actor'):
|
||||
if not isinstance(post_json_object['actor'], str):
|
||||
return None
|
||||
actor = postJsonObject['actor']
|
||||
postNickname = getNicknameFromActor(postJsonObject['actor'])
|
||||
actor = post_json_object['actor']
|
||||
postNickname = getNicknameFromActor(post_json_object['actor'])
|
||||
if not postNickname:
|
||||
print('No post Nickname in actor ' + postJsonObject['actor'])
|
||||
print('No post Nickname in actor ' + post_json_object['actor'])
|
||||
return None
|
||||
postDomain, postPort = getDomainFromActor(postJsonObject['actor'])
|
||||
postDomain, postPort = getDomainFromActor(post_json_object['actor'])
|
||||
if not postDomain:
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('No post Domain in actor')
|
||||
return None
|
||||
if isBlocked(base_dir, nickname, domain,
|
||||
|
@ -492,11 +492,11 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
|||
return None
|
||||
postDomain = getFullDomain(postDomain, postPort)
|
||||
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('inReplyTo'):
|
||||
if isinstance(postJsonObject['object']['inReplyTo'], str):
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('inReplyTo'):
|
||||
if isinstance(post_json_object['object']['inReplyTo'], str):
|
||||
inReplyTo = \
|
||||
postJsonObject['object']['inReplyTo']
|
||||
post_json_object['object']['inReplyTo']
|
||||
replyDomain, replyPort = \
|
||||
getDomainFromActor(inReplyTo)
|
||||
if isBlockedDomain(base_dir, replyDomain, blockedCache):
|
||||
|
@ -518,24 +518,25 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
|||
' to a blocked account: ' +
|
||||
replyNickname + '@' + replyDomain)
|
||||
return None
|
||||
if postJsonObject['object'].get('content'):
|
||||
contentStr = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
if post_json_object['object'].get('content'):
|
||||
contentStr = \
|
||||
getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if contentStr:
|
||||
if isFiltered(base_dir, nickname, domain, contentStr):
|
||||
if debug:
|
||||
print('WARN: post was filtered out due to content')
|
||||
return None
|
||||
originalPostId = None
|
||||
if postJsonObject.get('id'):
|
||||
if not isinstance(postJsonObject['id'], str):
|
||||
if post_json_object.get('id'):
|
||||
if not isinstance(post_json_object['id'], str):
|
||||
return None
|
||||
originalPostId = removeIdEnding(postJsonObject['id'])
|
||||
originalPostId = removeIdEnding(post_json_object['id'])
|
||||
|
||||
currTime = datetime.datetime.utcnow()
|
||||
|
||||
postId = None
|
||||
if postJsonObject.get('id'):
|
||||
postId = removeIdEnding(postJsonObject['id'])
|
||||
if post_json_object.get('id'):
|
||||
postId = removeIdEnding(post_json_object['id'])
|
||||
published = currTime.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
if not postId:
|
||||
statusNumber, published = getStatusNumber()
|
||||
|
@ -545,7 +546,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
|||
postId = localActorUrl(http_prefix, nickname, originalDomain) + \
|
||||
'/statuses/' + statusNumber
|
||||
|
||||
# NOTE: don't change postJsonObject['id'] before signature check
|
||||
# NOTE: don't change post_json_object['id'] before signature check
|
||||
|
||||
inboxQueueDir = createInboxQueueDir(nickname, domain, base_dir)
|
||||
|
||||
|
@ -580,7 +581,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
|
|||
'published': published,
|
||||
'httpHeaders': httpHeaders,
|
||||
'path': postPath,
|
||||
'post': postJsonObject,
|
||||
'post': post_json_object,
|
||||
'original': originalPostJsonObject,
|
||||
'digest': digest,
|
||||
'filename': filename,
|
||||
|
@ -627,7 +628,7 @@ def _inboxPostRecipientsAdd(base_dir: str, http_prefix: str, toList: [],
|
|||
return followerRecipients, recipientsDict
|
||||
|
||||
|
||||
def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
||||
def _inboxPostRecipients(base_dir: str, post_json_object: {},
|
||||
http_prefix: str, domain: str, port: int,
|
||||
debug: bool) -> ([], []):
|
||||
"""Returns dictionaries containing the recipients of the given post
|
||||
|
@ -636,9 +637,9 @@ def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
|||
recipientsDict = {}
|
||||
recipientsDictFollowers = {}
|
||||
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('WARNING: inbox post has no actor')
|
||||
return recipientsDict, recipientsDictFollowers
|
||||
|
||||
|
@ -647,16 +648,16 @@ def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
|||
domain = getFullDomain(domain, port)
|
||||
domainMatch = '/' + domain + '/users/'
|
||||
|
||||
actor = postJsonObject['actor']
|
||||
actor = post_json_object['actor']
|
||||
# first get any specific people which the post is addressed to
|
||||
|
||||
followerRecipients = False
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('to'):
|
||||
if isinstance(postJsonObject['object']['to'], list):
|
||||
recipientsList = postJsonObject['object']['to']
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('to'):
|
||||
if isinstance(post_json_object['object']['to'], list):
|
||||
recipientsList = post_json_object['object']['to']
|
||||
else:
|
||||
recipientsList = [postJsonObject['object']['to']]
|
||||
recipientsList = [post_json_object['object']['to']]
|
||||
if debug:
|
||||
print('DEBUG: resolving "to"')
|
||||
includesFollowers, recipientsDict = \
|
||||
|
@ -671,11 +672,11 @@ def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
|||
if debug:
|
||||
print('DEBUG: inbox post has no "to"')
|
||||
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if isinstance(postJsonObject['object']['cc'], list):
|
||||
recipientsList = postJsonObject['object']['cc']
|
||||
if post_json_object['object'].get('cc'):
|
||||
if isinstance(post_json_object['object']['cc'], list):
|
||||
recipientsList = post_json_object['object']['cc']
|
||||
else:
|
||||
recipientsList = [postJsonObject['object']['cc']]
|
||||
recipientsList = [post_json_object['object']['cc']]
|
||||
includesFollowers, recipientsDict = \
|
||||
_inboxPostRecipientsAdd(base_dir, http_prefix,
|
||||
recipientsList,
|
||||
|
@ -688,19 +689,19 @@ def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
|||
if debug:
|
||||
print('DEBUG: inbox post has no cc')
|
||||
else:
|
||||
if debug and postJsonObject.get('object'):
|
||||
if isinstance(postJsonObject['object'], str):
|
||||
if '/statuses/' in postJsonObject['object']:
|
||||
if debug and post_json_object.get('object'):
|
||||
if isinstance(post_json_object['object'], str):
|
||||
if '/statuses/' in post_json_object['object']:
|
||||
print('DEBUG: inbox item is a link to a post')
|
||||
else:
|
||||
if '/users/' in postJsonObject['object']:
|
||||
if '/users/' in post_json_object['object']:
|
||||
print('DEBUG: inbox item is a link to an actor')
|
||||
|
||||
if postJsonObject.get('to'):
|
||||
if isinstance(postJsonObject['to'], list):
|
||||
recipientsList = postJsonObject['to']
|
||||
if post_json_object.get('to'):
|
||||
if isinstance(post_json_object['to'], list):
|
||||
recipientsList = post_json_object['to']
|
||||
else:
|
||||
recipientsList = [postJsonObject['to']]
|
||||
recipientsList = [post_json_object['to']]
|
||||
includesFollowers, recipientsDict = \
|
||||
_inboxPostRecipientsAdd(base_dir, http_prefix,
|
||||
recipientsList,
|
||||
|
@ -710,11 +711,11 @@ def _inboxPostRecipients(base_dir: str, postJsonObject: {},
|
|||
if includesFollowers:
|
||||
followerRecipients = True
|
||||
|
||||
if postJsonObject.get('cc'):
|
||||
if isinstance(postJsonObject['cc'], list):
|
||||
recipientsList = postJsonObject['cc']
|
||||
if post_json_object.get('cc'):
|
||||
if isinstance(post_json_object['cc'], list):
|
||||
recipientsList = post_json_object['cc']
|
||||
else:
|
||||
recipientsList = [postJsonObject['cc']]
|
||||
recipientsList = [post_json_object['cc']]
|
||||
includesFollowers, recipientsDict = \
|
||||
_inboxPostRecipientsAdd(base_dir, http_prefix,
|
||||
recipientsList,
|
||||
|
@ -913,13 +914,13 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {},
|
|||
if not postFilename:
|
||||
return
|
||||
# load the json for the question
|
||||
postJsonObject = loadJson(postFilename, 1)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename, 1)
|
||||
if not post_json_object:
|
||||
return
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return
|
||||
# does the actor match?
|
||||
if postJsonObject['actor'] != messageJson['actor']:
|
||||
if post_json_object['actor'] != messageJson['actor']:
|
||||
return
|
||||
saveJson(messageJson, postFilename)
|
||||
# ensure that the cached post is removed if it exists, so
|
||||
|
@ -1930,20 +1931,20 @@ def _receiveAnnounce(recentPostsCache: {},
|
|||
if debug:
|
||||
print('Generated announce html ' + announceHtml.replace('\n', ''))
|
||||
|
||||
postJsonObject = downloadAnnounce(session, base_dir,
|
||||
http_prefix,
|
||||
nickname, domain,
|
||||
messageJson,
|
||||
__version__, translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
allow_local_network_access,
|
||||
recentPostsCache, debug,
|
||||
systemLanguage,
|
||||
domainFull, personCache,
|
||||
signingPrivateKeyPem,
|
||||
blockedCache)
|
||||
if not postJsonObject:
|
||||
post_json_object = downloadAnnounce(session, base_dir,
|
||||
http_prefix,
|
||||
nickname, domain,
|
||||
messageJson,
|
||||
__version__, translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
allow_local_network_access,
|
||||
recentPostsCache, debug,
|
||||
systemLanguage,
|
||||
domainFull, personCache,
|
||||
signingPrivateKeyPem,
|
||||
blockedCache)
|
||||
if not post_json_object:
|
||||
print('WARN: unable to download announce: ' + str(messageJson))
|
||||
notInOnion = True
|
||||
if onion_domain:
|
||||
|
@ -1963,17 +1964,17 @@ def _receiveAnnounce(recentPostsCache: {},
|
|||
messageJson['actor'] + ' -> ' + messageJson['object'])
|
||||
storeHashTags(base_dir, nickname, domain,
|
||||
http_prefix, domainFull,
|
||||
postJsonObject, translate)
|
||||
post_json_object, translate)
|
||||
# Try to obtain the actor for this person
|
||||
# so that their avatar can be shown
|
||||
lookupActor = None
|
||||
if postJsonObject.get('attributedTo'):
|
||||
if isinstance(postJsonObject['attributedTo'], str):
|
||||
lookupActor = postJsonObject['attributedTo']
|
||||
if post_json_object.get('attributedTo'):
|
||||
if isinstance(post_json_object['attributedTo'], str):
|
||||
lookupActor = post_json_object['attributedTo']
|
||||
else:
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('attributedTo'):
|
||||
attrib = postJsonObject['object']['attributedTo']
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('attributedTo'):
|
||||
attrib = post_json_object['object']['attributedTo']
|
||||
if isinstance(attrib, str):
|
||||
lookupActor = attrib
|
||||
if lookupActor:
|
||||
|
@ -1981,12 +1982,12 @@ def _receiveAnnounce(recentPostsCache: {},
|
|||
if '/statuses/' in lookupActor:
|
||||
lookupActor = lookupActor.split('/statuses/')[0]
|
||||
|
||||
if isRecentPost(postJsonObject, 3):
|
||||
if isRecentPost(post_json_object, 3):
|
||||
if not os.path.isfile(postFilename + '.tts'):
|
||||
domainFull = getFullDomain(domain, port)
|
||||
updateSpeaker(base_dir, http_prefix,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject, personCache,
|
||||
post_json_object, personCache,
|
||||
translate, lookupActor,
|
||||
themeName)
|
||||
try:
|
||||
|
@ -2059,10 +2060,10 @@ def _receiveUndoAnnounce(recentPostsCache: {},
|
|||
if debug:
|
||||
print('DEBUG: announced/repeated post to be undone found in inbox')
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
if not postJsonObject.get('type'):
|
||||
if postJsonObject['type'] != 'Announce':
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
if not post_json_object.get('type'):
|
||||
if post_json_object['type'] != 'Announce':
|
||||
if debug:
|
||||
print("DEBUG: Attempt to undo something " +
|
||||
"which isn't an announcement")
|
||||
|
@ -2078,30 +2079,30 @@ def _receiveUndoAnnounce(recentPostsCache: {},
|
|||
return True
|
||||
|
||||
|
||||
def jsonPostAllowsComments(postJsonObject: {}) -> bool:
|
||||
def jsonPostAllowsComments(post_json_object: {}) -> bool:
|
||||
"""Returns true if the given post allows comments/replies
|
||||
"""
|
||||
if 'commentsEnabled' in postJsonObject:
|
||||
return postJsonObject['commentsEnabled']
|
||||
if 'rejectReplies' in postJsonObject:
|
||||
return not postJsonObject['rejectReplies']
|
||||
if postJsonObject.get('object'):
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if 'commentsEnabled' in post_json_object:
|
||||
return post_json_object['commentsEnabled']
|
||||
if 'rejectReplies' in post_json_object:
|
||||
return not post_json_object['rejectReplies']
|
||||
if post_json_object.get('object'):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
elif 'commentsEnabled' in postJsonObject['object']:
|
||||
return postJsonObject['object']['commentsEnabled']
|
||||
elif 'rejectReplies' in postJsonObject['object']:
|
||||
return not postJsonObject['object']['rejectReplies']
|
||||
elif 'commentsEnabled' in post_json_object['object']:
|
||||
return post_json_object['object']['commentsEnabled']
|
||||
elif 'rejectReplies' in post_json_object['object']:
|
||||
return not post_json_object['object']['rejectReplies']
|
||||
return True
|
||||
|
||||
|
||||
def _postAllowsComments(postFilename: str) -> bool:
|
||||
"""Returns true if the given post allows comments/replies
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return False
|
||||
return jsonPostAllowsComments(postJsonObject)
|
||||
return jsonPostAllowsComments(post_json_object)
|
||||
|
||||
|
||||
def populateReplies(base_dir: str, http_prefix: str, domain: str,
|
||||
|
@ -2291,18 +2292,18 @@ def _validPostContent(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
def _obtainAvatarForReplyPost(session, base_dir: str, http_prefix: str,
|
||||
domain: str, onion_domain: str, personCache: {},
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
signingPrivateKeyPem: str) -> None:
|
||||
"""Tries to obtain the actor for the person being replied to
|
||||
so that their avatar can later be shown
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
|
||||
if not postJsonObject['object'].get('inReplyTo'):
|
||||
if not post_json_object['object'].get('inReplyTo'):
|
||||
return
|
||||
|
||||
lookupActor = postJsonObject['object']['inReplyTo']
|
||||
lookupActor = post_json_object['object']['inReplyTo']
|
||||
if not lookupActor:
|
||||
return
|
||||
|
||||
|
@ -2358,16 +2359,16 @@ def _alreadyLiked(base_dir: str, nickname: str, domain: str,
|
|||
locatePost(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
return False
|
||||
postJsonObject = loadJson(postFilename, 1)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('likes'):
|
||||
if not post_json_object['object'].get('likes'):
|
||||
return False
|
||||
if not postJsonObject['object']['likes'].get('items'):
|
||||
if not post_json_object['object']['likes'].get('items'):
|
||||
return False
|
||||
for like in postJsonObject['object']['likes']['items']:
|
||||
for like in post_json_object['object']['likes']['items']:
|
||||
if not like.get('type'):
|
||||
continue
|
||||
if not like.get('actor'):
|
||||
|
@ -2388,16 +2389,16 @@ def _alreadyReacted(base_dir: str, nickname: str, domain: str,
|
|||
locatePost(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
return False
|
||||
postJsonObject = loadJson(postFilename, 1)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('reactions'):
|
||||
if not post_json_object['object'].get('reactions'):
|
||||
return False
|
||||
if not postJsonObject['object']['reactions'].get('items'):
|
||||
if not post_json_object['object']['reactions'].get('items'):
|
||||
return False
|
||||
for react in postJsonObject['object']['reactions']['items']:
|
||||
for react in post_json_object['object']['reactions']['items']:
|
||||
if not react.get('type'):
|
||||
continue
|
||||
if not react.get('content'):
|
||||
|
@ -2606,7 +2607,7 @@ def _groupHandle(base_dir: str, handle: str) -> bool:
|
|||
|
||||
|
||||
def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
http_prefix: str, federationList: [],
|
||||
send_threads: [], postLog: [], cachedWebfingers: {},
|
||||
personCache: {}, debug: bool,
|
||||
|
@ -2633,17 +2634,17 @@ def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
|
|||
followersFile = base_dir + '/accounts/' + handle + '/followers.txt'
|
||||
if not os.path.isfile(followersFile):
|
||||
return
|
||||
if not postJsonObject.get('to'):
|
||||
if not post_json_object.get('to'):
|
||||
return
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
nickname = handle.split('@')[0].replace('!', '')
|
||||
domain = handle.split('@')[1]
|
||||
domainFull = getFullDomain(domain, port)
|
||||
groupActor = localActorUrl(http_prefix, nickname, domainFull)
|
||||
if groupActor not in postJsonObject['to']:
|
||||
if groupActor not in post_json_object['to']:
|
||||
return
|
||||
cc = ''
|
||||
nickname = handle.split('@')[0].replace('!', '')
|
||||
|
@ -2651,9 +2652,9 @@ def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
|
|||
# save to the group outbox so that replies will be to the group
|
||||
# rather than the original sender
|
||||
savePostToBox(base_dir, http_prefix, None,
|
||||
nickname, domain, postJsonObject, 'outbox')
|
||||
nickname, domain, post_json_object, 'outbox')
|
||||
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
if debug:
|
||||
print('Group announce: ' + postId)
|
||||
announceJson = \
|
||||
|
@ -2677,21 +2678,21 @@ def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
|
|||
|
||||
|
||||
def _inboxUpdateCalendar(base_dir: str, handle: str,
|
||||
postJsonObject: {}) -> None:
|
||||
post_json_object: {}) -> None:
|
||||
"""Detects whether the tag list on a post contains calendar events
|
||||
and if so saves the post id to a file in the calendar directory
|
||||
for the account
|
||||
"""
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('tag'):
|
||||
return
|
||||
if not isinstance(postJsonObject['object']['tag'], list):
|
||||
if not isinstance(post_json_object['object']['tag'], list):
|
||||
return
|
||||
|
||||
actor = postJsonObject['actor']
|
||||
actor = post_json_object['actor']
|
||||
actorNickname = getNicknameFromActor(actor)
|
||||
actorDomain, actorPort = getDomainFromActor(actor)
|
||||
handleNickname = handle.split('@')[0]
|
||||
|
@ -2701,10 +2702,10 @@ def _inboxUpdateCalendar(base_dir: str, handle: str,
|
|||
actorNickname, actorDomain):
|
||||
return
|
||||
|
||||
postId = removeIdEnding(postJsonObject['id']).replace('/', '#')
|
||||
postId = removeIdEnding(post_json_object['id']).replace('/', '#')
|
||||
|
||||
# look for events within the tags list
|
||||
for tagDict in postJsonObject['object']['tag']:
|
||||
for tagDict in post_json_object['object']['tag']:
|
||||
if not tagDict.get('type'):
|
||||
continue
|
||||
if tagDict['type'] != 'Event':
|
||||
|
@ -2844,7 +2845,7 @@ def _bounceDM(senderPostId: str, session, http_prefix: str,
|
|||
location = None
|
||||
conversationId = None
|
||||
low_bandwidth = False
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
createDirectMessagePost(base_dir, nickname, domain, port,
|
||||
http_prefix, content, followersOnly,
|
||||
saveToFile, client_to_server,
|
||||
|
@ -2856,12 +2857,12 @@ def _bounceDM(senderPostId: str, session, http_prefix: str,
|
|||
eventDate, eventTime, location,
|
||||
systemLanguage, conversationId, low_bandwidth,
|
||||
content_license_url)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
print('WARN: unable to create bounce message to ' + sendingHandle)
|
||||
return False
|
||||
# bounce DM goes back to the sender
|
||||
print('Sending bounce DM to ' + sendingHandle)
|
||||
sendSignedJson(postJsonObject, session, base_dir,
|
||||
sendSignedJson(post_json_object, session, base_dir,
|
||||
nickname, domain, port,
|
||||
senderNickname, senderDomain, senderPort, cc,
|
||||
http_prefix, False, False, federationList,
|
||||
|
@ -2872,7 +2873,7 @@ def _bounceDM(senderPostId: str, session, http_prefix: str,
|
|||
|
||||
|
||||
def _isValidDM(base_dir: str, nickname: str, domain: str, port: int,
|
||||
postJsonObject: {}, updateIndexList: [],
|
||||
post_json_object: {}, updateIndexList: [],
|
||||
session, http_prefix: str,
|
||||
federationList: [],
|
||||
send_threads: [], postLog: [],
|
||||
|
@ -2902,9 +2903,9 @@ def _isValidDM(base_dir: str, nickname: str, domain: str, port: int,
|
|||
# get the file containing following handles
|
||||
followingFilename = acctDir(base_dir, nickname, domain) + '/following.txt'
|
||||
# who is sending a DM?
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return False
|
||||
sendingActor = postJsonObject['actor']
|
||||
sendingActor = post_json_object['actor']
|
||||
sendingActorNickname = \
|
||||
getNicknameFromActor(sendingActor)
|
||||
if not sendingActorNickname:
|
||||
|
@ -2940,14 +2941,14 @@ def _isValidDM(base_dir: str, nickname: str, domain: str, port: int,
|
|||
nickname, domain,
|
||||
sendingActorDomain):
|
||||
# send back a bounce DM
|
||||
if postJsonObject.get('id') and \
|
||||
postJsonObject.get('object'):
|
||||
if post_json_object.get('id') and \
|
||||
post_json_object.get('object'):
|
||||
# don't send bounces back to
|
||||
# replies to bounce messages
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object['object']
|
||||
if isinstance(obj, dict):
|
||||
if not obj.get('inReplyTo'):
|
||||
bouncedId = removeIdEnding(postJsonObject['id'])
|
||||
bouncedId = removeIdEnding(post_json_object['id'])
|
||||
_bounceDM(bouncedId,
|
||||
session, http_prefix,
|
||||
base_dir,
|
||||
|
@ -2973,7 +2974,7 @@ def _isValidDM(base_dir: str, nickname: str, domain: str, port: int,
|
|||
|
||||
def _receiveQuestionVote(base_dir: str, nickname: str, domain: str,
|
||||
http_prefix: str, handle: str, debug: bool,
|
||||
postJsonObject: {}, recentPostsCache: {},
|
||||
post_json_object: {}, recentPostsCache: {},
|
||||
session, onion_domain: str,
|
||||
i2p_domain: str, port: int,
|
||||
federationList: [], send_threads: [], postLog: [],
|
||||
|
@ -2992,7 +2993,7 @@ def _receiveQuestionVote(base_dir: str, nickname: str, domain: str,
|
|||
"""
|
||||
# if this is a reply to a question then update the votes
|
||||
questionJson, questionPostFilename = \
|
||||
questionUpdateVotes(base_dir, nickname, domain, postJsonObject)
|
||||
questionUpdateVotes(base_dir, nickname, domain, post_json_object)
|
||||
if not questionJson:
|
||||
return
|
||||
if not questionPostFilename:
|
||||
|
@ -3055,7 +3056,7 @@ def _receiveQuestionVote(base_dir: str, nickname: str, domain: str,
|
|||
http_prefix, federationList,
|
||||
send_threads, postLog,
|
||||
cachedWebfingers, personCache,
|
||||
postJsonObject, debug, __version__,
|
||||
post_json_object, debug, __version__,
|
||||
shared_items_federated_domains,
|
||||
sharedItemFederationTokens,
|
||||
signingPrivateKeyPem)
|
||||
|
@ -3063,7 +3064,7 @@ def _receiveQuestionVote(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
def _createReplyNotificationFile(base_dir: str, nickname: str, domain: str,
|
||||
handle: str, debug: bool, postIsDM: bool,
|
||||
postJsonObject: {}, actor: str,
|
||||
post_json_object: {}, actor: str,
|
||||
updateIndexList: [], http_prefix: str,
|
||||
default_reply_interval_hrs: int) -> bool:
|
||||
"""Generates a file indicating that a new reply has arrived
|
||||
|
@ -3073,7 +3074,7 @@ def _createReplyNotificationFile(base_dir: str, nickname: str, domain: str,
|
|||
isReplyToMutedPost = False
|
||||
if postIsDM:
|
||||
return isReplyToMutedPost
|
||||
if not isReply(postJsonObject, actor):
|
||||
if not isReply(post_json_object, actor):
|
||||
return isReplyToMutedPost
|
||||
if nickname == 'inbox':
|
||||
return isReplyToMutedPost
|
||||
|
@ -3081,12 +3082,12 @@ def _createReplyNotificationFile(base_dir: str, nickname: str, domain: str,
|
|||
updateIndexList.append('tlreplies')
|
||||
|
||||
conversationId = None
|
||||
if postJsonObject['object'].get('conversation'):
|
||||
conversationId = postJsonObject['object']['conversation']
|
||||
if post_json_object['object'].get('conversation'):
|
||||
conversationId = post_json_object['object']['conversation']
|
||||
|
||||
if not postJsonObject['object'].get('inReplyTo'):
|
||||
if not post_json_object['object'].get('inReplyTo'):
|
||||
return isReplyToMutedPost
|
||||
inReplyTo = postJsonObject['object']['inReplyTo']
|
||||
inReplyTo = post_json_object['object']['inReplyTo']
|
||||
if not inReplyTo:
|
||||
return isReplyToMutedPost
|
||||
if not isinstance(inReplyTo, str):
|
||||
|
@ -3407,50 +3408,50 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
return True
|
||||
|
||||
if messageJson.get('postNickname'):
|
||||
postJsonObject = messageJson['post']
|
||||
post_json_object = messageJson['post']
|
||||
else:
|
||||
postJsonObject = messageJson
|
||||
post_json_object = messageJson
|
||||
|
||||
nickname = handle.split('@')[0]
|
||||
jsonObj = None
|
||||
domainFull = getFullDomain(domain, port)
|
||||
if _validPostContent(base_dir, nickname, domain,
|
||||
postJsonObject, max_mentions, max_emoji,
|
||||
post_json_object, max_mentions, max_emoji,
|
||||
allow_local_network_access, debug,
|
||||
systemLanguage, http_prefix,
|
||||
domainFull, personCache):
|
||||
# is the sending actor valid?
|
||||
if not validSendingActor(session, base_dir, nickname, domain,
|
||||
personCache, postJsonObject,
|
||||
personCache, post_json_object,
|
||||
signingPrivateKeyPem, debug, unit_test):
|
||||
return False
|
||||
|
||||
if postJsonObject.get('object'):
|
||||
jsonObj = postJsonObject['object']
|
||||
if post_json_object.get('object'):
|
||||
jsonObj = post_json_object['object']
|
||||
if not isinstance(jsonObj, dict):
|
||||
jsonObj = None
|
||||
else:
|
||||
jsonObj = postJsonObject
|
||||
jsonObj = post_json_object
|
||||
|
||||
if _checkForGitPatches(base_dir, nickname, domain,
|
||||
handle, jsonObj) == 2:
|
||||
return False
|
||||
|
||||
# replace YouTube links, so they get less tracking data
|
||||
replaceYouTube(postJsonObject, yt_replace_domain, systemLanguage)
|
||||
replaceYouTube(post_json_object, yt_replace_domain, systemLanguage)
|
||||
# replace twitter link domains, so that you can view twitter posts
|
||||
# without having an account
|
||||
replaceTwitter(postJsonObject, twitter_replacement_domain,
|
||||
replaceTwitter(post_json_object, twitter_replacement_domain,
|
||||
systemLanguage)
|
||||
|
||||
# list of indexes to be updated
|
||||
updateIndexList = ['inbox']
|
||||
populateReplies(base_dir, http_prefix, domain, postJsonObject,
|
||||
populateReplies(base_dir, http_prefix, domain, post_json_object,
|
||||
max_replies, debug)
|
||||
|
||||
_receiveQuestionVote(base_dir, nickname, domain,
|
||||
http_prefix, handle, debug,
|
||||
postJsonObject, recentPostsCache,
|
||||
post_json_object, recentPostsCache,
|
||||
session, onion_domain, i2p_domain, port,
|
||||
federationList, send_threads, postLog,
|
||||
cachedWebfingers, personCache,
|
||||
|
@ -3469,10 +3470,10 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
|
||||
if not isGroup:
|
||||
# create a DM notification file if needed
|
||||
postIsDM = isDM(postJsonObject)
|
||||
postIsDM = isDM(post_json_object)
|
||||
if postIsDM:
|
||||
if not _isValidDM(base_dir, nickname, domain, port,
|
||||
postJsonObject, updateIndexList,
|
||||
post_json_object, updateIndexList,
|
||||
session, http_prefix,
|
||||
federationList,
|
||||
send_threads, postLog,
|
||||
|
@ -3492,12 +3493,12 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
isReplyToMutedPost = \
|
||||
_createReplyNotificationFile(base_dir, nickname, domain,
|
||||
handle, debug, postIsDM,
|
||||
postJsonObject, actor,
|
||||
post_json_object, actor,
|
||||
updateIndexList, http_prefix,
|
||||
default_reply_interval_hrs)
|
||||
|
||||
if isImageMedia(session, base_dir, http_prefix,
|
||||
nickname, domain, postJsonObject,
|
||||
nickname, domain, post_json_object,
|
||||
translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
|
@ -3506,18 +3507,18 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
domainFull, personCache, signingPrivateKeyPem):
|
||||
# media index will be updated
|
||||
updateIndexList.append('tlmedia')
|
||||
if isBlogPost(postJsonObject):
|
||||
if isBlogPost(post_json_object):
|
||||
# blogs index will be updated
|
||||
updateIndexList.append('tlblogs')
|
||||
|
||||
# get the avatar for a reply/announce
|
||||
_obtainAvatarForReplyPost(session, base_dir,
|
||||
http_prefix, domain, onion_domain,
|
||||
personCache, postJsonObject, debug,
|
||||
personCache, post_json_object, debug,
|
||||
signingPrivateKeyPem)
|
||||
|
||||
# save the post to file
|
||||
if saveJson(postJsonObject, destinationFilename):
|
||||
if saveJson(post_json_object, destinationFilename):
|
||||
_lowFrequencyPostNotification(base_dir, http_prefix,
|
||||
nickname, domain, port,
|
||||
handle, postIsDM, jsonObj)
|
||||
|
@ -3540,11 +3541,11 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
print('ERROR: unable to update ' + boxname + ' index')
|
||||
else:
|
||||
if boxname == 'inbox':
|
||||
if isRecentPost(postJsonObject, 3):
|
||||
if isRecentPost(post_json_object, 3):
|
||||
domainFull = getFullDomain(domain, port)
|
||||
updateSpeaker(base_dir, http_prefix,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject, personCache,
|
||||
post_json_object, personCache,
|
||||
translate, None, themeName)
|
||||
if not unit_test:
|
||||
if debug:
|
||||
|
@ -3560,7 +3561,7 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
personCache,
|
||||
handleName,
|
||||
domain, port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
allow_deletion,
|
||||
boxname,
|
||||
show_published_date_only,
|
||||
|
@ -3585,9 +3586,9 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
# NOTE: this must be done before updateConversation is called
|
||||
editedFilename = \
|
||||
editedPostFilename(base_dir, handleName, domain,
|
||||
postJsonObject, debug, 300)
|
||||
post_json_object, debug, 300)
|
||||
|
||||
updateConversation(base_dir, handleName, domain, postJsonObject)
|
||||
updateConversation(base_dir, handleName, domain, post_json_object)
|
||||
|
||||
# If this was an edit then delete the previous version of the post
|
||||
if editedFilename:
|
||||
|
@ -3596,18 +3597,18 @@ def _inboxAfterInitial(recentPostsCache: {}, max_recent_posts: int,
|
|||
debug, recentPostsCache)
|
||||
|
||||
# store the id of the last post made by this actor
|
||||
_storeLastPostId(base_dir, nickname, domain, postJsonObject)
|
||||
_storeLastPostId(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
_inboxUpdateCalendar(base_dir, handle, postJsonObject)
|
||||
_inboxUpdateCalendar(base_dir, handle, post_json_object)
|
||||
|
||||
storeHashTags(base_dir, handleName, domain,
|
||||
http_prefix, domainFull,
|
||||
postJsonObject, translate)
|
||||
post_json_object, translate)
|
||||
|
||||
# send the post out to group members
|
||||
if isGroup:
|
||||
_sendToGroupMembers(session, base_dir, handle, port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
http_prefix, federationList, send_threads,
|
||||
postLog, cachedWebfingers, personCache,
|
||||
debug, systemLanguage,
|
||||
|
|
|
@ -273,13 +273,13 @@ def libretranslate(url: str, text: str,
|
|||
return translatedText
|
||||
|
||||
|
||||
def autoTranslatePost(base_dir: str, postJsonObject: {},
|
||||
def autoTranslatePost(base_dir: str, post_json_object: {},
|
||||
systemLanguage: str, translate: {}) -> str:
|
||||
"""Tries to automatically translate the given post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return ''
|
||||
msgObject = postJsonObject['object']
|
||||
msgObject = post_json_object['object']
|
||||
if not msgObject.get('contentMap'):
|
||||
return ''
|
||||
if not isinstance(msgObject['contentMap'], dict):
|
||||
|
|
40
like.py
40
like.py
|
@ -35,12 +35,12 @@ from auth import createBasicAuthHeader
|
|||
from posts import getPersonBox
|
||||
|
||||
|
||||
def noOfLikes(postJsonObject: {}) -> int:
|
||||
def noOfLikes(post_json_object: {}) -> int:
|
||||
"""Returns the number of likes ona given post
|
||||
"""
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
if not obj.get('likes'):
|
||||
return 0
|
||||
if not isinstance(obj['likes'], dict):
|
||||
|
@ -51,16 +51,16 @@ def noOfLikes(postJsonObject: {}) -> int:
|
|||
return len(obj['likes']['items'])
|
||||
|
||||
|
||||
def likedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
|
||||
def likedByPerson(post_json_object: {}, nickname: str, domain: str) -> bool:
|
||||
"""Returns True if the given post is liked by the given person
|
||||
"""
|
||||
if noOfLikes(postJsonObject) == 0:
|
||||
if noOfLikes(post_json_object) == 0:
|
||||
return False
|
||||
actorMatch = domain + '/users/' + nickname
|
||||
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
|
||||
for item in obj['likes']['items']:
|
||||
if item['actor'].endswith(actorMatch):
|
||||
|
@ -413,19 +413,19 @@ def updateLikesCollection(recentPostsCache: {},
|
|||
base_dir: str, postFilename: str,
|
||||
objectUrl: str, actor: str,
|
||||
nickname: str, domain: str, debug: bool,
|
||||
postJsonObject: {}) -> None:
|
||||
post_json_object: {}) -> None:
|
||||
"""Updates the likes collection within a post
|
||||
"""
|
||||
if not postJsonObject:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
# remove any cached version of this post so that the
|
||||
# like icon is changed
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -434,9 +434,9 @@ def updateLikesCollection(recentPostsCache: {},
|
|||
print('EX: updateLikesCollection unable to delete ' +
|
||||
cachedPostFilename)
|
||||
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
|
||||
if not objectUrl.endswith('/likes'):
|
||||
objectUrl = objectUrl + '/likes'
|
||||
|
@ -472,5 +472,5 @@ def updateLikesCollection(recentPostsCache: {},
|
|||
|
||||
if debug:
|
||||
print('DEBUG: saving post with likes added')
|
||||
pprint(postJsonObject)
|
||||
saveJson(postJsonObject, postFilename)
|
||||
pprint(post_json_object)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
|
22
media.py
22
media.py
|
@ -52,41 +52,41 @@ def _getBlurHash() -> str:
|
|||
return random.choice(hashes)
|
||||
|
||||
|
||||
def _replaceSiloDomain(postJsonObject: {},
|
||||
def _replaceSiloDomain(post_json_object: {},
|
||||
siloDomain: str, replacementDomain: str,
|
||||
systemLanguage: str) -> None:
|
||||
"""Replace a silo domain with a replacement domain
|
||||
"""
|
||||
if not replacementDomain:
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return
|
||||
contentStr = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
contentStr = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if siloDomain not in contentStr:
|
||||
return
|
||||
contentStr = contentStr.replace(siloDomain, replacementDomain)
|
||||
postJsonObject['object']['content'] = contentStr
|
||||
if postJsonObject['object'].get('contentMap'):
|
||||
postJsonObject['object']['contentMap'][systemLanguage] = contentStr
|
||||
post_json_object['object']['content'] = contentStr
|
||||
if post_json_object['object'].get('contentMap'):
|
||||
post_json_object['object']['contentMap'][systemLanguage] = contentStr
|
||||
|
||||
|
||||
def replaceYouTube(postJsonObject: {}, replacementDomain: str,
|
||||
def replaceYouTube(post_json_object: {}, replacementDomain: str,
|
||||
systemLanguage: str) -> None:
|
||||
"""Replace YouTube with a replacement domain
|
||||
This denies Google some, but not all, tracking data
|
||||
"""
|
||||
_replaceSiloDomain(postJsonObject, 'www.youtube.com',
|
||||
_replaceSiloDomain(post_json_object, 'www.youtube.com',
|
||||
replacementDomain, systemLanguage)
|
||||
|
||||
|
||||
def replaceTwitter(postJsonObject: {}, replacementDomain: str,
|
||||
def replaceTwitter(post_json_object: {}, replacementDomain: str,
|
||||
systemLanguage: str) -> None:
|
||||
"""Replace Twitter with a replacement domain
|
||||
This allows you to view twitter posts without having a twitter account
|
||||
"""
|
||||
_replaceSiloDomain(postJsonObject, 'twitter.com',
|
||||
_replaceSiloDomain(post_json_object, 'twitter.com',
|
||||
replacementDomain, systemLanguage)
|
||||
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ def hashtagRuleTree(operators: [],
|
|||
|
||||
|
||||
def _hashtagAdd(base_dir: str, http_prefix: str, domainFull: str,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
actionStr: str, hashtags: [], systemLanguage: str,
|
||||
translate: {}) -> None:
|
||||
"""Adds a hashtag via a hashtag rule
|
||||
|
@ -309,7 +309,7 @@ def _hashtagAdd(base_dir: str, http_prefix: str, domainFull: str,
|
|||
}
|
||||
# does the tag already exist?
|
||||
addTagObject = None
|
||||
for t in postJsonObject['object']['tag']:
|
||||
for t in post_json_object['object']['tag']:
|
||||
if t.get('type') and t.get('name'):
|
||||
if t['type'] == 'Hashtag' and \
|
||||
t['name'] == addHashtag:
|
||||
|
@ -317,12 +317,12 @@ def _hashtagAdd(base_dir: str, http_prefix: str, domainFull: str,
|
|||
break
|
||||
# append the tag if it wasn't found
|
||||
if not addTagObject:
|
||||
postJsonObject['object']['tag'].append(newTag)
|
||||
post_json_object['object']['tag'].append(newTag)
|
||||
# add corresponding html to the post content
|
||||
hashtagHtml = \
|
||||
" <a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \
|
||||
"rel=\"tag\">#<span>" + htId + "</span></a>"
|
||||
content = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
content = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if hashtagHtml in content:
|
||||
return
|
||||
|
||||
|
@ -332,16 +332,16 @@ def _hashtagAdd(base_dir: str, http_prefix: str, domainFull: str,
|
|||
hashtagHtml + '</p>'
|
||||
else:
|
||||
content += hashtagHtml
|
||||
postJsonObject['object']['content'] = content
|
||||
post_json_object['object']['content'] = content
|
||||
domain = domainFull
|
||||
if ':' in domain:
|
||||
domain = domain.split(':')[0]
|
||||
storeHashTags(base_dir, 'news', domain,
|
||||
http_prefix, domainFull,
|
||||
postJsonObject, translate)
|
||||
post_json_object, translate)
|
||||
|
||||
|
||||
def _hashtagRemove(http_prefix: str, domainFull: str, postJsonObject: {},
|
||||
def _hashtagRemove(http_prefix: str, domainFull: str, post_json_object: {},
|
||||
actionStr: str, hashtags: [], systemLanguage: str) -> None:
|
||||
"""Removes a hashtag via a hashtag rule
|
||||
"""
|
||||
|
@ -357,23 +357,23 @@ def _hashtagRemove(http_prefix: str, domainFull: str, postJsonObject: {},
|
|||
hashtagHtml = \
|
||||
"<a href=\"" + hashtagUrl + "\" class=\"addedHashtag\" " + \
|
||||
"rel=\"tag\">#<span>" + htId + "</span></a>"
|
||||
content = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
content = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if hashtagHtml in content:
|
||||
content = content.replace(hashtagHtml, '').replace(' ', ' ')
|
||||
postJsonObject['object']['content'] = content
|
||||
postJsonObject['object']['contentMap'][systemLanguage] = content
|
||||
post_json_object['object']['content'] = content
|
||||
post_json_object['object']['contentMap'][systemLanguage] = content
|
||||
rmTagObject = None
|
||||
for t in postJsonObject['object']['tag']:
|
||||
for t in post_json_object['object']['tag']:
|
||||
if t.get('type') and t.get('name'):
|
||||
if t['type'] == 'Hashtag' and \
|
||||
t['name'] == rmHashtag:
|
||||
rmTagObject = t
|
||||
break
|
||||
if rmTagObject:
|
||||
postJsonObject['object']['tag'].remove(rmTagObject)
|
||||
post_json_object['object']['tag'].remove(rmTagObject)
|
||||
|
||||
|
||||
def _newswireHashtagProcessing(session, base_dir: str, postJsonObject: {},
|
||||
def _newswireHashtagProcessing(session, base_dir: str, post_json_object: {},
|
||||
hashtags: [], http_prefix: str,
|
||||
domain: str, port: int,
|
||||
personCache: {},
|
||||
|
@ -398,10 +398,10 @@ def _newswireHashtagProcessing(session, base_dir: str, postJsonObject: {},
|
|||
|
||||
# get the full text content of the post
|
||||
content = ''
|
||||
if postJsonObject['object'].get('content'):
|
||||
content += getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
if postJsonObject['object'].get('summary'):
|
||||
content += ' ' + postJsonObject['object']['summary']
|
||||
if post_json_object['object'].get('content'):
|
||||
content += getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
if post_json_object['object'].get('summary'):
|
||||
content += ' ' + post_json_object['object']['summary']
|
||||
content = content.lower()
|
||||
|
||||
# actionOccurred = False
|
||||
|
@ -426,11 +426,11 @@ def _newswireHashtagProcessing(session, base_dir: str, postJsonObject: {},
|
|||
if actionStr.startswith('add '):
|
||||
# add a hashtag
|
||||
_hashtagAdd(base_dir, http_prefix, domainFull,
|
||||
postJsonObject, actionStr, hashtags, systemLanguage,
|
||||
post_json_object, actionStr, hashtags, systemLanguage,
|
||||
translate)
|
||||
elif actionStr.startswith('remove '):
|
||||
# remove a hashtag
|
||||
_hashtagRemove(http_prefix, domainFull, postJsonObject,
|
||||
_hashtagRemove(http_prefix, domainFull, post_json_object,
|
||||
actionStr, hashtags, systemLanguage)
|
||||
elif actionStr.startswith('block') or actionStr.startswith('drop'):
|
||||
# Block this item
|
||||
|
|
44
newswire.py
44
newswire.py
|
@ -962,35 +962,35 @@ def getRSSfromDict(base_dir: str, newswire: {},
|
|||
return rssStr
|
||||
|
||||
|
||||
def _isNewswireBlogPost(postJsonObject: {}) -> bool:
|
||||
def _isNewswireBlogPost(post_json_object: {}) -> bool:
|
||||
"""Is the given object a blog post?
|
||||
There isn't any difference between a blog post and a newswire blog post
|
||||
but we may here need to check for different properties than
|
||||
isBlogPost does
|
||||
"""
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if postJsonObject['object'].get('summary') and \
|
||||
postJsonObject['object'].get('url') and \
|
||||
postJsonObject['object'].get('content') and \
|
||||
postJsonObject['object'].get('published'):
|
||||
return isPublicPost(postJsonObject)
|
||||
if post_json_object['object'].get('summary') and \
|
||||
post_json_object['object'].get('url') and \
|
||||
post_json_object['object'].get('content') and \
|
||||
post_json_object['object'].get('published'):
|
||||
return isPublicPost(post_json_object)
|
||||
return False
|
||||
|
||||
|
||||
def _getHashtagsFromPost(postJsonObject: {}) -> []:
|
||||
def _getHashtagsFromPost(post_json_object: {}) -> []:
|
||||
"""Returns a list of any hashtags within a post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return []
|
||||
if not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('tag'):
|
||||
return []
|
||||
if not isinstance(postJsonObject['object']['tag'], list):
|
||||
if not isinstance(post_json_object['object']['tag'], list):
|
||||
return []
|
||||
tags = []
|
||||
for tg in postJsonObject['object']['tag']:
|
||||
for tg in post_json_object['object']['tag']:
|
||||
if not isinstance(tg, dict):
|
||||
continue
|
||||
if not tg.get('name'):
|
||||
|
@ -1051,25 +1051,27 @@ def _addAccountBlogsToNewswire(base_dir: str, nickname: str, domain: str,
|
|||
break
|
||||
continue
|
||||
|
||||
postJsonObject = None
|
||||
post_json_object = None
|
||||
if fullPostFilename:
|
||||
postJsonObject = loadJson(fullPostFilename)
|
||||
if _isNewswireBlogPost(postJsonObject):
|
||||
published = postJsonObject['object']['published']
|
||||
post_json_object = loadJson(fullPostFilename)
|
||||
if _isNewswireBlogPost(post_json_object):
|
||||
published = post_json_object['object']['published']
|
||||
published = published.replace('T', ' ')
|
||||
published = published.replace('Z', '+00:00')
|
||||
votes = []
|
||||
if os.path.isfile(fullPostFilename + '.votes'):
|
||||
votes = loadJson(fullPostFilename + '.votes')
|
||||
content = \
|
||||
getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object,
|
||||
systemLanguage)
|
||||
description = firstParagraphFromString(content)
|
||||
description = removeHtml(description)
|
||||
tagsFromPost = _getHashtagsFromPost(postJsonObject)
|
||||
tagsFromPost = _getHashtagsFromPost(post_json_object)
|
||||
summary = post_json_object['object']['summary']
|
||||
_addNewswireDictEntry(base_dir, domain,
|
||||
newswire, published,
|
||||
postJsonObject['object']['summary'],
|
||||
postJsonObject['object']['url'],
|
||||
summary,
|
||||
post_json_object['object']['url'],
|
||||
votes, fullPostFilename,
|
||||
description, moderated, False,
|
||||
tagsFromPost,
|
||||
|
|
|
@ -1657,14 +1657,14 @@ def addActorUpdateTimestamp(actorJson: {}) -> None:
|
|||
def validSendingActor(session, base_dir: str,
|
||||
nickname: str, domain: str,
|
||||
personCache: {},
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
signingPrivateKeyPem: str,
|
||||
debug: bool, unit_test: bool) -> bool:
|
||||
"""When a post arrives in the inbox this is used to check that
|
||||
the sending actor is valid
|
||||
"""
|
||||
# who sent this post?
|
||||
sendingActor = postJsonObject['actor']
|
||||
sendingActor = post_json_object['actor']
|
||||
|
||||
# If you are following them then allow their posts
|
||||
if isFollowingActor(base_dir, nickname, domain, sendingActor):
|
||||
|
|
424
posts.py
424
posts.py
|
@ -906,7 +906,7 @@ def deleteAllPosts(base_dir: str,
|
|||
|
||||
|
||||
def savePostToBox(base_dir: str, http_prefix: str, postId: str,
|
||||
nickname: str, domain: str, postJsonObject: {},
|
||||
nickname: str, domain: str, post_json_object: {},
|
||||
boxname: str) -> str:
|
||||
"""Saves the give json to the give box
|
||||
Returns the filename
|
||||
|
@ -923,15 +923,15 @@ def savePostToBox(base_dir: str, http_prefix: str, postId: str,
|
|||
postId = \
|
||||
localActorUrl(http_prefix, nickname, originalDomain) + \
|
||||
'/statuses/' + statusNumber
|
||||
postJsonObject['id'] = postId + '/activity'
|
||||
if hasObjectDict(postJsonObject):
|
||||
postJsonObject['object']['id'] = postId
|
||||
postJsonObject['object']['atomUri'] = postId
|
||||
post_json_object['id'] = postId + '/activity'
|
||||
if hasObjectDict(post_json_object):
|
||||
post_json_object['object']['id'] = postId
|
||||
post_json_object['object']['atomUri'] = postId
|
||||
|
||||
boxDir = createPersonDir(nickname, domain, base_dir, boxname)
|
||||
filename = boxDir + '/' + postId.replace('/', '#') + '.json'
|
||||
|
||||
saveJson(postJsonObject, filename)
|
||||
saveJson(post_json_object, filename)
|
||||
return filename
|
||||
|
||||
|
||||
|
@ -1601,26 +1601,26 @@ def outboxMessageCreateWrap(http_prefix: str,
|
|||
def _postIsAddressedToFollowers(base_dir: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
http_prefix: str,
|
||||
postJsonObject: {}) -> bool:
|
||||
post_json_object: {}) -> bool:
|
||||
"""Returns true if the given post is addressed to followers of the nickname
|
||||
"""
|
||||
domainFull = getFullDomain(domain, port)
|
||||
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
return False
|
||||
toList = []
|
||||
ccList = []
|
||||
if postJsonObject['type'] != 'Update' and \
|
||||
hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('to'):
|
||||
toList = postJsonObject['object']['to']
|
||||
if postJsonObject['object'].get('cc'):
|
||||
ccList = postJsonObject['object']['cc']
|
||||
if post_json_object['type'] != 'Update' and \
|
||||
hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('to'):
|
||||
toList = post_json_object['object']['to']
|
||||
if post_json_object['object'].get('cc'):
|
||||
ccList = post_json_object['object']['cc']
|
||||
else:
|
||||
if postJsonObject.get('to'):
|
||||
toList = postJsonObject['to']
|
||||
if postJsonObject.get('cc'):
|
||||
ccList = postJsonObject['cc']
|
||||
if post_json_object.get('to'):
|
||||
toList = post_json_object['to']
|
||||
if post_json_object.get('cc'):
|
||||
ccList = post_json_object['cc']
|
||||
|
||||
followersUrl = \
|
||||
localActorUrl(http_prefix, nickname, domainFull) + '/followers'
|
||||
|
@ -2163,13 +2163,13 @@ def createReportPost(base_dir: str,
|
|||
print(str(moderatorsList))
|
||||
postTo = moderatorsList
|
||||
postCc = None
|
||||
postJsonObject = None
|
||||
post_json_object = None
|
||||
for toUrl in postTo:
|
||||
# who is this report going to?
|
||||
toNickname = toUrl.split('/users/')[1]
|
||||
handle = toNickname + '@' + domain
|
||||
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_createPostBase(base_dir, nickname, domain, port,
|
||||
toUrl, postCc,
|
||||
http_prefix, content, followersOnly, saveToFile,
|
||||
|
@ -2181,7 +2181,7 @@ def createReportPost(base_dir: str,
|
|||
None, None, None,
|
||||
None, None, None, None, None, systemLanguage,
|
||||
None, low_bandwidth, content_license_url)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
continue
|
||||
|
||||
# save a notification file so that the moderator
|
||||
|
@ -2195,7 +2195,7 @@ def createReportPost(base_dir: str,
|
|||
except OSError:
|
||||
print('EX: createReportPost unable to write ' + newReportFile)
|
||||
|
||||
return postJsonObject
|
||||
return post_json_object
|
||||
|
||||
|
||||
def threadSendPost(session, postJsonStr: str, federationList: [],
|
||||
|
@ -2330,7 +2330,7 @@ def sendPost(signingPrivateKeyPem: str, project_version: str,
|
|||
return 5
|
||||
# sharedInbox is optional
|
||||
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_createPostBase(base_dir, nickname, domain, port,
|
||||
toPersonId, cc, http_prefix, content,
|
||||
followersOnly, saveToFile, client_to_server,
|
||||
|
@ -2354,18 +2354,18 @@ def sendPost(signingPrivateKeyPem: str, project_version: str,
|
|||
return 7
|
||||
postPath = inboxUrl.split(toDomain, 1)[1]
|
||||
|
||||
if not postJsonObject.get('signature'):
|
||||
if not post_json_object.get('signature'):
|
||||
try:
|
||||
signedPostJsonObject = postJsonObject.copy()
|
||||
signedPostJsonObject = post_json_object.copy()
|
||||
generateJsonSignature(signedPostJsonObject, privateKeyPem)
|
||||
postJsonObject = signedPostJsonObject
|
||||
post_json_object = signedPostJsonObject
|
||||
except Exception as ex:
|
||||
print('WARN: failed to JSON-LD sign post, ' + str(ex))
|
||||
pass
|
||||
|
||||
# convert json to string so that there are no
|
||||
# subsequent conversions after creating message body digest
|
||||
postJsonStr = json.dumps(postJsonObject)
|
||||
postJsonStr = json.dumps(post_json_object)
|
||||
|
||||
# construct the http header, including the message body digest
|
||||
signatureHeaderJson = \
|
||||
|
@ -2498,7 +2498,7 @@ def sendPostViaServer(signingPrivateKeyPem: str, project_version: str,
|
|||
toDomainFull = getFullDomain(toDomain, toPort)
|
||||
toPersonId = localActorUrl(http_prefix, toNickname, toDomainFull)
|
||||
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
_createPostBase(base_dir,
|
||||
fromNickname, fromDomain, fromPort,
|
||||
toPersonId, cc, http_prefix, content,
|
||||
|
@ -2534,7 +2534,7 @@ def sendPostViaServer(signingPrivateKeyPem: str, project_version: str,
|
|||
'Content-type': 'application/json',
|
||||
'Authorization': authHeader
|
||||
}
|
||||
postDumps = json.dumps(postJsonObject)
|
||||
postDumps = json.dumps(post_json_object)
|
||||
postResult, unauthorized, returnCode = \
|
||||
postJsonString(session, postDumps, [],
|
||||
inboxUrl, headers, debug, 5, True)
|
||||
|
@ -2575,39 +2575,40 @@ def groupFollowersByDomain(base_dir: str, nickname: str, domain: str) -> {}:
|
|||
return grouped
|
||||
|
||||
|
||||
def _addFollowersToPublicPost(postJsonObject: {}) -> None:
|
||||
def _addFollowersToPublicPost(post_json_object: {}) -> None:
|
||||
"""Adds followers entry to cc if it doesn't exist
|
||||
"""
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return
|
||||
|
||||
if isinstance(postJsonObject['object'], str):
|
||||
if not postJsonObject.get('to'):
|
||||
if isinstance(post_json_object['object'], str):
|
||||
if not post_json_object.get('to'):
|
||||
return
|
||||
if len(postJsonObject['to']) > 1:
|
||||
if len(post_json_object['to']) > 1:
|
||||
return
|
||||
if len(postJsonObject['to']) == 0:
|
||||
if len(post_json_object['to']) == 0:
|
||||
return
|
||||
if not postJsonObject['to'][0].endswith('#Public'):
|
||||
if not post_json_object['to'][0].endswith('#Public'):
|
||||
return
|
||||
if postJsonObject.get('cc'):
|
||||
if post_json_object.get('cc'):
|
||||
return
|
||||
postJsonObject['cc'] = postJsonObject['actor'] + '/followers'
|
||||
elif hasObjectDict(postJsonObject):
|
||||
if not postJsonObject['object'].get('to'):
|
||||
post_json_object['cc'] = post_json_object['actor'] + '/followers'
|
||||
elif hasObjectDict(post_json_object):
|
||||
if not post_json_object['object'].get('to'):
|
||||
return
|
||||
if len(postJsonObject['object']['to']) > 1:
|
||||
if len(post_json_object['object']['to']) > 1:
|
||||
return
|
||||
elif len(postJsonObject['object']['to']) == 0:
|
||||
elif len(post_json_object['object']['to']) == 0:
|
||||
return
|
||||
elif not postJsonObject['object']['to'][0].endswith('#Public'):
|
||||
elif not post_json_object['object']['to'][0].endswith('#Public'):
|
||||
return
|
||||
if postJsonObject['object'].get('cc'):
|
||||
if post_json_object['object'].get('cc'):
|
||||
return
|
||||
postJsonObject['object']['cc'] = postJsonObject['actor'] + '/followers'
|
||||
post_json_object['object']['cc'] = \
|
||||
post_json_object['actor'] + '/followers'
|
||||
|
||||
|
||||
def sendSignedJson(postJsonObject: {}, session, base_dir: str,
|
||||
def sendSignedJson(post_json_object: {}, session, base_dir: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
toNickname: str, toDomain: str, toPort: int, cc: str,
|
||||
http_prefix: str, saveToFile: bool, client_to_server: bool,
|
||||
|
@ -2724,20 +2725,20 @@ def sendSignedJson(postJsonObject: {}, session, base_dir: str,
|
|||
return 7
|
||||
postPath = inboxUrl.split(toDomain, 1)[1]
|
||||
|
||||
_addFollowersToPublicPost(postJsonObject)
|
||||
_addFollowersToPublicPost(post_json_object)
|
||||
|
||||
if not postJsonObject.get('signature'):
|
||||
if not post_json_object.get('signature'):
|
||||
try:
|
||||
signedPostJsonObject = postJsonObject.copy()
|
||||
signedPostJsonObject = post_json_object.copy()
|
||||
generateJsonSignature(signedPostJsonObject, privateKeyPem)
|
||||
postJsonObject = signedPostJsonObject
|
||||
post_json_object = signedPostJsonObject
|
||||
except Exception as ex:
|
||||
print('WARN: failed to JSON-LD sign post, ' + str(ex))
|
||||
pass
|
||||
|
||||
# convert json to string so that there are no
|
||||
# subsequent conversions after creating message body digest
|
||||
postJsonStr = json.dumps(postJsonObject)
|
||||
postJsonStr = json.dumps(post_json_object)
|
||||
|
||||
# construct the http header, including the message body digest
|
||||
signatureHeaderJson = \
|
||||
|
@ -2762,7 +2763,7 @@ def sendSignedJson(postJsonObject: {}, session, base_dir: str,
|
|||
|
||||
if debug:
|
||||
print('DEBUG: starting thread to send post')
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
thr = \
|
||||
threadWithTrace(target=threadSendPost,
|
||||
args=(session,
|
||||
|
@ -2777,81 +2778,81 @@ def sendSignedJson(postJsonObject: {}, session, base_dir: str,
|
|||
return 0
|
||||
|
||||
|
||||
def addToField(activityType: str, postJsonObject: {},
|
||||
def addToField(activityType: str, post_json_object: {},
|
||||
debug: bool) -> ({}, bool):
|
||||
"""The Follow/Add/Remove activity doesn't have a 'to' field and so one
|
||||
needs to be added so that activity distribution happens in a consistent way
|
||||
Returns true if a 'to' field exists or was added
|
||||
"""
|
||||
if postJsonObject.get('to'):
|
||||
return postJsonObject, True
|
||||
if post_json_object.get('to'):
|
||||
return post_json_object, True
|
||||
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('DEBUG: no "to" field when sending to named addresses 2')
|
||||
|
||||
isSameType = False
|
||||
toFieldAdded = False
|
||||
if postJsonObject.get('object'):
|
||||
if isinstance(postJsonObject['object'], str):
|
||||
if postJsonObject.get('type'):
|
||||
if postJsonObject['type'] == activityType:
|
||||
if post_json_object.get('object'):
|
||||
if isinstance(post_json_object['object'], str):
|
||||
if post_json_object.get('type'):
|
||||
if post_json_object['type'] == activityType:
|
||||
isSameType = True
|
||||
if debug:
|
||||
print('DEBUG: "to" field assigned to ' + activityType)
|
||||
toAddress = postJsonObject['object']
|
||||
toAddress = post_json_object['object']
|
||||
if '/statuses/' in toAddress:
|
||||
toAddress = toAddress.split('/statuses/')[0]
|
||||
postJsonObject['to'] = [toAddress]
|
||||
post_json_object['to'] = [toAddress]
|
||||
toFieldAdded = True
|
||||
elif hasObjectDict(postJsonObject):
|
||||
elif hasObjectDict(post_json_object):
|
||||
# add a to field to bookmark add or remove
|
||||
if postJsonObject.get('type') and \
|
||||
postJsonObject.get('actor') and \
|
||||
postJsonObject['object'].get('type'):
|
||||
if postJsonObject['type'] == 'Add' or \
|
||||
postJsonObject['type'] == 'Remove':
|
||||
if postJsonObject['object']['type'] == 'Document':
|
||||
postJsonObject['to'] = \
|
||||
[postJsonObject['actor']]
|
||||
postJsonObject['object']['to'] = \
|
||||
[postJsonObject['actor']]
|
||||
if post_json_object.get('type') and \
|
||||
post_json_object.get('actor') and \
|
||||
post_json_object['object'].get('type'):
|
||||
if post_json_object['type'] == 'Add' or \
|
||||
post_json_object['type'] == 'Remove':
|
||||
if post_json_object['object']['type'] == 'Document':
|
||||
post_json_object['to'] = \
|
||||
[post_json_object['actor']]
|
||||
post_json_object['object']['to'] = \
|
||||
[post_json_object['actor']]
|
||||
toFieldAdded = True
|
||||
|
||||
if not toFieldAdded and \
|
||||
postJsonObject['object'].get('type'):
|
||||
if postJsonObject['object']['type'] == activityType:
|
||||
post_json_object['object'].get('type'):
|
||||
if post_json_object['object']['type'] == activityType:
|
||||
isSameType = True
|
||||
if isinstance(postJsonObject['object']['object'], str):
|
||||
if isinstance(post_json_object['object']['object'], str):
|
||||
if debug:
|
||||
print('DEBUG: "to" field assigned to ' +
|
||||
activityType)
|
||||
toAddress = postJsonObject['object']['object']
|
||||
toAddress = post_json_object['object']['object']
|
||||
if '/statuses/' in toAddress:
|
||||
toAddress = toAddress.split('/statuses/')[0]
|
||||
postJsonObject['object']['to'] = [toAddress]
|
||||
postJsonObject['to'] = \
|
||||
[postJsonObject['object']['object']]
|
||||
post_json_object['object']['to'] = [toAddress]
|
||||
post_json_object['to'] = \
|
||||
[post_json_object['object']['object']]
|
||||
toFieldAdded = True
|
||||
|
||||
if not isSameType:
|
||||
return postJsonObject, True
|
||||
return post_json_object, True
|
||||
if toFieldAdded:
|
||||
return postJsonObject, True
|
||||
return postJsonObject, False
|
||||
return post_json_object, True
|
||||
return post_json_object, False
|
||||
|
||||
|
||||
def _isProfileUpdate(postJsonObject: {}) -> bool:
|
||||
def _isProfileUpdate(post_json_object: {}) -> bool:
|
||||
"""Is the given post a profile update?
|
||||
for actor updates there is no 'to' within the object
|
||||
"""
|
||||
if postJsonObject.get('type'):
|
||||
if hasObjectStringType(postJsonObject, False):
|
||||
if (postJsonObject['type'] == 'Update' and
|
||||
(postJsonObject['object']['type'] == 'Person' or
|
||||
postJsonObject['object']['type'] == 'Application' or
|
||||
postJsonObject['object']['type'] == 'Group' or
|
||||
postJsonObject['object']['type'] == 'Service')):
|
||||
if post_json_object.get('type'):
|
||||
if hasObjectStringType(post_json_object, False):
|
||||
if (post_json_object['type'] == 'Update' and
|
||||
(post_json_object['object']['type'] == 'Person' or
|
||||
post_json_object['object']['type'] == 'Application' or
|
||||
post_json_object['object']['type'] == 'Group' or
|
||||
post_json_object['object']['type'] == 'Service')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -2862,7 +2863,7 @@ def _sendToNamedAddresses(session, base_dir: str,
|
|||
http_prefix: str, federationList: [],
|
||||
send_threads: [], postLog: [],
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
project_version: str,
|
||||
shared_items_federated_domains: [],
|
||||
sharedItemFederationTokens: {},
|
||||
|
@ -2872,41 +2873,43 @@ def _sendToNamedAddresses(session, base_dir: str,
|
|||
if not session:
|
||||
print('WARN: No session for sendToNamedAddresses')
|
||||
return
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
return
|
||||
isProfileUpdate = False
|
||||
if hasObjectDict(postJsonObject):
|
||||
if _isProfileUpdate(postJsonObject):
|
||||
if hasObjectDict(post_json_object):
|
||||
if _isProfileUpdate(post_json_object):
|
||||
# use the original object, which has a 'to'
|
||||
recipientsObject = postJsonObject
|
||||
recipientsObject = post_json_object
|
||||
isProfileUpdate = True
|
||||
|
||||
if not isProfileUpdate:
|
||||
if not postJsonObject['object'].get('to'):
|
||||
if not post_json_object['object'].get('to'):
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('DEBUG: ' +
|
||||
'no "to" field when sending to named addresses')
|
||||
if hasObjectStringType(postJsonObject, debug):
|
||||
if postJsonObject['object']['type'] == 'Follow' or \
|
||||
postJsonObject['object']['type'] == 'Join':
|
||||
if isinstance(postJsonObject['object']['object'], str):
|
||||
if hasObjectStringType(post_json_object, debug):
|
||||
if post_json_object['object']['type'] == 'Follow' or \
|
||||
post_json_object['object']['type'] == 'Join':
|
||||
post_json_obj2 = post_json_object['object']['object']
|
||||
if isinstance(post_json_obj2, str):
|
||||
if debug:
|
||||
print('DEBUG: "to" field assigned to Follow')
|
||||
postJsonObject['object']['to'] = \
|
||||
[postJsonObject['object']['object']]
|
||||
if not postJsonObject['object'].get('to'):
|
||||
post_json_object['object']['to'] = \
|
||||
[post_json_object['object']['object']]
|
||||
if not post_json_object['object'].get('to'):
|
||||
return
|
||||
recipientsObject = postJsonObject['object']
|
||||
recipientsObject = post_json_object['object']
|
||||
else:
|
||||
postJsonObject, fieldAdded = \
|
||||
addToField('Follow', postJsonObject, debug)
|
||||
post_json_object, fieldAdded = \
|
||||
addToField('Follow', post_json_object, debug)
|
||||
if not fieldAdded:
|
||||
return
|
||||
postJsonObject, fieldAdded = addToField('Like', postJsonObject, debug)
|
||||
post_json_object, fieldAdded = \
|
||||
addToField('Like', post_json_object, debug)
|
||||
if not fieldAdded:
|
||||
return
|
||||
recipientsObject = postJsonObject
|
||||
recipientsObject = post_json_object
|
||||
|
||||
recipients = []
|
||||
recipientType = ('to', 'cc')
|
||||
|
@ -2996,7 +2999,7 @@ def _sendToNamedAddresses(session, base_dir: str,
|
|||
|
||||
groupAccount = hasGroupType(base_dir, address, personCache)
|
||||
|
||||
sendSignedJson(postJsonObject, session, base_dir,
|
||||
sendSignedJson(post_json_object, session, base_dir,
|
||||
nickname, fromDomain, port,
|
||||
toNickname, toDomain, toPort,
|
||||
cc, fromHttpPrefix, True, client_to_server,
|
||||
|
@ -3013,7 +3016,7 @@ def sendToNamedAddressesThread(session, base_dir: str,
|
|||
http_prefix: str, federationList: [],
|
||||
send_threads: [], postLog: [],
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
project_version: str,
|
||||
shared_items_federated_domains: [],
|
||||
sharedItemFederationTokens: {},
|
||||
|
@ -3028,7 +3031,7 @@ def sendToNamedAddressesThread(session, base_dir: str,
|
|||
http_prefix, federationList,
|
||||
send_threads, postLog,
|
||||
cachedWebfingers, personCache,
|
||||
postJsonObject, debug,
|
||||
post_json_object, debug,
|
||||
project_version,
|
||||
shared_items_federated_domains,
|
||||
sharedItemFederationTokens,
|
||||
|
@ -3066,14 +3069,14 @@ def _hasSharedInbox(session, http_prefix: str, domain: str,
|
|||
return False
|
||||
|
||||
|
||||
def _sendingProfileUpdate(postJsonObject: {}) -> bool:
|
||||
def _sendingProfileUpdate(post_json_object: {}) -> bool:
|
||||
"""Returns true if the given json is a profile update
|
||||
"""
|
||||
if postJsonObject['type'] != 'Update':
|
||||
if post_json_object['type'] != 'Update':
|
||||
return False
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
if not hasObjectStringType(post_json_object, False):
|
||||
return False
|
||||
activityType = postJsonObject['object']['type']
|
||||
activityType = post_json_object['object']['type']
|
||||
if activityType == 'Person' or \
|
||||
activityType == 'Application' or \
|
||||
activityType == 'Group' or \
|
||||
|
@ -3089,7 +3092,7 @@ def sendToFollowers(session, base_dir: str,
|
|||
http_prefix: str, federationList: [],
|
||||
send_threads: [], postLog: [],
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
project_version: str,
|
||||
shared_items_federated_domains: [],
|
||||
sharedItemFederationTokens: {},
|
||||
|
@ -3102,7 +3105,7 @@ def sendToFollowers(session, base_dir: str,
|
|||
return
|
||||
if not _postIsAddressedToFollowers(base_dir, nickname, domain,
|
||||
port, http_prefix,
|
||||
postJsonObject):
|
||||
post_json_object):
|
||||
if debug:
|
||||
print('Post is not addressed to followers')
|
||||
return
|
||||
|
@ -3196,8 +3199,8 @@ def sendToFollowers(session, base_dir: str,
|
|||
if len(followerHandles) > 1:
|
||||
toNickname = 'inbox'
|
||||
|
||||
if toNickname != 'inbox' and postJsonObject.get('type'):
|
||||
if _sendingProfileUpdate(postJsonObject):
|
||||
if toNickname != 'inbox' and post_json_object.get('type'):
|
||||
if _sendingProfileUpdate(post_json_object):
|
||||
print('Sending post to followers ' +
|
||||
'shared inbox of ' + toDomain)
|
||||
toNickname = 'inbox'
|
||||
|
@ -3206,7 +3209,7 @@ def sendToFollowers(session, base_dir: str,
|
|||
nickname + '@' + domain +
|
||||
' to ' + toNickname + '@' + toDomain)
|
||||
|
||||
sendSignedJson(postJsonObject, session, base_dir,
|
||||
sendSignedJson(post_json_object, session, base_dir,
|
||||
nickname, fromDomain, port,
|
||||
toNickname, toDomain, toPort,
|
||||
cc, fromHttpPrefix, True, client_to_server,
|
||||
|
@ -3226,7 +3229,7 @@ def sendToFollowers(session, base_dir: str,
|
|||
groupAccount = True
|
||||
toNickname = toNickname[1:]
|
||||
|
||||
if postJsonObject['type'] != 'Update':
|
||||
if post_json_object['type'] != 'Update':
|
||||
print('Sending post to followers from ' +
|
||||
nickname + '@' + domain + ' to ' +
|
||||
toNickname + '@' + toDomain)
|
||||
|
@ -3235,7 +3238,7 @@ def sendToFollowers(session, base_dir: str,
|
|||
nickname + '@' + domain + ' to ' +
|
||||
toNickname + '@' + toDomain)
|
||||
|
||||
sendSignedJson(postJsonObject, session, base_dir,
|
||||
sendSignedJson(post_json_object, session, base_dir,
|
||||
nickname, fromDomain, port,
|
||||
toNickname, toDomain, toPort,
|
||||
cc, fromHttpPrefix, True, client_to_server,
|
||||
|
@ -3262,7 +3265,7 @@ def sendToFollowersThread(session, base_dir: str,
|
|||
http_prefix: str, federationList: [],
|
||||
send_threads: [], postLog: [],
|
||||
cachedWebfingers: {}, personCache: {},
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
project_version: str,
|
||||
shared_items_federated_domains: [],
|
||||
sharedItemFederationTokens: {},
|
||||
|
@ -3277,7 +3280,7 @@ def sendToFollowersThread(session, base_dir: str,
|
|||
http_prefix, federationList,
|
||||
send_threads, postLog,
|
||||
cachedWebfingers, personCache,
|
||||
postJsonObject.copy(), debug,
|
||||
post_json_object.copy(), debug,
|
||||
project_version,
|
||||
shared_items_federated_domains,
|
||||
sharedItemFederationTokens,
|
||||
|
@ -3441,9 +3444,9 @@ def createModeration(base_dir: str, nickname: str, domain: str, port: int,
|
|||
postFilename = \
|
||||
boxDir + '/' + postUrl.replace('/', '#') + '.json'
|
||||
if os.path.isfile(postFilename):
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
boxItems['orderedItems'].append(postJsonObject)
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
boxItems['orderedItems'].append(post_json_object)
|
||||
|
||||
if headerOnly:
|
||||
return boxHeader
|
||||
|
@ -3452,7 +3455,7 @@ def createModeration(base_dir: str, nickname: str, domain: str, port: int,
|
|||
|
||||
def isImageMedia(session, base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str,
|
||||
postJsonObject: {}, translate: {},
|
||||
post_json_object: {}, translate: {},
|
||||
yt_replace_domain: str,
|
||||
twitter_replacement_domain: str,
|
||||
allow_local_network_access: bool,
|
||||
|
@ -3462,11 +3465,11 @@ def isImageMedia(session, base_dir: str, http_prefix: str,
|
|||
signingPrivateKeyPem: str) -> bool:
|
||||
"""Returns true if the given post has attached image media
|
||||
"""
|
||||
if postJsonObject['type'] == 'Announce':
|
||||
if post_json_object['type'] == 'Announce':
|
||||
blockedCache = {}
|
||||
postJsonAnnounce = \
|
||||
downloadAnnounce(session, base_dir, http_prefix,
|
||||
nickname, domain, postJsonObject,
|
||||
nickname, domain, post_json_object,
|
||||
__version__, translate,
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
|
@ -3477,23 +3480,23 @@ def isImageMedia(session, base_dir: str, http_prefix: str,
|
|||
signingPrivateKeyPem,
|
||||
blockedCache)
|
||||
if postJsonAnnounce:
|
||||
postJsonObject = postJsonAnnounce
|
||||
if postJsonObject['type'] != 'Create':
|
||||
post_json_object = postJsonAnnounce
|
||||
if post_json_object['type'] != 'Create':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if postJsonObject['object'].get('moderationStatus'):
|
||||
if post_json_object['object'].get('moderationStatus'):
|
||||
return False
|
||||
if postJsonObject['object']['type'] != 'Note' and \
|
||||
postJsonObject['object']['type'] != 'Page' and \
|
||||
postJsonObject['object']['type'] != 'Event' and \
|
||||
postJsonObject['object']['type'] != 'Article':
|
||||
if post_json_object['object']['type'] != 'Note' and \
|
||||
post_json_object['object']['type'] != 'Page' and \
|
||||
post_json_object['object']['type'] != 'Event' and \
|
||||
post_json_object['object']['type'] != 'Article':
|
||||
return False
|
||||
if not postJsonObject['object'].get('attachment'):
|
||||
if not post_json_object['object'].get('attachment'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object']['attachment'], list):
|
||||
if not isinstance(post_json_object['object']['attachment'], list):
|
||||
return False
|
||||
for attach in postJsonObject['object']['attachment']:
|
||||
for attach in post_json_object['object']['attachment']:
|
||||
if attach.get('mediaType') and attach.get('url'):
|
||||
if attach['mediaType'].startswith('image/') or \
|
||||
attach['mediaType'].startswith('audio/') or \
|
||||
|
@ -3559,24 +3562,24 @@ def _addPostToTimeline(filePath: str, boxname: str,
|
|||
return False
|
||||
|
||||
|
||||
def removePostInteractions(postJsonObject: {}, force: bool) -> bool:
|
||||
def removePostInteractions(post_json_object: {}, force: bool) -> bool:
|
||||
""" Don't show likes, replies, bookmarks, DMs or shares (announces) to
|
||||
unauthorized viewers. This makes the timeline less useful to
|
||||
marketers and other surveillance-oriented organizations.
|
||||
Returns False if this is a private post
|
||||
"""
|
||||
hasObject = False
|
||||
if hasObjectDict(postJsonObject):
|
||||
if hasObjectDict(post_json_object):
|
||||
hasObject = True
|
||||
if hasObject:
|
||||
postObj = postJsonObject['object']
|
||||
postObj = post_json_object['object']
|
||||
if not force:
|
||||
# If not authorized and it's a private post
|
||||
# then just don't show it within timelines
|
||||
if not isPublicPost(postJsonObject):
|
||||
if not isPublicPost(post_json_object):
|
||||
return False
|
||||
else:
|
||||
postObj = postJsonObject
|
||||
postObj = post_json_object
|
||||
|
||||
# clear the likes
|
||||
if postObj.get('likes'):
|
||||
|
@ -4442,10 +4445,10 @@ def populateRepliesJson(base_dir: str, nickname: str, domain: str,
|
|||
if os.path.isfile(searchFilename):
|
||||
if authorized or \
|
||||
pubStr in open(searchFilename).read():
|
||||
postJsonObject = loadJson(searchFilename)
|
||||
if postJsonObject:
|
||||
if postJsonObject['object'].get('cc'):
|
||||
pjo = postJsonObject
|
||||
post_json_object = loadJson(searchFilename)
|
||||
if post_json_object:
|
||||
if post_json_object['object'].get('cc'):
|
||||
pjo = post_json_object
|
||||
if (authorized or
|
||||
(pubStr in pjo['object']['to'] or
|
||||
pubStr in pjo['object']['cc'])):
|
||||
|
@ -4453,8 +4456,8 @@ def populateRepliesJson(base_dir: str, nickname: str, domain: str,
|
|||
replyFound = True
|
||||
else:
|
||||
if authorized or \
|
||||
pubStr in postJsonObject['object']['to']:
|
||||
pjo = postJsonObject
|
||||
pubStr in post_json_object['object']['to']:
|
||||
pjo = post_json_object
|
||||
repliesJson['orderedItems'].append(pjo)
|
||||
replyFound = True
|
||||
break
|
||||
|
@ -4471,19 +4474,19 @@ def populateRepliesJson(base_dir: str, nickname: str, domain: str,
|
|||
pubStr in open(searchFilename).read():
|
||||
# get the json of the reply and append it to
|
||||
# the collection
|
||||
postJsonObject = loadJson(searchFilename)
|
||||
if postJsonObject:
|
||||
if postJsonObject['object'].get('cc'):
|
||||
pjo = postJsonObject
|
||||
post_json_object = loadJson(searchFilename)
|
||||
if post_json_object:
|
||||
if post_json_object['object'].get('cc'):
|
||||
pjo = post_json_object
|
||||
if (authorized or
|
||||
(pubStr in pjo['object']['to'] or
|
||||
pubStr in pjo['object']['cc'])):
|
||||
pjo = postJsonObject
|
||||
pjo = post_json_object
|
||||
repliesJson['orderedItems'].append(pjo)
|
||||
else:
|
||||
if authorized or \
|
||||
pubStr in postJsonObject['object']['to']:
|
||||
pjo = postJsonObject
|
||||
pubStr in post_json_object['object']['to']:
|
||||
pjo = post_json_object
|
||||
repliesJson['orderedItems'].append(pjo)
|
||||
|
||||
|
||||
|
@ -4502,7 +4505,7 @@ def _rejectAnnounce(announceFilename: str,
|
|||
|
||||
def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str,
|
||||
postJsonObject: {}, project_version: str,
|
||||
post_json_object: {}, project_version: str,
|
||||
translate: {},
|
||||
yt_replace_domain: str,
|
||||
twitter_replacement_domain: str,
|
||||
|
@ -4514,12 +4517,12 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
blockedCache: {}) -> {}:
|
||||
"""Download the post referenced by an announce
|
||||
"""
|
||||
if not postJsonObject.get('object'):
|
||||
if not post_json_object.get('object'):
|
||||
return None
|
||||
if not isinstance(postJsonObject['object'], str):
|
||||
if not isinstance(post_json_object['object'], str):
|
||||
return None
|
||||
# ignore self-boosts
|
||||
if postJsonObject['actor'] in postJsonObject['object']:
|
||||
if post_json_object['actor'] in post_json_object['object']:
|
||||
return None
|
||||
|
||||
# get the announced post
|
||||
|
@ -4528,11 +4531,11 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
os.mkdir(announceCacheDir)
|
||||
|
||||
postId = None
|
||||
if postJsonObject.get('id'):
|
||||
postId = removeIdEnding(postJsonObject['id'])
|
||||
if post_json_object.get('id'):
|
||||
postId = removeIdEnding(post_json_object['id'])
|
||||
announceFilename = \
|
||||
announceCacheDir + '/' + \
|
||||
postJsonObject['object'].replace('/', '#') + '.json'
|
||||
post_json_object['object'].replace('/', '#') + '.json'
|
||||
|
||||
if os.path.isfile(announceFilename + '.reject'):
|
||||
return None
|
||||
|
@ -4540,10 +4543,10 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
if os.path.isfile(announceFilename):
|
||||
if debug:
|
||||
print('Reading cached Announce content for ' +
|
||||
postJsonObject['object'])
|
||||
postJsonObject = loadJson(announceFilename)
|
||||
if postJsonObject:
|
||||
return postJsonObject
|
||||
post_json_object['object'])
|
||||
post_json_object = loadJson(announceFilename)
|
||||
if post_json_object:
|
||||
return post_json_object
|
||||
else:
|
||||
profileStr = 'https://www.w3.org/ns/activitystreams'
|
||||
acceptStr = \
|
||||
|
@ -4552,31 +4555,32 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
asHeader = {
|
||||
'Accept': acceptStr
|
||||
}
|
||||
if '/channel/' in postJsonObject['actor'] or \
|
||||
'/accounts/' in postJsonObject['actor']:
|
||||
if '/channel/' in post_json_object['actor'] or \
|
||||
'/accounts/' in post_json_object['actor']:
|
||||
acceptStr = \
|
||||
'application/ld+json; ' + \
|
||||
'profile="' + profileStr + '"'
|
||||
asHeader = {
|
||||
'Accept': acceptStr
|
||||
}
|
||||
actorNickname = getNicknameFromActor(postJsonObject['actor'])
|
||||
actorDomain, actorPort = getDomainFromActor(postJsonObject['actor'])
|
||||
actorNickname = getNicknameFromActor(post_json_object['actor'])
|
||||
actorDomain, actorPort = getDomainFromActor(post_json_object['actor'])
|
||||
if not actorDomain:
|
||||
print('Announce actor does not contain a ' +
|
||||
'valid domain or port number: ' +
|
||||
str(postJsonObject['actor']))
|
||||
str(post_json_object['actor']))
|
||||
return None
|
||||
if isBlocked(base_dir, nickname, domain, actorNickname, actorDomain):
|
||||
print('Announce download blocked actor: ' +
|
||||
actorNickname + '@' + actorDomain)
|
||||
return None
|
||||
objectNickname = getNicknameFromActor(postJsonObject['object'])
|
||||
objectDomain, objectPort = getDomainFromActor(postJsonObject['object'])
|
||||
objectNickname = getNicknameFromActor(post_json_object['object'])
|
||||
objectDomain, objectPort = \
|
||||
getDomainFromActor(post_json_object['object'])
|
||||
if not objectDomain:
|
||||
print('Announce object does not contain a ' +
|
||||
'valid domain or port number: ' +
|
||||
str(postJsonObject['object']))
|
||||
str(post_json_object['object']))
|
||||
return None
|
||||
if isBlocked(base_dir, nickname, domain, objectNickname, objectDomain):
|
||||
if objectNickname and objectDomain:
|
||||
|
@ -4584,14 +4588,14 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
objectNickname + '@' + objectDomain)
|
||||
else:
|
||||
print('Announce download blocked object: ' +
|
||||
str(postJsonObject['object']))
|
||||
str(post_json_object['object']))
|
||||
return None
|
||||
if debug:
|
||||
print('Downloading Announce content for ' +
|
||||
postJsonObject['object'])
|
||||
post_json_object['object'])
|
||||
announcedJson = \
|
||||
getJson(signingPrivateKeyPem, session,
|
||||
postJsonObject['object'],
|
||||
post_json_object['object'],
|
||||
asHeader, None, debug, project_version,
|
||||
http_prefix, domain)
|
||||
|
||||
|
@ -4600,7 +4604,7 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
|
||||
if not isinstance(announcedJson, dict):
|
||||
print('WARN: announce json is not a dict - ' +
|
||||
postJsonObject['object'])
|
||||
post_json_object['object'])
|
||||
_rejectAnnounce(announceFilename,
|
||||
base_dir, nickname, domain, postId,
|
||||
recentPostsCache)
|
||||
|
@ -4706,10 +4710,10 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
recentPostsCache)
|
||||
return None
|
||||
|
||||
# labelAccusatoryPost(postJsonObject, translate)
|
||||
# labelAccusatoryPost(post_json_object, translate)
|
||||
# set the id to the original status
|
||||
announcedJson['id'] = postJsonObject['object']
|
||||
announcedJson['object']['id'] = postJsonObject['object']
|
||||
announcedJson['id'] = post_json_object['object']
|
||||
announcedJson['object']['id'] = post_json_object['object']
|
||||
# check that the repeat isn't for a blocked account
|
||||
attributedNickname = \
|
||||
getNicknameFromActor(announcedJson['object']['id'])
|
||||
|
@ -4723,12 +4727,12 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str,
|
|||
base_dir, nickname, domain, postId,
|
||||
recentPostsCache)
|
||||
return None
|
||||
postJsonObject = announcedJson
|
||||
replaceYouTube(postJsonObject, yt_replace_domain, systemLanguage)
|
||||
replaceTwitter(postJsonObject, twitter_replacement_domain,
|
||||
post_json_object = announcedJson
|
||||
replaceYouTube(post_json_object, yt_replace_domain, systemLanguage)
|
||||
replaceTwitter(post_json_object, twitter_replacement_domain,
|
||||
systemLanguage)
|
||||
if saveJson(postJsonObject, announceFilename):
|
||||
return postJsonObject
|
||||
if saveJson(post_json_object, announceFilename):
|
||||
return post_json_object
|
||||
return None
|
||||
|
||||
|
||||
|
@ -5089,12 +5093,12 @@ def sendUndoBlockViaServer(base_dir: str, session,
|
|||
|
||||
|
||||
def postIsMuted(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}, messageId: str) -> bool:
|
||||
post_json_object: {}, messageId: str) -> bool:
|
||||
""" Returns true if the given post is muted
|
||||
"""
|
||||
isMuted = None
|
||||
if 'muted' in postJsonObject:
|
||||
isMuted = postJsonObject['muted']
|
||||
if 'muted' in post_json_object:
|
||||
isMuted = post_json_object['muted']
|
||||
if isMuted is True or isMuted is False:
|
||||
return isMuted
|
||||
|
||||
|
@ -5175,33 +5179,33 @@ def secondsBetweenPublished(published1: str, published2: str) -> int:
|
|||
|
||||
|
||||
def editedPostFilename(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}, debug: bool,
|
||||
post_json_object: {}, debug: bool,
|
||||
maxTimeDiffSeconds: int) -> str:
|
||||
"""Returns the filename of the edited post
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return ''
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('type'):
|
||||
if not post_json_object['object'].get('type'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('published'):
|
||||
if not post_json_object['object'].get('published'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('id'):
|
||||
if not post_json_object['object'].get('id'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('attributedTo'):
|
||||
if not post_json_object['object'].get('attributedTo'):
|
||||
return ''
|
||||
if not isinstance(postJsonObject['object']['attributedTo'], str):
|
||||
if not isinstance(post_json_object['object']['attributedTo'], str):
|
||||
return ''
|
||||
actor = postJsonObject['object']['attributedTo']
|
||||
actor = post_json_object['object']['attributedTo']
|
||||
actorFilename = \
|
||||
acctDir(base_dir, nickname, domain) + '/lastpost/' + \
|
||||
actor.replace('/', '#')
|
||||
if not os.path.isfile(actorFilename):
|
||||
return ''
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
lastpostId = None
|
||||
try:
|
||||
with open(actorFilename, 'r') as fp:
|
||||
|
@ -5222,11 +5226,11 @@ def editedPostFilename(base_dir: str, nickname: str, domain: str,
|
|||
return ''
|
||||
if not lastpostJson.get('type'):
|
||||
return ''
|
||||
if lastpostJson['type'] != postJsonObject['type']:
|
||||
if lastpostJson['type'] != post_json_object['type']:
|
||||
return ''
|
||||
if not lastpostJson['object'].get('type'):
|
||||
return ''
|
||||
if lastpostJson['object']['type'] != postJsonObject['object']['type']:
|
||||
if lastpostJson['object']['type'] != post_json_object['object']['type']:
|
||||
return
|
||||
if not lastpostJson['object'].get('published'):
|
||||
return ''
|
||||
|
@ -5240,13 +5244,13 @@ def editedPostFilename(base_dir: str, nickname: str, domain: str,
|
|||
return ''
|
||||
timeDiffSeconds = \
|
||||
secondsBetweenPublished(lastpostJson['object']['published'],
|
||||
postJsonObject['object']['published'])
|
||||
post_json_object['object']['published'])
|
||||
if timeDiffSeconds > maxTimeDiffSeconds:
|
||||
return ''
|
||||
if debug:
|
||||
print(postId + ' might be an edit of ' + lastpostId)
|
||||
if wordsSimilarity(lastpostJson['object']['content'],
|
||||
postJsonObject['object']['content'], 10) < 70:
|
||||
post_json_object['object']['content'], 10) < 70:
|
||||
return ''
|
||||
print(postId + ' is an edit of ' + lastpostId)
|
||||
return lastpostFilename
|
||||
|
|
38
reaction.py
38
reaction.py
|
@ -443,20 +443,20 @@ def updateReactionCollection(recentPostsCache: {},
|
|||
base_dir: str, postFilename: str,
|
||||
objectUrl: str, actor: str,
|
||||
nickname: str, domain: str, debug: bool,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
emojiContent: str) -> None:
|
||||
"""Updates the reactions collection within a post
|
||||
"""
|
||||
if not postJsonObject:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
|
||||
# remove any cached version of this post so that the
|
||||
# reaction icon is changed
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -465,9 +465,9 @@ def updateReactionCollection(recentPostsCache: {},
|
|||
print('EX: updateReactionCollection unable to delete ' +
|
||||
cachedPostFilename)
|
||||
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
|
||||
if not objectUrl.endswith('/reactions'):
|
||||
objectUrl = objectUrl + '/reactions'
|
||||
|
@ -509,27 +509,27 @@ def updateReactionCollection(recentPostsCache: {},
|
|||
|
||||
if debug:
|
||||
print('DEBUG: saving post with emoji reaction added')
|
||||
pprint(postJsonObject)
|
||||
saveJson(postJsonObject, postFilename)
|
||||
pprint(post_json_object)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
|
||||
def htmlEmojiReactions(post_json_object: {}, interactive: bool,
|
||||
actor: str, maxReactionTypes: int,
|
||||
boxName: str, pageNumber: int) -> str:
|
||||
"""html containing row of emoji reactions
|
||||
displayed at the bottom of posts, above the icons
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return ''
|
||||
if not postJsonObject.get('actor'):
|
||||
if not post_json_object.get('actor'):
|
||||
return ''
|
||||
if not postJsonObject['object'].get('reactions'):
|
||||
if not post_json_object['object'].get('reactions'):
|
||||
return ''
|
||||
if not postJsonObject['object']['reactions'].get('items'):
|
||||
if not post_json_object['object']['reactions'].get('items'):
|
||||
return ''
|
||||
reactions = {}
|
||||
reactedToByThisActor = []
|
||||
for item in postJsonObject['object']['reactions']['items']:
|
||||
for item in post_json_object['object']['reactions']['items']:
|
||||
emojiContent = item['content']
|
||||
emojiActor = item['actor']
|
||||
emojiNickname = getNicknameFromActor(emojiActor)
|
||||
|
@ -550,7 +550,7 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
|
|||
reactions[emojiContent]['handles'].append(emojiHandle)
|
||||
if len(reactions.items()) == 0:
|
||||
return ''
|
||||
reactBy = removeIdEnding(postJsonObject['object']['id'])
|
||||
reactBy = removeIdEnding(post_json_object['object']['id'])
|
||||
htmlStr = '<div class="emojiReactionBar">\n'
|
||||
for emojiContent, item in reactions.items():
|
||||
count = item['count']
|
||||
|
@ -567,7 +567,7 @@ def htmlEmojiReactions(postJsonObject: {}, interactive: bool,
|
|||
baseUrl = actor + '?react=' + reactBy
|
||||
else:
|
||||
baseUrl = actor + '?unreact=' + reactBy
|
||||
baseUrl += '?actor=' + postJsonObject['actor']
|
||||
baseUrl += '?actor=' + post_json_object['actor']
|
||||
baseUrl += '?tl=' + boxName
|
||||
baseUrl += '?page=' + str(pageNumber)
|
||||
baseUrl += '?emojreact='
|
||||
|
|
16
schedule.py
16
schedule.py
|
@ -73,8 +73,8 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
indexLines.remove(line)
|
||||
continue
|
||||
# load post
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
print('WARN: schedule json not loaded')
|
||||
indexLines.remove(line)
|
||||
continue
|
||||
|
@ -83,11 +83,11 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
# If this is not recent then http checks on the receiving side
|
||||
# will reject it
|
||||
statusNumber, published = getStatusNumber()
|
||||
if postJsonObject.get('published'):
|
||||
postJsonObject['published'] = published
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('published'):
|
||||
postJsonObject['published'] = published
|
||||
if post_json_object.get('published'):
|
||||
post_json_object['published'] = published
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('published'):
|
||||
post_json_object['published'] = published
|
||||
|
||||
print('Sending scheduled post ' + postId)
|
||||
|
||||
|
@ -95,7 +95,7 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
|
|||
httpd.postToNickname = nickname
|
||||
if not postMessageToOutbox(httpd.session,
|
||||
httpd.translate,
|
||||
postJsonObject, nickname,
|
||||
post_json_object, nickname,
|
||||
httpd, base_dir,
|
||||
httpd.http_prefix,
|
||||
httpd.domain,
|
||||
|
|
10
session.py
10
session.py
|
@ -291,7 +291,7 @@ def downloadHtml(signingPrivateKeyPem: str,
|
|||
|
||||
|
||||
def postJson(http_prefix: str, domainFull: str,
|
||||
session, postJsonObject: {}, federationList: [],
|
||||
session, post_json_object: {}, federationList: [],
|
||||
inboxUrl: str, headers: {}, timeoutSec: int = 60,
|
||||
quiet: bool = False) -> str:
|
||||
"""Post a json message to the inbox of another person
|
||||
|
@ -310,18 +310,18 @@ def postJson(http_prefix: str, domainFull: str,
|
|||
try:
|
||||
postResult = \
|
||||
session.post(url=inboxUrl,
|
||||
data=json.dumps(postJsonObject),
|
||||
data=json.dumps(post_json_object),
|
||||
headers=headers, timeout=timeoutSec)
|
||||
except requests.Timeout as ex:
|
||||
if not quiet:
|
||||
print('ERROR: postJson timeout ' + inboxUrl + ' ' +
|
||||
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||
json.dumps(post_json_object) + ' ' + str(headers))
|
||||
print(ex)
|
||||
return ''
|
||||
except requests.exceptions.RequestException as ex:
|
||||
if not quiet:
|
||||
print('ERROR: postJson requests failed ' + inboxUrl + ' ' +
|
||||
json.dumps(postJsonObject) + ' ' + str(headers) +
|
||||
json.dumps(post_json_object) + ' ' + str(headers) +
|
||||
' ' + str(ex))
|
||||
return None
|
||||
except SocketError as ex:
|
||||
|
@ -331,7 +331,7 @@ def postJson(http_prefix: str, domainFull: str,
|
|||
except ValueError as ex:
|
||||
if not quiet:
|
||||
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
||||
json.dumps(postJsonObject) + ' ' + str(headers) +
|
||||
json.dumps(post_json_object) + ' ' + str(headers) +
|
||||
' ' + str(ex))
|
||||
return None
|
||||
if postResult:
|
||||
|
|
41
speaker.py
41
speaker.py
|
@ -404,7 +404,7 @@ def speakableText(base_dir: str, content: str, translate: {}) -> (str, []):
|
|||
|
||||
def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {}, personCache: {},
|
||||
post_json_object: {}, personCache: {},
|
||||
translate: {}, announcingActor: str,
|
||||
themeName: str) -> {}:
|
||||
"""Converts an ActivityPub post into some Json containing
|
||||
|
@ -412,14 +412,14 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
|||
NOTE: There currently appears to be no standardized json
|
||||
format for speech synthesis
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return
|
||||
if not isinstance(postJsonObject['object']['content'], str):
|
||||
if not isinstance(post_json_object['object']['content'], str):
|
||||
return
|
||||
detectedLinks = []
|
||||
content = urllib.parse.unquote_plus(postJsonObject['object']['content'])
|
||||
content = urllib.parse.unquote_plus(post_json_object['object']['content'])
|
||||
content = html.unescape(content)
|
||||
content = content.replace('<p>', '').replace('</p>', ' ')
|
||||
if not isPGPEncrypted(content):
|
||||
|
@ -442,8 +442,8 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
|||
sayContent = content
|
||||
|
||||
imageDescription = ''
|
||||
if postJsonObject['object'].get('attachment'):
|
||||
attachList = postJsonObject['object']['attachment']
|
||||
if post_json_object['object'].get('attachment'):
|
||||
attachList = post_json_object['object']['attachment']
|
||||
if isinstance(attachList, list):
|
||||
for img in attachList:
|
||||
if not isinstance(img, dict):
|
||||
|
@ -453,29 +453,30 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
|||
imageDescription += \
|
||||
img['name'] + '. '
|
||||
|
||||
isDirect = isDM(postJsonObject)
|
||||
isDirect = isDM(post_json_object)
|
||||
actor = localActorUrl(http_prefix, nickname, domainFull)
|
||||
replyToYou = isReply(postJsonObject, actor)
|
||||
replyToYou = isReply(post_json_object, actor)
|
||||
|
||||
published = ''
|
||||
if postJsonObject['object'].get('published'):
|
||||
published = postJsonObject['object']['published']
|
||||
if post_json_object['object'].get('published'):
|
||||
published = post_json_object['object']['published']
|
||||
|
||||
summary = ''
|
||||
if postJsonObject['object'].get('summary'):
|
||||
if isinstance(postJsonObject['object']['summary'], str):
|
||||
if post_json_object['object'].get('summary'):
|
||||
if isinstance(post_json_object['object']['summary'], str):
|
||||
post_json_object_summary = post_json_object['object']['summary']
|
||||
summary = \
|
||||
urllib.parse.unquote_plus(postJsonObject['object']['summary'])
|
||||
urllib.parse.unquote_plus(post_json_object_summary)
|
||||
summary = html.unescape(summary)
|
||||
|
||||
speakerName = \
|
||||
getDisplayName(base_dir, postJsonObject['actor'], personCache)
|
||||
getDisplayName(base_dir, post_json_object['actor'], personCache)
|
||||
if not speakerName:
|
||||
return
|
||||
speakerName = _removeEmojiFromText(speakerName)
|
||||
speakerName = speakerName.replace('_', ' ')
|
||||
speakerName = camelCaseSplit(speakerName)
|
||||
gender = getGenderFromBio(base_dir, postJsonObject['actor'],
|
||||
gender = getGenderFromBio(base_dir, post_json_object['actor'],
|
||||
personCache, translate)
|
||||
if announcingActor:
|
||||
announcedNickname = getNicknameFromActor(announcingActor)
|
||||
|
@ -489,8 +490,8 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
|||
translate['announces'] + ' ' + \
|
||||
announcedHandle + '. ' + content
|
||||
postId = None
|
||||
if postJsonObject['object'].get('id'):
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
if post_json_object['object'].get('id'):
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
|
||||
followRequestsExist = False
|
||||
followRequestsList = []
|
||||
|
@ -535,7 +536,7 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
|
|||
|
||||
def updateSpeaker(base_dir: str, http_prefix: str,
|
||||
nickname: str, domain: str, domainFull: str,
|
||||
postJsonObject: {}, personCache: {},
|
||||
post_json_object: {}, personCache: {},
|
||||
translate: {}, announcingActor: str,
|
||||
themeName: str) -> None:
|
||||
""" Generates a json file which can be used for TTS announcement
|
||||
|
@ -544,7 +545,7 @@ def updateSpeaker(base_dir: str, http_prefix: str,
|
|||
speakerJson = \
|
||||
_postToSpeakerJson(base_dir, http_prefix,
|
||||
nickname, domain, domainFull,
|
||||
postJsonObject, personCache,
|
||||
post_json_object, personCache,
|
||||
translate, announcingActor,
|
||||
themeName)
|
||||
speakerFilename = acctDir(base_dir, nickname, domain) + '/speaker.json'
|
||||
|
|
107
tests.py
107
tests.py
|
@ -2944,9 +2944,9 @@ def testClientToServer(base_dir: str):
|
|||
statusNumber = name.split('#statuses#')[1].replace('.json', '')
|
||||
statusNumber = int(statusNumber.replace('#activity', ''))
|
||||
outboxPostFilename = outboxPath + '/' + name
|
||||
postJsonObject = loadJson(outboxPostFilename, 0)
|
||||
if postJsonObject:
|
||||
outboxPostId = removeIdEnding(postJsonObject['id'])
|
||||
post_json_object = loadJson(outboxPostFilename, 0)
|
||||
if post_json_object:
|
||||
outboxPostId = removeIdEnding(post_json_object['id'])
|
||||
assert outboxPostId
|
||||
print('message id obtained: ' + outboxPostId)
|
||||
assert validInbox(bobDir, 'bob', bobDomain)
|
||||
|
@ -3535,11 +3535,11 @@ def _testRecentPostsCache():
|
|||
max_recent_posts = 3
|
||||
htmlStr = '<html></html>'
|
||||
for i in range(5):
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"id": "https://somesite.whatever/users/someuser/statuses/" + str(i)
|
||||
}
|
||||
updateRecentPostsCache(recentPostsCache, max_recent_posts,
|
||||
postJsonObject, htmlStr)
|
||||
post_json_object, htmlStr)
|
||||
assert len(recentPostsCache['index']) == max_recent_posts
|
||||
assert len(recentPostsCache['json'].items()) == max_recent_posts
|
||||
assert len(recentPostsCache['html'].items()) == max_recent_posts
|
||||
|
@ -3793,44 +3793,44 @@ def _runHtmlReplaceQuoteMarks():
|
|||
|
||||
def _testJsonPostAllowsComments():
|
||||
print('testJsonPostAllowsComments')
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"id": "123"
|
||||
}
|
||||
assert jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"commentsEnabled": False
|
||||
}
|
||||
assert not jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert not jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"rejectReplies": False
|
||||
}
|
||||
assert jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"rejectReplies": True
|
||||
}
|
||||
assert not jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert not jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"commentsEnabled": True
|
||||
}
|
||||
assert jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"object": {
|
||||
"commentsEnabled": True
|
||||
}
|
||||
}
|
||||
assert jsonPostAllowsComments(postJsonObject)
|
||||
postJsonObject = {
|
||||
assert jsonPostAllowsComments(post_json_object)
|
||||
post_json_object = {
|
||||
"id": "123",
|
||||
"object": {
|
||||
"commentsEnabled": False
|
||||
}
|
||||
}
|
||||
assert not jsonPostAllowsComments(postJsonObject)
|
||||
assert not jsonPostAllowsComments(post_json_object)
|
||||
|
||||
|
||||
def _testRemoveIdEnding():
|
||||
|
@ -4799,7 +4799,7 @@ def _testLinksWithinPost(base_dir: str) -> None:
|
|||
low_bandwidth = True
|
||||
content_license_url = 'https://creativecommons.org/licenses/by/4.0'
|
||||
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
createPublicPost(base_dir, nickname, domain, port, http_prefix,
|
||||
content, followersOnly, saveToFile,
|
||||
client_to_server, commentsEnabled,
|
||||
|
@ -4811,7 +4811,7 @@ def _testLinksWithinPost(base_dir: str) -> None:
|
|||
testIsArticle, systemLanguage, conversationId,
|
||||
low_bandwidth, content_license_url)
|
||||
|
||||
assert postJsonObject['object']['content'] == \
|
||||
assert post_json_object['object']['content'] == \
|
||||
'<p>This is a test post with links.<br><br>' + \
|
||||
'<a href="ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/v4/" ' + \
|
||||
'rel="nofollow noopener noreferrer" target="_blank">' + \
|
||||
|
@ -4822,8 +4822,8 @@ def _testLinksWithinPost(base_dir: str) -> None:
|
|||
'rel="nofollow noopener noreferrer" target="_blank">' + \
|
||||
'<span class="invisible">https://</span>' + \
|
||||
'<span class="ellipsis">libreserver.org</span></a></p>'
|
||||
assert postJsonObject['object']['content'] == \
|
||||
postJsonObject['object']['contentMap'][systemLanguage]
|
||||
assert post_json_object['object']['content'] == \
|
||||
post_json_object['object']['contentMap'][systemLanguage]
|
||||
|
||||
content = "<p>Some text</p><p>Other text</p><p>More text</p>" + \
|
||||
"<pre><code>Errno::EOHNOES (No such file or rodent @ " + \
|
||||
|
@ -4835,7 +4835,7 @@ def _testLinksWithinPost(base_dir: str) -> None:
|
|||
"<p><a href=\"https://whocodedthis.huh/tags/" + \
|
||||
"taggedthing\" class=\"mention hashtag\" rel=\"tag\" " + \
|
||||
"target=\"_blank\">#<span>taggedthing</span></a></p>"
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
createPublicPost(base_dir, nickname, domain, port, http_prefix,
|
||||
content,
|
||||
False, False,
|
||||
|
@ -4847,8 +4847,8 @@ def _testLinksWithinPost(base_dir: str) -> None:
|
|||
testEventDate, testEventTime, testLocation,
|
||||
testIsArticle, systemLanguage, conversationId,
|
||||
low_bandwidth, content_license_url)
|
||||
assert postJsonObject['object']['content'] == content
|
||||
assert postJsonObject['object']['contentMap'][systemLanguage] == content
|
||||
assert post_json_object['object']['content'] == content
|
||||
assert post_json_object['object']['contentMap'][systemLanguage] == content
|
||||
|
||||
|
||||
def _testMastoApi():
|
||||
|
@ -5179,7 +5179,7 @@ def testUpdateActor(base_dir: str):
|
|||
|
||||
def _testRemovePostInteractions() -> None:
|
||||
print('testRemovePostInteractions')
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"type": "Create",
|
||||
"object": {
|
||||
"to": ["#Public"],
|
||||
|
@ -5200,14 +5200,14 @@ def _testRemovePostInteractions() -> None:
|
|||
}
|
||||
}
|
||||
}
|
||||
removePostInteractions(postJsonObject, True)
|
||||
assert postJsonObject['object']['likes']['items'] == []
|
||||
assert postJsonObject['object']['replies'] == {}
|
||||
assert postJsonObject['object']['shares'] == {}
|
||||
assert postJsonObject['object']['bookmarks'] == {}
|
||||
assert postJsonObject['object']['ignores'] == {}
|
||||
postJsonObject['object']['to'] = ["some private address"]
|
||||
assert not removePostInteractions(postJsonObject, False)
|
||||
removePostInteractions(post_json_object, True)
|
||||
assert post_json_object['object']['likes']['items'] == []
|
||||
assert post_json_object['object']['replies'] == {}
|
||||
assert post_json_object['object']['shares'] == {}
|
||||
assert post_json_object['object']['bookmarks'] == {}
|
||||
assert post_json_object['object']['ignores'] == {}
|
||||
post_json_object['object']['to'] = ["some private address"]
|
||||
assert not removePostInteractions(post_json_object, False)
|
||||
|
||||
|
||||
def _testSpoofGeolocation() -> None:
|
||||
|
@ -5786,7 +5786,7 @@ def _testCanReplyTo(base_dir: str) -> None:
|
|||
low_bandwidth = True
|
||||
content_license_url = 'https://creativecommons.org/licenses/by/4.0'
|
||||
|
||||
postJsonObject = \
|
||||
post_json_object = \
|
||||
createPublicPost(base_dir, nickname, domain, port, http_prefix,
|
||||
content, followersOnly, saveToFile,
|
||||
client_to_server, commentsEnabled,
|
||||
|
@ -5799,24 +5799,24 @@ def _testCanReplyTo(base_dir: str) -> None:
|
|||
low_bandwidth, content_license_url)
|
||||
# set the date on the post
|
||||
currDateStr = "2021-09-08T20:45:00Z"
|
||||
postJsonObject['published'] = currDateStr
|
||||
postJsonObject['object']['published'] = currDateStr
|
||||
post_json_object['published'] = currDateStr
|
||||
post_json_object['object']['published'] = currDateStr
|
||||
|
||||
# test a post within the reply interval
|
||||
postUrl = postJsonObject['object']['id']
|
||||
postUrl = post_json_object['object']['id']
|
||||
replyIntervalHours = 2
|
||||
currDateStr = "2021-09-08T21:32:10Z"
|
||||
assert canReplyTo(base_dir, nickname, domain,
|
||||
postUrl, replyIntervalHours,
|
||||
currDateStr,
|
||||
postJsonObject)
|
||||
post_json_object)
|
||||
|
||||
# test a post outside of the reply interval
|
||||
currDateStr = "2021-09-09T09:24:47Z"
|
||||
assert not canReplyTo(base_dir, nickname, domain,
|
||||
postUrl, replyIntervalHours,
|
||||
currDateStr,
|
||||
postJsonObject)
|
||||
post_json_object)
|
||||
|
||||
|
||||
def _testSecondsBetweenPublished() -> None:
|
||||
|
@ -5862,38 +5862,39 @@ def _testAddCWfromLists(base_dir: str) -> None:
|
|||
CWlists = loadCWLists(base_dir, True)
|
||||
assert CWlists
|
||||
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"object": {
|
||||
"sensitive": False,
|
||||
"summary": None,
|
||||
"content": ""
|
||||
}
|
||||
}
|
||||
addCWfromLists(postJsonObject, CWlists, translate, 'Murdoch press')
|
||||
assert postJsonObject['object']['sensitive'] is False
|
||||
assert postJsonObject['object']['summary'] is None
|
||||
addCWfromLists(post_json_object, CWlists, translate, 'Murdoch press')
|
||||
assert post_json_object['object']['sensitive'] is False
|
||||
assert post_json_object['object']['summary'] is None
|
||||
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"object": {
|
||||
"sensitive": False,
|
||||
"summary": None,
|
||||
"content": "Blah blah news.co.uk blah blah"
|
||||
}
|
||||
}
|
||||
addCWfromLists(postJsonObject, CWlists, translate, 'Murdoch press')
|
||||
assert postJsonObject['object']['sensitive'] is True
|
||||
assert postJsonObject['object']['summary'] == "Murdoch Press"
|
||||
addCWfromLists(post_json_object, CWlists, translate, 'Murdoch press')
|
||||
assert post_json_object['object']['sensitive'] is True
|
||||
assert post_json_object['object']['summary'] == "Murdoch Press"
|
||||
|
||||
postJsonObject = {
|
||||
post_json_object = {
|
||||
"object": {
|
||||
"sensitive": True,
|
||||
"summary": "Existing CW",
|
||||
"content": "Blah blah news.co.uk blah blah"
|
||||
}
|
||||
}
|
||||
addCWfromLists(postJsonObject, CWlists, translate, 'Murdoch press')
|
||||
assert postJsonObject['object']['sensitive'] is True
|
||||
assert postJsonObject['object']['summary'] == "Murdoch Press / Existing CW"
|
||||
addCWfromLists(post_json_object, CWlists, translate, 'Murdoch press')
|
||||
assert post_json_object['object']['sensitive'] is True
|
||||
assert post_json_object['object']['summary'] == \
|
||||
"Murdoch Press / Existing CW"
|
||||
|
||||
|
||||
def _testValidEmojiContent() -> None:
|
||||
|
|
399
utils.py
399
utils.py
|
@ -77,14 +77,14 @@ def getActorLanguagesList(actorJson: {}) -> []:
|
|||
return []
|
||||
|
||||
|
||||
def getContentFromPost(postJsonObject: {}, systemLanguage: str,
|
||||
def getContentFromPost(post_json_object: {}, systemLanguage: str,
|
||||
languagesUnderstood: []) -> str:
|
||||
"""Returns the content from the post in the given language
|
||||
including searching for a matching entry within contentMap
|
||||
"""
|
||||
thisPostJson = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
thisPostJson = postJsonObject['object']
|
||||
thisPostJson = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
thisPostJson = post_json_object['object']
|
||||
if not thisPostJson.get('content'):
|
||||
return ''
|
||||
content = ''
|
||||
|
@ -105,12 +105,12 @@ def getContentFromPost(postJsonObject: {}, systemLanguage: str,
|
|||
return content
|
||||
|
||||
|
||||
def getBaseContentFromPost(postJsonObject: {}, systemLanguage: str) -> str:
|
||||
def getBaseContentFromPost(post_json_object: {}, systemLanguage: str) -> str:
|
||||
"""Returns the content from the post in the given language
|
||||
"""
|
||||
thisPostJson = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
thisPostJson = postJsonObject['object']
|
||||
thisPostJson = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
thisPostJson = post_json_object['object']
|
||||
if not thisPostJson.get('content'):
|
||||
return ''
|
||||
return thisPostJson['content']
|
||||
|
@ -1359,15 +1359,15 @@ def locatePost(base_dir: str, nickname: str, domain: str,
|
|||
return None
|
||||
|
||||
|
||||
def _getPublishedDate(postJsonObject: {}) -> str:
|
||||
def _getPublishedDate(post_json_object: {}) -> str:
|
||||
"""Returns the published date on the given post
|
||||
"""
|
||||
published = None
|
||||
if postJsonObject.get('published'):
|
||||
published = postJsonObject['published']
|
||||
elif hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('published'):
|
||||
published = postJsonObject['object']['published']
|
||||
if post_json_object.get('published'):
|
||||
published = post_json_object['published']
|
||||
elif hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('published'):
|
||||
published = post_json_object['object']['published']
|
||||
if not published:
|
||||
return None
|
||||
if not isinstance(published, str):
|
||||
|
@ -1414,21 +1414,21 @@ def setReplyIntervalHours(base_dir: str, nickname: str, domain: str,
|
|||
def canReplyTo(base_dir: str, nickname: str, domain: str,
|
||||
postUrl: str, replyIntervalHours: int,
|
||||
currDateStr: str = None,
|
||||
postJsonObject: {} = None) -> bool:
|
||||
post_json_object: {} = None) -> bool:
|
||||
"""Is replying to the given post permitted?
|
||||
This is a spam mitigation feature, so that spammers can't
|
||||
add a lot of replies to old post which you don't notice.
|
||||
"""
|
||||
if '/statuses/' not in postUrl:
|
||||
return True
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
postFilename = locatePost(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
return False
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return False
|
||||
published = _getPublishedDate(postJsonObject)
|
||||
published = _getPublishedDate(post_json_object)
|
||||
if not published:
|
||||
return False
|
||||
try:
|
||||
|
@ -1502,19 +1502,19 @@ def removeModerationPostFromIndex(base_dir: str, postUrl: str,
|
|||
|
||||
|
||||
def _isReplyToBlogPost(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: str):
|
||||
post_json_object: str):
|
||||
"""Is the given post a reply to a blog post?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('inReplyTo'):
|
||||
if not post_json_object['object'].get('inReplyTo'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object']['inReplyTo'], str):
|
||||
if not isinstance(post_json_object['object']['inReplyTo'], str):
|
||||
return False
|
||||
blogsIndexFilename = acctDir(base_dir, nickname, domain) + '/tlblogs.index'
|
||||
if not os.path.isfile(blogsIndexFilename):
|
||||
return False
|
||||
postId = removeIdEnding(postJsonObject['object']['inReplyTo'])
|
||||
postId = removeIdEnding(post_json_object['object']['inReplyTo'])
|
||||
postId = postId.replace('/', '#')
|
||||
if postId in open(blogsIndexFilename).read():
|
||||
return True
|
||||
|
@ -1561,19 +1561,19 @@ def _isBookmarked(base_dir: str, nickname: str, domain: str,
|
|||
return False
|
||||
|
||||
|
||||
def removePostFromCache(postJsonObject: {}, recentPostsCache: {}) -> None:
|
||||
def removePostFromCache(post_json_object: {}, recentPostsCache: {}) -> None:
|
||||
""" if the post exists in the recent posts cache then remove it
|
||||
"""
|
||||
if not recentPostsCache:
|
||||
return
|
||||
|
||||
if not postJsonObject.get('id'):
|
||||
if not post_json_object.get('id'):
|
||||
return
|
||||
|
||||
if not recentPostsCache.get('index'):
|
||||
return
|
||||
|
||||
postId = postJsonObject['id']
|
||||
postId = post_json_object['id']
|
||||
if '#' in postId:
|
||||
postId = postId.split('#', 1)[0]
|
||||
postId = removeIdEnding(postId).replace('/', '#')
|
||||
|
@ -1594,11 +1594,11 @@ def removePostFromCache(postJsonObject: {}, recentPostsCache: {}) -> None:
|
|||
|
||||
|
||||
def _deleteCachedHtml(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}):
|
||||
post_json_object: {}):
|
||||
"""Removes cached html file for the given post
|
||||
"""
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, postJsonObject)
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -1609,25 +1609,25 @@ def _deleteCachedHtml(base_dir: str, nickname: str, domain: str,
|
|||
str(cachedPostFilename))
|
||||
|
||||
|
||||
def _deleteHashtagsOnPost(base_dir: str, postJsonObject: {}) -> None:
|
||||
def _deleteHashtagsOnPost(base_dir: str, post_json_object: {}) -> None:
|
||||
"""Removes hashtags when a post is deleted
|
||||
"""
|
||||
removeHashtagIndex = False
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('content'):
|
||||
if '#' in postJsonObject['object']['content']:
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('content'):
|
||||
if '#' in post_json_object['object']['content']:
|
||||
removeHashtagIndex = True
|
||||
|
||||
if not removeHashtagIndex:
|
||||
return
|
||||
|
||||
if not postJsonObject['object'].get('id') or \
|
||||
not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('id') or \
|
||||
not post_json_object['object'].get('tag'):
|
||||
return
|
||||
|
||||
# get the id of the post
|
||||
postId = removeIdEnding(postJsonObject['object']['id'])
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
postId = removeIdEnding(post_json_object['object']['id'])
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not tag.get('type'):
|
||||
continue
|
||||
if tag['type'] != 'Hashtag':
|
||||
|
@ -1664,19 +1664,19 @@ def _deleteHashtagsOnPost(base_dir: str, postJsonObject: {}) -> None:
|
|||
|
||||
|
||||
def _deleteConversationPost(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> None:
|
||||
post_json_object: {}) -> None:
|
||||
"""Deletes a post from a conversation
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('conversation'):
|
||||
if not post_json_object['object'].get('conversation'):
|
||||
return False
|
||||
if not postJsonObject['object'].get('id'):
|
||||
if not post_json_object['object'].get('id'):
|
||||
return False
|
||||
conversationDir = acctDir(base_dir, nickname, domain) + '/conversation'
|
||||
conversationId = postJsonObject['object']['conversation']
|
||||
conversationId = post_json_object['object']['conversation']
|
||||
conversationId = conversationId.replace('/', '#')
|
||||
postId = postJsonObject['object']['id']
|
||||
postId = post_json_object['object']['id']
|
||||
conversationFilename = conversationDir + '/' + conversationId
|
||||
if not os.path.isfile(conversationFilename):
|
||||
return False
|
||||
|
@ -1710,8 +1710,8 @@ def deletePost(base_dir: str, http_prefix: str,
|
|||
debug: bool, recentPostsCache: {}) -> None:
|
||||
"""Recursively deletes a post and its replies and attachments
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename, 1)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename, 1)
|
||||
if not post_json_object:
|
||||
# remove any replies
|
||||
_deletePostRemoveReplies(base_dir, nickname, domain,
|
||||
http_prefix, postFilename,
|
||||
|
@ -1731,17 +1731,17 @@ def deletePost(base_dir: str, http_prefix: str,
|
|||
|
||||
# don't remove replies to blog posts
|
||||
if _isReplyToBlogPost(base_dir, nickname, domain,
|
||||
postJsonObject):
|
||||
post_json_object):
|
||||
return
|
||||
|
||||
# remove from recent posts cache in memory
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
# remove from conversation index
|
||||
_deleteConversationPost(base_dir, nickname, domain, postJsonObject)
|
||||
_deleteConversationPost(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
# remove any attachment
|
||||
_removeAttachment(base_dir, http_prefix, domain, postJsonObject)
|
||||
_removeAttachment(base_dir, http_prefix, domain, post_json_object)
|
||||
|
||||
extensions = ('votes', 'arrived', 'muted', 'tts', 'reject')
|
||||
for ext in extensions:
|
||||
|
@ -1754,23 +1754,23 @@ def deletePost(base_dir: str, http_prefix: str,
|
|||
str(extFilename))
|
||||
|
||||
# remove cached html version of the post
|
||||
_deleteCachedHtml(base_dir, nickname, domain, postJsonObject)
|
||||
_deleteCachedHtml(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
hasObject = False
|
||||
if postJsonObject.get('object'):
|
||||
if post_json_object.get('object'):
|
||||
hasObject = True
|
||||
|
||||
# remove from moderation index file
|
||||
if hasObject:
|
||||
if hasObjectDict(postJsonObject):
|
||||
if postJsonObject['object'].get('moderationStatus'):
|
||||
if postJsonObject.get('id'):
|
||||
postId = removeIdEnding(postJsonObject['id'])
|
||||
if hasObjectDict(post_json_object):
|
||||
if post_json_object['object'].get('moderationStatus'):
|
||||
if post_json_object.get('id'):
|
||||
postId = removeIdEnding(post_json_object['id'])
|
||||
removeModerationPostFromIndex(base_dir, postId, debug)
|
||||
|
||||
# remove any hashtags index entries
|
||||
if hasObject:
|
||||
_deleteHashtagsOnPost(base_dir, postJsonObject)
|
||||
_deleteHashtagsOnPost(base_dir, post_json_object)
|
||||
|
||||
# remove any replies
|
||||
_deletePostRemoveReplies(base_dir, nickname, domain,
|
||||
|
@ -1943,24 +1943,24 @@ def isPublicPostFromUrl(base_dir: str, nickname: str, domain: str,
|
|||
postFilename = locatePost(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
return False
|
||||
postJsonObject = loadJson(postFilename, 1)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename, 1)
|
||||
if not post_json_object:
|
||||
return False
|
||||
return isPublicPost(postJsonObject)
|
||||
return isPublicPost(post_json_object)
|
||||
|
||||
|
||||
def isPublicPost(postJsonObject: {}) -> bool:
|
||||
def isPublicPost(post_json_object: {}) -> bool:
|
||||
"""Returns true if the given post is public
|
||||
"""
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return False
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('to'):
|
||||
if not post_json_object['object'].get('to'):
|
||||
return False
|
||||
for recipient in postJsonObject['object']['to']:
|
||||
for recipient in post_json_object['object']['to']:
|
||||
if recipient.endswith('#Public'):
|
||||
return True
|
||||
return False
|
||||
|
@ -1986,7 +1986,7 @@ def getCachedPostDirectory(base_dir: str, nickname: str, domain: str) -> str:
|
|||
|
||||
|
||||
def getCachedPostFilename(base_dir: str, nickname: str, domain: str,
|
||||
postJsonObject: {}) -> str:
|
||||
post_json_object: {}) -> str:
|
||||
"""Returns the html cache filename for the given post
|
||||
"""
|
||||
cachedPostDir = getCachedPostDirectory(base_dir, nickname, domain)
|
||||
|
@ -1996,18 +1996,18 @@ def getCachedPostFilename(base_dir: str, nickname: str, domain: str,
|
|||
if '@' not in cachedPostDir:
|
||||
# print('ERROR: invalid html cache directory ' + cachedPostDir)
|
||||
return None
|
||||
cachedPostId = removeIdEnding(postJsonObject['id'])
|
||||
cachedPostId = removeIdEnding(post_json_object['id'])
|
||||
cachedPostFilename = cachedPostDir + '/' + cachedPostId.replace('/', '#')
|
||||
return cachedPostFilename + '.html'
|
||||
|
||||
|
||||
def updateRecentPostsCache(recentPostsCache: {}, max_recent_posts: int,
|
||||
postJsonObject: {}, htmlStr: str) -> None:
|
||||
post_json_object: {}, htmlStr: str) -> None:
|
||||
"""Store recent posts in memory so that they can be quickly recalled
|
||||
"""
|
||||
if not postJsonObject.get('id'):
|
||||
if not post_json_object.get('id'):
|
||||
return
|
||||
postId = postJsonObject['id']
|
||||
postId = post_json_object['id']
|
||||
if '#' in postId:
|
||||
postId = postId.split('#', 1)[0]
|
||||
postId = removeIdEnding(postId).replace('/', '#')
|
||||
|
@ -2015,8 +2015,8 @@ def updateRecentPostsCache(recentPostsCache: {}, max_recent_posts: int,
|
|||
if postId in recentPostsCache['index']:
|
||||
return
|
||||
recentPostsCache['index'].append(postId)
|
||||
postJsonObject['muted'] = False
|
||||
recentPostsCache['json'][postId] = json.dumps(postJsonObject)
|
||||
post_json_object['muted'] = False
|
||||
recentPostsCache['json'][postId] = json.dumps(post_json_object)
|
||||
recentPostsCache['html'][postId] = htmlStr
|
||||
|
||||
while len(recentPostsCache['html'].items()) > max_recent_posts:
|
||||
|
@ -2030,7 +2030,7 @@ def updateRecentPostsCache(recentPostsCache: {}, max_recent_posts: int,
|
|||
recentPostsCache['index'] = [postId]
|
||||
recentPostsCache['json'] = {}
|
||||
recentPostsCache['html'] = {}
|
||||
recentPostsCache['json'][postId] = json.dumps(postJsonObject)
|
||||
recentPostsCache['json'][postId] = json.dumps(post_json_object)
|
||||
recentPostsCache['html'][postId] = htmlStr
|
||||
|
||||
|
||||
|
@ -2071,26 +2071,26 @@ def getCSS(base_dir: str, cssFilename: str, cssCache: {}) -> str:
|
|||
return None
|
||||
|
||||
|
||||
def isBlogPost(postJsonObject: {}) -> bool:
|
||||
def isBlogPost(post_json_object: {}) -> bool:
|
||||
"""Is the given post a blog post?
|
||||
"""
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
if not hasObjectStringType(post_json_object, False):
|
||||
return False
|
||||
if not postJsonObject['object'].get('content'):
|
||||
if not post_json_object['object'].get('content'):
|
||||
return False
|
||||
if postJsonObject['object']['type'] != 'Article':
|
||||
if post_json_object['object']['type'] != 'Article':
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def isNewsPost(postJsonObject: {}) -> bool:
|
||||
def isNewsPost(post_json_object: {}) -> bool:
|
||||
"""Is the given post a blog post?
|
||||
"""
|
||||
return postJsonObject.get('news')
|
||||
return post_json_object.get('news')
|
||||
|
||||
|
||||
def _searchVirtualBoxPosts(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -2204,18 +2204,18 @@ def getFileCaseInsensitive(path: str) -> str:
|
|||
def undoLikesCollectionEntry(recentPostsCache: {},
|
||||
base_dir: str, postFilename: str, objectUrl: str,
|
||||
actor: str, domain: str, debug: bool,
|
||||
postJsonObject: {}) -> None:
|
||||
post_json_object: {}) -> None:
|
||||
"""Undoes a like for a particular actor
|
||||
"""
|
||||
if not postJsonObject:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this post so that the
|
||||
# like icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2224,15 +2224,15 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
|||
print('EX: undoLikesCollectionEntry ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
if not obj.get('likes'):
|
||||
return
|
||||
if not isinstance(obj['likes'], dict):
|
||||
|
@ -2261,25 +2261,26 @@ def undoLikesCollectionEntry(recentPostsCache: {},
|
|||
itlen = len(obj['likes']['items'])
|
||||
obj['likes']['totalItems'] = itlen
|
||||
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def undoReactionCollectionEntry(recentPostsCache: {},
|
||||
base_dir: str, postFilename: str,
|
||||
objectUrl: str,
|
||||
actor: str, domain: str, debug: bool,
|
||||
postJsonObject: {}, emojiContent: str) -> None:
|
||||
post_json_object: {},
|
||||
emojiContent: str) -> None:
|
||||
"""Undoes an emoji reaction for a particular actor
|
||||
"""
|
||||
if not postJsonObject:
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
if not post_json_object:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this post so that the
|
||||
# like icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname,
|
||||
domain, postJsonObject)
|
||||
domain, post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2288,15 +2289,15 @@ def undoReactionCollectionEntry(recentPostsCache: {},
|
|||
print('EX: undoReactionCollectionEntry ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return
|
||||
obj = postJsonObject
|
||||
if hasObjectDict(postJsonObject):
|
||||
obj = postJsonObject['object']
|
||||
obj = post_json_object
|
||||
if hasObjectDict(post_json_object):
|
||||
obj = post_json_object['object']
|
||||
if not obj.get('reactions'):
|
||||
return
|
||||
if not isinstance(obj['reactions'], dict):
|
||||
|
@ -2326,7 +2327,7 @@ def undoReactionCollectionEntry(recentPostsCache: {},
|
|||
itlen = len(obj['reactions']['items'])
|
||||
obj['reactions']['totalItems'] = itlen
|
||||
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def undoAnnounceCollectionEntry(recentPostsCache: {},
|
||||
|
@ -2337,14 +2338,14 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
|
|||
collection has no relation to shared items in shares.py. It's
|
||||
shares of posts, not shares of physical objects.
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this announce so that the announce
|
||||
# icon is changed
|
||||
nickname = getNicknameFromActor(actor)
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname, domain,
|
||||
postJsonObject)
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2354,32 +2355,32 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
|
|||
print('EX: undoAnnounceCollectionEntry ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
if not postJsonObject.get('type'):
|
||||
if not post_json_object.get('type'):
|
||||
return
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('DEBUG: post has no object')
|
||||
return
|
||||
if not postJsonObject['object'].get('shares'):
|
||||
if not post_json_object['object'].get('shares'):
|
||||
return
|
||||
if not postJsonObject['object']['shares'].get('items'):
|
||||
if not post_json_object['object']['shares'].get('items'):
|
||||
return
|
||||
totalItems = 0
|
||||
if postJsonObject['object']['shares'].get('totalItems'):
|
||||
totalItems = postJsonObject['object']['shares']['totalItems']
|
||||
if post_json_object['object']['shares'].get('totalItems'):
|
||||
totalItems = post_json_object['object']['shares']['totalItems']
|
||||
itemFound = False
|
||||
for announceItem in postJsonObject['object']['shares']['items']:
|
||||
for announceItem in post_json_object['object']['shares']['items']:
|
||||
if announceItem.get('actor'):
|
||||
if announceItem['actor'] == actor:
|
||||
if debug:
|
||||
print('DEBUG: Announce was removed for ' + actor)
|
||||
anIt = announceItem
|
||||
postJsonObject['object']['shares']['items'].remove(anIt)
|
||||
post_json_object['object']['shares']['items'].remove(anIt)
|
||||
itemFound = True
|
||||
break
|
||||
if not itemFound:
|
||||
|
@ -2388,12 +2389,12 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
|
|||
if debug:
|
||||
print('DEBUG: shares (announcements) ' +
|
||||
'was removed from post')
|
||||
del postJsonObject['object']['shares']
|
||||
del post_json_object['object']['shares']
|
||||
else:
|
||||
itlen = len(postJsonObject['object']['shares']['items'])
|
||||
postJsonObject['object']['shares']['totalItems'] = itlen
|
||||
itlen = len(post_json_object['object']['shares']['items'])
|
||||
post_json_object['object']['shares']['totalItems'] = itlen
|
||||
|
||||
saveJson(postJsonObject, postFilename)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def updateAnnounceCollection(recentPostsCache: {},
|
||||
|
@ -2405,13 +2406,13 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
same as shared items within shares.py
|
||||
It's shares of posts, not shares of physical objects.
|
||||
"""
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return
|
||||
# remove any cached version of this announce so that the announce
|
||||
# icon is changed
|
||||
cachedPostFilename = getCachedPostFilename(base_dir, nickname, domain,
|
||||
postJsonObject)
|
||||
post_json_object)
|
||||
if cachedPostFilename:
|
||||
if os.path.isfile(cachedPostFilename):
|
||||
try:
|
||||
|
@ -2421,15 +2422,15 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
print('EX: updateAnnounceCollection ' +
|
||||
'unable to delete cached post ' +
|
||||
str(cachedPostFilename))
|
||||
removePostFromCache(postJsonObject, recentPostsCache)
|
||||
removePostFromCache(post_json_object, recentPostsCache)
|
||||
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
if debug:
|
||||
pprint(postJsonObject)
|
||||
pprint(post_json_object)
|
||||
print('DEBUG: post ' + postFilename + ' has no object')
|
||||
return
|
||||
postUrl = removeIdEnding(postJsonObject['id']) + '/shares'
|
||||
if not postJsonObject['object'].get('shares'):
|
||||
postUrl = removeIdEnding(post_json_object['id']) + '/shares'
|
||||
if not post_json_object['object'].get('shares'):
|
||||
if debug:
|
||||
print('DEBUG: Adding initial shares (announcements) to ' +
|
||||
postUrl)
|
||||
|
@ -2443,10 +2444,10 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
'actor': actor
|
||||
}]
|
||||
}
|
||||
postJsonObject['object']['shares'] = announcementsJson
|
||||
post_json_object['object']['shares'] = announcementsJson
|
||||
else:
|
||||
if postJsonObject['object']['shares'].get('items'):
|
||||
sharesItems = postJsonObject['object']['shares']['items']
|
||||
if post_json_object['object']['shares'].get('items'):
|
||||
sharesItems = post_json_object['object']['shares']['items']
|
||||
for announceItem in sharesItems:
|
||||
if announceItem.get('actor'):
|
||||
if announceItem['actor'] == actor:
|
||||
|
@ -2455,9 +2456,9 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
'type': 'Announce',
|
||||
'actor': actor
|
||||
}
|
||||
postJsonObject['object']['shares']['items'].append(newAnnounce)
|
||||
itlen = len(postJsonObject['object']['shares']['items'])
|
||||
postJsonObject['object']['shares']['totalItems'] = itlen
|
||||
post_json_object['object']['shares']['items'].append(newAnnounce)
|
||||
itlen = len(post_json_object['object']['shares']['items'])
|
||||
post_json_object['object']['shares']['totalItems'] = itlen
|
||||
else:
|
||||
if debug:
|
||||
print('DEBUG: shares (announcements) section of post ' +
|
||||
|
@ -2465,8 +2466,8 @@ def updateAnnounceCollection(recentPostsCache: {},
|
|||
|
||||
if debug:
|
||||
print('DEBUG: saving post with shares (announcements) added')
|
||||
pprint(postJsonObject)
|
||||
saveJson(postJsonObject, postFilename)
|
||||
pprint(post_json_object)
|
||||
saveJson(post_json_object, postFilename)
|
||||
|
||||
|
||||
def weekDayOfMonthStart(monthNumber: int, year: int) -> int:
|
||||
|
@ -2504,20 +2505,20 @@ def mediaFileMimeType(filename: str) -> str:
|
|||
return extensions[fileExt]
|
||||
|
||||
|
||||
def isRecentPost(postJsonObject: {}, maxDays: int) -> bool:
|
||||
def isRecentPost(post_json_object: {}, maxDays: int) -> bool:
|
||||
""" Is the given post recent?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if not postJsonObject['object'].get('published'):
|
||||
if not post_json_object['object'].get('published'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object']['published'], str):
|
||||
if not isinstance(post_json_object['object']['published'], str):
|
||||
return False
|
||||
currTime = datetime.datetime.utcnow()
|
||||
daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
||||
recently = daysSinceEpoch - maxDays
|
||||
|
||||
publishedDateStr = postJsonObject['object']['published']
|
||||
publishedDateStr = post_json_object['object']['published']
|
||||
try:
|
||||
publishedDate = \
|
||||
datetime.datetime.strptime(publishedDateStr,
|
||||
|
@ -2579,26 +2580,26 @@ def rejectPostId(base_dir: str, nickname: str, domain: str,
|
|||
rejectFile.write('\n')
|
||||
|
||||
|
||||
def isDM(postJsonObject: {}) -> bool:
|
||||
def isDM(post_json_object: {}) -> bool:
|
||||
"""Returns true if the given post is a DM
|
||||
"""
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if postJsonObject['object']['type'] != 'Note' and \
|
||||
postJsonObject['object']['type'] != 'Page' and \
|
||||
postJsonObject['object']['type'] != 'Patch' and \
|
||||
postJsonObject['object']['type'] != 'EncryptedMessage' and \
|
||||
postJsonObject['object']['type'] != 'Article':
|
||||
if post_json_object['object']['type'] != 'Note' and \
|
||||
post_json_object['object']['type'] != 'Page' and \
|
||||
post_json_object['object']['type'] != 'Patch' and \
|
||||
post_json_object['object']['type'] != 'EncryptedMessage' and \
|
||||
post_json_object['object']['type'] != 'Article':
|
||||
return False
|
||||
if postJsonObject['object'].get('moderationStatus'):
|
||||
if post_json_object['object'].get('moderationStatus'):
|
||||
return False
|
||||
fields = ('to', 'cc')
|
||||
for f in fields:
|
||||
if not postJsonObject['object'].get(f):
|
||||
if not post_json_object['object'].get(f):
|
||||
continue
|
||||
for toAddress in postJsonObject['object'][f]:
|
||||
for toAddress in post_json_object['object'][f]:
|
||||
if toAddress.endswith('#Public'):
|
||||
return False
|
||||
if toAddress.endswith('followers'):
|
||||
|
@ -2606,29 +2607,29 @@ def isDM(postJsonObject: {}) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
def isReply(postJsonObject: {}, actor: str) -> bool:
|
||||
def isReply(post_json_object: {}, actor: str) -> bool:
|
||||
"""Returns true if the given post is a reply to the given actor
|
||||
"""
|
||||
if postJsonObject['type'] != 'Create':
|
||||
if post_json_object['type'] != 'Create':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False
|
||||
if postJsonObject['object'].get('moderationStatus'):
|
||||
if post_json_object['object'].get('moderationStatus'):
|
||||
return False
|
||||
if postJsonObject['object']['type'] != 'Note' and \
|
||||
postJsonObject['object']['type'] != 'Page' and \
|
||||
postJsonObject['object']['type'] != 'EncryptedMessage' and \
|
||||
postJsonObject['object']['type'] != 'Article':
|
||||
if post_json_object['object']['type'] != 'Note' and \
|
||||
post_json_object['object']['type'] != 'Page' and \
|
||||
post_json_object['object']['type'] != 'EncryptedMessage' and \
|
||||
post_json_object['object']['type'] != 'Article':
|
||||
return False
|
||||
if postJsonObject['object'].get('inReplyTo'):
|
||||
if isinstance(postJsonObject['object']['inReplyTo'], str):
|
||||
if postJsonObject['object']['inReplyTo'].startswith(actor):
|
||||
if post_json_object['object'].get('inReplyTo'):
|
||||
if isinstance(post_json_object['object']['inReplyTo'], str):
|
||||
if post_json_object['object']['inReplyTo'].startswith(actor):
|
||||
return True
|
||||
if not postJsonObject['object'].get('tag'):
|
||||
if not post_json_object['object'].get('tag'):
|
||||
return False
|
||||
if not isinstance(postJsonObject['object']['tag'], list):
|
||||
if not isinstance(post_json_object['object']['tag'], list):
|
||||
return False
|
||||
for tag in postJsonObject['object']['tag']:
|
||||
for tag in post_json_object['object']['tag']:
|
||||
if not tag.get('type'):
|
||||
continue
|
||||
if tag['type'] == 'Mention':
|
||||
|
@ -2843,11 +2844,11 @@ def userAgentDomain(userAgent: str, debug: bool) -> str:
|
|||
return agentDomain
|
||||
|
||||
|
||||
def hasObjectDict(postJsonObject: {}) -> bool:
|
||||
def hasObjectDict(post_json_object: {}) -> bool:
|
||||
"""Returns true if the given post has an object dict
|
||||
"""
|
||||
if postJsonObject.get('object'):
|
||||
if isinstance(postJsonObject['object'], dict):
|
||||
if post_json_object.get('object'):
|
||||
if isinstance(post_json_object['object'], dict):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -3152,72 +3153,72 @@ def replaceUsersWithAt(actor: str) -> str:
|
|||
return actor
|
||||
|
||||
|
||||
def hasActor(postJsonObject: {}, debug: bool) -> bool:
|
||||
def hasActor(post_json_object: {}, debug: bool) -> bool:
|
||||
"""Does the given post have an actor?
|
||||
"""
|
||||
if postJsonObject.get('actor'):
|
||||
if '#' in postJsonObject['actor']:
|
||||
if post_json_object.get('actor'):
|
||||
if '#' in post_json_object['actor']:
|
||||
return False
|
||||
return True
|
||||
if debug:
|
||||
if postJsonObject.get('type'):
|
||||
msg = postJsonObject['type'] + ' has missing actor'
|
||||
if postJsonObject.get('id'):
|
||||
msg += ' ' + postJsonObject['id']
|
||||
if post_json_object.get('type'):
|
||||
msg = post_json_object['type'] + ' has missing actor'
|
||||
if post_json_object.get('id'):
|
||||
msg += ' ' + post_json_object['id']
|
||||
print(msg)
|
||||
return False
|
||||
|
||||
|
||||
def hasObjectStringType(postJsonObject: {}, debug: bool) -> bool:
|
||||
def hasObjectStringType(post_json_object: {}, debug: bool) -> bool:
|
||||
"""Does the given post have a type field within an object dict?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
if debug:
|
||||
print('hasObjectStringType no object found')
|
||||
return False
|
||||
if postJsonObject['object'].get('type'):
|
||||
if isinstance(postJsonObject['object']['type'], str):
|
||||
if post_json_object['object'].get('type'):
|
||||
if isinstance(post_json_object['object']['type'], str):
|
||||
return True
|
||||
elif debug:
|
||||
if postJsonObject.get('type'):
|
||||
print('DEBUG: ' + postJsonObject['type'] +
|
||||
if post_json_object.get('type'):
|
||||
print('DEBUG: ' + post_json_object['type'] +
|
||||
' type within object is not a string')
|
||||
if debug:
|
||||
print('No type field within object ' + postJsonObject['id'])
|
||||
print('No type field within object ' + post_json_object['id'])
|
||||
return False
|
||||
|
||||
|
||||
def hasObjectStringObject(postJsonObject: {}, debug: bool) -> bool:
|
||||
def hasObjectStringObject(post_json_object: {}, debug: bool) -> bool:
|
||||
"""Does the given post have an object string field within an object dict?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if not hasObjectDict(post_json_object):
|
||||
if debug:
|
||||
print('hasObjectStringType no object found')
|
||||
return False
|
||||
if postJsonObject['object'].get('object'):
|
||||
if isinstance(postJsonObject['object']['object'], str):
|
||||
if post_json_object['object'].get('object'):
|
||||
if isinstance(post_json_object['object']['object'], str):
|
||||
return True
|
||||
elif debug:
|
||||
if postJsonObject.get('type'):
|
||||
print('DEBUG: ' + postJsonObject['type'] +
|
||||
if post_json_object.get('type'):
|
||||
print('DEBUG: ' + post_json_object['type'] +
|
||||
' object within dict is not a string')
|
||||
if debug:
|
||||
print('No object field within dict ' + postJsonObject['id'])
|
||||
print('No object field within dict ' + post_json_object['id'])
|
||||
return False
|
||||
|
||||
|
||||
def hasObjectString(postJsonObject: {}, debug: bool) -> bool:
|
||||
def hasObjectString(post_json_object: {}, debug: bool) -> bool:
|
||||
"""Does the given post have an object string field?
|
||||
"""
|
||||
if postJsonObject.get('object'):
|
||||
if isinstance(postJsonObject['object'], str):
|
||||
if post_json_object.get('object'):
|
||||
if isinstance(post_json_object['object'], str):
|
||||
return True
|
||||
elif debug:
|
||||
if postJsonObject.get('type'):
|
||||
print('DEBUG: ' + postJsonObject['type'] +
|
||||
if post_json_object.get('type'):
|
||||
print('DEBUG: ' + post_json_object['type'] +
|
||||
' object is not a string')
|
||||
if debug:
|
||||
print('No object field within post ' + postJsonObject['id'])
|
||||
print('No object field within post ' + post_json_object['id'])
|
||||
return False
|
||||
|
||||
|
||||
|
|
68
video.py
68
video.py
|
@ -17,7 +17,7 @@ from filters import isFiltered
|
|||
|
||||
def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
||||
systemLanguage: str,
|
||||
postJsonObject: {}, blockedCache: {}) -> {}:
|
||||
post_json_object: {}, blockedCache: {}) -> {}:
|
||||
"""Converts a PeerTube Video ActivityPub(ish) object into
|
||||
a Note, so that it can then be displayed in a timeline
|
||||
"""
|
||||
|
@ -28,18 +28,18 @@ def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
|||
'name', 'url'
|
||||
)
|
||||
for fieldName in requiredFields:
|
||||
if not postJsonObject.get(fieldName):
|
||||
if not post_json_object.get(fieldName):
|
||||
return None
|
||||
|
||||
if postJsonObject['type'] != 'Video':
|
||||
if post_json_object['type'] != 'Video':
|
||||
return None
|
||||
|
||||
# who is this attributed to ?
|
||||
attributedTo = None
|
||||
if isinstance(postJsonObject['attributedTo'], str):
|
||||
attributedTo = postJsonObject['attributedTo']
|
||||
elif isinstance(postJsonObject['attributedTo'], list):
|
||||
for entity in postJsonObject['attributedTo']:
|
||||
if isinstance(post_json_object['attributedTo'], str):
|
||||
attributedTo = post_json_object['attributedTo']
|
||||
elif isinstance(post_json_object['attributedTo'], list):
|
||||
for entity in post_json_object['attributedTo']:
|
||||
if not isinstance(entity, dict):
|
||||
continue
|
||||
if not entity.get('type'):
|
||||
|
@ -55,10 +55,10 @@ def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
# get the language of the video
|
||||
postLanguage = systemLanguage
|
||||
if postJsonObject.get('language'):
|
||||
if isinstance(postJsonObject['language'], dict):
|
||||
if postJsonObject['language'].get('identifier'):
|
||||
postLanguage = postJsonObject['language']['identifier']
|
||||
if post_json_object.get('language'):
|
||||
if isinstance(post_json_object['language'], dict):
|
||||
if post_json_object['language'].get('identifier'):
|
||||
postLanguage = post_json_object['language']['identifier']
|
||||
|
||||
# check that the attributed actor is not blocked
|
||||
postNickname = getNicknameFromActor(attributedTo)
|
||||
|
@ -73,29 +73,29 @@ def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
|||
return None
|
||||
|
||||
# check that the content is valid
|
||||
if isFiltered(base_dir, nickname, domain, postJsonObject['name']):
|
||||
if isFiltered(base_dir, nickname, domain, post_json_object['name']):
|
||||
return None
|
||||
if isFiltered(base_dir, nickname, domain, postJsonObject['content']):
|
||||
if isFiltered(base_dir, nickname, domain, post_json_object['content']):
|
||||
return None
|
||||
|
||||
# get the content
|
||||
content = '<p><b>' + postJsonObject['name'] + '</b></p>'
|
||||
if postJsonObject.get('license'):
|
||||
if isinstance(postJsonObject['license'], dict):
|
||||
if postJsonObject['license'].get('name'):
|
||||
content = '<p><b>' + post_json_object['name'] + '</b></p>'
|
||||
if post_json_object.get('license'):
|
||||
if isinstance(post_json_object['license'], dict):
|
||||
if post_json_object['license'].get('name'):
|
||||
if isFiltered(base_dir, nickname, domain,
|
||||
postJsonObject['license']['name']):
|
||||
post_json_object['license']['name']):
|
||||
return None
|
||||
content += '<p>' + postJsonObject['license']['name'] + '</p>'
|
||||
content += postJsonObject['content']
|
||||
content += '<p>' + post_json_object['license']['name'] + '</p>'
|
||||
content += post_json_object['content']
|
||||
|
||||
conversationId = removeIdEnding(postJsonObject['id'])
|
||||
conversationId = removeIdEnding(post_json_object['id'])
|
||||
|
||||
mediaType = None
|
||||
mediaUrl = None
|
||||
mediaTorrent = None
|
||||
mediaMagnet = None
|
||||
for mediaLink in postJsonObject['url']:
|
||||
for mediaLink in post_json_object['url']:
|
||||
if not isinstance(mediaLink, dict):
|
||||
continue
|
||||
if not mediaLink.get('mediaType'):
|
||||
|
@ -118,7 +118,7 @@ def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
attachment = [{
|
||||
'mediaType': mediaType,
|
||||
'name': postJsonObject['content'],
|
||||
'name': post_json_object['content'],
|
||||
'type': 'Document',
|
||||
'url': mediaUrl
|
||||
}]
|
||||
|
@ -131,31 +131,31 @@ def convertVideoToNote(base_dir: str, nickname: str, domain: str,
|
|||
content += '<a href="' + mediaMagnet + '">🧲</a>'
|
||||
content += '</p>'
|
||||
|
||||
newPostId = removeIdEnding(postJsonObject['id'])
|
||||
newPostId = removeIdEnding(post_json_object['id'])
|
||||
newPost = {
|
||||
'@context': postJsonObject['@context'],
|
||||
'@context': post_json_object['@context'],
|
||||
'id': newPostId + '/activity',
|
||||
'type': 'Create',
|
||||
'actor': attributedTo,
|
||||
'published': postJsonObject['published'],
|
||||
'to': postJsonObject['to'],
|
||||
'cc': postJsonObject['cc'],
|
||||
'published': post_json_object['published'],
|
||||
'to': post_json_object['to'],
|
||||
'cc': post_json_object['cc'],
|
||||
'object': {
|
||||
'id': newPostId,
|
||||
'conversation': conversationId,
|
||||
'type': 'Note',
|
||||
'summary': None,
|
||||
'inReplyTo': None,
|
||||
'published': postJsonObject['published'],
|
||||
'published': post_json_object['published'],
|
||||
'url': newPostId,
|
||||
'attributedTo': attributedTo,
|
||||
'to': postJsonObject['to'],
|
||||
'cc': postJsonObject['cc'],
|
||||
'sensitive': postJsonObject['sensitive'],
|
||||
'to': post_json_object['to'],
|
||||
'cc': post_json_object['cc'],
|
||||
'sensitive': post_json_object['sensitive'],
|
||||
'atomUri': newPostId,
|
||||
'inReplyToAtomUri': None,
|
||||
'commentsEnabled': postJsonObject['commentsEnabled'],
|
||||
'rejectReplies': not postJsonObject['commentsEnabled'],
|
||||
'commentsEnabled': post_json_object['commentsEnabled'],
|
||||
'rejectReplies': not post_json_object['commentsEnabled'],
|
||||
'mediaType': 'text/html',
|
||||
'content': content,
|
||||
'contentMap': {
|
||||
|
|
|
@ -47,8 +47,8 @@ def htmlCalendarDeleteConfirm(cssCache: {}, translate: {}, base_dir: str,
|
|||
if not postFilename:
|
||||
return None
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return None
|
||||
|
||||
deletePostStr = None
|
||||
|
|
|
@ -662,8 +662,8 @@ def htmlEditNewsPost(cssCache: {}, translate: {}, base_dir: str, path: str,
|
|||
postFilename = locatePost(base_dir, nickname, domain, postUrl)
|
||||
if not postFilename:
|
||||
return ''
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return ''
|
||||
|
||||
cssFilename = base_dir + '/epicyon-links.css'
|
||||
|
@ -699,12 +699,12 @@ def htmlEditNewsPost(cssCache: {}, translate: {}, base_dir: str, path: str,
|
|||
' <input type="hidden" name="newsPostUrl" value="' + \
|
||||
postUrl + '">\n'
|
||||
|
||||
newsPostTitle = postJsonObject['object']['summary']
|
||||
newsPostTitle = post_json_object['object']['summary']
|
||||
editNewsPostForm += \
|
||||
' <input type="text" name="newsPostTitle" value="' + \
|
||||
newsPostTitle + '"><br>\n'
|
||||
|
||||
newsPostContent = getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
newsPostContent = getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
editNewsPostForm += \
|
||||
' <textarea id="message" name="editedNewsPost" ' + \
|
||||
'style="height:600px" spellcheck="true">' + \
|
||||
|
|
|
@ -51,8 +51,8 @@ def htmlConfirmDelete(cssCache: {},
|
|||
if not postFilename:
|
||||
return None
|
||||
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
return None
|
||||
|
||||
deletePostStr = None
|
||||
|
@ -69,7 +69,7 @@ def htmlConfirmDelete(cssCache: {},
|
|||
True, recentPostsCache, max_recent_posts,
|
||||
translate, pageNumber,
|
||||
base_dir, session, cachedWebfingers, personCache,
|
||||
nickname, domain, port, postJsonObject,
|
||||
nickname, domain, port, post_json_object,
|
||||
None, True, False,
|
||||
http_prefix, project_version, 'outbox',
|
||||
yt_replace_domain,
|
||||
|
|
|
@ -200,7 +200,7 @@ def htmlNewPost(cssCache: {}, media_instance: bool, translate: {},
|
|||
recentPostsCache: {}, max_recent_posts: int,
|
||||
session, cachedWebfingers: {},
|
||||
personCache: {}, port: int,
|
||||
postJsonObject: {},
|
||||
post_json_object: {},
|
||||
project_version: str,
|
||||
yt_replace_domain: str,
|
||||
twitter_replacement_domain: str,
|
||||
|
@ -257,7 +257,7 @@ def htmlNewPost(cssCache: {}, media_instance: bool, translate: {},
|
|||
'" rel="nofollow noopener noreferrer" ' + \
|
||||
'target="_blank">' + \
|
||||
translate['this post'] + '</a></p>\n'
|
||||
if postJsonObject:
|
||||
if post_json_object:
|
||||
newPostText += \
|
||||
individualPostAsHtml(signingPrivateKeyPem,
|
||||
True, recentPostsCache,
|
||||
|
@ -267,7 +267,7 @@ def htmlNewPost(cssCache: {}, media_instance: bool, translate: {},
|
|||
cachedWebfingers,
|
||||
personCache,
|
||||
nickname, domain, port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
None, True, False,
|
||||
http_prefix, project_version,
|
||||
boxName,
|
||||
|
|
342
webapp_post.py
342
webapp_post.py
File diff suppressed because it is too large
Load Diff
|
@ -76,49 +76,49 @@ from webapp_timeline import htmlIndividualShare
|
|||
from blocking import getCWlistVariable
|
||||
|
||||
|
||||
def _validProfilePreviewPost(postJsonObject: {},
|
||||
def _validProfilePreviewPost(post_json_object: {},
|
||||
personUrl: str) -> (bool, {}):
|
||||
"""Returns true if the given post should appear on a person/group profile
|
||||
after searching for a handle
|
||||
"""
|
||||
isAnnouncedFeedItem = False
|
||||
if isCreateInsideAnnounce(postJsonObject):
|
||||
if isCreateInsideAnnounce(post_json_object):
|
||||
isAnnouncedFeedItem = True
|
||||
postJsonObject = postJsonObject['object']
|
||||
if not postJsonObject.get('type'):
|
||||
post_json_object = post_json_object['object']
|
||||
if not post_json_object.get('type'):
|
||||
return False, None
|
||||
if postJsonObject['type'] == 'Create':
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if post_json_object['type'] == 'Create':
|
||||
if not hasObjectDict(post_json_object):
|
||||
return False, None
|
||||
if postJsonObject['type'] != 'Create' and \
|
||||
postJsonObject['type'] != 'Announce':
|
||||
if postJsonObject['type'] != 'Note' and \
|
||||
postJsonObject['type'] != 'Page':
|
||||
if post_json_object['type'] != 'Create' and \
|
||||
post_json_object['type'] != 'Announce':
|
||||
if post_json_object['type'] != 'Note' and \
|
||||
post_json_object['type'] != 'Page':
|
||||
return False, None
|
||||
if not postJsonObject.get('to'):
|
||||
if not post_json_object.get('to'):
|
||||
return False, None
|
||||
if not postJsonObject.get('id'):
|
||||
if not post_json_object.get('id'):
|
||||
return False, None
|
||||
# wrap in create
|
||||
cc = []
|
||||
if postJsonObject.get('cc'):
|
||||
cc = postJsonObject['cc']
|
||||
if post_json_object.get('cc'):
|
||||
cc = post_json_object['cc']
|
||||
newPostJsonObject = {
|
||||
'object': postJsonObject,
|
||||
'to': postJsonObject['to'],
|
||||
'object': post_json_object,
|
||||
'to': post_json_object['to'],
|
||||
'cc': cc,
|
||||
'id': postJsonObject['id'],
|
||||
'id': post_json_object['id'],
|
||||
'actor': personUrl,
|
||||
'type': 'Create'
|
||||
}
|
||||
postJsonObject = newPostJsonObject
|
||||
if not postJsonObject.get('actor'):
|
||||
post_json_object = newPostJsonObject
|
||||
if not post_json_object.get('actor'):
|
||||
return False, None
|
||||
if not isAnnouncedFeedItem:
|
||||
if postJsonObject['actor'] != personUrl and \
|
||||
postJsonObject['object']['type'] != 'Page':
|
||||
if post_json_object['actor'] != personUrl and \
|
||||
post_json_object['object']['type'] != 'Page':
|
||||
return False, None
|
||||
return True, postJsonObject
|
||||
return True, post_json_object
|
||||
|
||||
|
||||
def htmlProfileAfterSearch(cssCache: {},
|
||||
|
@ -327,7 +327,7 @@ def htmlProfileAfterSearch(cssCache: {},
|
|||
if userFeed:
|
||||
i = 0
|
||||
for item in userFeed:
|
||||
showItem, postJsonObject = \
|
||||
showItem, post_json_object = \
|
||||
_validProfilePreviewPost(item, personUrl)
|
||||
if not showItem:
|
||||
continue
|
||||
|
@ -338,7 +338,7 @@ def htmlProfileAfterSearch(cssCache: {},
|
|||
translate, None, base_dir,
|
||||
session, cachedWebfingers, personCache,
|
||||
nickname, domain, port,
|
||||
postJsonObject, avatarUrl, False, False,
|
||||
post_json_object, avatarUrl, False, False,
|
||||
http_prefix, project_version, 'inbox',
|
||||
yt_replace_domain,
|
||||
twitter_replacement_domain,
|
||||
|
|
|
@ -16,14 +16,14 @@ from utils import acctDir
|
|||
def insertQuestion(base_dir: str, translate: {},
|
||||
nickname: str, domain: str, port: int,
|
||||
content: str,
|
||||
postJsonObject: {}, pageNumber: int) -> str:
|
||||
post_json_object: {}, pageNumber: int) -> str:
|
||||
""" Inserts question selection into a post
|
||||
"""
|
||||
if not isQuestion(postJsonObject):
|
||||
if not isQuestion(post_json_object):
|
||||
return content
|
||||
if len(postJsonObject['object']['oneOf']) == 0:
|
||||
if len(post_json_object['object']['oneOf']) == 0:
|
||||
return content
|
||||
messageId = removeIdEnding(postJsonObject['id'])
|
||||
messageId = removeIdEnding(post_json_object['id'])
|
||||
if '#' in messageId:
|
||||
messageId = messageId.split('#', 1)[0]
|
||||
pageNumberStr = ''
|
||||
|
@ -47,7 +47,7 @@ def insertQuestion(base_dir: str, translate: {},
|
|||
content += \
|
||||
'<input type="hidden" name="messageId" value="' + \
|
||||
messageId + '">\n<br>\n'
|
||||
for choice in postJsonObject['object']['oneOf']:
|
||||
for choice in post_json_object['object']['oneOf']:
|
||||
if not choice.get('type'):
|
||||
continue
|
||||
if not choice.get('name'):
|
||||
|
@ -65,7 +65,7 @@ def insertQuestion(base_dir: str, translate: {},
|
|||
|
||||
# get the maximum number of votes
|
||||
maxVotes = 1
|
||||
for questionOption in postJsonObject['object']['oneOf']:
|
||||
for questionOption in post_json_object['object']['oneOf']:
|
||||
if not questionOption.get('name'):
|
||||
continue
|
||||
if not questionOption.get('replies'):
|
||||
|
@ -80,7 +80,7 @@ def insertQuestion(base_dir: str, translate: {},
|
|||
|
||||
# show the votes as sliders
|
||||
questionCtr = 1
|
||||
for questionOption in postJsonObject['object']['oneOf']:
|
||||
for questionOption in post_json_object['object']['oneOf']:
|
||||
if not questionOption.get('name'):
|
||||
continue
|
||||
if not questionOption.get('replies'):
|
||||
|
|
|
@ -666,8 +666,8 @@ def htmlHistorySearch(cssCache: {}, translate: {}, base_dir: str,
|
|||
if not postFilename:
|
||||
index += 1
|
||||
continue
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
index += 1
|
||||
continue
|
||||
showIndividualPostIcons = True
|
||||
|
@ -680,7 +680,7 @@ def htmlHistorySearch(cssCache: {}, translate: {}, base_dir: str,
|
|||
base_dir, session, cachedWebfingers,
|
||||
personCache,
|
||||
nickname, domain, port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
None, True, allow_deletion,
|
||||
http_prefix, project_version,
|
||||
'search',
|
||||
|
@ -835,11 +835,11 @@ def htmlHashtagSearch(cssCache: {},
|
|||
if not postFilename:
|
||||
index += 1
|
||||
continue
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if not postJsonObject:
|
||||
post_json_object = loadJson(postFilename)
|
||||
if not post_json_object:
|
||||
index += 1
|
||||
continue
|
||||
if not isPublicPost(postJsonObject):
|
||||
if not isPublicPost(post_json_object):
|
||||
index += 1
|
||||
continue
|
||||
showIndividualPostIcons = False
|
||||
|
@ -862,7 +862,7 @@ def htmlHashtagSearch(cssCache: {},
|
|||
base_dir, session, cachedWebfingers,
|
||||
personCache,
|
||||
nickname, domain, port,
|
||||
postJsonObject,
|
||||
post_json_object,
|
||||
avatarUrl, showAvatarOptions,
|
||||
allow_deletion,
|
||||
http_prefix, project_version,
|
||||
|
@ -962,39 +962,39 @@ def rssHashtagSearch(nickname: str, domain: str, port: int,
|
|||
if index >= maxFeedLength:
|
||||
break
|
||||
continue
|
||||
postJsonObject = loadJson(postFilename)
|
||||
if postJsonObject:
|
||||
if not isPublicPost(postJsonObject):
|
||||
post_json_object = loadJson(postFilename)
|
||||
if post_json_object:
|
||||
if not isPublicPost(post_json_object):
|
||||
index += 1
|
||||
if index >= maxFeedLength:
|
||||
break
|
||||
continue
|
||||
# add to feed
|
||||
if postJsonObject['object'].get('content') and \
|
||||
postJsonObject['object'].get('attributedTo') and \
|
||||
postJsonObject['object'].get('published'):
|
||||
published = postJsonObject['object']['published']
|
||||
if post_json_object['object'].get('content') and \
|
||||
post_json_object['object'].get('attributedTo') and \
|
||||
post_json_object['object'].get('published'):
|
||||
published = post_json_object['object']['published']
|
||||
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
|
||||
rssDateStr = pubDate.strftime("%a, %d %b %Y %H:%M:%S UT")
|
||||
hashtagFeed += ' <item>'
|
||||
hashtagFeed += \
|
||||
' <author>' + \
|
||||
postJsonObject['object']['attributedTo'] + \
|
||||
post_json_object['object']['attributedTo'] + \
|
||||
'</author>'
|
||||
if postJsonObject['object'].get('summary'):
|
||||
if post_json_object['object'].get('summary'):
|
||||
hashtagFeed += \
|
||||
' <title>' + \
|
||||
postJsonObject['object']['summary'] + \
|
||||
post_json_object['object']['summary'] + \
|
||||
'</title>'
|
||||
description = \
|
||||
getBaseContentFromPost(postJsonObject, systemLanguage)
|
||||
getBaseContentFromPost(post_json_object, systemLanguage)
|
||||
description = firstParagraphFromString(description)
|
||||
hashtagFeed += \
|
||||
' <description>' + description + '</description>'
|
||||
hashtagFeed += \
|
||||
' <pubDate>' + rssDateStr + '</pubDate>'
|
||||
if postJsonObject['object'].get('attachment'):
|
||||
for attach in postJsonObject['object']['attachment']:
|
||||
if post_json_object['object'].get('attachment'):
|
||||
for attach in post_json_object['object']['attachment']:
|
||||
if not attach.get('url'):
|
||||
continue
|
||||
hashtagFeed += \
|
||||
|
|
|
@ -446,20 +446,20 @@ def sharesTimelineJson(actor: str, pageNumber: int, itemsPerPage: int,
|
|||
return resultJson, lastPage
|
||||
|
||||
|
||||
def postContainsPublic(postJsonObject: {}) -> bool:
|
||||
def postContainsPublic(post_json_object: {}) -> bool:
|
||||
"""Does the given post contain #Public
|
||||
"""
|
||||
containsPublic = False
|
||||
if not postJsonObject['object'].get('to'):
|
||||
if not post_json_object['object'].get('to'):
|
||||
return containsPublic
|
||||
|
||||
for toAddress in postJsonObject['object']['to']:
|
||||
for toAddress in post_json_object['object']['to']:
|
||||
if toAddress.endswith('#Public'):
|
||||
containsPublic = True
|
||||
break
|
||||
if not containsPublic:
|
||||
if postJsonObject['object'].get('cc'):
|
||||
for toAddress in postJsonObject['object']['cc']:
|
||||
if post_json_object['object'].get('cc'):
|
||||
for toAddress in post_json_object['object']['cc']:
|
||||
if toAddress.endswith('#Public'):
|
||||
containsPublic = True
|
||||
break
|
||||
|
@ -858,13 +858,13 @@ def htmlFooter() -> str:
|
|||
|
||||
def loadIndividualPostAsHtmlFromCache(base_dir: str,
|
||||
nickname: str, domain: str,
|
||||
postJsonObject: {}) -> str:
|
||||
post_json_object: {}) -> str:
|
||||
"""If a cached html version of the given post exists then load it and
|
||||
return the html text
|
||||
This is much quicker than generating the html from the json object
|
||||
"""
|
||||
cachedPostFilename = \
|
||||
getCachedPostFilename(base_dir, nickname, domain, postJsonObject)
|
||||
getCachedPostFilename(base_dir, nickname, domain, post_json_object)
|
||||
|
||||
postHtml = ''
|
||||
if not cachedPostFilename:
|
||||
|
@ -1004,7 +1004,7 @@ def _isAttachedVideo(attachmentFilename: str) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
|
||||
def getPostAttachmentsAsHtml(post_json_object: {}, boxName: str, translate: {},
|
||||
isMuted: bool, avatarLink: str,
|
||||
replyStr: str, announceStr: str, likeStr: str,
|
||||
bookmarkStr: str, deleteStr: str,
|
||||
|
@ -1013,16 +1013,16 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
|
|||
"""
|
||||
attachmentStr = ''
|
||||
galleryStr = ''
|
||||
if not postJsonObject['object'].get('attachment'):
|
||||
if not post_json_object['object'].get('attachment'):
|
||||
return attachmentStr, galleryStr
|
||||
|
||||
if not isinstance(postJsonObject['object']['attachment'], list):
|
||||
if not isinstance(post_json_object['object']['attachment'], list):
|
||||
return attachmentStr, galleryStr
|
||||
|
||||
attachmentCtr = 0
|
||||
attachmentStr = ''
|
||||
mediaStyleAdded = False
|
||||
for attach in postJsonObject['object']['attachment']:
|
||||
for attach in post_json_object['object']['attachment']:
|
||||
if not (attach.get('mediaType') and attach.get('url')):
|
||||
continue
|
||||
|
||||
|
@ -1047,10 +1047,10 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
|
|||
' <img loading="lazy" src="' + \
|
||||
imageUrl + '" alt="" title="">\n'
|
||||
galleryStr += ' </a>\n'
|
||||
if postJsonObject['object'].get('url'):
|
||||
imagePostUrl = postJsonObject['object']['url']
|
||||
if post_json_object['object'].get('url'):
|
||||
imagePostUrl = post_json_object['object']['url']
|
||||
else:
|
||||
imagePostUrl = postJsonObject['object']['id']
|
||||
imagePostUrl = post_json_object['object']['id']
|
||||
if imageDescription and not isMuted:
|
||||
galleryStr += \
|
||||
' <a href="' + imagePostUrl + \
|
||||
|
@ -1101,10 +1101,10 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
|
|||
galleryStr += ' </video>\n'
|
||||
galleryStr += ' </figure>\n'
|
||||
galleryStr += ' </a>\n'
|
||||
if postJsonObject['object'].get('url'):
|
||||
videoPostUrl = postJsonObject['object']['url']
|
||||
if post_json_object['object'].get('url'):
|
||||
videoPostUrl = post_json_object['object']['url']
|
||||
else:
|
||||
videoPostUrl = postJsonObject['object']['id']
|
||||
videoPostUrl = post_json_object['object']['id']
|
||||
if imageDescription and not isMuted:
|
||||
galleryStr += \
|
||||
' <a href="' + videoPostUrl + \
|
||||
|
@ -1160,10 +1160,10 @@ def getPostAttachmentsAsHtml(postJsonObject: {}, boxName: str, translate: {},
|
|||
galleryStr += translate[idx]
|
||||
galleryStr += ' </audio>\n'
|
||||
galleryStr += ' </a>\n'
|
||||
if postJsonObject['object'].get('url'):
|
||||
audioPostUrl = postJsonObject['object']['url']
|
||||
if post_json_object['object'].get('url'):
|
||||
audioPostUrl = post_json_object['object']['url']
|
||||
else:
|
||||
audioPostUrl = postJsonObject['object']['id']
|
||||
audioPostUrl = post_json_object['object']['id']
|
||||
if imageDescription and not isMuted:
|
||||
galleryStr += \
|
||||
' <a href="' + audioPostUrl + \
|
||||
|
|
Loading…
Reference in New Issue