Improve follow checking when a DM arrives

merge-requests/21/head
Bob Mottram 2021-02-24 09:54:37 +00:00
parent 94b666d803
commit 764f6673c0
2 changed files with 11 additions and 3 deletions

View File

@ -126,6 +126,7 @@ def _removeFromFollowRejects(baseDir: str,
def isFollowingActor(baseDir: str, def isFollowingActor(baseDir: str,
nickname: str, domain: str, actor: str) -> bool: nickname: str, domain: str, actor: str) -> bool:
"""Is the given nickname following the given actor? """Is the given nickname following the given actor?
The actor can also be a handle: nickname@domain
""" """
if ':' in domain: if ':' in domain:
domain = domain.split(':')[0] domain = domain.split(':')[0]
@ -137,6 +138,12 @@ def isFollowingActor(baseDir: str,
return False return False
if actor.lower() in open(followingFile).read().lower(): if actor.lower() in open(followingFile).read().lower():
return True return True
if '@' in actor and '://' not in actor:
# the actor is a handle: nickname@domain
followingHandle = actor.lower()
if followingHandle in open(followingFile).read().lower():
return True
return False
followingNickname = getNicknameFromActor(actor) followingNickname = getNicknameFromActor(actor)
if not followingNickname: if not followingNickname:
print('WARN: unable to find nickname in ' + actor) print('WARN: unable to find nickname in ' + actor)

View File

@ -40,6 +40,7 @@ from categories import setHashtagCategory
from httpsig import verifyPostHeaders from httpsig import verifyPostHeaders
from session import createSession from session import createSession
from session import getJson from session import getJson
from follow import isFollowingActor
from follow import receiveFollowRequest from follow import receiveFollowRequest
from follow import getFollowersOfActor from follow import getFollowersOfActor
from follow import unfollowerOfAccount from follow import unfollowerOfAccount
@ -73,7 +74,6 @@ from git import receiveGitPatch
from followingCalendar import receivingCalendarEvents from followingCalendar import receivingCalendarEvents
from happening import saveEventPost from happening import saveEventPost
from delete import removeOldHashtags from delete import removeOldHashtags
from follow import isFollowingActor
from categories import guessHashtagCategory from categories import guessHashtagCategory
from context import hasValidContext from context import hasValidContext
@ -2288,8 +2288,9 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
sendH = \ sendH = \
sendingActorNickname + '@' + sendingActorDomain sendingActorNickname + '@' + sendingActorDomain
if sendH != nickname + '@' + domain: if sendH != nickname + '@' + domain:
if sendH not in \ if not isFollowingActor(baseDir,
open(followingFilename).read(): nickname, domain,
sendH):
print(nickname + '@' + domain + print(nickname + '@' + domain +
' cannot receive DM from ' + ' cannot receive DM from ' +
sendH + sendH +