diff --git a/inbox.py b/inbox.py index 01623b270..f44d17d2b 100644 --- a/inbox.py +++ b/inbox.py @@ -58,6 +58,7 @@ from utils import updateAnnounceCollection from utils import undoAnnounceCollectionEntry from utils import dangerousMarkup from httpsig import messageContentDigest +from posts import createDirectMessagePost from posts import validContentWarning from posts import downloadAnnounce from posts import isDM @@ -2056,6 +2057,67 @@ def _updateLastSeen(baseDir: str, handle: str, actor: str) -> None: lastSeenFile.write(str(daysSinceEpoch)) +def _bounceDM(senderPostId: str, session, httpPrefix: str, + baseDir: str, nickname: str, domain: str, port: int, + sendingHandle: str, federationList: [], + sendThreads: [], postLog: [], + cachedWebfingers: {}, personCache: {}, + translate: {}, debug: bool) -> None: + """Sends a bounce message back to the sending handle + if a DM has been rejected + """ + print(nickname + '@' + domain + + ' cannot receive DM from ' + sendingHandle + + ' because they do not follow them') + senderNickname = sendingHandle.split('@')[0] + senderDomain = sendingHandle.split('@')[1] + senderPort = port + if ':' in senderDomain: + senderPortStr = senderDomain.split(':')[1] + if senderPortStr.isdigit(): + senderPort = int(senderPortStr) + senderDomain = senderDomain.split(':')[0] + cc = [] + + # create the bounce DM + subject = None + content = translate['DM bounce'] + followersOnly = False + saveToFile = False + clientToServer = False + commentsEnabled = False + attachImageFilename = None + mediaType = None + imageDescription = '' + inReplyTo = removeIdEnding(senderPostId) + inReplyToAtomUri = None + schedulePost = False + eventDate = None + eventTime = None + location = None + postJsonObject = \ + createDirectMessagePost(baseDir, nickname, domain, port, + httpPrefix, content, followersOnly, + saveToFile, clientToServer, + commentsEnabled, + attachImageFilename, mediaType, + imageDescription, + inReplyTo, inReplyToAtomUri, + subject, debug, schedulePost, + eventDate, eventTime, location) + if not postJsonObject: + print('WARN: unable to create bounce message to ' + sendingHandle) + return + # bounce DM goes back to the sender + print('Sending bounce DM to ' + sendingHandle) + sendSignedJson(postJsonObject, session, baseDir, + nickname, domain, port, + senderNickname, senderDomain, senderPort, cc, + httpPrefix, False, False, federationList, + sendThreads, postLog, cachedWebfingers, + personCache, debug, __version__) + + def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, session, keyId: str, handle: str, messageJson: {}, baseDir: str, httpPrefix: str, sendThreads: [], @@ -2302,11 +2364,17 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, if not isFollowingActor(baseDir, nickname, domain, sendH): - print(nickname + '@' + domain + - ' cannot receive DM from ' + - sendH + - ' because they do not ' + - 'follow them') + # send back a bounce DM + if postJsonObject.get('id'): + senderPostId = \ + postJsonObject['id'] + _bounceDM(senderPostId, + session, httpPrefix, + baseDir, nickname, domain, port, + sendH, federationList, + sendThreads, postLog, + cachedWebfingers, personCache, + translate, debug) return False # dm index will be updated diff --git a/translations/ar.json b/translations/ar.json index bec3a0389..6d4b5b6d8 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -370,5 +370,6 @@ "Publish a blog article": "نشر مقال بلوق", "Featured writer": "كاتب متميز", "Broch mode": "وضع الكتيب", - "Pixel": "بكسل" + "Pixel": "بكسل", + "DM bounce": "يتم قبول الرسائل فقط من الحسابات المتبعة" } diff --git a/translations/ca.json b/translations/ca.json index ae3607114..17ee18c1c 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -370,5 +370,6 @@ "Publish a blog article": "Publicar un article del bloc", "Featured writer": "Escriptor destacat", "Broch mode": "Mode Broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Els missatges només s’accepten des dels comptes seguits" } diff --git a/translations/cy.json b/translations/cy.json index 0ab618d79..b3e77400d 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -370,5 +370,6 @@ "Publish a blog article": "Cyhoeddi erthygl blog", "Featured writer": "Awdur dan sylw", "Broch mode": "Modd Broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Dim ond o gyfrifon a ddilynir y derbynnir negeseuon" } diff --git a/translations/de.json b/translations/de.json index a5f963c83..c7c1cb650 100644 --- a/translations/de.json +++ b/translations/de.json @@ -370,5 +370,6 @@ "Publish a blog article": "Veröffentlichen Sie einen Blog-Artikel", "Featured writer": "Ausgewählter Schriftsteller", "Broch mode": "Broch-Modus", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Nachrichten werden nur von folgenden Konten akzeptiert" } diff --git a/translations/en.json b/translations/en.json index 4d2af2ec5..4e3db4794 100644 --- a/translations/en.json +++ b/translations/en.json @@ -370,5 +370,6 @@ "Publish a blog article": "Publish a blog article", "Featured writer": "Featured writer", "Broch mode": "Broch mode", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Messages are only accepted from followed accounts" } diff --git a/translations/es.json b/translations/es.json index 095363f66..fa7f25060 100644 --- a/translations/es.json +++ b/translations/es.json @@ -370,5 +370,6 @@ "Publish a blog article": "Publica un artículo de blog", "Featured writer": "Escritora destacada", "Broch mode": "Modo broche", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Solo se aceptan mensajes de cuentas seguidas" } diff --git a/translations/fr.json b/translations/fr.json index 835b52d5f..0c8d6f0c6 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -370,5 +370,6 @@ "Publish a blog article": "Publier un article de blog", "Featured writer": "Écrivain en vedette", "Broch mode": "Mode Broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Les messages ne sont acceptés que des comptes suivis" } diff --git a/translations/ga.json b/translations/ga.json index b04c8b874..d9eb10393 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -370,5 +370,6 @@ "Publish a blog article": "Foilsigh alt blagála", "Featured writer": "Scríbhneoir mór le rá", "Broch mode": "Modh broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Ní ghlactar le teachtaireachtaí ach ó chuntais a leanann" } diff --git a/translations/hi.json b/translations/hi.json index a3a81ab27..ac8b0b00e 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -370,5 +370,6 @@ "Publish a blog article": "एक ब्लॉग लेख प्रकाशित करें", "Featured writer": "फीचर्ड लेखक", "Broch mode": "ब्रोच मोड", - "Pixel": "पिक्सेल" + "Pixel": "पिक्सेल", + "DM bounce": "संदेश केवल अनुसरण किए गए खातों से स्वीकार किए जाते हैं" } diff --git a/translations/it.json b/translations/it.json index 13a001e35..a22a09d4e 100644 --- a/translations/it.json +++ b/translations/it.json @@ -370,5 +370,6 @@ "Publish a blog article": "Pubblica un articolo sul blog", "Featured writer": "Scrittore in primo piano", "Broch mode": "Modalità Broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "I messaggi sono accettati solo dagli account seguiti" } diff --git a/translations/ja.json b/translations/ja.json index 36ea8d2ef..736dde695 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -370,5 +370,6 @@ "Publish a blog article": "ブログ記事を公開する", "Featured writer": "注目の作家", "Broch mode": "ブロッホモード", - "Pixel": "ピクセル" + "Pixel": "ピクセル", + "DM bounce": "メッセージはフォローされているアカウントからのみ受け付けられます" } diff --git a/translations/oc.json b/translations/oc.json index ce631490f..75d48eee6 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -366,5 +366,6 @@ "Publish a blog article": "Publish a blog article", "Featured writer": "Featured writer", "Broch mode": "Broch mode", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Messages are only accepted from followed accounts" } diff --git a/translations/pt.json b/translations/pt.json index b86088f68..e1d37d4f7 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -370,5 +370,6 @@ "Publish a blog article": "Publique um artigo de blog", "Featured writer": "Escritor em destaque", "Broch mode": "Modo broch", - "Pixel": "Pixel" + "Pixel": "Pixel", + "DM bounce": "Mensagens são aceitas apenas de contas seguidas" } diff --git a/translations/ru.json b/translations/ru.json index 88ea8db79..a1d021f05 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -370,5 +370,6 @@ "Publish a blog article": "Опубликовать статью в блоге", "Featured writer": "Избранный писатель", "Broch mode": "Брош режим", - "Pixel": "Пиксель" + "Pixel": "Пиксель", + "DM bounce": "Сообщения принимаются только от следующих аккаунтов" } diff --git a/translations/zh.json b/translations/zh.json index 90283d086..8cd6a124d 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -370,5 +370,6 @@ "Publish a blog article": "发布博客文章", "Featured writer": "特色作家", "Broch mode": "断点模式", - "Pixel": "像素点" + "Pixel": "像素点", + "DM bounce": "仅接受来自后续帐户的邮件" }