Removing bookmarks from index

merge-requests/30/head
Bob Mottram 2019-11-18 15:21:35 +00:00
parent 3b83a30e41
commit 79789014d4
1 changed files with 69 additions and 59 deletions

View File

@ -29,7 +29,9 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
"""Undoes a bookmark for a particular actor """Undoes a bookmark for a particular actor
""" """
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if postJsonObject: if not postJsonObject:
return
# remove any cached version of this post so that the bookmark icon is changed # remove any cached version of this post so that the bookmark icon is changed
nickname=getNicknameFromActor(actor) nickname=getNicknameFromActor(actor)
cachedPostFilename= \ cachedPostFilename= \
@ -66,7 +68,10 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
postJsonObject['object']['bookmarks']['items'].remove(bookmarkItem) postJsonObject['object']['bookmarks']['items'].remove(bookmarkItem)
itemFound=True itemFound=True
break break
if itemFound:
if not itemFound:
return
if totalItems==1: if totalItems==1:
if debug: if debug:
print('DEBUG: bookmarks was removed from post') print('DEBUG: bookmarks was removed from post')
@ -78,13 +83,18 @@ def undoBookmarksCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,
# remove from the index # remove from the index
bookmarksIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/bookmarks.index' bookmarksIndexFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/bookmarks.index'
if os.path.isfile(bookmarksIndexFilename): if not os.path.isfile(bookmarksIndexFilename):
bookmarkIndex=postFilename.split('/')[-1]+'\n' return
if bookmarkIndex in open(bookmarksIndexFilename).read(): if '/' in postFilename:
bookmarkIndex=postFilename.split('/')[-1].strip()
else:
bookmarkIndex=postFilename.strip()
if bookmarkIndex not in open(bookmarksIndexFilename).read():
return
indexStr='' indexStr=''
indexStrChanged=False indexStrChanged=False
with open(bookmarksIndexFilename, 'r') as indexFile: with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr=indexFile.read().replace(bookmarkIndex,'') indexStr=indexFile.read().replace(bookmarkIndex+'\n','')
indexStrChanged=True indexStrChanged=True
if indexStrChanged: if indexStrChanged:
bookmarksIndexFile=open(bookmarksIndexFilename,'w') bookmarksIndexFile=open(bookmarksIndexFilename,'w')