__filename__ = "webapp_person_options.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.1.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" import os from shutil import copyfile from petnames import getPetName from person import isPersonSnoozed from posts import isModerator from utils import getFullDomain from utils import getConfigParam from utils import isDormant from utils import removeHtml from utils import getDomainFromActor from utils import getNicknameFromActor from blocking import isBlocked from follow import isFollowingActor from followingCalendar import receivingCalendarEvents from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter from webapp_utils import getBrokenLinkSubstitute def htmlPersonOptions(defaultTimeline: str, cssCache: {}, translate: {}, baseDir: str, domain: str, domainFull: str, originPathStr: str, optionsActor: str, optionsProfileUrl: str, optionsLink: str, pageNumber: int, donateUrl: str, xmppAddress: str, matrixAddress: str, ssbAddress: str, blogAddress: str, toxAddress: str, jamiAddress: str, PGPpubKey: str, PGPfingerprint: str, emailAddress: str, dormantMonths: int) -> str: """Show options for a person: view/follow/block/report """ optionsDomain, optionsPort = getDomainFromActor(optionsActor) optionsDomainFull = getFullDomain(optionsDomain, optionsPort) if os.path.isfile(baseDir + '/accounts/options-background-custom.jpg'): if not os.path.isfile(baseDir + '/accounts/options-background.jpg'): copyfile(baseDir + '/accounts/options-background.jpg', baseDir + '/accounts/options-background.jpg') dormant = False followStr = 'Follow' blockStr = 'Block' nickname = None optionsNickname = None if originPathStr.startswith('/users/'): nickname = originPathStr.split('/users/')[1] if '/' in nickname: nickname = nickname.split('/')[0] if '?' in nickname: nickname = nickname.split('?')[0] followerDomain, followerPort = getDomainFromActor(optionsActor) if isFollowingActor(baseDir, nickname, domain, optionsActor): followStr = 'Unfollow' dormant = \ isDormant(baseDir, nickname, domain, optionsActor, dormantMonths) optionsNickname = getNicknameFromActor(optionsActor) optionsDomainFull = getFullDomain(optionsDomain, optionsPort) if isBlocked(baseDir, nickname, domain, optionsNickname, optionsDomainFull): blockStr = 'Block' optionsLinkStr = '' if optionsLink: optionsLinkStr = \ ' \n' cssFilename = baseDir + '/epicyon-options.css' if os.path.isfile(baseDir + '/options.css'): cssFilename = baseDir + '/options.css' # To snooze, or not to snooze? That is the question snoozeButtonStr = 'Snooze' if nickname: if isPersonSnoozed(baseDir, nickname, domain, optionsActor): snoozeButtonStr = 'Unsnooze' donateStr = '' if donateUrl: donateStr = \ ' \n' optionsStr = htmlHeaderWithExternalStyle(cssFilename) optionsStr += '

\n' optionsStr += '
\n' optionsStr += '
\n' optionsStr += '
\n' optionsStr += ' \n' optionsStr += ' \n' handle = getNicknameFromActor(optionsActor) + '@' + optionsDomain handleShown = handle if dormant: handleShown += ' 💤' optionsStr += \ '

' + translate['Options for'] + \ ' @' + handleShown + '

\n' if emailAddress: optionsStr += \ '

' + translate['Email'] + \ ': ' + removeHtml(emailAddress) + '

\n' if xmppAddress: optionsStr += \ '

' + translate['XMPP'] + \ ': ' + \ xmppAddress + '

\n' if matrixAddress: optionsStr += \ '

' + translate['Matrix'] + ': ' + \ removeHtml(matrixAddress) + '

\n' if ssbAddress: optionsStr += \ '

SSB: ' + removeHtml(ssbAddress) + '

\n' if blogAddress: optionsStr += \ '

Blog: ' + \ removeHtml(blogAddress) + '

\n' if toxAddress: optionsStr += \ '

Tox: ' + removeHtml(toxAddress) + '

\n' if jamiAddress: optionsStr += \ '

Jami: ' + removeHtml(jamiAddress) + '

\n' if PGPfingerprint: optionsStr += '

PGP: ' + \ removeHtml(PGPfingerprint).replace('\n', '
') + '

\n' if PGPpubKey: optionsStr += '

' + \ removeHtml(PGPpubKey).replace('\n', '
') + '

\n' optionsStr += '
\n' optionsStr += ' \n' optionsStr += ' \n' optionsStr += ' \n' if optionsNickname: handle = optionsNickname + '@' + optionsDomainFull petname = getPetName(baseDir, nickname, domain, handle) optionsStr += \ ' ' + translate['Petname'] + ': \n' + \ ' \n' \ '
\n' # checkbox for receiving calendar events if isFollowingActor(baseDir, nickname, domain, optionsActor): checkboxStr = \ ' ' + \ translate['Receive calendar events from this account'] + \ '\n
\n' if not receivingCalendarEvents(baseDir, nickname, domain, optionsNickname, optionsDomainFull): checkboxStr = checkboxStr.replace(' checked>', '>') optionsStr += checkboxStr # checkbox for permission to post to newswire if optionsDomainFull == domainFull: adminNickname = getConfigParam(baseDir, 'admin') if (nickname == adminNickname or (isModerator(baseDir, nickname) and not isModerator(baseDir, optionsNickname))): newswireBlockedFilename = \ baseDir + '/accounts/' + \ optionsNickname + '@' + optionsDomain + '/.nonewswire' checkboxStr = \ ' ' + \ translate['Allow news posts'] + \ '\n
\n' if os.path.isfile(newswireBlockedFilename): checkboxStr = checkboxStr.replace(' checked>', '>') optionsStr += checkboxStr optionsStr += optionsLinkStr backPath = '/' if nickname: backPath = '/users/' + nickname + '/' + defaultTimeline optionsStr += \ ' \n' optionsStr += \ ' \n' optionsStr += donateStr optionsStr += \ ' \n' optionsStr += \ ' \n' optionsStr += \ ' \n' optionsStr += \ ' \n' optionsStr += \ ' \n' if isModerator(baseDir, nickname): optionsStr += \ ' \n' personNotes = '' personNotesFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + \ '/notes/' + handle + '.txt' if os.path.isfile(personNotesFilename): with open(personNotesFilename, 'r') as fp: personNotes = fp.read() optionsStr += \ '

' + translate['Notes'] + ': \n' optionsStr += '
\n' optionsStr += \ ' \n' optionsStr += '
\n' optionsStr += '
\n' optionsStr += '
\n' optionsStr += '
\n' optionsStr += htmlFooter() return optionsStr