Highlight new DM/replies/calendar events in text based browsers

main
Bob Mottram 2020-06-17 12:38:04 +01:00
parent 18b80efcb7
commit fca6add614
1 changed files with 29 additions and 6 deletions

View File

@ -4189,6 +4189,17 @@ def isQuestion(postObjectJson: {}) -> bool:
return True return True
def htmlHighlightLabel(label: str, highlight: bool) -> str:
"""If the give text should be highlighted then return
the appropriate markup.
This is so that in shell browsers, like lynx, it's possible
to see if the replies or DM button are highlighted.
"""
if not highlight:
return label
return '<u>' + label + '</u>'
def htmlTimeline(defaultTimeline: str, def htmlTimeline(defaultTimeline: str,
recentPostsCache: {}, maxRecentPosts: int, recentPostsCache: {}, maxRecentPosts: int,
translate: {}, pageNumber: int, translate: {}, pageNumber: int,
@ -4204,10 +4215,12 @@ def htmlTimeline(defaultTimeline: str,
accountDir = baseDir + '/accounts/' + nickname + '@' + domain accountDir = baseDir + '/accounts/' + nickname + '@' + domain
# should the calendar icon be highlighted? # should the calendar icon be highlighted?
newCalendarEvent = False
calendarImage = 'calendar.png' calendarImage = 'calendar.png'
calendarPath = '/calendar' calendarPath = '/calendar'
calendarFile = accountDir + '/.newCalendar' calendarFile = accountDir + '/.newCalendar'
if os.path.isfile(calendarFile): if os.path.isfile(calendarFile):
newCalendarEvent = True
calendarImage = 'calendar_notify.png' calendarImage = 'calendar_notify.png'
with open(calendarFile, 'r') as calfile: with open(calendarFile, 'r') as calfile:
calendarPath = calfile.read().replace('##sent##', '') calendarPath = calfile.read().replace('##sent##', '')
@ -4352,14 +4365,16 @@ def htmlTimeline(defaultTimeline: str,
'<a href="' + usersPath + \ '<a href="' + usersPath + \
'/moderation"><button class="' + \ '/moderation"><button class="' + \
moderationButton + '"><span>' + \ moderationButton + '"><span>' + \
translate['Mod'] + ' </span></button></a>' htmlHighlightLabel(translate['Mod'], newReport) + \
' </span></button></a>'
sharesButtonStr = '' sharesButtonStr = ''
bookmarksButtonStr = '' bookmarksButtonStr = ''
if not minimal: if not minimal:
sharesButtonStr = \ sharesButtonStr = \
'<a href="' + usersPath + '/tlshares"><button class="' + \ '<a href="' + usersPath + '/tlshares"><button class="' + \
sharesButton + '"><span>' + translate['Shares'] + \ sharesButton + '"><span>' + \
htmlHighlightLabel(translate['Shares'], newShare) + \
' </span></button></a>' ' </span></button></a>'
bookmarksButtonStr = \ bookmarksButtonStr = \
@ -4441,10 +4456,13 @@ def htmlTimeline(defaultTimeline: str,
tlStr += \ tlStr += \
' <a href="' + usersPath + '/dm"><button class="' + dmButton + \ ' <a href="' + usersPath + '/dm"><button class="' + dmButton + \
'"><span>' + translate['DM'] + '</span></button></a>' '"><span>' + htmlHighlightLabel(translate['DM'], newDM) + \
'</span></button></a>'
tlStr += \ tlStr += \
' <a href="' + usersPath + '/tlreplies"><button class="' + \ ' <a href="' + usersPath + '/tlreplies"><button class="' + \
repliesButton + '"><span>' + translate['Replies'] + \ repliesButton + '"><span>' + \
htmlHighlightLabel(translate['Replies'], newReply) + \
'</span></button></a>' '</span></button></a>'
# typically the media button # typically the media button
@ -4493,12 +4511,17 @@ def htmlTimeline(defaultTimeline: str,
iconsDir + '/search.png" title="' + \ iconsDir + '/search.png" title="' + \
translate['Search and follow'] + '" alt="' + \ translate['Search and follow'] + '" alt="' + \
translate['Search and follow'] + '" class="timelineicon"/></a>' translate['Search and follow'] + '" class="timelineicon"/></a>'
calendarAltText = translate['Calendar']
if newCalendarEvent:
# indicate that the calendar icon is highlighted
calendarAltText = '*' + calendarAltText + '*'
tlStr += \ tlStr += \
' <a href="' + usersPath + calendarPath + \ ' <a href="' + usersPath + calendarPath + \
'"><img loading="lazy" src="/' + iconsDir + '/' + \ '"><img loading="lazy" src="/' + iconsDir + '/' + \
calendarImage + '" title="' + translate['Calendar'] + \ calendarImage + '" title="' + translate['Calendar'] + \
'" alt="' + translate['Calendar'] + \ '" alt="' + calendarAltText + '" class="timelineicon"/></a>'
'" class="timelineicon"/></a>'
tlStr += \ tlStr += \
' <a href="' + usersPath + '/minimal' + \ ' <a href="' + usersPath + '/minimal' + \
'"><img loading="lazy" src="/' + iconsDir + \ '"><img loading="lazy" src="/' + iconsDir + \