简体   繁体   中英

GetStream-IO Add activity without foreignId to multiple feeds, but these activities share same Id

I'm using the Stream Java client version 1.3.2.

I have three flat customer feeds: customer:101 , customer:102 , and customer103 .

There is also a flat timeline feed, timeline:201 , which follows the above three customer feeds.

I added an activity to customer:101 . The activity has the to field set to customer:102 and customer:103 .

The activity should now be in the three customer feeds and the timeline feed.

The foreignId and time fields are not set for that activity. Should I expect the same activity to have different id s in the different feeds?

I was under the impression that if I don't set the foreignId and time fields on an activity, the same activity on different feeds will have different id s. But that does not seem to be the case from what I ran so far.

Here's a snippet of my code:

Feed feedOne = streamClient.newFeed("customer", "101");
FlatActivityServiceImpl<SimpleActivity> feedOneService =
    feedOne.newFlatActivityService(SimpleActivity.class);

Feed feedTwo = streamClient.newFeed("customer", "102");
FlatActivityServiceImpl<SimpleActivity> feedTwoService =
    feedTwo.newFlatActivityService(SimpleActivity.class);

Feed feedThree = streamClient.newFeed("customer", "103");
FlatActivityServiceImpl<SimpleActivity> feedThreeService =
    feedThree.newFlatActivityService(SimpleActivity.class);

Feed timeline = streamClient.newFeed("timeline", "201");
FlatActivityServiceImpl<SimpleActivity> timelineService =
    timeline.newFlatActivityService(SimpleActivity.class);

timeline.follow("customer", "101", 0);
timeline.follow("customer", "102", 0);
timeline.follow("customer", "103", 0);

// Create a new activity
SimpleActivity activity = new SimpleActivity();
activity.setActor("customer:101");
activity.setObject("tweet:1");
activity.setVerb("tweet");
activity.setTo(Arrays.asList("customer:102", "customer:103"));
feedOneService.addActivity(activity);

System.out.println("Feed one activities:");
feedOneService.getActivities().getResults().forEach(System.out::println);

System.out.println("Feed two activities:");
feedTwoService.getActivities().getResults().forEach(System.out::println);

System.out.println("Feed Three activities:");
feedThreeService.getActivities().getResults().forEach(System.out::println);

System.out.println("Timeline activities:");
timelineService.getActivities().getResults().forEach(System.out::println);

I got the following output:

13:34:11.835 [main] DEBUG i.g.c.a.repo.StreamRepositoryImpl - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/timeline/201/following/?api_key=
13:34:12.323 [main] DEBUG i.g.c.a.repo.StreamRepositoryImpl - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/timeline/201/following/?api_key=
13:34:12.433 [main] DEBUG i.g.c.a.repo.StreamRepositoryImpl - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/timeline/201/following/?api_key=
13:34:12.573 [main] DEBUG i.g.c.a.r.StreamActivityRepository - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/customer/101/?api_key='
Feed one activities:
13:34:12.817 [main] DEBUG i.g.c.a.r.StreamActivityRepository - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/customer/101/?api_key=w&limit=25'
SimpleActivity{id=f3d610da-81df-11e7-8080-80000cce824c, actor=customer:101, verb=tweet, object=tweet:1, target=null, time=Tue Aug 15 13:34:12 EDT 2017, to=[customer:102, customer:103], origin=null, score=null, duration=null}
Feed two activities:
13:34:12.892 [main] DEBUG i.g.c.a.r.StreamActivityRepository - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/customer/102/?api_key=w&limit=25'
SimpleActivity{id=f3d610da-81df-11e7-8080-80000cce824c, actor=customer:101, verb=tweet, object=tweet:1, target=null, time=Tue Aug 15 13:34:12 EDT 2017, to=[customer:102, customer:103], origin=null, score=null, duration=null}
Feed Three activities:
13:34:12.963 [main] DEBUG i.g.c.a.r.StreamActivityRepository - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/customer/103/?api_key=&limit=25'
SimpleActivity{id=f3d610da-81df-11e7-8080-80000cce824c, actor=customer:101, verb=tweet, object=tweet:1, target=null, time=Tue Aug 15 13:34:12 EDT 2017, to=[customer:102, customer:103], origin=customer:102, score=null, duration=null}
Timeline activities: 
13:34:13.012 [main] DEBUG i.g.c.a.r.StreamActivityRepository - Invoking url: 'https://us-east-api.getstream.io/api/v1.0/feed/timeline/201/?api_key=&limit=25'
SimpleActivity{id=f3d610da-81df-11e7-8080-80000cce824c, actor=customer:101, verb=tweet, object=tweet:1, target=null, time=Tue Aug 15 13:34:12 EDT 2017, to=[customer:102, customer:103], origin=customer:103, score=null, duration=null}

Is this the expected behavior? I expected them to all have different id s.

Apologies for the confusion on the call about this. Because you're using the To field, it writes the same payload into each of the feeds, which because they have the same time field would indeed have the same activity ID value. If you had written the activities in separate calls it should have given different activity ID values.

Issuing a delete using the activity ID, however, is specific only to a single feed, so a call like:

feedTwoService.deleteActivity('f3d6...824c');

... should delete the activity ONLY from that one feed.

If you were using foreign_id values, and you used that foreign_id in the delete call on the original feed, it would also delete the activity from any feeds that got a copy through follow relationships, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM