diff --git a/daemon.py b/daemon.py index 3002e21c..0465c469 100644 --- a/daemon.py +++ b/daemon.py @@ -89,6 +89,7 @@ from inbox import getPersonPubKey from follow import getFollowingFeed from follow import sendFollowRequest from follow import unfollowPerson +from follow import createInitialLastSeen from auth import authorize from auth import createPassword from auth import createBasicAuthHeader @@ -13261,6 +13262,8 @@ def runDaemon(dormantMonths: int, httpd.iconsCache = {} httpd.fontsCache = {} + createInitialLastSeen(baseDir, httpPrefix) + print('Creating inbox queue') httpd.thrInboxQueue = \ threadWithTrace(target=runInboxQueue, diff --git a/follow.py b/follow.py index 9403f92e..53349f05 100644 --- a/follow.py +++ b/follow.py @@ -27,6 +27,42 @@ from auth import createBasicAuthHeader from session import postJson +def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None: + """Creates initial lastseen files for all follows + """ + for subdir, dirs, files in os.walk(baseDir + '/accounts'): + for acct in dirs: + if '@' not in acct: + continue + if 'inbox@' in acct or 'news@' in acct: + continue + accountDir = os.path.join(baseDir + '/accounts', acct) + followingFilename = accountDir + '/following.txt' + if not os.path.isfile(followingFilename): + continue + lastSeenDir = accountDir + '/lastseen' + if not os.path.isdir(lastSeenDir): + os.mkdir(lastSeenDir) + with open(followingFilename, 'r') as fp: + followingHandles = fp.readlines() + for handle in followingHandles: + if '#' in handle: + continue + if '@' not in handle: + continue + nickname = handle.split('@')[0] + domain = handle.split('@')[1] + actor = \ + httpPrefix + '://' + \ + nickname + '@' + domain + '/users/' + nickname + lastSeenFilename = \ + lastSeenDir + '/' + actor.replace('/', '#') + '.txt' + if not os.path.isfile(lastSeenFilename): + with open(lastSeenFilename, 'w+') as fp: + fp.write(str(0)) + break + + def preApprovedFollower(baseDir: str, nickname: str, domain: str, approveHandle: str,