mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
force a feed refresh when someone subscribes
This commit is contained in:
@@ -69,7 +69,16 @@ public class FeedRefreshWorker {
|
||||
}
|
||||
return new AsyncResult<Void>(null);
|
||||
}
|
||||
|
||||
|
||||
@Asynchronous
|
||||
public void updateAsync(Feed feed){
|
||||
try {
|
||||
update(feed);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void update(Feed feed) throws NotSupportedException,
|
||||
SystemException, SecurityException, IllegalStateException,
|
||||
RollbackException, HeuristicMixedException,
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FeedSubscriptionService {
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Lock(LockType.WRITE)
|
||||
public void subscribe(User user, String url, String title,
|
||||
public Feed subscribe(User user, String url, String title,
|
||||
FeedCategory category) {
|
||||
|
||||
Feed feed = feedDAO.findByUrl(url);
|
||||
@@ -72,5 +72,6 @@ public class FeedSubscriptionService {
|
||||
}
|
||||
feedEntryStatusDAO.save(statuses);
|
||||
}
|
||||
return feed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
@@ -22,6 +23,7 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.backend.feeds.FeedRefreshWorker;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
@@ -34,6 +36,9 @@ import com.google.common.base.Preconditions;
|
||||
@Path("subscriptions")
|
||||
public class SubscriptionsREST extends AbstractREST {
|
||||
|
||||
@Inject
|
||||
FeedRefreshWorker worker;
|
||||
|
||||
@GET
|
||||
@Path("fetch")
|
||||
public Feed fetchFeed(@QueryParam("url") String url) {
|
||||
@@ -62,11 +67,11 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
url = fetchFeed(url).getUrl();
|
||||
|
||||
FeedCategory category = EntriesREST.ALL.equals(req.getCategoryId()) ? null
|
||||
: feedCategoryDAO
|
||||
.findById(Long.valueOf(req.getCategoryId()));
|
||||
: feedCategoryDAO.findById(Long.valueOf(req.getCategoryId()));
|
||||
Feed fetchedFeed = fetchFeed(url);
|
||||
feedSubscriptionService.subscribe(getUser(), fetchedFeed.getUrl(),
|
||||
req.getTitle(), category);
|
||||
Feed feed = feedSubscriptionService.subscribe(getUser(),
|
||||
fetchedFeed.getUrl(), req.getTitle(), category);
|
||||
worker.updateAsync(feed);
|
||||
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
@@ -145,8 +150,8 @@ public class SubscriptionsREST extends AbstractREST {
|
||||
public Response deleteCategory(@QueryParam("id") Long id) {
|
||||
FeedCategory cat = feedCategoryDAO.findById(getUser(), id);
|
||||
if (cat != null) {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO
|
||||
.findByCategory(getUser(), cat);
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategory(
|
||||
getUser(), cat);
|
||||
for (FeedSubscription sub : subs) {
|
||||
sub.setCategory(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user