Highlight DM button when a new DM arrives

main2
Bob Mottram 2019-10-03 17:22:34 +01:00
parent a10645d871
commit e6c2fc11a3
2 changed files with 28 additions and 0 deletions

View File

@ -44,6 +44,7 @@ from announce import updateAnnounceCollection
from httpsig import messageContentDigest
from blocking import isBlockedDomain
from posts import downloadAnnounce
from posts import isDM
def validInbox(baseDir: str,nickname: str,domain: str) -> bool:
"""Checks whether files were correctly saved to the inbox
@ -1218,6 +1219,17 @@ def obtainAvatarForReplyPost(session,baseDir: str,httpPrefix: str,domain: str,pe
' obtaining actor for '+lookupActor)
time.sleep(5)
def dmNotify(baseDir: str,handle: str) -> None:
"""Creates a notification that a new DM has arrived
"""
accountDir=baseDir+'/accounts/'+handle
if not os.path.isdir(accountDir):
return
dmFile=accountDir+'/.newDM'
if not os.path.isfile(dmFile):
with open(dmFile, 'w') as fp:
fp.write('\n')
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
baseDir: str,httpPrefix: str,sendThreads: [], \
postLog: [],cachedWebfingers: {},personCache: {}, \
@ -1308,6 +1320,8 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
if messageJson.get('postNickname'):
if validPostContent(messageJson['post'],maxMentions):
if isDM(messageJson['post']):
dmNotify(baseDir,handle)
obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson['post'],debug)
try:
with open(destinationFilename, 'w+') as fp:
@ -1316,6 +1330,8 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
print(e)
else:
if validPostContent(messageJson,maxMentions):
if isDM(messageJson):
dmNotify(baseDir,handle)
obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson,debug)
try:
with open(destinationFilename, 'w+') as fp:

View File

@ -2030,6 +2030,14 @@ def htmlTimeline(translate: {},pageNumber: int, \
manuallyApproveFollowers: bool) -> str:
"""Show the timeline as html
"""
# should the DM button be highlighted?
newDM=False
dmFile=baseDir+'/accounts/'+nickname+'@'+domain+'/.newDM'
if os.path.isfile(dmFile):
newDM=True
if boxName=='dm':
os.remove(dmFile)
iconsDir=getIconsDir(baseDir)
cssFilename=baseDir+'/epicyon-profile.css'
if os.path.isfile(baseDir+'/epicyon.css'):
@ -2043,6 +2051,8 @@ def htmlTimeline(translate: {},pageNumber: int, \
inboxButton='button'
dmButton='button'
if newDM:
dmButton='buttonhighlighted'
repliesButton='button'
mediaButton='button'
sentButton='button'
@ -2051,6 +2061,8 @@ def htmlTimeline(translate: {},pageNumber: int, \
inboxButton='buttonselected'
elif boxName=='dm':
dmButton='buttonselected'
if newDM:
dmButton='buttonselectedhighlighted'
elif boxName=='tlreplies':
repliesButton='buttonselected'
elif boxName=='tlmedia':