merge-requests/30/head
Bob Mottram 2021-03-19 14:49:40 +00:00
parent 4de012144a
commit 6c460743b8
1 changed files with 31 additions and 0 deletions

View File

@ -389,6 +389,35 @@ def _textOnlyContent(content: str) -> str:
return removeHtml(content)
def _getImageDescription(postJsonObject: {}) -> str:
"""Returns a image description/s on a post
"""
imageDescription = ''
if not postJsonObject['object'].get('attachment'):
return imageDescription
attachList = postJsonObject['object']['attachment']
if not isinstance(attachList, list):
return imageDescription
# for each attachment
for img in attachList:
if not isinstance(img, dict):
continue
if not img.get('name'):
continue
if not isinstance(img['name'], str):
continue
messageStr = img['name']
if messageStr:
messageStr = messageStr.strip()
if not messageStr.endswith('.'):
imageDescription += messageStr + '. '
else:
imageDescription += messageStr + ' '
return imageDescription
def _readLocalBoxPost(session, nickname: str, domain: str,
httpPrefix: str, baseDir: str, boxName: str,
pageNumber: int, index: int, boxJson: {},
@ -440,6 +469,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
time.sleep(2)
content = \
_textOnlyContent(postJsonObject2['object']['content'])
content += _getImageDescription(postJsonObject2)
messageStr, detectedLinks = \
speakableText(baseDir, content, translate)
sayStr = content
@ -451,6 +481,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
actor = postJsonObject['object']['attributedTo']
nameStr = getNicknameFromActor(actor)
content = _textOnlyContent(postJsonObject['object']['content'])
content += _getImageDescription(postJsonObject)
if isPGPEncrypted(content):
sayStr = 'Encrypted message. Please enter your passphrase.'