From 764f6673c0db19d5fbad1688c2e229f465d22d77 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 24 Feb 2021 09:54:37 +0000 Subject: [PATCH] Improve follow checking when a DM arrives --- follow.py | 7 +++++++ inbox.py | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/follow.py b/follow.py index cce18f1b2..b29632ea1 100644 --- a/follow.py +++ b/follow.py @@ -126,6 +126,7 @@ def _removeFromFollowRejects(baseDir: str, def isFollowingActor(baseDir: str, nickname: str, domain: str, actor: str) -> bool: """Is the given nickname following the given actor? + The actor can also be a handle: nickname@domain """ if ':' in domain: domain = domain.split(':')[0] @@ -137,6 +138,12 @@ def isFollowingActor(baseDir: str, return False if actor.lower() in open(followingFile).read().lower(): 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) if not followingNickname: print('WARN: unable to find nickname in ' + actor) diff --git a/inbox.py b/inbox.py index 86507b87d..321a27480 100644 --- a/inbox.py +++ b/inbox.py @@ -40,6 +40,7 @@ from categories import setHashtagCategory from httpsig import verifyPostHeaders from session import createSession from session import getJson +from follow import isFollowingActor from follow import receiveFollowRequest from follow import getFollowersOfActor from follow import unfollowerOfAccount @@ -73,7 +74,6 @@ from git import receiveGitPatch from followingCalendar import receivingCalendarEvents from happening import saveEventPost from delete import removeOldHashtags -from follow import isFollowingActor from categories import guessHashtagCategory from context import hasValidContext @@ -2288,8 +2288,9 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, sendH = \ sendingActorNickname + '@' + sendingActorDomain if sendH != nickname + '@' + domain: - if sendH not in \ - open(followingFilename).read(): + if not isFollowingActor(baseDir, + nickname, domain, + sendH): print(nickname + '@' + domain + ' cannot receive DM from ' + sendH +