Skip to content

Commit

Permalink
Twitter: don't fetch replies to @-mentions. for snarfed/bridgy#631
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Mar 11, 2016
1 parent 2cebe0d commit e74cdfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion granary/test/test_twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,10 @@ def test_get_activities_fetch_mentions(self):
])
self.mox.ReplayAll()

got = self.twitter.get_activities(fetch_mentions=True, min_id='567')
# fetch_replies as well as fetch_mentions to make sure we don't try to find
# replies to the mentions. https://github.com/snarfed/bridgy/issues/631
got = self.twitter.get_activities(fetch_mentions=True, fetch_replies=True,
min_id='567')
self.assert_equals([tag_uri('3'), tag_uri('4')], [a['id'] for a in got])

def test_get_activities_quote_tweets(self):
Expand Down
13 changes: 8 additions & 5 deletions granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,18 @@ def _user():
retweet_calls += 1
cache_updates['ATR ' + id] = count

if fetch_mentions:
tweets += self.fetch_mentions(_user().get('screen_name'), tweets,
min_id=min_id)

tweet_activities = [self.tweet_to_activity(t) for t in tweets]

if fetch_replies:
self.fetch_replies(tweet_activities, min_id=min_id)

if fetch_mentions:
# fetch mentions *after* replies so that we don't get replies to mentions
# https://github.com/snarfed/bridgy/issues/631
mentions = self.fetch_mentions(_user().get('screen_name'), tweets,
min_id=min_id)
tweet_activities += [self.tweet_to_activity(m) for m in mentions]

if fetch_likes:
for tweet, activity in zip(tweets, tweet_activities):
id = tweet['id_str']
Expand Down Expand Up @@ -410,7 +413,7 @@ def fetch_mentions(self, username, tweets, min_id=None):
Args:
username: string
tweets: list of Twitter API objects
tweets: list of Twitter API objects. used to find quote tweets quoting them.
min_id: only return activities with ids greater than this
Returns:
Expand Down

0 comments on commit e74cdfc

Please sign in to comment.