Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.getstream.client.model.feeds.BaseFeed Maven / Gradle / Ivy
package io.getstream.client.model.feeds;
import io.getstream.client.exception.StreamClientException;
import io.getstream.client.model.activities.BaseActivity;
import io.getstream.client.model.beans.FeedFollow;
import io.getstream.client.model.beans.FollowMany;
import io.getstream.client.model.filters.FeedFilter;
import io.getstream.client.repo.StreamRepository;
import io.getstream.client.service.AggregatedActivityServiceImpl;
import io.getstream.client.service.FlatActivityServiceImpl;
import io.getstream.client.service.NotificationActivityServiceImpl;
import io.getstream.client.service.UserActivityServiceImpl;
import java.io.IOException;
import java.util.List;
/**
* Provide basic operation to perform against a feed.
*/
public class BaseFeed implements Feed {
private static final int DEFAULT_ACTIVITY_COPY_LIMIT = 300;
private static final boolean DEFAULT_KEEP_HISTORY = false;
protected final StreamRepository streamRepository;
protected final String feedSlug;
protected final String userId;
private final String id;
/**
* Create a new feed using the given slug and user id.
*
* @param streamRepository Provide data repository to perform actual operation on a given feed.
* It must implement {@link StreamRepository}.
* @param feedSlug Feed slug
* @param userId User ID
*/
public BaseFeed(StreamRepository streamRepository, String feedSlug, String userId) {
this.streamRepository = streamRepository;
this.feedSlug = feedSlug;
this.userId = userId;
this.id = feedSlug.concat(":").concat(userId);
}
@Override
public String getReadOnlyToken() {
return streamRepository.getReadOnlyToken(this);
}
@Override
public void follow(String feedSlug, String userId) throws IOException, StreamClientException {
String feedId = String.format("%s:%s", feedSlug, userId);
streamRepository.follow(this, feedId, DEFAULT_ACTIVITY_COPY_LIMIT);
}
@Override
public void follow(String feedSlug, String userId, int activityCopyLimit) throws IOException, StreamClientException {
String feedId = String.format("%s:%s", feedSlug, userId);
streamRepository.follow(this, feedId, activityCopyLimit);
}
@Override
public void followMany(FollowMany follows, int activityCopyLimit) throws IOException, StreamClientException {
streamRepository.followMany(this, follows, activityCopyLimit);
}
@Override
public void followMany(FollowMany follows) throws IOException, StreamClientException {
streamRepository.followMany(this, follows, DEFAULT_ACTIVITY_COPY_LIMIT);
}
@Override
public void unfollow(String feedSlug, String userId) throws IOException, StreamClientException {
String feedId = String.format("%s:%s", feedSlug, userId);
streamRepository.unfollow(this, feedId, DEFAULT_KEEP_HISTORY);
}
@Override
public void unfollow(String feedSlug, String userId, boolean keepHistory) throws IOException, StreamClientException {
String feedId = String.format("%s:%s", feedSlug, userId);
streamRepository.unfollow(this, feedId, keepHistory);
}
@Override
public List getFollowers() throws IOException, StreamClientException {
return streamRepository.getFollowers(this, new FeedFilter.Builder().build());
}
@Override
public List getFollowers(FeedFilter filter) throws IOException, StreamClientException {
return streamRepository.getFollowers(this, filter);
}
@Override
public List getFollowing() throws IOException, StreamClientException {
return streamRepository.getFollowing(this, new FeedFilter.Builder().build());
}
@Override
public List getFollowing(FeedFilter filter) throws IOException, StreamClientException {
return streamRepository.getFollowing(this, filter);
}
@Override
public void deleteActivity(String activityId) throws IOException, StreamClientException {
streamRepository.deleteActivityById(this, activityId);
}
@Override
public void deleteActivityByForeignId(String foreignId) throws IOException, StreamClientException {
streamRepository.deleteActivityByForeignId(this, foreignId);
}
@Override
public AggregatedActivityServiceImpl newAggregatedActivityService(Class clazz) {
return new AggregatedActivityServiceImpl<>(this, clazz, streamRepository);
}
@Override
public FlatActivityServiceImpl newFlatActivityService(Class clazz) {
return new FlatActivityServiceImpl<>(this, clazz, streamRepository);
}
@Override
public UserActivityServiceImpl newUserActivityService(Class clazz) {
return new UserActivityServiceImpl<>(this, clazz, streamRepository);
}
@Override
public NotificationActivityServiceImpl newNotificationActivityService(Class clazz) {
return new NotificationActivityServiceImpl<>(this, clazz, streamRepository);
}
public String getFeedSlug() {
return feedSlug;
}
public String getFeedId() {
return getFeedSlug().concat(getUserId());
}
public String getUserId() {
return userId;
}
@Override
public String getId() {
return id;
}
@Override
public String getToken() {
return streamRepository.getToken(this);
}
}