forked from indymedia/epicyon
Remove cached post on like update
parent
ced51e7647
commit
255a32c0dc
5
inbox.py
5
inbox.py
|
@ -879,7 +879,8 @@ def receiveLike(session,handle: str,isGroup: bool,baseDir: str, \
|
||||||
return True
|
return True
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: liked post found in inbox')
|
print('DEBUG: liked post found in inbox')
|
||||||
updateLikesCollection(postFilename,messageJson['object'],messageJson['actor'],debug)
|
|
||||||
|
updateLikesCollection(baseDir,postFilename,messageJson['object'],messageJson['actor'],domain,debug)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def receiveUndoLike(session,handle: str,isGroup: bool,baseDir: str, \
|
def receiveUndoLike(session,handle: str,isGroup: bool,baseDir: str, \
|
||||||
|
@ -930,7 +931,7 @@ def receiveUndoLike(session,handle: str,isGroup: bool,baseDir: str, \
|
||||||
return True
|
return True
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: liked post found in inbox. Now undoing.')
|
print('DEBUG: liked post found in inbox. Now undoing.')
|
||||||
undoLikesCollectionEntry(postFilename,messageJson['object'],messageJson['actor'],debug)
|
undoLikesCollectionEntry(baseDir,postFilename,messageJson['object'],messageJson['actor'],domain,debug)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def receiveDelete(session,handle: str,isGroup: bool,baseDir: str, \
|
def receiveDelete(session,handle: str,isGroup: bool,baseDir: str, \
|
||||||
|
|
26
like.py
26
like.py
|
@ -6,6 +6,7 @@ __maintainer__ = "Bob Mottram"
|
||||||
__email__ = "bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__ = "Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
|
import os
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import commentjson
|
import commentjson
|
||||||
|
@ -14,13 +15,14 @@ from utils import urlPermitted
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
|
from utils import getCachedPostFilename
|
||||||
from posts import sendSignedJson
|
from posts import sendSignedJson
|
||||||
from session import postJson
|
from session import postJson
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
|
|
||||||
def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug: bool) -> None:
|
def undoLikesCollectionEntry(baseDir: str,postFilename: str,objectUrl: str,actor: str,domain: str,debug: bool) -> None:
|
||||||
"""Undoes a like for a particular actor
|
"""Undoes a like for a particular actor
|
||||||
"""
|
"""
|
||||||
postJsonObject=None
|
postJsonObject=None
|
||||||
|
@ -36,6 +38,12 @@ def undoLikesCollectionEntry(postFilename: str,objectUrl: str,actor: str,debug:
|
||||||
tries+=1
|
tries+=1
|
||||||
|
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
|
# remove any cached version of this post so that the like icon is changed
|
||||||
|
nickname=getNicknameFromActor(actor)
|
||||||
|
cachedPostFilename=getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
|
||||||
|
if os.path.isfile(cachedPostFilename):
|
||||||
|
os.remove(cachedPostFilename)
|
||||||
|
|
||||||
if not postJsonObject.get('type'):
|
if not postJsonObject.get('type'):
|
||||||
return
|
return
|
||||||
if postJsonObject['type']!='Create':
|
if postJsonObject['type']!='Create':
|
||||||
|
@ -110,7 +118,7 @@ def noOfLikes(postJsonObject: {}) -> int:
|
||||||
postJsonObject['object']['likes']['totalItems']=0
|
postJsonObject['object']['likes']['totalItems']=0
|
||||||
return len(postJsonObject['object']['likes']['items'])
|
return len(postJsonObject['object']['likes']['items'])
|
||||||
|
|
||||||
def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bool) -> None:
|
def updateLikesCollection(baseDir: str,postFilename: str,objectUrl: str, actor: str,domain: str,debug: bool) -> None:
|
||||||
"""Updates the likes collection within a post
|
"""Updates the likes collection within a post
|
||||||
"""
|
"""
|
||||||
postJsonObject=None
|
postJsonObject=None
|
||||||
|
@ -126,6 +134,12 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo
|
||||||
tries+=1
|
tries+=1
|
||||||
|
|
||||||
if postJsonObject:
|
if postJsonObject:
|
||||||
|
# remove any cached version of this post so that the like icon is changed
|
||||||
|
nickname=getNicknameFromActor(actor)
|
||||||
|
cachedPostFilename=getCachedPostFilename(baseDir,nickname,domain,postJsonObject)
|
||||||
|
if os.path.isfile(cachedPostFilename):
|
||||||
|
os.remove(cachedPostFilename)
|
||||||
|
|
||||||
if not postJsonObject.get('object'):
|
if not postJsonObject.get('object'):
|
||||||
if debug:
|
if debug:
|
||||||
pprint(postJsonObject)
|
pprint(postJsonObject)
|
||||||
|
@ -226,7 +240,7 @@ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port:
|
||||||
print('DEBUG: like objectUrl: '+objectUrl)
|
print('DEBUG: like objectUrl: '+objectUrl)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
updateLikesCollection(postFilename,objectUrl,newLikeJson['actor'],debug)
|
updateLikesCollection(baseDir,postFilename,objectUrl,newLikeJson['actor'],domain,debug)
|
||||||
|
|
||||||
sendSignedJson(newLikeJson,session,baseDir, \
|
sendSignedJson(newLikeJson,session,baseDir, \
|
||||||
nickname,domain,port, \
|
nickname,domain,port, \
|
||||||
|
@ -321,7 +335,7 @@ def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,p
|
||||||
if not postFilename:
|
if not postFilename:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
undoLikesCollectionEntry(postFilename,objectUrl,newLikeJson['actor'],debug)
|
undoLikesCollectionEntry(baseDir,postFilename,objectUrl,newLikeJson['actor'],domain,debug)
|
||||||
|
|
||||||
sendSignedJson(newUndoLikeJson,session,baseDir, \
|
sendSignedJson(newUndoLikeJson,session,baseDir, \
|
||||||
nickname,domain,port, \
|
nickname,domain,port, \
|
||||||
|
@ -562,7 +576,7 @@ def outboxLike(baseDir: str,httpPrefix: str, \
|
||||||
print('DEBUG: c2s like post not found in inbox or outbox')
|
print('DEBUG: c2s like post not found in inbox or outbox')
|
||||||
print(messageId)
|
print(messageId)
|
||||||
return True
|
return True
|
||||||
updateLikesCollection(postFilename,messageId,messageJson['actor'],debug)
|
updateLikesCollection(baseDir,postFilename,messageId,messageJson['actor'],domain,debug)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post liked via c2s - '+postFilename)
|
print('DEBUG: post liked via c2s - '+postFilename)
|
||||||
|
|
||||||
|
@ -619,6 +633,6 @@ def outboxUndoLike(baseDir: str,httpPrefix: str, \
|
||||||
print('DEBUG: c2s undo like post not found in inbox or outbox')
|
print('DEBUG: c2s undo like post not found in inbox or outbox')
|
||||||
print(messageId)
|
print(messageId)
|
||||||
return True
|
return True
|
||||||
undoLikesCollectionEntry(postFilename,messageId,messageJson['actor'],debug)
|
undoLikesCollectionEntry(baseDir,postFilename,messageId,messageJson['actor'],domain,debug)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post undo liked via c2s - '+postFilename)
|
print('DEBUG: post undo liked via c2s - '+postFilename)
|
||||||
|
|
3
tests.py
3
tests.py
|
@ -405,7 +405,8 @@ def testPostMessageBetweenServers():
|
||||||
if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])>0:
|
if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])>0:
|
||||||
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1:
|
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1:
|
||||||
if len([name for name in os.listdir(mediaPath) if os.path.isfile(os.path.join(mediaPath, name))])>0:
|
if len([name for name in os.listdir(mediaPath) if os.path.isfile(os.path.join(mediaPath, name))])>0:
|
||||||
break
|
if len([name for name in os.listdir(queuePath) if os.path.isfile(os.path.join(queuePath, name))])==0:
|
||||||
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# Image attachment created
|
# Image attachment created
|
||||||
|
|
15
utils.py
15
utils.py
|
@ -379,3 +379,18 @@ def copytree(src: str, dst: str, symlinks=False, ignore=None):
|
||||||
shutil.copytree(s, d, symlinks, ignore)
|
shutil.copytree(s, d, symlinks, ignore)
|
||||||
else:
|
else:
|
||||||
shutil.copy2(s, d)
|
shutil.copy2(s, d)
|
||||||
|
|
||||||
|
def getCachedPostDirectory(baseDir: str,nickname: str,domain: str) -> str:
|
||||||
|
"""Returns the directory where the html post cache exists
|
||||||
|
"""
|
||||||
|
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
||||||
|
return htmlPostCacheDir
|
||||||
|
|
||||||
|
def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \
|
||||||
|
postJsonObject: {}) -> str:
|
||||||
|
"""Returns the html cache filename for the given post
|
||||||
|
"""
|
||||||
|
cachedPostFilename= \
|
||||||
|
getCachedPostDirectory(baseDir,nickname,domain)+ \
|
||||||
|
'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
|
||||||
|
return cachedPostFilename
|
||||||
|
|
|
@ -23,6 +23,8 @@ from utils import locatePost
|
||||||
from utils import noOfAccounts
|
from utils import noOfAccounts
|
||||||
from utils import isPublicPost
|
from utils import isPublicPost
|
||||||
from utils import getDisplayName
|
from utils import getDisplayName
|
||||||
|
from utils import getCachedPostDirectory
|
||||||
|
from utils import getCachedPostFilename
|
||||||
from follow import isFollowingActor
|
from follow import isFollowingActor
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
from posts import isDM
|
from posts import isDM
|
||||||
|
@ -1712,21 +1714,6 @@ def postContainsPublic(postJsonObject: {}) -> bool:
|
||||||
break
|
break
|
||||||
return containsPublic
|
return containsPublic
|
||||||
|
|
||||||
def getCachedPostDirectory(baseDir: str,nickname: str,domain: str) -> str:
|
|
||||||
"""Returns the directory where the html post cache exists
|
|
||||||
"""
|
|
||||||
htmlPostCacheDir=baseDir+'/accounts/'+nickname+'@'+domain+'/postcache'
|
|
||||||
return htmlPostCacheDir
|
|
||||||
|
|
||||||
def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \
|
|
||||||
postJsonObject: {}) -> str:
|
|
||||||
"""Returns the html cache filename for the given post
|
|
||||||
"""
|
|
||||||
cachedPostFilename= \
|
|
||||||
getCachedPostDirectory(baseDir,nickname,domain)+ \
|
|
||||||
'/'+postJsonObject['id'].replace('/activity','').replace('/','#')+'.html'
|
|
||||||
return cachedPostFilename
|
|
||||||
|
|
||||||
def loadIndividualPostAsHtmlFromCache(baseDir: str,nickname: str,domain: str, \
|
def loadIndividualPostAsHtmlFromCache(baseDir: str,nickname: str,domain: str, \
|
||||||
postJsonObject: {}) -> str:
|
postJsonObject: {}) -> str:
|
||||||
"""If a cached html version of the given post exists then load it and
|
"""If a cached html version of the given post exists then load it and
|
||||||
|
|
Loading…
Reference in New Issue