From 4ae19caeb4417d1044754035f2d22085d757cb4f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 8 Sep 2021 20:30:49 +0100 Subject: [PATCH] Set reply interval from edit profile screen --- daemon.py | 11 ++++++++++- translations/ar.json | 3 ++- translations/ca.json | 3 ++- translations/cy.json | 3 ++- translations/de.json | 3 ++- translations/en.json | 3 ++- translations/es.json | 3 ++- translations/fr.json | 3 ++- translations/ga.json | 3 ++- translations/hi.json | 3 ++- translations/it.json | 3 ++- translations/ja.json | 3 ++- translations/ku.json | 3 ++- translations/oc.json | 3 ++- translations/pt.json | 3 ++- translations/ru.json | 3 ++- translations/sw.json | 3 ++- translations/zh.json | 3 ++- utils.py | 19 ++++++++++++++++++- webapp_profile.py | 20 +++++++++++++++++--- 20 files changed, 79 insertions(+), 22 deletions(-) diff --git a/daemon.py b/daemon.py index 0fb40703e..8de90078e 100644 --- a/daemon.py +++ b/daemon.py @@ -232,6 +232,7 @@ from categories import updateHashtagCategories from languages import getActorLanguages from languages import setActorLanguages from like import updateLikesCollection +from utils import setReplyIntervalHours from utils import canReplyTo from utils import isDM from utils import replaceUsersWithAt @@ -4539,6 +4540,12 @@ class PubServer(BaseHTTPRequestHandler): storeBasicCredentials(baseDir, nickname, fields['password']) + # reply interval in hours + if fields.get('replyhours'): + if fields['replyhours'].isdigit(): + setReplyIntervalHours(baseDir, nickname, domain, + fields['replyhours']) + # change city if fields.get('cityDropdown'): cityFilename = \ @@ -11367,6 +11374,7 @@ class PubServer(BaseHTTPRequestHandler): if self.server.keyShortcuts.get(nickname): accessKeys = self.server.keyShortcuts[nickname] + defaultReplyIntervalHours = self.server.defaultReplyIntervalHours msg = htmlEditProfile(self.server.cssCache, translate, baseDir, @@ -11379,7 +11387,8 @@ class PubServer(BaseHTTPRequestHandler): self.server.textModeBanner, city, self.server.userAgentsBlocked, - accessKeys).encode('utf-8') + accessKeys, + defaultReplyIntervalHours).encode('utf-8') if msg: msglen = len(msg) self._set_headers('text/html', msglen, diff --git a/translations/ar.json b/translations/ar.json index dfc32a780..fb9071fad 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -477,5 +477,6 @@ "Low Bandwidth": "انخفاض النطاق الترددي", "accommodation": "الإقامة", "Forbidden": "محرم", - "You're not allowed": "كنت لا يسمح" + "You're not allowed": "كنت لا يسمح", + "Hours after posting during which replies are allowed": "ساعات بعد النشر المسموح بها خلال الردود" } diff --git a/translations/ca.json b/translations/ca.json index 8f73ec075..059adea12 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Ample de banda baixa", "accommodation": "allotjament", "Forbidden": "Prohibit", - "You're not allowed": "No està permès" + "You're not allowed": "No està permès", + "Hours after posting during which replies are allowed": "Hores després de la publicació durant les respostes" } diff --git a/translations/cy.json b/translations/cy.json index abb119458..23ea0077e 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Lled band isel", "accommodation": "llety", "Forbidden": "Wedi'i wahardd", - "You're not allowed": "Ni chaniateir i chi" + "You're not allowed": "Ni chaniateir i chi", + "Hours after posting during which replies are allowed": "Oriau ar ôl postio pan ganiateir atebion" } diff --git a/translations/de.json b/translations/de.json index 51f748e04..d4134fc3b 100644 --- a/translations/de.json +++ b/translations/de.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Niedrige Bandbreite", "accommodation": "unterkunft", "Forbidden": "Verboten", - "You're not allowed": "Du darfst nicht" + "You're not allowed": "Du darfst nicht", + "Hours after posting during which replies are allowed": "Stunden nach dem Posten, während denen Antworten erlaubt sind" } diff --git a/translations/en.json b/translations/en.json index 8c845274e..3a80afc89 100644 --- a/translations/en.json +++ b/translations/en.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Low Bandwidth", "accommodation": "accommodation", "Forbidden": "Forbidden", - "You're not allowed": "You're not allowed" + "You're not allowed": "You're not allowed", + "Hours after posting during which replies are allowed": "Hours after posting during which replies are allowed" } diff --git a/translations/es.json b/translations/es.json index 5f1954c63..6427d1542 100644 --- a/translations/es.json +++ b/translations/es.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Ancho de banda bajo", "accommodation": "alojamiento", "Forbidden": "Prohibida", - "You're not allowed": "No tienes permiso" + "You're not allowed": "No tienes permiso", + "Hours after posting during which replies are allowed": "Horas después de la publicación durante las cuales se permiten las respuestas" } diff --git a/translations/fr.json b/translations/fr.json index 4faf980a8..4e3965c5d 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Bas débit", "accommodation": "hébergement", "Forbidden": "Interdite", - "You're not allowed": "Tu n'as pas le droit" + "You're not allowed": "Tu n'as pas le droit", + "Hours after posting during which replies are allowed": "Heures après la publication pendant laquelle les réponses sont autorisées" } diff --git a/translations/ga.json b/translations/ga.json index f50567c05..2b1bbdf25 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Bandaleithead íseal", "accommodation": "lóistín", "Forbidden": "Toirmiscthe", - "You're not allowed": "Níl cead agat" + "You're not allowed": "Níl cead agat", + "Hours after posting during which replies are allowed": "Uair an chloig tar éis an phostála ina gceadaítear freagraí" } diff --git a/translations/hi.json b/translations/hi.json index cb948e1c6..73c393041 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -477,5 +477,6 @@ "Low Bandwidth": "कम बैंडविड्थ", "accommodation": "निवास स्थान", "Forbidden": "निषिद्ध", - "You're not allowed": "आपको अनुमति नहीं है" + "You're not allowed": "आपको अनुमति नहीं है", + "Hours after posting during which replies are allowed": "पोस्ट करने के कुछ घंटे जिसके बाद जवाब देने की अनुमति है" } diff --git a/translations/it.json b/translations/it.json index b1e46e249..caac28a7f 100644 --- a/translations/it.json +++ b/translations/it.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Bassa larghezza di banda", "accommodation": "struttura ricettiva", "Forbidden": "Proibita", - "You're not allowed": "Non ti è permesso" + "You're not allowed": "Non ti è permesso", + "Hours after posting during which replies are allowed": "Ore dopo la pubblicazione durante le quali le risposte sono consentite" } diff --git a/translations/ja.json b/translations/ja.json index 5ff84212d..60e77ad1c 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -477,5 +477,6 @@ "Low Bandwidth": "低帯域幅", "accommodation": "宿泊施設", "Forbidden": "禁断", - "You're not allowed": "あなたは許可されていません" + "You're not allowed": "あなたは許可されていません", + "Hours after posting during which replies are allowed": "転記後の時間返信が許可されています" } diff --git a/translations/ku.json b/translations/ku.json index 3915ac9df..263c8e2fc 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Bandwidth kêm", "accommodation": "cih", "Forbidden": "Qedexekirî", - "You're not allowed": "Destûrê nadin te" + "You're not allowed": "Destûrê nadin te", + "Hours after posting during which replies are allowed": "Demjimêran piştî şandina di dema bersivê de destûr tê dayîn" } diff --git a/translations/oc.json b/translations/oc.json index 1199e3154..8904ef514 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -473,5 +473,6 @@ "Low Bandwidth": "Low Bandwidth", "accommodation": "accommodation", "Forbidden": "Forbidden", - "You're not allowed": "You're not allowed" + "You're not allowed": "You're not allowed", + "Hours after posting during which replies are allowed": "Hours after posting during which replies are allowed" } diff --git a/translations/pt.json b/translations/pt.json index 9c7f14fd5..b577723da 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Baixa largura de banda", "accommodation": "alojamento", "Forbidden": "Proibida", - "You're not allowed": "Você não tem permissão" + "You're not allowed": "Você não tem permissão", + "Hours after posting during which replies are allowed": "Horas após a postagem durante as quais as respostas são permitidas" } diff --git a/translations/ru.json b/translations/ru.json index 514ef74af..5268bd9bb 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Низкая пропускная способность", "accommodation": "размещение", "Forbidden": "Запрещенный", - "You're not allowed": "Вам не разрешено" + "You're not allowed": "Вам не разрешено", + "Hours after posting during which replies are allowed": "Часы после размещения, в течение которых разрешены ответы" } diff --git a/translations/sw.json b/translations/sw.json index f7bb38937..ff4a574b5 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -477,5 +477,6 @@ "Low Bandwidth": "Bandwidth ya chini", "accommodation": "malazi", "Forbidden": "Imekatazwa", - "You're not allowed": "Hauruhusiwi" + "You're not allowed": "Hauruhusiwi", + "Hours after posting during which replies are allowed": "Masaa baada ya kuchapisha wakati majibu yanaruhusiwa." } diff --git a/translations/zh.json b/translations/zh.json index 684fe5322..3c2f75a98 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -477,5 +477,6 @@ "Low Bandwidth": "低带宽", "accommodation": "住所", "Forbidden": "禁止的", - "You're not allowed": "你不被允许" + "You're not allowed": "你不被允许", + "Hours after posting during which replies are allowed": "发布后的时间允许答复" } diff --git a/utils.py b/utils.py index 716c35112..6d85e6955 100644 --- a/utils.py +++ b/utils.py @@ -1350,6 +1350,23 @@ def getReplyIntervalHours(baseDir: str, nickname: str, domain: str, return defaultReplyIntervalHours +def setReplyIntervalHours(baseDir: str, nickname: str, domain: str, + replyIntervalHours: int) -> bool: + """Sets the reply interval for the given account. + The reply interval is the number of hours after a post being made + during which replies are allowed + """ + replyIntervalFilename = \ + acctDir(baseDir, nickname, domain) + '/.replyIntervalHours' + with open(replyIntervalFilename, 'w+') as fp: + try: + fp.write(str(replyIntervalHours)) + return True + except BaseException: + pass + return False + + def canReplyTo(baseDir: str, nickname: str, domain: str, postUrl: str, replyIntervalHours: int, currDateStr: str = None) -> bool: @@ -1380,7 +1397,7 @@ def canReplyTo(baseDir: str, nickname: str, domain: str, return False hoursSincePublication = int((currDate - pubDate).total_seconds() / 3600) if hoursSincePublication < 0 or \ - hoursSincePublication > replyIntervalHours: + hoursSincePublication >= replyIntervalHours: return False return True diff --git a/webapp_profile.py b/webapp_profile.py index ac87c99c2..0ee01a0da 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -25,6 +25,7 @@ from utils import getImageFormats from utils import acctDir from utils import getSupportedLanguages from utils import localActorUrl +from utils import getReplyIntervalHours from languages import getActorLanguages from skills import getSkills from theme import getThemesList @@ -1435,7 +1436,8 @@ def _htmlEditProfileSharedItems(baseDir: str, nickname: str, domain: str, def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str, - userAgentsBlocked: str, translate: {}) -> str: + userAgentsBlocked: str, translate: {}, + replyIntervalHours: int) -> str: """Filtering and blocking section of edit profile screen """ filterStr = '' @@ -1489,6 +1491,14 @@ def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str, editProfileForm = beginEditSection(translate['Filtering and Blocking']) + idx = 'Hours after posting during which replies are allowed' + editProfileForm += \ + '
\n' + editProfileForm += \ '