From 0c8b0964d71cfff8e69765931b471d04ac6f734e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Jul 2021 14:11:00 +0100 Subject: [PATCH] Remove unused webfinger aliases --- webfinger.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webfinger.py b/webfinger.py index d51869dbb..fb890c40a 100644 --- a/webfinger.py +++ b/webfinger.py @@ -271,6 +271,10 @@ def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool: "tox": "toxId" } + aliasesNotFound = [] + for name, _ in webfingerPropertyName.items(): + aliasesNotFound.append(name) + for propertyValue in actorJson['attachment']: if not propertyValue.get('name'): continue @@ -278,6 +282,8 @@ def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool: found = False for name, alias in webfingerPropertyName.items(): if name == propertyName: + if name in aliasesNotFound: + aliasesNotFound.remove(name) found = True break if not found: @@ -308,6 +314,17 @@ def _webfingerUpdateFromProfile(wfJson: {}, actorJson: {}) -> bool: else: wfJson['aliases'].append(newAlias) changed = True + + # remove any aliases which are no longer in the actor profile + removeAlias = [] + for name in aliasesNotFound: + for alias in wfJson['aliases']: + if alias.startswith(name + ':'): + removeAlias.append(alias) + for alias in removeAlias: + wfJson['aliases'].remove(alias) + changed = True + return changed