mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
unread count sync
This commit is contained in:
@@ -2,12 +2,15 @@ package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import com.commafeed.model.Feed;
|
||||
import com.commafeed.model.FeedEntry;
|
||||
import com.commafeed.model.User;
|
||||
|
||||
@Stateless
|
||||
public class FeedEntryService extends GenericDAO<FeedEntry, String> {
|
||||
@@ -28,4 +31,13 @@ public class FeedEntryService extends GenericDAO<FeedEntry, String> {
|
||||
em.merge(feed);
|
||||
}
|
||||
|
||||
public List<FeedEntry> getUnreadEntries(Feed feed, User user) {
|
||||
String query = "select entry from FeedEntry entry where entry.feed = :feed and not in (select status.entry from FeedEntryStatus status where status.user = :user and status.read = true)";
|
||||
TypedQuery<FeedEntry> typedQuery = em.createQuery(query,
|
||||
FeedEntry.class);
|
||||
typedQuery.setParameter("feed", feed);
|
||||
typedQuery.setParameter("user", user);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.commafeed.frontend.components.auth.LoginPage;
|
||||
import com.commafeed.frontend.components.auth.LogoutPage;
|
||||
import com.commafeed.frontend.pages.home.HomePage;
|
||||
import com.commafeed.frontend.rest.FeedSubscriptionsREST;
|
||||
import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
|
||||
|
||||
public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
@@ -42,6 +43,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
|
||||
mountPage("login", LoginPage.class);
|
||||
mountPage("logout", LogoutPage.class);
|
||||
mountPage("error", DisplayExceptionPage.class);
|
||||
|
||||
mountPage("subscriptions", FeedSubscriptionsREST.class);
|
||||
|
||||
setupInjection();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.commafeed.frontend.components.auth;
|
||||
|
||||
import org.apache.wicket.markup.html.WebPage;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LogoutPage extends WebPage {
|
||||
public LogoutPage() {
|
||||
getSession().invalidate();
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
<script src="vendor/jquery/jquery-1.9.1.min.js"></script>
|
||||
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="vendor/angular/angular.min.js"></script>
|
||||
<script src="vendor/angular/angular-resource.min.js"></script>
|
||||
<script src="vendor/angular-ui/angular-ui.min.js"></script>
|
||||
<script src="vendor/angular-ui-bootstrap/ui-bootstrap-tpls-0.2.0.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/controllers.js"></script>
|
||||
<script src="js/directives.js"></script>
|
||||
<script src="js/services.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.inject.Inject;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.backend.dao.FeedCategoryService;
|
||||
import com.commafeed.backend.dao.FeedEntryService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.CommaFeedSession;
|
||||
import com.commafeed.frontend.pages.JSONPage;
|
||||
@@ -25,12 +26,14 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
@Inject
|
||||
FeedCategoryService FeedCategoryService;
|
||||
|
||||
@Inject
|
||||
FeedEntryService feedEntryService;
|
||||
|
||||
User user = CommaFeedSession.get().getUser();
|
||||
|
||||
@Override
|
||||
protected Object getObject() {
|
||||
|
||||
User user = CommaFeedSession.get().getUser();
|
||||
List<FeedCategory> categories = FeedCategoryService.findAll(user);
|
||||
|
||||
Category root = new Category();
|
||||
addChildren(categories, root);
|
||||
for (FeedSubscription subscription : feedSubscriptionService
|
||||
@@ -39,7 +42,10 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
Subscription sub = new Subscription();
|
||||
sub.setId(subscription.getId());
|
||||
sub.setName(subscription.getTitle());
|
||||
sub.setUnread(77);
|
||||
int size = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), user).size();
|
||||
sub.setUnread(size);
|
||||
root.getFeeds().add(sub);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
@@ -58,7 +64,10 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
Subscription sub = new Subscription();
|
||||
sub.setId(subscription.getId());
|
||||
sub.setName(subscription.getTitle());
|
||||
sub.setUnread(77);
|
||||
int size = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), user).size();
|
||||
sub.setUnread(size);
|
||||
child.getFeeds().add(sub);
|
||||
}
|
||||
current.getChildren().add(child);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.commafeed.frontend.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.commafeed.frontend.rest.FeedSubscriptionsREST.Subscription;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class Category {
|
||||
private Long id;
|
||||
private String name;
|
||||
private List<Category> children = Lists.newArrayList();
|
||||
private List<Subscription> feeds = Lists.newArrayList();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Category> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Category> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public List<Subscription> getFeeds() {
|
||||
return feeds;
|
||||
}
|
||||
|
||||
public void setFeeds(List<Subscription> feeds) {
|
||||
this.feeds = feeds;
|
||||
}
|
||||
|
||||
}
|
||||
25
src/main/java/com/commafeed/frontend/rest/model/Entries.java
Normal file
25
src/main/java/com/commafeed/frontend/rest/model/Entries.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.commafeed.frontend.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Entries {
|
||||
private String name;
|
||||
private List<Entry> entries;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void setEntries(List<Entry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
}
|
||||
86
src/main/java/com/commafeed/frontend/rest/model/Entry.java
Normal file
86
src/main/java/com/commafeed/frontend/rest/model/Entry.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.commafeed.frontend.rest.model;
|
||||
|
||||
public class Entry {
|
||||
private String id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String date;
|
||||
private String feedId;
|
||||
private String feedName;
|
||||
private String url;
|
||||
private boolean read;
|
||||
private boolean starred;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getFeedId() {
|
||||
return feedId;
|
||||
}
|
||||
|
||||
public void setFeedId(String feedId) {
|
||||
this.feedId = feedId;
|
||||
}
|
||||
|
||||
public String getFeedName() {
|
||||
return feedName;
|
||||
}
|
||||
|
||||
public void setFeedName(String feedName) {
|
||||
this.feedName = feedName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
public boolean isStarred() {
|
||||
return starred;
|
||||
}
|
||||
|
||||
public void setStarred(boolean starred) {
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.commafeed.frontend.rest.model;
|
||||
|
||||
public class Subscription {
|
||||
private Long id;
|
||||
private String name;
|
||||
private int unread;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getUnread() {
|
||||
return unread;
|
||||
}
|
||||
|
||||
public void setUnread(int unread) {
|
||||
this.unread = unread;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user