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