Snooze button

main2
Bob Mottram 2019-11-06 11:39:41 +00:00
parent 9ff4ee4166
commit 057251ae6f
17 changed files with 161 additions and 15 deletions

View File

@ -34,6 +34,8 @@ from person import suspendAccount
from person import unsuspendAccount from person import unsuspendAccount
from person import removeAccount from person import removeAccount
from person import canRemovePost from person import canRemovePost
from person import personSnooze
from person import personUnsnooze
from posts import outboxMessageCreateWrap from posts import outboxMessageCreateWrap
from posts import savePostToBox from posts import savePostToBox
from posts import sendToFollowersThread from posts import sendToFollowersThread
@ -4046,6 +4048,26 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg) self._write(msg)
self.server.POSTbusy=False self.server.POSTbusy=False
return 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 '&submitReport=' in optionsConfirmParams:
if self.server.debug: if self.server.debug:
print('Reporting '+optionsActor) print('Reporting '+optionsActor)

View File

@ -750,3 +750,85 @@ def activateAccount(baseDir: str,nickname: str,domain: str) -> None:
if os.path.isdir(deactivatedSharefilesDir+'/'+nickname): if os.path.isdir(deactivatedSharefilesDir+'/'+nickname):
if not os.path.isdir(baseDir+'/sharefiles/'+nickname): if not os.path.isdir(baseDir+'/sharefiles/'+nickname):
shutil.move(deactivatedSharefilesDir+'/'+nickname,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()

View File

@ -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", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Només les persones que segueixo em poden enviar missatges directes", "Only people I follow can send me DMs": "Només les persones que segueixo em poden enviar missatges directes",
"Logout": "a fora", "Logout": "a fora",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Only people I follow can send me DMs": "Dim ond y bobl rwy'n eu dilyn all anfon negeseuon uniongyrchol ataf",
"Logout": "Allgofnodi", "Logout": "Allgofnodi",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Nur Personen, denen ich folge, können mir direkte Nachrichten senden", "Only people I follow can send me DMs": "Nur Personen, denen ich folge, können mir direkte Nachrichten senden",
"Logout": "Aus", "Logout": "Aus",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Only people I follow can send me DMs", "Only people I follow can send me DMs": "Only people I follow can send me DMs",
"Logout": "Logout", "Logout": "Logout",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Solo las personas que sigo pueden enviarme mensajes directos", "Only people I follow can send me DMs": "Solo las personas que sigo pueden enviarme mensajes directos",
"Logout": "Cerrar", "Logout": "Cerrar",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Only people I follow can send me DMs": "Seules les personnes que je suis en contact peuvent m'envoyer des messages directs",
"Logout": "Dehors", "Logout": "Dehors",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Only people I follow can send me DMs": "Ní féidir ach le daoine a leanaim teachtaireachtaí díreacha a chur chugam",
"Logout": "Amach", "Logout": "Amach",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Solo le persone che seguo possono inviarmi messaggi diretti", "Only people I follow can send me DMs": "Solo le persone che seguo possono inviarmi messaggi diretti",
"Logout": "Su", "Logout": "Su",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -167,5 +167,7 @@
"Only people I follow can send me DMs": "Somente as pessoas que eu sigo podem me enviar mensagens diretas", "Only people I follow can send me DMs": "Somente as pessoas que eu sigo podem me enviar mensagens diretas",
"Logout": "Sair", "Logout": "Sair",
"Danger Zone": "Danger Zone", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -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", "Danger Zone": "Danger Zone",
"Deactivate this account": "Deactivate this account" "Deactivate this account": "Deactivate this account",
"Snooze": "Snooze",
"Unsnooze": "Unsnooze"
} }

View File

@ -18,6 +18,7 @@ from shutil import copyfile
from shutil import copyfileobj from shutil import copyfileobj
from pprint import pprint from pprint import pprint
from person import personBoxJson from person import personBoxJson
from person import isPersonSnoozed
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import locatePost from utils import locatePost
@ -1837,6 +1838,10 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
""" """
postActor=postJsonObject['actor'] postActor=postJsonObject['actor']
# ZZZzzz
if isPersonSnoozed(baseDir,nickname,domain,postActor):
return ''
if not showPublicOnly and storeToCache and boxName!='tlmedia': if not showPublicOnly and storeToCache and boxName!='tlmedia':
# update avatar if needed # update avatar if needed
if not avatarUrl: if not avatarUrl:
@ -2837,6 +2842,7 @@ def htmlPersonOptions(translate: {},baseDir: str, \
followStr='Follow' followStr='Follow'
blockStr='Block' blockStr='Block'
nickname=None
if originPathStr.startswith('/users/'): if originPathStr.startswith('/users/'):
nickname=originPathStr.split('/users/')[1] nickname=originPathStr.split('/users/')[1]
if '/' in nickname: if '/' in nickname:
@ -2863,6 +2869,13 @@ def htmlPersonOptions(translate: {},baseDir: str, \
cssFilename=baseDir+'/follow.css' cssFilename=baseDir+'/follow.css'
with open(cssFilename, 'r') as cssFile: with open(cssFilename, 'r') as cssFile:
profileStyle = cssFile.read() 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=htmlHeader(cssFilename,profileStyle)
optionsStr+='<div class="options">' optionsStr+='<div class="options">'
optionsStr+=' <div class="optionsAvatar">' optionsStr+=' <div class="optionsAvatar">'
@ -2879,7 +2892,8 @@ def htmlPersonOptions(translate: {},baseDir: str, \
' <button type="submit" class="button" name="submitView">'+translate['View']+'</button>' \ ' <button type="submit" class="button" name="submitView">'+translate['View']+'</button>' \
' <button type="submit" class="button" name="submit'+followStr+'">'+translate[followStr]+'</button>' \ ' <button type="submit" class="button" name="submit'+followStr+'">'+translate[followStr]+'</button>' \
' <button type="submit" class="button" name="submit'+blockStr+'">'+translate[blockStr]+'</button>' \ ' <button type="submit" class="button" name="submit'+blockStr+'">'+translate[blockStr]+'</button>' \
' <button type="submit" class="button" name="submitDM">'+translate['DM']+'</button>' \ ' <button type="submit" class="button" name="submitDM">'+translate['DM']+'</button>'+ \
' <button type="submit" class="button" name="submit"'+snoozeButtonStr+'>'+translate[snoozeButtonStr]+'</button>' \
' <button type="submit" class="button" name="submitReport">'+translate['Report']+'</button>' \ ' <button type="submit" class="button" name="submitReport">'+translate['Report']+'</button>' \
' </form>' ' </form>'
optionsStr+='</center>' optionsStr+='</center>'