From 6af9c8e6fee92dc900e6e6cf0003def4631af505 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Wed, 9 Nov 2022 04:54:46 -0500 Subject: [PATCH] add follow request management methods to database --- relay/database.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/relay/database.py b/relay/database.py index c5993d4..d2d31bf 100644 --- a/relay/database.py +++ b/relay/database.py @@ -11,6 +11,7 @@ class RelayDatabase(dict): dict.__init__(self, { 'relay-list': {}, 'private-key': None, + 'follow-requests': {}, 'version': 1 }) @@ -161,3 +162,39 @@ class RelayDatabase(dict): def set_followid(self, domain, followid): data = self.get_inbox(domain, fail=True) data['followid'] = followid + + + def get_request(self, domain, fail=True): + if domain.startswith('http'): + domain = urlparse(domain).hostname + + try: + return self['follow-requests'][domain] + + except KeyError as e: + if fail: + raise e + + + def add_request(self, actor, inbox, followid): + domain = urlparse(inbox).hostname + + try: + request = self.get_request(domain) + request['followid'] = followid + + except KeyError: + pass + + self['follow-requests'][domain] = { + 'actor': actor, + 'inbox': inbox, + 'followid': followid + } + + + def del_request(self, domain): + if domain.startswith('http'): + domain = urlparse(inbox).hostname + + del self['follow-requests'][domain]