@Test public void countUnread() throws Exception { assertEquals(0, service.countUnread(account)); FeedAsset a1 = service.createReplyFeed(nextFlakeId(), account.getAccountId()); FeedAsset a2 = service.createReplyFeed(nextFlakeId(), account.getAccountId()); assertEquals(2, service.countUnread(account)); service.acknowledge(account, a1.getAssetId()); assertEquals(1, service.countUnread(account)); service.acknowledge(account, a2.getAssetId()); assertEquals(0, service.countUnread(account)); IntStream.range(0, 20) .forEach(i -> service.createReplyFeed(nextFlakeId(), account.getAccountId())); assertEquals(11, service.countUnread(account)); }
@Override public int countUnread(Authorization authorization) { List<FeedAsset> recent = feedAssetDao.listFeedsDesc(authorization.authenticatedId(), null, NewsFeed.MAX_UNREAD_COUNT); return recent.stream() .filter(FeedAsset::isAcked) .findFirst() .map(recent::indexOf) .orElse(recent.size()); }
FeedServiceImpl implements FeedService { @Override public int countUnread(Authorization authorization) { List<FeedAsset> recent = feedAssetDao.listFeedsDesc(authorization.authenticatedId(), null, NewsFeed.MAX_UNREAD_COUNT); return recent.stream() .filter(FeedAsset::isAcked) .findFirst() .map(recent::indexOf) .orElse(recent.size()); } }
FeedServiceImpl implements FeedService { @Override public int countUnread(Authorization authorization) { List<FeedAsset> recent = feedAssetDao.listFeedsDesc(authorization.authenticatedId(), null, NewsFeed.MAX_UNREAD_COUNT); return recent.stream() .filter(FeedAsset::isAcked) .findFirst() .map(recent::indexOf) .orElse(recent.size()); }  }
FeedServiceImpl implements FeedService { @Override public int countUnread(Authorization authorization) { List<FeedAsset> recent = feedAssetDao.listFeedsDesc(authorization.authenticatedId(), null, NewsFeed.MAX_UNREAD_COUNT); return recent.stream() .filter(FeedAsset::isAcked) .findFirst() .map(recent::indexOf) .orElse(recent.size()); }  @Override FeedAsset createReplyFeed(FlakeId debateId, UUID replyToAccountId); @Override List<FeedAsset> listFeeds(Authorization authorization, FlakeId startAssetId); @Override void acknowledge(Authorization authorization, FlakeId assetId); @Override int countUnread(Authorization authorization); }
FeedServiceImpl implements FeedService { @Override public int countUnread(Authorization authorization) { List<FeedAsset> recent = feedAssetDao.listFeedsDesc(authorization.authenticatedId(), null, NewsFeed.MAX_UNREAD_COUNT); return recent.stream() .filter(FeedAsset::isAcked) .findFirst() .map(recent::indexOf) .orElse(recent.size()); }  @Override FeedAsset createReplyFeed(FlakeId debateId, UUID replyToAccountId); @Override List<FeedAsset> listFeeds(Authorization authorization, FlakeId startAssetId); @Override void acknowledge(Authorization authorization, FlakeId assetId); @Override int countUnread(Authorization authorization);  }