This commit is contained in:
Athou
2013-04-09 11:10:26 +02:00
parent 1f8aa26571
commit 384bafa38e
8 changed files with 130 additions and 21 deletions

View File

@@ -48,6 +48,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
} }
} }
if (foundEntry == null) { if (foundEntry == null) {
entry.setInserted(Calendar.getInstance().getTime());
addFeedToEntry(entry, feed); addFeedToEntry(entry, feed);
} else { } else {
boolean foundFeed = false; boolean foundFeed = false;

View File

@@ -1,5 +1,6 @@
package com.commafeed.backend.dao; package com.commafeed.backend.dao;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -152,27 +153,33 @@ public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
return query.getResultList(); 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); 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); 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); 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(); List<FeedEntryStatus> list = Lists.newArrayList();
for (FeedEntryStatus status : statuses) { for (FeedEntryStatus status : statuses) {
if (!status.isRead()) { if (!status.isRead()) {
status.setRead(true); Date inserted = status.getEntry().getInserted();
list.add(status); if (olderThan == null || inserted == null
|| olderThan.after(inserted)) {
status.setRead(true);
list.add(status);
}
} }
} }
return list; return list;

View File

@@ -40,6 +40,10 @@ public class FeedEntry extends AbstractModel {
@Column(length = 2048) @Column(length = 2048)
private String url; private String url;
@Temporal(TemporalType.TIMESTAMP)
@Index(name = "inserted_index")
private Date inserted;
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
@Index(name = "updated_index") @Index(name = "updated_index")
private Date updated; private Date updated;
@@ -103,4 +107,12 @@ public class FeedEntry extends AbstractModel {
this.statuses = statuses; this.statuses = statuses;
} }
public Date getInserted() {
return inserted;
}
public void setInserted(Date inserted) {
this.inserted = inserted;
}
} }

View File

@@ -42,8 +42,9 @@ import com.commafeed.frontend.pages.FaviconPage;
import com.commafeed.frontend.pages.GoogleImportCallbackPage; import com.commafeed.frontend.pages.GoogleImportCallbackPage;
import com.commafeed.frontend.pages.GoogleImportRedirectPage; import com.commafeed.frontend.pages.GoogleImportRedirectPage;
import com.commafeed.frontend.pages.HomePage; import com.commafeed.frontend.pages.HomePage;
import com.commafeed.frontend.pages.WelcomePage;
import com.commafeed.frontend.pages.LogoutPage; 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 com.commafeed.frontend.utils.exception.DisplayExceptionPage;
import de.agilecoders.wicket.Bootstrap; import de.agilecoders.wicket.Bootstrap;
@@ -64,6 +65,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
mountPage("google/import/redirect", GoogleImportRedirectPage.class); mountPage("google/import/redirect", GoogleImportRedirectPage.class);
mountPage("google/import/callback", GoogleImportCallbackPage.class); mountPage("google/import/callback", GoogleImportCallbackPage.class);
mountPage("testfeed", TestRssPage.class);
setupInjection(); setupInjection();
getMarkupSettings().setStripWicketTags(true); getMarkupSettings().setStripWicketTags(true);

View File

@@ -10,6 +10,7 @@ public class Entries implements Serializable {
private String name; private String name;
private String message; private String message;
private int errorCount; private int errorCount;
private long timestamp;
private List<Entry> entries = Lists.newArrayList(); private List<Entry> entries = Lists.newArrayList();
public String getName() { public String getName() {
@@ -44,4 +45,12 @@ public class Entries implements Serializable {
this.errorCount = errorCount; this.errorCount = errorCount;
} }
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
} }

View 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()));
}
}

View File

