GetStream-IO将没有f​​oreignId的活动添加到多个订阅源,但这些活动共享相同的Id

时间:2017-08-15 18:30:27

标签: java getstream-io

我正在使用Stream Java客户端版本1.3.2。

我有三个平展的customer Feed:customer:101customer:102customer103

还有一个平展的timeline Feed timeline:201,它跟随上述三个customer Feed。

我向customer:101添加了一项活动。活动的to字段设置为customer:102customer:103

活动现在应该在三个customer Feed和timeline Feed中。

未为该活动设置foreignIdtime字段。我是否应该期望相同的活动在不同的Feed中有不同的id

我的印象是,如果我未在活动中设置foreignIdtime字段,则不同Feed上的相同活动将具有不同的id s。但到目前为止我的情况似乎并非如此。

以下是我的代码片段:

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);

我得到了以下输出:

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}

这是预期的行为吗?我希望他们都有不同的id s。

1 个答案:

答案 0 :(得分:0)

对此呼吁混淆的道歉。因为您正在使用“收件人”字段,所以它会将相同的有效内容写入每个供稿中,因为它们具有相同的time字段,实际上具有相同的活动ID值。如果您已经在单独的调用中编写了活动,那么它应该给出不同的活动ID值。

但是,使用活动ID发布删除仅针对单个Feed,因此请执行以下调用:

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

...应仅从该一个Feed中删除该活动。

如果 使用foreign_id值,并且您在原始Feed上的删除调用中使用了foreign_id,那么它也会删除所有Feed中的活动通过跟随关系等的副本。