From b54c9e52f7bb2bb7acf7a361b90e92d77fc41d76 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 3 Sep 2020 11:09:40 +0100 Subject: [PATCH] Improve handling of the first follow --- utils.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/utils.py b/utils.py index b723097a..eae0e75f 100644 --- a/utils.py +++ b/utils.py @@ -356,7 +356,6 @@ def followPerson(baseDir: str, nickname: str, domain: str, if not os.path.isdir(baseDir + '/accounts'): os.mkdir(baseDir + '/accounts') - followAdded = False handleToFollow = followNickname + '@' + followDomain filename = baseDir + '/accounts/' + handle + '/' + followFile if os.path.isfile(filename): @@ -372,25 +371,24 @@ def followPerson(baseDir: str, nickname: str, domain: str, followFile.write(handleToFollow + '\n' + content) if debug: print('DEBUG: follow added') - followAdded = True except Exception as e: print('WARN: Failed to write entry to follow file ' + filename + ' ' + str(e)) + else: + # first follow + if debug: + print('DEBUG: creating new following file to follow ' + + handleToFollow) + with open(filename, 'w+') as followfile: + followfile.write(handleToFollow + '\n') - if followAdded: - # Default to adding new follows to the calendar. - # Possibly this could be made optional - if followFile == 'following.txt': - # if following a person add them to the list of - # calendar follows - addPersonToCalendar(baseDir, nickname, domain, - followNickname, followDomain) - return True - - if debug: - print('DEBUG: creating new following file to follow ' + handleToFollow) - with open(filename, 'w+') as followfile: - followfile.write(handleToFollow + '\n') + # Default to adding new follows to the calendar. + # Possibly this could be made optional + if followFile == 'following.txt': + # if following a person add them to the list of + # calendar follows + addPersonToCalendar(baseDir, nickname, domain, + followNickname, followDomain) return True