From 71af23ff6f760ca4ac3097483cbddc09faf90695 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 29 Oct 2019 10:49:23 +0000 Subject: [PATCH] Option to only receive DMs from people you follow --- daemon.py | 14 ++++++++++++++ inbox.py | 15 +++++++++++++++ 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/it.json | 3 ++- webinterface.py | 4 ++++ 10 files changed, 47 insertions(+), 7 deletions(-) diff --git a/daemon.py b/daemon.py index e5531eed1..aab614d9d 100644 --- a/daemon.py +++ b/daemon.py @@ -3050,18 +3050,32 @@ class PubServer(BaseHTTPRequestHandler): if approveFollowers!=actorJson['manuallyApprovesFollowers']: actorJson['manuallyApprovesFollowers']=approveFollowers actorChanged=True + # only receive DMs from accounts you follow + followDMsFilename=self.server.baseDir+'/accounts/'+nickname+'@'+self.server.domain+'/.followDMs' + followDMsActive=False + if fields.get('followDMs'): + if fields['followDMs']=='on': + followDMsActive=True + with open(followDMsFilename, "w") as followDMsFile: + followDMsFile.write('\n') + if not followDMsActive: + if os.path.isfile(followDMsFilename): + os.remove(followDMsFilename) + # this account is a bot if fields.get('isBot'): if fields['isBot']=='on': if actorJson['type']!='Service': actorJson['type']='Service' actorChanged=True else: + # this account is a group if fields.get('isGroup'): if fields['isGroup']=='on': if actorJson['type']!='Group': actorJson['type']='Group' actorChanged=True else: + # this account is a person (default) if actorJson['type']!='Person': actorJson['type']='Person' actorChanged=True diff --git a/inbox.py b/inbox.py index 0a2f69787..236fbd6f0 100644 --- a/inbox.py +++ b/inbox.py @@ -1562,6 +1562,21 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ if isDM(postJsonObject): nickname=handle.split('@')[0] if nickname!='inbox': + followDMsFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/.followDMs' + if os.path.isfile(followDMsFilename): + followingFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/following.txt' + if not postJsonObject.get('actor'): + return False + sendingActor=postJsonObject['actor'] + sendingActorNickname=getNicknameFromActor(sendingActor) + sendingActorDomain,sendingActorPort=getDomainFromActor(sendingActor) + if sendingActorNickname and sendingActorDomain: + if sendingActorNickname+'@'+sendingActorDomain != nickname+'@'+domain: + if sendingActorNickname+'@'+sendingActorDomain not in open(followingFilename).read(): + print(nickname+'@'+domain+' cannot receive DM from '+sendingActorNickname+'@'+sendingActorDomain+' because they do not follow them') + return False + else: + return False # dm index will be updated updateIndexList.append('dm') dmNotify(baseDir,handle,httpPrefix+'://'+domain+'/users/'+nickname+'/dm') diff --git a/translations/cy.json b/translations/cy.json index 9e7e91f20..02e728812 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/de.json b/translations/de.json index a95e9bc4e..4c2322bb5 100644 --- a/translations/de.json +++ b/translations/de.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/en.json b/translations/en.json index f58b2c69c..e7802ec70 100644 --- a/translations/en.json +++ b/translations/en.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/es.json b/translations/es.json index 76a26789a..5cfd3de3a 100644 --- a/translations/es.json +++ b/translations/es.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/fr.json b/translations/fr.json index 2115c9b72..aeda29056 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/ga.json b/translations/ga.json index 39e8b45e0..308834ebf 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/translations/it.json b/translations/it.json index 9e6d652ae..8ff0e5cee 100644 --- a/translations/it.json +++ b/translations/it.json @@ -163,5 +163,6 @@ "September": "September", "October": "October", "November": "November", - "December": "December" + "December": "December", + "Only people I follow can send me DMs": "Only people I follow can send me DMs" } diff --git a/webinterface.py b/webinterface.py index b4df87307..5a46af6e8 100644 --- a/webinterface.py +++ b/webinterface.py @@ -518,6 +518,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) isBot='' isGroup='' + followDMs='' displayNickname=nickname bioStr='' manuallyApprovesFollowers='' @@ -539,6 +540,8 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) elif actorJson['type']=='Group': isGroup='checked' isBot='' + if os.path.isfile(actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/.followDMs'): + followDMs='checked' filterStr='' filterFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/filters.txt' @@ -620,6 +623,7 @@ def htmlEditProfile(translate: {},baseDir: str,path: str,domain: str,port: int) ' '+translate['Approve follower requests']+'
' \ ' '+translate['This is a bot account']+'
' \ ' '+translate['This is a group account']+'
' \ + ' '+translate['Only people I follow can send me DMs']+'
' \ '
'+translate['Filtered words']+'' \ '
'+translate['One per line']+ \ ' ' \