forked from Archives/Athou_commafeed
fix #20
This commit is contained in:
@@ -48,6 +48,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
||||
}
|
||||
}
|
||||
if (foundEntry == null) {
|
||||
entry.setInserted(Calendar.getInstance().getTime());
|
||||
addFeedToEntry(entry, feed);
|
||||
} else {
|
||||
boolean foundFeed = false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -152,27 +153,33 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public void markFeedEntries(User user, Feed feed) {
|
||||
public void markFeedEntries(User user, Feed feed, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = getStatuses(feed, user, true);
|
||||
update(markList(statuses));
|
||||
update(markList(statuses, olderThan));
|
||||
}
|
||||
|
||||
public void markCategoryEntries(User user, List<FeedCategory> categories) {
|
||||
public void markCategoryEntries(User user, List<FeedCategory> categories,
|
||||
Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = getStatuses(categories, user, true);
|
||||
update(markList(statuses));
|
||||
update(markList(statuses, olderThan));
|
||||
}
|
||||
|
||||
public void markAllEntries(User user) {
|
||||
public void markAllEntries(User user, Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = getStatuses(user, true);
|
||||
update(markList(statuses));
|
||||
update(markList(statuses, olderThan));
|
||||
}
|
||||
|
||||
private List<FeedEntryStatus> markList(List<FeedEntryStatus> statuses) {
|
||||
private List<FeedEntryStatus> markList(List<FeedEntryStatus> statuses,
|
||||
Date olderThan) {
|
||||
List<FeedEntryStatus> list = Lists.newArrayList();
|
||||
for (FeedEntryStatus status : statuses) {
|
||||
if (!status.isRead()) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
Date inserted = status.getEntry().getInserted();
|
||||
if (olderThan == null || inserted == null
|
||||
|| olderThan.after(inserted)) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
||||
@@ -40,6 +40,10 @@ public class FeedEntry extends AbstractModel {
|
||||
@Column(length = 2048)
|
||||
private String url;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Index(name = "inserted_index")
|
||||
private Date inserted;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Index(name = "updated_index")
|
||||
private Date updated;
|
||||
@@ -103,4 +107,12 @@ public class FeedEntry extends AbstractModel {
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
public Date getInserted() {
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public void setInserted(Date inserted) {
|
||||
this.inserted = inserted;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,9 @@ import com.commafeed.frontend.pages.FaviconPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportCallbackPage;
|
||||
import com.commafeed.frontend.pages.GoogleImportRedirectPage;
|
||||
import com.commafeed.frontend.pages.HomePage;
|
||||
import com.commafeed.frontend.pages.WelcomePage;
|
||||
import com.commafeed.frontend.pages.LogoutPage;
|
||||
import com.commafeed.frontend.pages.TestRssPage;
|
||||
import com.commafeed.frontend.pages.WelcomePage;
|
||||
import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
|
||||
|
||||
import de.agilecoders.wicket.Bootstrap;
|
||||
@@ -64,6 +65,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
mountPage("google/import/redirect", GoogleImportRedirectPage.class);
|
||||
mountPage("google/import/callback", GoogleImportCallbackPage.class);
|
||||
|
||||
mountPage("testfeed", TestRssPage.class);
|
||||
|
||||
setupInjection();
|
||||
|
||||
getMarkupSettings().setStripWicketTags(true);
|
||||
|
||||
@@ -10,6 +10,7 @@ public class Entries implements Serializable {
|
||||
private String name;
|
||||
private String message;
|
||||
private int errorCount;
|
||||
private long timestamp;
|
||||
private List<Entry> entries = Lists.newArrayList();
|
||||
|
||||
public String getName() {
|
||||
@@ -44,4 +45,12 @@ public class Entries implements Serializable {
|
||||
this.errorCount = errorCount;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
53
src/main/java/com/commafeed/frontend/pages/TestRssPage.java
Normal file
53
src/main/java/com/commafeed/frontend/pages/TestRssPage.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.commafeed.frontend.pages;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
import org.apache.wicket.request.handler.TextRequestHandler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndEntryImpl;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.feed.synd.SyndFeedImpl;
|
||||
import com.sun.syndication.io.SyndFeedOutput;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class TestRssPage extends WebPage {
|
||||
|
||||
public TestRssPage() {
|
||||
SyndFeed feed = new SyndFeedImpl();
|
||||
feed.setFeedType("rss_2.0");
|
||||
feed.setTitle("Test RSS");
|
||||
|
||||
feed.setLink("");
|
||||
feed.setDescription("New entries everytime it is accessed");
|
||||
|
||||
List<SyndEntry> entries = Lists.newArrayList();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
entry.setUri(uuid);
|
||||
entry.setTitle(uuid);
|
||||
entry.setLink("http://www.example.com/" + uuid);
|
||||
entry.setPublishedDate(Calendar.getInstance().getTime());
|
||||
entries.add(entry);
|
||||
}
|
||||
feed.setEntries(entries);
|
||||
SyndFeedOutput output = new SyndFeedOutput();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
try {
|
||||
output.output(feed, writer);
|
||||
} catch (Exception e) {
|
||||
writer.write("Could not get feed information");
|
||||
}
|
||||
|
||||
getRequestCycle().scheduleRequestHandlerAfterCurrent(
|
||||
new TextRequestHandler("text/xml", "UTF-8", writer.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.DefaultValue;
|
||||
@@ -92,7 +94,7 @@ public class EntriesREST extends AbstractREST {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
entries.setTimestamp(Calendar.getInstance().getTimeInMillis());
|
||||
return entries;
|
||||
}
|
||||
|
||||
@@ -117,11 +119,15 @@ public class EntriesREST extends AbstractREST {
|
||||
@Path("mark")
|
||||
@GET
|
||||
public Response mark(@QueryParam("type") Type type,
|
||||
@QueryParam("id") String id, @QueryParam("read") boolean read) {
|
||||
@QueryParam("id") String id, @QueryParam("read") boolean read,
|
||||
@QueryParam("olderThan") Long olderThanTimestamp) {
|
||||
Preconditions.checkNotNull(type);
|
||||
Preconditions.checkNotNull(id);
|
||||
Preconditions.checkNotNull(read);
|
||||
|
||||
Date olderThan = olderThanTimestamp == null ? null : new Date(
|
||||
olderThanTimestamp);
|
||||
|
||||
if (type == Type.entry) {
|
||||
FeedEntryStatus status = feedEntryStatusService.findById(getUser(),
|
||||
Long.valueOf(id));
|
||||
@@ -132,7 +138,7 @@ public class EntriesREST extends AbstractREST {
|
||||
FeedSubscription subscription = feedSubscriptionService
|
||||
.findById(getUser(), Long.valueOf(id));
|
||||
feedEntryStatusService.markFeedEntries(getUser(),
|
||||
subscription.getFeed());
|
||||
subscription.getFeed(), olderThan);
|
||||
} else {
|
||||
throw new WebApplicationException(Response.status(
|
||||
Status.INTERNAL_SERVER_ERROR).build());
|
||||
@@ -140,14 +146,14 @@ public class EntriesREST extends AbstractREST {
|
||||
} else if (type == Type.category) {
|
||||
if (read) {
|
||||
if (ALL.equals(id)) {
|
||||
feedEntryStatusService.markAllEntries(getUser());
|
||||
feedEntryStatusService.markAllEntries(getUser(), olderThan);
|
||||
} else {
|
||||
List<FeedCategory> categories = feedCategoryService
|
||||
.findAllChildrenCategories(getUser(),
|
||||
feedCategoryService.findById(getUser(),
|
||||
Long.valueOf(id)));
|
||||
feedEntryStatusService.markCategoryEntries(getUser(),
|
||||
categories);
|
||||
categories, olderThan);
|
||||
}
|
||||
} else {
|
||||
throw new WebApplicationException(Response.status(
|
||||
|
||||
@@ -5,6 +5,12 @@ module.run(function($rootScope) {
|
||||
// args.entry - the entry
|
||||
$rootScope.$broadcast('mark', args);
|
||||
});
|
||||
$rootScope.$on('emitMarkAll', function(event, args) {
|
||||
// args.type
|
||||
// args.id
|
||||
// args.read
|
||||
$rootScope.$broadcast('markAll', args);
|
||||
});
|
||||
$rootScope.$on('emitReload', function(event, args) {
|
||||
$rootScope.$broadcast('reload');
|
||||
});
|
||||
@@ -212,14 +218,10 @@ module.controller('ToolbarCtrl', function($scope, $http, $state, $stateParams,
|
||||
$scope.$emit('emitReload');
|
||||
};
|
||||
$scope.markAllAsRead = function() {
|
||||
EntryService.mark({
|
||||
$scope.$emit('emitMarkAll', {
|
||||
type : $stateParams._type,
|
||||
id : $stateParams._id,
|
||||
read : true
|
||||
}, function() {
|
||||
SubscriptionService.init(function() {
|
||||
$scope.$emit('emitReload');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -246,7 +248,7 @@ module.controller('ToolbarCtrl', function($scope, $http, $state, $stateParams,
|
||||
});
|
||||
|
||||
module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
||||
$window, EntryService, SettingsService) {
|
||||
$window, EntryService, SettingsService, SubscriptionService) {
|
||||
|
||||
$scope.selectedType = $stateParams._type;
|
||||
$scope.selectedId = $stateParams._id;
|
||||
@@ -255,6 +257,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
||||
$scope.name = null;
|
||||
$scope.message = null;
|
||||
$scope.errorCount = 0;
|
||||
$scope.timestamp = 0;
|
||||
$scope.entries = [];
|
||||
|
||||
$scope.settingsService = SettingsService;
|
||||
@@ -290,6 +293,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
||||
$scope.name = data.name;
|
||||
$scope.message = data.message;
|
||||
$scope.errorCount = data.errorCount;
|
||||
$scope.timestamp = data.timestamp;
|
||||
$scope.busy = false;
|
||||
$scope.hasMore = data.entries.length == limit;
|
||||
};
|
||||
@@ -406,12 +410,26 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
|
||||
openPreviousEntry(e);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$on('markAll', function(event, args) {
|
||||
EntryService.mark({
|
||||
type : $scope.selectedType,
|
||||
id : $scope.selectedId,
|
||||
olderThan : $scope.timestamp,
|
||||
read : true
|
||||
}, function() {
|
||||
SubscriptionService.init(function() {
|
||||
$scope.$emit('emitReload');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$on('reload', function(event, args) {
|
||||
$scope.name = null;
|
||||
$scope.entries = [];
|
||||
$scope.message = null;
|
||||
$scope.errorCount = 0;
|
||||
$scope.timestamp = 0;
|
||||
$scope.busy = false;
|
||||
$scope.hasMore = true;
|
||||
$scope.loadMoreEntries();
|
||||
|
||||
Reference in New Issue
Block a user