Skip to content

Commit

Permalink
refactor targets_for_response() method out of poll
Browse files Browse the repository at this point in the history
for #524
  • Loading branch information
snarfed committed Oct 28, 2015
1 parent be4a3d7 commit ad3b249
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
22 changes: 22 additions & 0 deletions original_post_discovery.py
Expand Up @@ -36,6 +36,7 @@
from granary import source as gr_source
from google.appengine.api.datastore import MAX_ALLOWABLE_QUERIES
from bs4 import BeautifulSoup
import models
from models import SyndicatedPost

from google.appengine.api import memcache
Expand Down Expand Up @@ -137,6 +138,27 @@ def refetch(source):
return results


def targets_for_response(resp, originals, mentions):
"""Returns the URLs that we should send webmentions to for a given response.
...specifically, all responses except posts get sent to original post URLs,
but only posts and comments get sent to mentioned URLs.
Args:
resp: ActivityStreams response object
originals, mentions: sequence of string URLs
Returns: set of string URLs
"""
type = models.Response.get_type(resp)
targets = set()
if type != 'post':
targets |= originals
if type in ('post', 'comment'):
targets |= mentions
return targets


def _posse_post_discovery(source, activity, syndication_url, fetch_hfeed):
"""Performs the actual meat of the posse-post-discover.
Expand Down
10 changes: 2 additions & 8 deletions tasks.py
Expand Up @@ -293,14 +293,8 @@ def strip_likes_shares(objs):
original_post_discovery.discover(source, activity,
include_redirect_sources=False)

# send wms to all original posts, but only posts and comments (not
# likes, reposts, or rsvps) to mentions. matches logic in handlers.py!
targets = set()
if resp_type != 'post':
targets |= activity['originals']
if resp_type in ('post', 'comment'):
targets |= activity['mentions']

targets = original_post_discovery.targets_for_response(
resp, originals=activity['originals'], mentions=activity['mentions'])
if targets:
logging.info('%s has %d webmention target(s): %s', activity.get('url'),
len(targets), ' '.join(targets))
Expand Down

0 comments on commit ad3b249

Please sign in to comment.