Skip to content

Commit f994a8c

Browse files
committed
Merge pull request GetStream#36 from GetStream/feature-activity-copy-limit
Added activity_copy_limit to follow method
2 parents 56320bd + 126d6aa commit f994a8c

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

stream/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,20 @@ def add_to_many(self, activity, feeds):
235235
data = {'activity': activity, 'feeds': feeds}
236236
self._make_signed_request('post', 'feed/add_to_many/', data=data)
237237

238-
def follow_many(self, follows):
238+
def follow_many(self, follows, activity_copy_limit=None):
239239
'''
240240
Creates many follows
241241
:param follows: the list of follow relations
242242
243243
eg. [{'source': source, 'target': target}]
244244
245245
'''
246-
self._make_signed_request('post', 'follow_many/', data=follows)
246+
params = None
247+
248+
if activity_copy_limit != None:
249+
params = dict(activity_copy_limit=activity_copy_limit)
250+
251+
self._make_signed_request('post', 'follow_many/', params=params, data=follows)
247252

248253
def update_activities(self, activities):
249254
'''

stream/feed.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get(self, **params):
126126
self.feed_url, params=params, signature=token)
127127
return response
128128

129-
def follow(self, target_feed_slug, target_user_id, **extra_data):
129+
def follow(self, target_feed_slug, target_user_id, activity_copy_limit, **extra_data):
130130
'''
131131
Follows the given feed
132132
@@ -141,6 +141,8 @@ def follow(self, target_feed_slug, target_user_id, **extra_data):
141141
'target': target_feed_id,
142142
'target_token': self.client.feed(target_feed_slug, target_user_id).token
143143
}
144+
if activity_copy_limit != None:
145+
data['activity_copy_limit'] = activity_copy_limit
144146
token = self.create_scope_token('follower', 'write')
145147
data.update(extra_data)
146148
response = self.client.post(

stream/tests.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
def connect_debug():
2121
return stream.connect(
22-
'gav9ygr75by3',
23-
'5ws2hnua79n9qga6e2dy572qdfapwgdc83853mjm3mjp66czyb2xkahbdhs98an8',
22+
'2a7ug7h97y6v',
23+
'rg24qz8qtqq2dqqejushqt7m8v7fzrnkad6xmu2b9e3ejrjb7wabktyvgenu3car',
2424
location='us-east',
2525
timeout=10
2626
)
@@ -309,6 +309,17 @@ def test_follow_and_source(self):
309309
activity_id_found = activity['id'] if activity is not None else None
310310
self.assertEqual(activity['origin'], feed.id)
311311
self.assertEqual(activity_id_found, activity_id)
312+
313+
def test_follow_activity_copy_limit(self):
314+
feed = getfeed('user', 'test_follow_acl')
315+
feed1 = getfeed('user', 'test_follow_acl1')
316+
actor_id = random.randint(10, 100000)
317+
feed1.add_activity({ 'actor': actor_id, 'verb': 'tweet', 'object': 1 })
318+
feed.follow(feed1.slug, feed1.user_id, activity_copy_limit=0)
319+
time.sleep(10)
320+
activities = feed.get(limit=5)['results']
321+
322+
self.assertEqual(len(activities), 0)
312323

313324
def test_follow_and_delete(self):
314325
user_feed = getfeed('user', 'test_follow')
@@ -690,6 +701,22 @@ def test_follow_many(self):
690701
self.assertEqual(follows[0]['feed_id'], source)
691702
self.assertIn(follows[0]['target_id'], targets)
692703

704+
def test_follow_many_acl(self):
705+
sources = [getfeed('user', str(i)) for i in range(10)]
706+
targets = [getfeed('flat', str(i)) for i in range(10)]
707+
sources_id = [source.id for source in sources]
708+
targets_id = [target.id for target in targets]
709+
feeds = [{'source': s, 'target': t} for s,t in zip(sources_id, targets_id)]
710+
711+
for target in targets:
712+
target.add_activity({ 'actor': 'barry', 'object': '09', 'verb': 'tweet' })
713+
714+
self.c.follow_many(feeds, activity_copy_limit=0)
715+
716+
for source in sources:
717+
activities = source.get(limit=5)['results']
718+
self.assertEqual(len(activities), 0)
719+
693720
def test_add_to_many(self):
694721
activity = {'actor': 1, 'verb': 'tweet', 'object': 1, 'custom': 'data'}
695722
feeds = [getfeed('flat', str(i)).id for i in range(10, 20)]

0 commit comments

Comments
 (0)