From a7b8f7453add0a7e61debd8ce1ba8a46d7d50512 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 24 Jun 2020 12:53:43 +0100 Subject: [PATCH] Reminder post type, for posting to yourself --- daemon.py | 42 +++++++++++++++++++++++++++++++++++++++++- posts.py | 32 ++++++++++++++++++++++++++++++++ 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/oc.json | 4 +++- translations/pt.json | 4 +++- translations/ru.json | 4 +++- translations/zh.json | 4 +++- webinterface.py | 15 ++++++++++++++- 18 files changed, 132 insertions(+), 17 deletions(-) diff --git a/daemon.py b/daemon.py index 0665fa2e6..a29206203 100644 --- a/daemon.py +++ b/daemon.py @@ -66,6 +66,7 @@ from posts import createReportPost from posts import createUnlistedPost from posts import createFollowersOnlyPost from posts import createDirectMessagePost +from posts import createReminderPost from posts import populateRepliesJson from posts import addToField from posts import expireCache @@ -3360,6 +3361,7 @@ class PubServer(BaseHTTPRequestHandler): if ('/users/' in self.path and (self.path.endswith('/newpost') or self.path.endswith('/newblog') or + self.path.endswith('/newreminder') or self.path.endswith('/newunlisted') or self.path.endswith('/newfollowers') or self.path.endswith('/newdm') or @@ -5435,6 +5437,44 @@ class PubServer(BaseHTTPRequestHandler): return 1 else: return -1 + elif postType == 'newreminder': + messageJson = None + print('A reminder was posted for ' + + nickname + '@' + self.server.domainFull) + messageJson = \ + createReminderPost(self.server.baseDir, + nickname, + self.server.domain, + self.server.port, + self.server.httpPrefix, + fields['message'], + True, False, False, + filename, attachmentMediaType, + fields['imageDescription'], + self.server.useBlurHash, + None, None, + fields['subject'], + True, fields['schedulePost'], + fields['eventDate'], + fields['eventTime'], + fields['location']) + if messageJson: + # ensure that this is only being sent to the author + messageJson['object']['cc'] = [] + messageJson['cc'] = [] + messageJson['object']['to'] = [ + self.server.httpPrefix + ':\\' + + self.server.domainFull + '/users/' + nickname + ] + messageJson['to'] = messageJson['object']['to'] + if fields['schedulePost']: + return 1 + print('DEBUG: new reminder to ' + + str(messageJson['object']['to'])) + if self._postToOutbox(messageJson, __version__, nickname): + return 1 + else: + return -1 elif postType == 'newreport': if attachmentMediaType: if attachmentMediaType != 'image': @@ -7732,7 +7772,7 @@ class PubServer(BaseHTTPRequestHandler): # receive different types of post created by htmlNewPost postTypes = ("newpost", "newblog", "newunlisted", "newfollowers", "newdm", "newreport", "newshare", "newquestion", - "editblogpost") + "editblogpost", "newreminder") for currPostType in postTypes: if not authorized: break diff --git a/posts.py b/posts.py index 4b1a09d88..48ca42403 100644 --- a/posts.py +++ b/posts.py @@ -1177,6 +1177,38 @@ def createDirectMessagePost(baseDir: str, return messageJson +def createReminderPost(baseDir: str, + nickname: str, domain: str, port: int, + httpPrefix: str, + content: str, followersOnly: bool, + saveToFile: bool, clientToServer: bool, + attachImageFilename: str, mediaType: str, + imageDescription: str, useBlurhash: bool, + inReplyTo=None, inReplyToAtomUri=None, + subject=None, debug=False, + schedulePost=False, + eventDate=None, eventTime=None, + location=None) -> {}: + """Reminder post to self + For example, adding something to your calendar to remind you of an event + """ + postTo = None + postCc = None + messageJson = \ + createPostBase(baseDir, nickname, domain, port, + postTo, postCc, + httpPrefix, content, followersOnly, saveToFile, + clientToServer, + attachImageFilename, mediaType, + imageDescription, useBlurhash, + False, False, inReplyTo, inReplyToAtomUri, subject, + schedulePost, eventDate, eventTime, location) + if schedulePost: + savePostToBox(baseDir, httpPrefix, messageJson['object']['id'], + nickname, domain, messageJson, 'scheduled') + return messageJson + + def createReportPost(baseDir: str, nickname: str, domain: str, port: int, httpPrefix: str, content: str, followersOnly: bool, saveToFile: bool, diff --git a/translations/ar.json b/translations/ar.json index 00e8e5f4c..1701f3210 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -232,5 +232,7 @@ "Starlight": "ضوء النجوم", "Search banner image": "البحث عن صورة بانر", "Henge": "هنج", - "QR Code": "رمز الاستجابة السريعة" + "QR Code": "رمز الاستجابة السريعة", + "Reminder": "تذكير", + "Scheduled note to yourself": "ملاحظة مجدولة لنفسك" } diff --git a/translations/ca.json b/translations/ca.json index 8ebd3dbc8..08062ab34 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -232,5 +232,7 @@ "Starlight": "Starlight", "Search banner image": "Cerca imatge del banner", "Henge": "Henge", - "QR Code": "Codi QR" + "QR Code": "Codi QR", + "Reminder": "Recordatori", + "Scheduled note to yourself": "Nota programada a tu mateix" } diff --git a/translations/cy.json b/translations/cy.json index 66eba4306..de620ae9d 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -232,5 +232,7 @@ "Starlight": "Starlight", "Search banner image": "Chwilio delwedd baner", "Henge": "Henge", - "QR Code": "Cod QR" + "QR Code": "Cod QR", + "Reminder": "Nodyn atgoffa", + "Scheduled note to yourself": "Nodyn wedi'i drefnu i chi'ch hun" } diff --git a/translations/de.json b/translations/de.json index 01e333189..9b6c8146a 100644 --- a/translations/de.json +++ b/translations/de.json @@ -232,5 +232,7 @@ "Starlight": "Sternenlicht", "Search banner image": "Suche Banner Bild", "Henge": "Henge", - "QR Code": "QR-Code" + "QR Code": "QR-Code", + "Reminder": "Erinnerung", + "Scheduled note to yourself": "Geplante Notiz an dich" } diff --git a/translations/en.json b/translations/en.json index 266da8fbf..3a099eaf6 100644 --- a/translations/en.json +++ b/translations/en.json @@ -232,5 +232,7 @@ "Starlight": "Starlight", "Search banner image": "Search banner image", "Henge": "Henge", - "QR Code": "QR Code" + "QR Code": "QR Code", + "Reminder": "Reminder", + "Scheduled note to yourself": "Scheduled note to yourself" } diff --git a/translations/es.json b/translations/es.json index df5fa28f3..531daada1 100644 --- a/translations/es.json +++ b/translations/es.json @@ -232,5 +232,7 @@ "Starlight": "Luz de las estrellas", "Search banner image": "Buscar imagen de banner", "Henge": "Henge", - "QR Code": "Código QR" + "QR Code": "Código QR", + "Reminder": "Recordatorio", + "Scheduled note to yourself": "Nota programada para ti" } diff --git a/translations/fr.json b/translations/fr.json index f1ccb3c03..0f5be6db5 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -232,5 +232,7 @@ "Starlight": "Lumière des étoiles", "Search banner image": "Image de bannière de recherche", "Henge": "Henge", - "QR Code": "QR Code" + "QR Code": "QR Code", + "Reminder": "Rappel", + "Scheduled note to yourself": "Note programmée pour vous" } diff --git a/translations/ga.json b/translations/ga.json index 058689a61..37c801230 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -232,5 +232,7 @@ "Starlight": "Starlight", "Search banner image": "Cuardaigh íomhá meirge", "Henge": "Henge", - "QR Code": "Cód QR" + "QR Code": "Cód QR", + "Reminder": "Meabhrúchán", + "Scheduled note to yourself": "Nóta sceidealta duit féin" } diff --git a/translations/hi.json b/translations/hi.json index 0e6104204..9ca5ed9ba 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -232,5 +232,7 @@ "Starlight": "तारों का", "Search banner image": "बैनर छवि खोजें", "Henge": "हेंगे", - "QR Code": "क्यूआर कोड" + "QR Code": "क्यूआर कोड", + "Reminder": "अनुस्मारक", + "Scheduled note to yourself": "खुद को निर्धारित नोट" } diff --git a/translations/it.json b/translations/it.json index c78761a64..0cea49608 100644 --- a/translations/it.json +++ b/translations/it.json @@ -232,5 +232,7 @@ "Starlight": "luce stellare", "Search banner image": "Cerca immagine banner", "Henge": "Henge", - "QR Code": "QR Code" + "QR Code": "QR Code", + "Reminder": "Promemoria", + "Scheduled note to yourself": "Nota programmata per te" } diff --git a/translations/ja.json b/translations/ja.json index c88bc4ebb..2b183341f 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -232,5 +232,7 @@ "Starlight": "スターライト", "Search banner image": "バナー画像を検索", "Henge": "ヘンゲ", - "QR Code": "QRコード" + "QR Code": "QRコード", + "Reminder": "リマインダー", + "Scheduled note to yourself": "自分への予定されたメモ" } diff --git a/translations/oc.json b/translations/oc.json index c460935c6..6030ac425 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -228,5 +228,7 @@ "Starlight": "Starlight", "Search banner image": "Search banner image", "Henge": "Henge", - "QR Code": "QR Code" + "QR Code": "QR Code", + "Reminder": "Reminder", + "Scheduled note to yourself": "Scheduled note to yourself" } diff --git a/translations/pt.json b/translations/pt.json index d041c6eaf..9827d1aa3 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -232,5 +232,7 @@ "Starlight": "Luz das estrelas", "Search banner image": "Pesquisar imagem do banner", "Henge": "Henge", - "QR Code": "Código QR" + "QR Code": "Código QR", + "Reminder": "Lembrete", + "Scheduled note to yourself": "Nota agendada para si mesmo" } diff --git a/translations/ru.json b/translations/ru.json index 85324abb6..b46c05241 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -232,5 +232,7 @@ "Starlight": "Звездный свет", "Search banner image": "Поиск изображения баннера", "Henge": "Хендж", - "QR Code": "QR код" + "QR Code": "QR код", + "Reminder": "напоминание", + "Scheduled note to yourself": "Запланированная заметка для себя" } diff --git a/translations/zh.json b/translations/zh.json index 8e04468f7..cc4ce0483 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -231,5 +231,7 @@ "Starlight": "星光", "Search banner image": "搜索横幅图像", "Henge": "亨格", - "QR Code": "二维码" + "QR Code": "二维码", + "Reminder": "提醒", + "Scheduled note to yourself": "预定给自己的笔记" } diff --git a/webinterface.py b/webinterface.py index fea05c007..b885ad858 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1703,7 +1703,7 @@ def htmlNewPost(mediaInstance: bool, translate: {}, if not path.endswith('/newshare'): if not path.endswith('/newreport'): - if not inReplyTo: + if not inReplyTo or path.endswith('/newreminder'): newPostText = '

' + \ translate['Write your post text below.'] + '

' else: @@ -1781,6 +1781,7 @@ def htmlNewPost(mediaInstance: bool, translate: {}, pathBase = path.replace('/newreport', '').replace('/newpost', '') pathBase = pathBase.replace('/newblog', '').replace('/newshare', '') pathBase = pathBase.replace('/newunlisted', '') + pathBase = pathBase.replace('/newreminder', '') pathBase = pathBase.replace('/newfollowers', '').replace('/newdm', '') newPostImageSection = '
' @@ -1819,6 +1820,10 @@ def htmlNewPost(mediaInstance: bool, translate: {}, scopeIcon = 'scope_dm.png' scopeDescription = translate['DM'] endpoint = 'newdm' + elif path.endswith('/newreminder'): + scopeIcon = 'scope_reminder.png' + scopeDescription = translate['Reminder'] + endpoint = 'newreminder' elif path.endswith('/newreport'): scopeIcon = 'scope_report.png' scopeDescription = translate['Report'] @@ -1941,6 +1946,7 @@ def htmlNewPost(mediaInstance: bool, translate: {}, dropdownUnlistedSuffix = '/newunlisted' dropdownFollowersSuffix = '/newfollowers' dropdownDMSuffix = '/newdm' + dropdownReminderSuffix = '/newreminder' dropdownReportSuffix = '/newreport' if inReplyTo or mentions: dropdownNewPostSuffix = '' @@ -1948,6 +1954,7 @@ def htmlNewPost(mediaInstance: bool, translate: {}, dropdownUnlistedSuffix = '' dropdownFollowersSuffix = '' dropdownDMSuffix = '' + dropdownReminderSuffix = '' dropdownReportSuffix = '' if inReplyTo: dropdownNewPostSuffix += '?replyto=' + inReplyTo @@ -1998,6 +2005,12 @@ def htmlNewPost(mediaInstance: bool, translate: {}, '">' + translate['DM'] + \ '
' + translate['Only to mentioned people'] + '' + dropDownContent += \ + ' ' + translate['Reminder'] + \ + '
' + translate['Scheduled note to yourself'] + '
' dropDownContent += \ '