Remove bookmark from index first

main
Bob Mottram 2020-05-21 23:12:31 +01:00
parent a87072e130
commit 949f52ae9b
1 changed files with 22 additions and 22 deletions

View File

@ -42,6 +42,28 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
os.remove(cachedPostFilename)
removePostFromCache(postJsonObject, recentPostsCache)
# remove from the index
bookmarksIndexFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/bookmarks.index'
if not os.path.isfile(bookmarksIndexFilename):
return
if '/' in postFilename:
bookmarkIndex = postFilename.split('/')[-1].strip()
else:
bookmarkIndex = postFilename.strip()
if bookmarkIndex not in open(bookmarksIndexFilename).read():
return
indexStr = ''
indexStrChanged = False
with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
indexStrChanged = True
if indexStrChanged:
bookmarksIndexFile = open(bookmarksIndexFilename, 'w')
if bookmarksIndexFile:
bookmarksIndexFile.write(indexStr)
bookmarksIndexFile.close()
if not postJsonObject.get('type'):
return
if postJsonObject['type'] != 'Create':
@ -85,28 +107,6 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
postJsonObject['object']['bookmarks']['totalItems'] = bmItLen
saveJson(postJsonObject, postFilename)
# remove from the index
bookmarksIndexFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/bookmarks.index'
if not os.path.isfile(bookmarksIndexFilename):
return
if '/' in postFilename:
bookmarkIndex = postFilename.split('/')[-1].strip()
else:
bookmarkIndex = postFilename.strip()
if bookmarkIndex not in open(bookmarksIndexFilename).read():
return
indexStr = ''
indexStrChanged = False
with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
indexStrChanged = True
if indexStrChanged:
bookmarksIndexFile = open(bookmarksIndexFilename, 'w')
if bookmarksIndexFile:
bookmarksIndexFile.write(indexStr)
bookmarksIndexFile.close()
def bookmarkedByPerson(postJsonObject: {}, nickname: str, domain: str) -> bool:
"""Returns True if the given post is bookmarked by the given person