Setting ignores on announces

merge-requests/30/head
Bob Mottram 2021-09-28 12:20:14 +01:00
parent a317e69d31
commit 450a9faf57
1 changed files with 63 additions and 60 deletions

View File

@ -472,16 +472,18 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
return return
print('mutePost: ' + str(postJsonObject)) print('mutePost: ' + str(postJsonObject))
postJsonObj = postJsonObject
if hasObjectDict(postJsonObject): if hasObjectDict(postJsonObject):
postJsonObj = postJsonObject['object']
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
actor = localActorUrl(httpPrefix, nickname, domainFull) actor = localActorUrl(httpPrefix, nickname, domainFull)
if postJsonObject['object'].get('conversation'): if postJsonObj.get('conversation'):
muteConversation(baseDir, nickname, domain, muteConversation(baseDir, nickname, domain,
postJsonObject['object']['conversation']) postJsonObj['conversation'])
# does this post have ignores on it from differenent actors? # does this post have ignores on it from differenent actors?
if not postJsonObject['object'].get('ignores'): if not postJsonObj.get('ignores'):
if debug: if debug:
print('DEBUG: Adding initial mute to ' + postId) print('DEBUG: Adding initial mute to ' + postId)
ignoresJson = { ignoresJson = {
@ -494,11 +496,11 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
'actor': actor 'actor': actor
}] }]
} }
postJsonObject['object']['ignores'] = ignoresJson postJsonObj['ignores'] = ignoresJson
else: else:
if not postJsonObject['object']['ignores'].get('items'): if not postJsonObj['ignores'].get('items'):
postJsonObject['object']['ignores']['items'] = [] postJsonObj['ignores']['items'] = []
itemsList = postJsonObject['object']['ignores']['items'] itemsList = postJsonObj['ignores']['items']
for ignoresItem in itemsList: for ignoresItem in itemsList:
if ignoresItem.get('actor'): if ignoresItem.get('actor'):
if ignoresItem['actor'] == actor: if ignoresItem['actor'] == actor:
@ -509,7 +511,7 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
} }
igIt = len(itemsList) igIt = len(itemsList)
itemsList.append(newIgnore) itemsList.append(newIgnore)
postJsonObject['object']['ignores']['totalItems'] = igIt postJsonObj['ignores']['totalItems'] = igIt
saveJson(postJsonObject, postFilename) saveJson(postJsonObject, postFilename)
# remove cached post so that the muted version gets recreated # remove cached post so that the muted version gets recreated
@ -564,19 +566,20 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
pass pass
print('UNMUTE: ' + muteFilename + ' file removed') print('UNMUTE: ' + muteFilename + ' file removed')
postJsonObj = postJsonObject
if hasObjectDict(postJsonObject): if hasObjectDict(postJsonObject):
if postJsonObject['object'].get('conversation'): postJsonObj = postJsonObject['object']
if postJsonObj.get('conversation'):
unmuteConversation(baseDir, nickname, domain, unmuteConversation(baseDir, nickname, domain,
postJsonObject['object']['conversation']) postJsonObj['conversation'])
if postJsonObject['object'].get('ignores'): if postJsonObj.get('ignores'):
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
actor = localActorUrl(httpPrefix, nickname, domainFull) actor = localActorUrl(httpPrefix, nickname, domainFull)
totalItems = 0 totalItems = 0
if postJsonObject['object']['ignores'].get('totalItems'): if postJsonObj['ignores'].get('totalItems'):
totalItems = \ totalItems = postJsonObj['ignores']['totalItems']
postJsonObject['object']['ignores']['totalItems'] itemsList = postJsonObj['ignores']['items']
itemsList = postJsonObject['object']['ignores']['items']
for ignoresItem in itemsList: for ignoresItem in itemsList:
if ignoresItem.get('actor'): if ignoresItem.get('actor'):
if ignoresItem['actor'] == actor: if ignoresItem['actor'] == actor:
@ -587,10 +590,10 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int,
if totalItems == 1: if totalItems == 1:
if debug: if debug:
print('DEBUG: mute was removed from post') print('DEBUG: mute was removed from post')
del postJsonObject['object']['ignores'] del postJsonObj['ignores']
else: else:
igItLen = len(postJsonObject['object']['ignores']['items']) igItLen = len(postJsonObj['ignores']['items'])
postJsonObject['object']['ignores']['totalItems'] = igItLen postJsonObj['ignores']['totalItems'] = igItLen
saveJson(postJsonObject, postFilename) saveJson(postJsonObject, postFilename)
# remove cached post so that the muted version gets recreated # remove cached post so that the muted version gets recreated