From 1dde784bd869b4d85d29568325092c8a0df06f09 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 31 Jul 2019 13:44:08 +0100 Subject: [PATCH] Add content warnings in wen interface --- epicyon-follow.css | 16 ++++++++++++++++ epicyon-profile.css | 16 ++++++++++++++++ person.py | 5 +++-- webinterface.py | 44 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/epicyon-follow.css b/epicyon-follow.css index 8ae28dcd..af4f415b 100644 --- a/epicyon-follow.css +++ b/epicyon-follow.css @@ -58,3 +58,19 @@ input[type=text] { color: var(--text-entry-foreground); background-color: var(--text-entry-background); } + +.cwButton { + border-radius: 4px; + background-color: #999; + border: none; + color: #FFFFFF; + text-align: center; + font-size: 18px; + padding: 2px; + cursor: pointer; + margin: 5px; +} + +.cwText { + display: none; +} diff --git a/epicyon-profile.css b/epicyon-profile.css index 1eee4cee..a60ab40b 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -6,6 +6,22 @@ body, html { margin: 0 auto; } +.cwButton { + border-radius: 4px; + background-color: #999; + border: none; + color: #FFFFFF; + text-align: center; + font-size: 18px; + padding: 2px; + cursor: pointer; + margin: 5px; +} + +.cwText { + display: none; +} + .timeline-banner { background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("banner.png"); height: 10%; diff --git a/person.py b/person.py index 02e47cea..a8b0f85b 100644 --- a/person.py +++ b/person.py @@ -162,6 +162,7 @@ def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \ 'name': nickname, 'outbox': httpPrefix+'://'+domain+'/users/'+nickname+'/outbox', 'preferredUsername': ''+nickname, + 'summary': '', 'publicKey': {'id': httpPrefix+'://'+domain+'/users/'+nickname+'#main-key', 'owner': httpPrefix+'://'+domain+'/users/'+nickname, 'publicKeyPem': publicKeyPem, @@ -406,9 +407,9 @@ def setBio(baseDir: str,nickname: str, domain: str, bio: str) -> bool: personJson=commentjson.load(fp) if not personJson: return False - if not personJson.get('publicKey'): + if not personJson.get('summary'): return False - personJson['publicKey']['summary']=bio + personJson['summary']=bio with open(filename, 'w') as fp: commentjson.dump(personJson, fp, indent=4, sort_keys=False) return True diff --git a/webinterface.py b/webinterface.py index 193cf0f9..f19d92e4 100644 --- a/webinterface.py +++ b/webinterface.py @@ -20,6 +20,7 @@ from webfinger import webfingerHandle from posts import getUserUrl from posts import parseUserFeed from session import getJson +from auth import createPassword def htmlGetLoginCredentials(loginParams: str,lastLoginTime: int) -> (str,str): """Receives login credentials via HTTPServer POST @@ -198,6 +199,7 @@ def htmlProfilePosts(baseDir: str,httpPrefix: str, \ 4, 'outbox', \ authorized, \ ocapAlways) + profileStr+='' for item in outboxFeed['orderedItems']: if item['type']=='Create' or item['type']=='Announce': profileStr+= \ @@ -280,7 +282,7 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool, \ domainFull=domain if port: domainFull=domain+':'+str(port) - profileDescription=profileJson['publicKey']['summary'] + profileDescription=profileJson['summary'] profileDescription='A test description' postsButton='button' followingButton='button' @@ -413,6 +415,20 @@ def individualFollowAsHtml(session,wfRequest: {}, \ '

'+titleStr+'

'+ \ '\n' +def contentWarningScript() -> str: + """Returns a script used for content warnings + """ + script= \ + 'function showContentWarning(postID) {' \ + ' var x = document.getElementById(postID);' \ + ' if (x.style.display === "none") {' \ + ' x.style.display = "block";' \ + ' } else {' \ + ' x.style.display = "none";' \ + ' }' \ + '}' + return script + def individualPostAsHtml(baseDir: str, \ session,wfRequest: {},personCache: {}, \ nickname: str,domain: str,port: int, \ @@ -535,12 +551,25 @@ def individualPostAsHtml(baseDir: str, \ footerStr+=''+postJsonObject['object']['published']+'' footerStr+='' + if not postJsonObject['object']['sensitive']: + contentStr=postJsonObject['object']['content']+attachmentStr + else: + postID='post'+str(createPassword(8)) + contentStr='' + if postJsonObject['object'].get('summary'): + contentStr+=''+postJsonObject['object']['summary']+' ' + else: + contentStr+='Sensitive ' + contentStr+='' + contentStr+='
' + contentStr+=postJsonObject['object']['content']+attachmentStr + contentStr+='
' + return \ '
\n'+ \ avatarDropdown+ \ '

'+titleStr+'

'+ \ - postJsonObject['object']['content']+'\n'+ \ - attachmentStr+footerStr+ \ + contentStr+footerStr+ \ '
\n' def htmlTimeline(session,baseDir: str,wfRequest: {},personCache: {}, \ @@ -587,11 +616,13 @@ def htmlTimeline(session,baseDir: str,wfRequest: {},personCache: {}, \ ' Search and follow'+ \ followApprovals+ \ '' + tlStr+='' for item in timelineJson['orderedItems']: if item['type']=='Create' or item['type']=='Announce': tlStr+=individualPostAsHtml(baseDir,session,wfRequest,personCache, \ nickname,domain,port,item,None,True,showIndividualPostIcons) tlStr+=htmlFooter() + print(tlStr) return tlStr def htmlInbox(session,baseDir: str,wfRequest: {},personCache: {}, \ @@ -775,9 +806,8 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \ if profileJson.get('preferredUsername'): preferredName=profileJson['preferredUsername'] profileDescription='' - if profileJson.get('publicKey'): - if profileJson['publicKey'].get('summary'): - profileDescription=profileJson['publicKey']['summary'] + if profileJson.get('summary'): + profileDescription=profileJson['summary'] outboxUrl=None if not profileJson.get('outbox'): if debug: @@ -816,6 +846,8 @@ def htmlProfileAfterSearch(baseDir: str,path: str,httpPrefix: str, \ ' ' \ '' + profileStr+='' + result = [] i = 0 for item in parseUserFeed(session,outboxUrl,asHeader):