From 057251ae6f9d118d82cfa7c0fc1d7c68a67e9fb2 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 6 Nov 2019 11:39:41 +0000 Subject: [PATCH] Snooze button --- daemon.py | 22 ++++++++++++ person.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ translations/ar.json | 4 ++- translations/ca.json | 4 ++- translations/cy.json | 4 ++- translations/de.json | 4 ++- translations/en.json | 4 ++- translations/es.json | 4 ++- translations/fr.json | 4 ++- translations/ga.json | 4 ++- translations/hi.json | 4 ++- translations/it.json | 4 ++- translations/ja.json | 4 ++- translations/pt.json | 4 ++- translations/ru.json | 4 ++- translations/zh.json | 4 ++- webinterface.py | 16 ++++++++- 17 files changed, 161 insertions(+), 15 deletions(-) diff --git a/daemon.py b/daemon.py index 700a9bc7b..3160ab624 100644 --- a/daemon.py +++ b/daemon.py @@ -34,6 +34,8 @@ from person import suspendAccount from person import unsuspendAccount from person import removeAccount from person import canRemovePost +from person import personSnooze +from person import personUnsnooze from posts import outboxMessageCreateWrap from posts import savePostToBox from posts import sendToFollowersThread @@ -4046,6 +4048,26 @@ class PubServer(BaseHTTPRequestHandler): self._write(msg) self.server.POSTbusy=False return + if '&submitSnooze=' in optionsConfirmParams: + if self.server.debug: + print('Snoozing '+optionsActor) + thisActor=self.path.split('/personoptions')[0] + if '/users/' in thisActor: + nickname=thisActor.split('/users/')[1] + personSnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) + self._redirect_headers(thisActor+ \ + '/inbox?page='+str(pageNumber),cookie) + self.server.POSTbusy=False + if '&submitUnSnooze=' in optionsConfirmParams: + if self.server.debug: + print('Unsnoozing '+optionsActor) + thisActor=self.path.split('/personoptions')[0] + if '/users/' in thisActor: + nickname=thisActor.split('/users/')[1] + personUnsnooze(self.server.baseDir,nickname,self.server.domain,optionsActor) + self._redirect_headers(thisActor+ \ + '/inbox?page='+str(pageNumber),cookie) + self.server.POSTbusy=False if '&submitReport=' in optionsConfirmParams: if self.server.debug: print('Reporting '+optionsActor) diff --git a/person.py b/person.py index 4045f645d..d85c9ec58 100644 --- a/person.py +++ b/person.py @@ -750,3 +750,85 @@ def activateAccount(baseDir: str,nickname: str,domain: str) -> None: if os.path.isdir(deactivatedSharefilesDir+'/'+nickname): if not os.path.isdir(baseDir+'/sharefiles/'+nickname): shutil.move(deactivatedSharefilesDir+'/'+nickname,baseDir+'/sharefiles/'+nickname) + +def isPersonSnoozed(baseDir: str,nickname: str,domain: str,actor: str) -> bool: + """Returns true if the given actor is snoozed + """ + snoozedFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/snoozed.txt' + if not os.path.isfile(snoozedFilename): + return False + if snoozeActor+' ' not in open(snoozedFilename).read(): + return False + # remove the snooze entry if it has timed out + replaceStr=None + with open(snoozedFilename, 'r') as snoozedFile: + for line in snoozedFile: + # is this the entry for the actor? + if line.startswith(snoozeActor+' '): + snoozedTimeStr=line.split(' ')[1].replace('\n','') + # is there a time appended? + if snoozedTimeStr.isdigit(): + snoozedTime=int(snoozedTimeStr) + currTime=int(time.time()) + # has the snooze timed out? + if int(currTime-snoozedTime)>60*60*24: + replaceStr=line + else: + replaceStr=line + break + if replaceStr: + content=None + with open(snoozedFilename, 'r') as snoozedFile: + content=snoozedFile.read().replace(replaceStr,'') + if content: + writeSnoozedFile=open(snoozedFilename, 'w') + if writeSnoozedFile: + writeSnoozedFile.write(content) + writeSnoozedFile.close() + + if snoozeActor+' ' in open(snoozedFilename).read(): + return True + return False + +def personSnooze(baseDir: str,nickname: str,domain: str,snoozeActor: str) -> None: + """Temporarily ignores the given actor + """ + accountDir=baseDir+'/accounts/'+nickname+'@'+domain + if not os.path.isdir(accountDir): + print('ERROR: unknown account '+accountDir) + return + snoozedFilename=accountDir+'/snoozed.txt' + if snoozeActor+' ' in open(snoozedFilename).read(): + return + snoozedFile=open(snoozedFilename, "a+") + if snoozedFile: + snoozedFile.write(snoozeActor+' '+str(int(time.time()))+'\n') + snoozedFile.close() + +def personUnsnooze(baseDir: str,nickname: str,domain: str,snoozeActor: str) -> None: + """Undoes a temporarily ignore of the given actor + """ + accountDir=baseDir+'/accounts/'+nickname+'@'+domain + if not os.path.isdir(accountDir): + print('ERROR: unknown account '+accountDir) + return + snoozedFilename=accountDir+'/snoozed.txt' + if not os.path.isfile(snoozedFilename): + return + if snoozeActor+' ' not in open(snoozedFilename).read(): + return + replaceStr=None + with open(snoozedFilename, 'r') as snoozedFile: + for line in snoozedFile: + if line.startswith(snoozeActor+' '): + replaceStr=line + break + if replaceStr: + content=None + with open(snoozedFilename, 'r') as snoozedFile: + content=snoozedFile.read().replace(replaceStr,'') + if content: + writeSnoozedFile=open(snoozedFilename, 'w') + if writeSnoozedFile: + writeSnoozedFile.write(content) + writeSnoozedFile.close() diff --git a/translations/ar.json b/translations/ar.json index 6cbd1246c..e572557db 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "يمكن للأشخاص الذين أتابعهم فقط إرسال رسائل مباشرة إلي", "Logout": "خارج", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/ca.json b/translations/ca.json index 00dde0a02..6250bc0f2 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Només les persones que segueixo em poden enviar missatges directes", "Logout": "a fora", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/cy.json b/translations/cy.json index 2607bc1e0..86172a02b 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Dim ond y bobl rwy'n eu dilyn all anfon negeseuon uniongyrchol ataf", "Logout": "Allgofnodi", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/de.json b/translations/de.json index c0374eac0..436056d7e 100644 --- a/translations/de.json +++ b/translations/de.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Nur Personen, denen ich folge, können mir direkte Nachrichten senden", "Logout": "Aus", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/en.json b/translations/en.json index 2e4165f1c..52b0397cf 100644 --- a/translations/en.json +++ b/translations/en.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Only people I follow can send me DMs", "Logout": "Logout", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/es.json b/translations/es.json index 454b6f6c1..921498953 100644 --- a/translations/es.json +++ b/translations/es.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Solo las personas que sigo pueden enviarme mensajes directos", "Logout": "Cerrar", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/fr.json b/translations/fr.json index 5fe584727..1d8b97430 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Seules les personnes que je suis en contact peuvent m'envoyer des messages directs", "Logout": "Dehors", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/ga.json b/translations/ga.json index 53382bf2a..eb294b6b9 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Ní féidir ach le daoine a leanaim teachtaireachtaí díreacha a chur chugam", "Logout": "Amach", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/hi.json b/translations/hi.json index 85b1a2245..9463a9134 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "मेरे द्वारा अनुसरण किए जाने वाले लोग ही मुझे सीधे संदेश भेज सकते हैं", "Logout": "बाहर", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/it.json b/translations/it.json index bb2390b75..0ec4ecb6a 100644 --- a/translations/it.json +++ b/translations/it.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Solo le persone che seguo possono inviarmi messaggi diretti", "Logout": "Su", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/ja.json b/translations/ja.json index c065bba26..9a82cc35c 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "直接メッセージを送信できるのは、フォローしている人だけです", "Logout": "ログアウト", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/pt.json b/translations/pt.json index 864bc934d..5f47957a5 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Somente as pessoas que eu sigo podem me enviar mensagens diretas", "Logout": "Sair", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/ru.json b/translations/ru.json index 248246513..ae20f3226 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "Только люди, на которых я подписан, могут отправлять мне прямые сообщения", "Logout": "Выйти", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/translations/zh.json b/translations/zh.json index 27894dc52..75982d192 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -167,5 +167,7 @@ "Only people I follow can send me DMs": "只有我关注的人可以向我发送直接消息", "Logout": "登出", "Danger Zone": "Danger Zone", - "Deactivate this account": "Deactivate this account" + "Deactivate this account": "Deactivate this account", + "Snooze": "Snooze", + "Unsnooze": "Unsnooze" } diff --git a/webinterface.py b/webinterface.py index dd189404a..02cbc0869 100644 --- a/webinterface.py +++ b/webinterface.py @@ -18,6 +18,7 @@ from shutil import copyfile from shutil import copyfileobj from pprint import pprint from person import personBoxJson +from person import isPersonSnoozed from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost @@ -1837,6 +1838,10 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \ """ postActor=postJsonObject['actor'] + # ZZZzzz + if isPersonSnoozed(baseDir,nickname,domain,postActor): + return '' + if not showPublicOnly and storeToCache and boxName!='tlmedia': # update avatar if needed if not avatarUrl: @@ -2837,6 +2842,7 @@ def htmlPersonOptions(translate: {},baseDir: str, \ followStr='Follow' blockStr='Block' + nickname=None if originPathStr.startswith('/users/'): nickname=originPathStr.split('/users/')[1] if '/' in nickname: @@ -2863,6 +2869,13 @@ def htmlPersonOptions(translate: {},baseDir: str, \ cssFilename=baseDir+'/follow.css' with open(cssFilename, 'r') as cssFile: profileStyle = cssFile.read() + + # To snooze, or not to snooze? That is the question + snoozeButtonStr='Snooze' + if nickname: + if isPersonSnoozed(baseDir,nickname,domain,optionsActor): + snoozeButtonStr='Unsnooze' + optionsStr=htmlHeader(cssFilename,profileStyle) optionsStr+='
' optionsStr+='
' @@ -2879,7 +2892,8 @@ def htmlPersonOptions(translate: {},baseDir: str, \ ' ' \ ' ' \ ' ' \ - ' ' \ + ' '+ \ + ' ' \ ' ' \ ' ' optionsStr+=''