Link desktop notifications to timelines

main
Bob Mottram 2021-03-09 22:12:12 +00:00
parent 2b67cff4dc
commit 4414666587
1 changed files with 24 additions and 13 deletions

View File

@ -11,6 +11,7 @@ import html
import time import time
import sys import sys
import select import select
from utils import getFullDomain
from session import createSession from session import createSession
from speaker import getSpeakerFromServer from speaker import getSpeakerFromServer
from speaker import getSpeakerPitch from speaker import getSpeakerPitch
@ -117,6 +118,8 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
print('Running desktop notifications for ' + nickname + '@' + domain) print('Running desktop notifications for ' + nickname + '@' + domain)
print('/q or /quit to exit') print('/q or /quit to exit')
domainFull = getFullDomain(domain, port)
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
prevSay = '' prevSay = ''
prevDM = False prevDM = False
prevReply = False prevReply = False
@ -132,7 +135,6 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
shareSoundFilename = 'share.ogg' shareSoundFilename = 'share.ogg'
player = 'ffplay' player = 'ffplay'
notificationType = 'notify-send' notificationType = 'notify-send'
instanceTitle = 'Epicyon'
while (1): while (1):
session = createSession(proxyType) session = createSession(proxyType)
speakerJson = \ speakerJson = \
@ -140,6 +142,9 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
domain, port, httpPrefix, True, __version__) domain, port, httpPrefix, True, __version__)
if speakerJson: if speakerJson:
if speakerJson.get('notify'): if speakerJson.get('notify'):
title = 'Epicyon'
if speakerJson['notify'].get('title'):
title = speakerJson['notify']['title']
soundsDir = 'theme/default/sounds' soundsDir = 'theme/default/sounds'
if speakerJson['notify'].get('theme'): if speakerJson['notify'].get('theme'):
soundsDir = \ soundsDir = \
@ -152,47 +157,53 @@ def runNotificationsClient(baseDir: str, proxyType: str, httpPrefix: str,
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
dmSoundFilename, player) dmSoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New direct message') 'New direct message ' +
actor + '/dm')
elif replySoundFilename: elif replySoundFilename:
if speakerJson['notify']['reply'] and \ if speakerJson['notify']['reply'] and \
speakerJson['notify']['reply'] != prevReply: speakerJson['notify']['reply'] != prevReply:
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
replySoundFilename, player) replySoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New reply') 'New reply ' +
actor + '/tlreplies')
elif calendarSoundFilename: elif calendarSoundFilename:
if speakerJson['notify']['calendar'] and \ if speakerJson['notify']['calendar'] and \
speakerJson['notify']['calendar'] != prevCalendar: speakerJson['notify']['calendar'] != prevCalendar:
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
calendarSoundFilename, player) calendarSoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New calendar event') 'New calendar event ' +
actor + '/calendar')
elif followSoundFilename: elif followSoundFilename:
if speakerJson['notify']['followRequests'] and \ if speakerJson['notify']['followRequests'] and \
speakerJson['notify']['followRequests'] != prevFollow: speakerJson['notify']['followRequests'] != prevFollow:
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
followSoundFilename, player) followSoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New follow request') 'New follow request ' +
actor + '/followers#buttonheader')
elif likeSoundFilename: elif likeSoundFilename:
if speakerJson['notify']['likedBy'] != prevLike: if speakerJson['notify']['likedBy'] != prevLike:
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
likeSoundFilename, player) likeSoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New like') 'New like ' +
speakerJson['notify']['likedBy'])
elif shareSoundFilename: elif shareSoundFilename:
if speakerJson['notify']['share'] and \ if speakerJson['notify']['share'] and \
speakerJson['notify']['share'] != prevShare: speakerJson['notify']['share'] != prevShare:
_playNotificationSound(soundsDir + '/' + _playNotificationSound(soundsDir + '/' +
shareSoundFilename, player) shareSoundFilename, player)
_desktopNotification(notificationType, _desktopNotification(notificationType,
instanceTitle, title,
'New shared item') 'New shared item ' +
actor + '/shares')
prevDM = speakerJson['notify']['dm'] prevDM = speakerJson['notify']['dm']
prevReply = speakerJson['notify']['reply'] prevReply = speakerJson['notify']['reply']