Nofification client stores outgoing dms locally

merge-requests/21/head
Bob Mottram 2021-03-12 14:55:37 +00:00
parent ed05285ace
commit 0e2ee60547
1 changed files with 23 additions and 4 deletions

View File

@ -13,6 +13,7 @@ import sys
import select import select
from pathlib import Path from pathlib import Path
from random import randint from random import randint
from utils import getStatusNumber
from utils import saveJson from utils import saveJson
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
@ -322,6 +323,7 @@ def _notificationNewDM(session, toHandle: str,
# if there is a local PGP key then attempt to encrypt the DM # if there is a local PGP key then attempt to encrypt the DM
# using the PGP public key of the recipient # using the PGP public key of the recipient
newMessageOriginal = newMessage
if hasLocalPGPkey(): if hasLocalPGPkey():
sayStr = \ sayStr = \
'Local PGP key detected...' + \ 'Local PGP key detected...' + \
@ -366,13 +368,30 @@ def _notificationNewDM(session, toHandle: str,
attachedImageDescription, attachedImageDescription,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
debug, None, None, subject) == 0: debug, None, None, subject) == 0:
# store the DM locally
statusNumber, published = getStatusNumber()
postId = \
httpPrefix + '://' + getFullDomain(domain, port) + \
'/users/' + nickname + '/statuses/' + statusNumber
speakerJson = {
"name": nickname,
"summary": "",
"content": newMessageOriginal,
"say": newMessageOriginal,
"published": published,
"imageDescription": "",
"detectedLinks": [],
"id": postId,
"direct": True
}
_storeMessage(speakerJson, 'sent')
sayStr = 'Direct message sent' sayStr = 'Direct message sent'
else: else:
sayStr = 'Direct message failed' sayStr = 'Direct message failed'
_sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak) _sayCommand(sayStr, sayStr, screenreader, systemLanguage, espeak)
def _storeMessage(speakerJson: {}) -> None: def _storeMessage(speakerJson: {}, boxName: str) -> None:
"""Stores a message in your home directory for later reading """Stores a message in your home directory for later reading
""" """
if not speakerJson.get('published'): if not speakerJson.get('published'):
@ -382,7 +401,7 @@ def _storeMessage(speakerJson: {}) -> None:
os.mkdir(homeDir + '/.config') os.mkdir(homeDir + '/.config')
if not os.path.isdir(homeDir + '/.config/epicyon'): if not os.path.isdir(homeDir + '/.config/epicyon'):
os.mkdir(homeDir + '/.config/epicyon') os.mkdir(homeDir + '/.config/epicyon')
msgDir = homeDir + '/.config/epicyon/dm' msgDir = homeDir + '/.config/epicyon/' + boxName
if not os.path.isdir(msgDir): if not os.path.isdir(msgDir):
os.mkdir(msgDir) os.mkdir(msgDir)
msgFilename = msgDir + '/' + speakerJson['published'] + '.json' msgFilename = msgDir + '/' + speakerJson['published'] + '.json'
@ -568,10 +587,10 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
speakerJson['content'] = content speakerJson['content'] = content
speakerJson['say'] = messageStr speakerJson['say'] = messageStr
speakerJson['decrypted'] = True speakerJson['decrypted'] = True
_storeMessage(speakerJson) _storeMessage(speakerJson, 'dm')
elif speakerJson.get('direct'): elif speakerJson.get('direct'):
speakerJson['decrypted'] = False speakerJson['decrypted'] = False
_storeMessage(speakerJson) _storeMessage(speakerJson, 'dm')
print('') print('')