Option to only receive DMs from people you follow

main2
Bob Mottram 2019-10-29 10:49:23 +00:00
parent 841367fa76
commit 71af23ff6f
10 changed files with 47 additions and 7 deletions

View File

@ -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

View File

@ -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')

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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)
' <input type="checkbox" class=profilecheckbox" name="approveFollowers" '+manuallyApprovesFollowers+'>'+translate['Approve follower requests']+'<br>' \
' <input type="checkbox" class=profilecheckbox" name="isBot" '+isBot+'>'+translate['This is a bot account']+'<br>' \
' <input type="checkbox" class=profilecheckbox" name="isGroup" '+isGroup+'>'+translate['This is a group account']+'<br>' \
' <input type="checkbox" class=profilecheckbox" name="followDMs" '+followDMs+'>'+translate['Only people I follow can send me DMs']+'<br>' \
' <br><b>'+translate['Filtered words']+'</b>' \
' <br>'+translate['One per line']+ \
' <textarea id="message" name="filteredWords" placeholder="" style="height:200px">'+filterStr+'</textarea>' \