@@ -1,5 +1,7 @@
package com.commafeed.frontend.rest.resources; package com.commafeed.frontend.rest.resources;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
@@ -92,7 +94,7 @@ public class EntriesREST extends AbstractREST {
} }
} }
entries.setTimestamp(Calendar.getInstance().getTimeInMillis());
return entries; return entries;
} }
@@ -117,11 +119,15 @@ public class EntriesREST extends AbstractREST {
@Path("mark") @Path("mark")
@GET @GET
public Response mark(@QueryParam("type") Type type, 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(type);
Preconditions.checkNotNull(id); Preconditions.checkNotNull(id);
Preconditions.checkNotNull(read); Preconditions.checkNotNull(read);
Date olderThan = olderThanTimestamp == null ? null : new Date(
olderThanTimestamp);
if (type == Type.entry) { if (type == Type.entry) {
FeedEntryStatus status = feedEntryStatusService.findById(getUser(), FeedEntryStatus status = feedEntryStatusService.findById(getUser(),
Long.valueOf(id)); Long.valueOf(id));
@@ -132,7 +138,7 @@ public class EntriesREST extends AbstractREST {
FeedSubscription subscription = feedSubscriptionService FeedSubscription subscription = feedSubscriptionService
.findById(getUser(), Long.valueOf(id)); .findById(getUser(), Long.valueOf(id));
feedEntryStatusService.markFeedEntries(getUser(), feedEntryStatusService.markFeedEntries(getUser(),
subscription.getFeed()); subscription.getFeed(), olderThan);
} else { } else {
throw new WebApplicationException(Response.status( throw new WebApplicationException(Response.status(
Status.INTERNAL_SERVER_ERROR).build()); Status.INTERNAL_SERVER_ERROR).build());
@@ -140,14 +146,14 @@ public class EntriesREST extends AbstractREST {
} else if (type == Type.category) { } else if (type == Type.category) {
if (read) { if (read) {
if (ALL.equals(id)) { if (ALL.equals(id)) {
feedEntryStatusService.markAllEntries(getUser()); feedEntryStatusService.markAllEntries(getUser(), olderThan);
} else { } else {
List<FeedCategory> categories = feedCategoryService List<FeedCategory> categories = feedCategoryService
.findAllChildrenCategories(getUser(), .findAllChildrenCategories(getUser(),
feedCategoryService.findById(getUser(), feedCategoryService.findById(getUser(),
Long.valueOf(id))); Long.valueOf(id)));
feedEntryStatusService.markCategoryEntries(getUser(), feedEntryStatusService.markCategoryEntries(getUser(),
categories); categories, olderThan);
} }
} else { } else {
throw new WebApplicationException(Response.status( throw new WebApplicationException(Response.status(

View File

@@ -5,6 +5,12 @@ module.run(function($rootScope) {
// args.entry - the entry // args.entry - the entry
$rootScope.$broadcast('mark', args); $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.$on('emitReload', function(event, args) {
$rootScope.$broadcast('reload'); $rootScope.$broadcast('reload');
}); });
@@ -212,14 +218,10 @@ module.controller('ToolbarCtrl', function($scope, $http, $state, $stateParams,
$scope.$emit('emitReload'); $scope.$emit('emitReload');
}; };
$scope.markAllAsRead = function() { $scope.markAllAsRead = function() {
EntryService.mark({ $scope.$emit('emitMarkAll', {
type : $stateParams._type, type : $stateParams._type,
id : $stateParams._id, id : $stateParams._id,
read : true 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, module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$window, EntryService, SettingsService) { $window, EntryService, SettingsService, SubscriptionService) {
$scope.selectedType = $stateParams._type; $scope.selectedType = $stateParams._type;
$scope.selectedId = $stateParams._id; $scope.selectedId = $stateParams._id;
@@ -255,6 +257,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$scope.name = null; $scope.name = null;
$scope.message = null; $scope.message = null;
$scope.errorCount = 0; $scope.errorCount = 0;
$scope.timestamp = 0;
$scope.entries = []; $scope.entries = [];
$scope.settingsService = SettingsService; $scope.settingsService = SettingsService;
@@ -290,6 +293,7 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
$scope.name = data.name; $scope.name = data.name;
$scope.message = data.message; $scope.message = data.message;
$scope.errorCount = data.errorCount; $scope.errorCount = data.errorCount;
$scope.timestamp = data.timestamp;
$scope.busy = false; $scope.busy = false;
$scope.hasMore = data.entries.length == limit; $scope.hasMore = data.entries.length == limit;
}; };
@@ -406,12 +410,26 @@ module.controller('FeedListCtrl', function($scope, $stateParams, $http, $route,
openPreviousEntry(e); 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.$on('reload', function(event, args) {
$scope.name = null; $scope.name = null;
$scope.entries = []; $scope.entries = [];
$scope.message = null; $scope.message = null;
$scope.errorCount = 0; $scope.errorCount = 0;
$scope.timestamp = 0;
$scope.busy = false; $scope.busy = false;
$scope.hasMore = true; $scope.hasMore = true;
$scope.loadMoreEntries(); $scope.loadMoreEntries();