kopia lustrzana https://github.com/snarfed/bridgy-fed
Web: add superfeedr_subscribed prop, populate it in maybe_superfeedr_subscribe
for #550pull/746/head
rodzic
b113521f94
commit
eb4e11ae3d
|
@ -1771,8 +1771,9 @@ class WebTest(TestCase):
|
||||||
self.assertEqual(400, got.status_code)
|
self.assertEqual(400, got.status_code)
|
||||||
|
|
||||||
@patch('oauth_dropins.webutil.appengine_info.LOCAL_SERVER', False)
|
@patch('oauth_dropins.webutil.appengine_info.LOCAL_SERVER', False)
|
||||||
def test_superfeedr_subscribe(self, mock_get, mock_post):
|
def test_maybe_superfeedr_subscribe(self, mock_get, mock_post):
|
||||||
web.superfeedr_subscribe(self.user)
|
self.assertFalse(self.user.superfeedr_subscribed)
|
||||||
|
web.maybe_superfeedr_subscribe(self.user)
|
||||||
self.assert_req(mock_post, SUPERFEEDR_PUSH_API, data={
|
self.assert_req(mock_post, SUPERFEEDR_PUSH_API, data={
|
||||||
'hub.mode': 'subscribe',
|
'hub.mode': 'subscribe',
|
||||||
'hub.topic': 'https://user.com/feed',
|
'hub.topic': 'https://user.com/feed',
|
||||||
|
@ -1780,6 +1781,13 @@ class WebTest(TestCase):
|
||||||
'format': 'atom',
|
'format': 'atom',
|
||||||
'retrieve': 'true',
|
'retrieve': 'true',
|
||||||
}, auth=ANY)
|
}, auth=ANY)
|
||||||
|
self.assertTrue(self.user.key.get().superfeedr_subscribed)
|
||||||
|
|
||||||
|
def test_maybe_superfeedr_subscribe_already_subscribed(self, mock_get, mock_post):
|
||||||
|
self.user.superfeedr_subscribed = True
|
||||||
|
self.user.put()
|
||||||
|
web.maybe_superfeedr_subscribe(self.user)
|
||||||
|
# should be a noop
|
||||||
|
|
||||||
def _test_verify(self, redirects, hcard, actor, redirects_error=None):
|
def _test_verify(self, redirects, hcard, actor, redirects_error=None):
|
||||||
self.user.has_redirects = False
|
self.user.has_redirects = False
|
||||||
|
|
11
web.py
11
web.py
|
@ -95,6 +95,7 @@ class Web(User, Protocol):
|
||||||
redirects_error = ndb.TextProperty()
|
redirects_error = ndb.TextProperty()
|
||||||
has_hcard = ndb.BooleanProperty()
|
has_hcard = ndb.BooleanProperty()
|
||||||
last_webmention_in = ndb.DateTimeProperty(tzinfo=timezone.utc)
|
last_webmention_in = ndb.DateTimeProperty(tzinfo=timezone.utc)
|
||||||
|
superfeedr_subscribed = ndb.BooleanProperty(default=False)
|
||||||
|
|
||||||
# Originally, BF served Web users' AP actor ids on fed.brid.gy, eg
|
# Originally, BF served Web users' AP actor ids on fed.brid.gy, eg
|
||||||
# https://fed.brid.gy/snarfed.org . When we started adding new protocols, we
|
# https://fed.brid.gy/snarfed.org . When we started adding new protocols, we
|
||||||
|
@ -591,12 +592,16 @@ def webmention_interactive():
|
||||||
return redirect('/', code=302)
|
return redirect('/', code=302)
|
||||||
|
|
||||||
|
|
||||||
def superfeedr_subscribe(user):
|
def maybe_superfeedr_subscribe(user):
|
||||||
"""Subscribes to a user's Atom or RSS feed in Superfeedr.
|
"""Subscribes to a user's Atom or RSS feed in Superfeedr.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user (Web)
|
user (Web)
|
||||||
"""
|
"""
|
||||||
|
if user.superfeedr_subscribed:
|
||||||
|
logger.info('Already subscribed via Superfeedr')
|
||||||
|
return
|
||||||
|
|
||||||
logger.info(f'Subscribing to {user.key.id()} via Superfeedr')
|
logger.info(f'Subscribing to {user.key.id()} via Superfeedr')
|
||||||
if appengine_info.LOCAL_SERVER:
|
if appengine_info.LOCAL_SERVER:
|
||||||
logger.info(f"Skipping since we're local")
|
logger.info(f"Skipping since we're local")
|
||||||
|
@ -613,7 +618,9 @@ def superfeedr_subscribe(user):
|
||||||
'retrieve': 'true',
|
'retrieve': 'true',
|
||||||
})
|
})
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return resp
|
|
||||||
|
user.superfeedr_subscribed = True
|
||||||
|
user.put()
|
||||||
|
|
||||||
|
|
||||||
# generate/check per-user token for auth?
|
# generate/check per-user token for auth?
|
||||||
|
|
Ładowanie…
Reference in New Issue