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 httpsig import messageContentDigest
from blocking import isBlockedDomain from blocking import isBlockedDomain
from posts import downloadAnnounce from posts import downloadAnnounce
from posts import isDM
def validInbox(baseDir: str,nickname: str,domain: str) -> bool: def validInbox(baseDir: str,nickname: str,domain: str) -> bool:
"""Checks whether files were correctly saved to the inbox """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) ' obtaining actor for '+lookupActor)
time.sleep(5) 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: {}, \ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
baseDir: str,httpPrefix: str,sendThreads: [], \ baseDir: str,httpPrefix: str,sendThreads: [], \
postLog: [],cachedWebfingers: {},personCache: {}, \ postLog: [],cachedWebfingers: {},personCache: {}, \
@ -1308,6 +1320,8 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
if messageJson.get('postNickname'): if messageJson.get('postNickname'):
if validPostContent(messageJson['post'],maxMentions): if validPostContent(messageJson['post'],maxMentions):
if isDM(messageJson['post']):
dmNotify(baseDir,handle)
obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson['post'],debug) obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson['post'],debug)
try: try:
with open(destinationFilename, 'w+') as fp: with open(destinationFilename, 'w+') as fp:
@ -1316,6 +1330,8 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
print(e) print(e)
else: else:
if validPostContent(messageJson,maxMentions): if validPostContent(messageJson,maxMentions):
if isDM(messageJson):
dmNotify(baseDir,handle)
obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson,debug) obtainAvatarForReplyPost(session,baseDir,httpPrefix,domain,personCache,messageJson,debug)
try: try:
with open(destinationFilename, 'w+') as fp: with open(destinationFilename, 'w+') as fp:

View File

@ -2030,6 +2030,14 @@ def htmlTimeline(translate: {},pageNumber: int, \
manuallyApproveFollowers: bool) -> str: manuallyApproveFollowers: bool) -> str:
"""Show the timeline as html """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) iconsDir=getIconsDir(baseDir)
cssFilename=baseDir+'/epicyon-profile.css' cssFilename=baseDir+'/epicyon-profile.css'
if os.path.isfile(baseDir+'/epicyon.css'): if os.path.isfile(baseDir+'/epicyon.css'):
@ -2043,6 +2051,8 @@ def htmlTimeline(translate: {},pageNumber: int, \
inboxButton='button' inboxButton='button'
dmButton='button' dmButton='button'
if newDM:
dmButton='buttonhighlighted'
repliesButton='button' repliesButton='button'
mediaButton='button' mediaButton='button'
sentButton='button' sentButton='button'
@ -2051,6 +2061,8 @@ def htmlTimeline(translate: {},pageNumber: int, \
inboxButton='buttonselected' inboxButton='buttonselected'
elif boxName=='dm': elif boxName=='dm':
dmButton='buttonselected' dmButton='buttonselected'
if newDM:
dmButton='buttonselectedhighlighted'
elif boxName=='tlreplies': elif boxName=='tlreplies':
repliesButton='buttonselected' repliesButton='buttonselected'
elif boxName=='tlmedia': elif boxName=='tlmedia':