From: James Moger Date: Thu, 3 Nov 2011 11:46:10 +0000 (-0400) Subject: Differentiate new activity on feeds panel X-Git-Tag: v0.7.0~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bab9c96e0f4730d52415469c45b92798e03f0733;p=gitblit.git Differentiate new activity on feeds panel --- diff --git a/src/com/gitblit/client/FeedsPanel.java b/src/com/gitblit/client/FeedsPanel.java index 60d2d5f0..a9a24731 100644 --- a/src/com/gitblit/client/FeedsPanel.java +++ b/src/com/gitblit/client/FeedsPanel.java @@ -130,7 +130,7 @@ public abstract class FeedsPanel extends JPanel { controls.add(viewTree); NameRenderer nameRenderer = new NameRenderer(); - tableModel = new SyndicatedEntryTableModel(); + tableModel = new SyndicatedEntryTableModel(gitblit); header = new HeaderPanel(Translation.get("gb.timeline"), "feed_16x16.png"); table = Utils.newTable(tableModel, Utils.DATE_FORMAT); defaultSorter = new TableRowSorter(tableModel); @@ -264,7 +264,10 @@ public abstract class FeedsPanel extends JPanel { } private void updateAuthors() { - String repository = repositorySelector.getSelectedItem().toString(); + String repository = ALL; + if (repositorySelector.getSelectedIndex() > -1) { + repository = repositorySelector.getSelectedItem().toString(); + } // determine unique repositories and authors Set uniqueAuthors = new HashSet(); diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java index 2a08b85c..cc2b4584 100644 --- a/src/com/gitblit/client/GitblitClient.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -51,6 +51,8 @@ public class GitblitClient implements Serializable { private static final long serialVersionUID = 1L; + private static final Date NEVER = new Date(0); + protected final GitblitRegistration reg; public final String url; @@ -213,12 +215,14 @@ public class GitblitClient implements Serializable { Set allEntries = new HashSet(); if (reg.feeds.size() > 0) { for (FeedModel feed : reg.feeds) { - feed.lastRefresh = new Date(); + feed.lastRefreshDate = feed.currentRefreshDate; + feed.currentRefreshDate = new Date(); List entries = SyndicationUtils.readFeed(url, feed.repository, feed.branch, -1, account, password); allEntries.addAll(entries); } } + reg.cacheFeeds(); syndicatedEntries.clear(); syndicatedEntries.addAll(allEntries); Collections.sort(syndicatedEntries); @@ -241,6 +245,18 @@ public class GitblitClient implements Serializable { } } + public Date getLastFeedRefresh(String repository, String branch) { + FeedModel feed = new FeedModel(); + feed.repository = repository; + feed.branch = branch; + if (reg.feeds.contains(feed)) { + int idx = reg.feeds.indexOf(feed); + feed = reg.feeds.get(idx); + return feed.lastRefreshDate; + } + return NEVER; + } + public boolean isSubscribed(RepositoryModel repository) { return subscribedRepositories.contains(repository.name.toLowerCase()); } diff --git a/src/com/gitblit/client/GitblitManager.java b/src/com/gitblit/client/GitblitManager.java index 22f98eb6..a16cfe64 100644 --- a/src/com/gitblit/client/GitblitManager.java +++ b/src/com/gitblit/client/GitblitManager.java @@ -25,7 +25,10 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.net.ConnectException; import java.text.MessageFormat; @@ -34,6 +37,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; @@ -310,7 +314,13 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist } else { password = new String(Base64.decode(pw)).toCharArray(); } - GitblitRegistration reg = new GitblitRegistration(server, url, account, password); + GitblitRegistration reg = new GitblitRegistration(server, url, account, password) { + private static final long serialVersionUID = 1L; + + protected void cacheFeeds() { + writeFeedCache(this); + } + }; String[] feeds = config.getStringList(SERVER, server, FEED); if (feeds != null) { // deserialize the field definitions @@ -320,6 +330,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist } } reg.lastLogin = lastLogin; + loadFeedCache(reg); registrations.put(reg.name, reg); } } catch (Throwable t) { @@ -388,6 +399,49 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist return config; } + private void loadFeedCache(GitblitRegistration reg) { + File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url) + + ".cache"); + if (!feedCache.exists()) { + // no cache for this registration + return; + } + try { + BufferedReader reader = new BufferedReader(new FileReader(feedCache)); + Map cache = new HashMap(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + String line = null; + while ((line = reader.readLine()) != null) { + String[] kvp = line.split("="); + cache.put(kvp[0], df.parse(kvp[1])); + } + reader.close(); + for (FeedModel feed : reg.feeds) { + String name = feed.toString(); + if (cache.containsKey(name)) { + feed.currentRefreshDate = cache.get(name); + } + } + } catch (Exception e) { + Utils.showException(GitblitManager.this, e); + } + } + + private void writeFeedCache(GitblitRegistration reg) { + try { + File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url) + + ".cache"); + FileWriter writer = new FileWriter(feedCache); + for (FeedModel feed : reg.feeds) { + writer.append(MessageFormat.format("{0}={1,date,yyyy-MM-dd'T'HH:mm:ss}\n", + feed.toString(), feed.currentRefreshDate)); + } + writer.close(); + } catch (Exception e) { + Utils.showException(GitblitManager.this, e); + } + } + public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { diff --git a/src/com/gitblit/client/GitblitRegistration.java b/src/com/gitblit/client/GitblitRegistration.java index 05b23d01..33399b16 100644 --- a/src/com/gitblit/client/GitblitRegistration.java +++ b/src/com/gitblit/client/GitblitRegistration.java @@ -75,4 +75,7 @@ public class GitblitRegistration implements Serializable, Comparable entries; enum Columns { - Date, Repository,Author, Message, Branch; + Date, Repository, Author, Message, Branch; @Override public String toString() { @@ -45,12 +47,9 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { } } - public SyndicatedEntryTableModel() { - this(new ArrayList()); - } - - public SyndicatedEntryTableModel(List entries) { - setEntries(entries); + public SyndicatedEntryTableModel(GitblitClient gitblit) { + this.gitblit = gitblit; + this.entries = new ArrayList(); } public void setEntries(List entries) { @@ -114,6 +113,10 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { case Author: return entry.author; case Message: + Date lastRefresh = gitblit.getLastFeedRefresh(entry.repository, entry.branch); + if (entry.published.after(lastRefresh)) { + return "" + entry.title; + } return entry.title; } return null; diff --git a/src/com/gitblit/models/FeedModel.java b/src/com/gitblit/models/FeedModel.java index d5535850..08f9e48e 100644 --- a/src/com/gitblit/models/FeedModel.java +++ b/src/com/gitblit/models/FeedModel.java @@ -29,7 +29,8 @@ public class FeedModel implements Serializable, Comparable { public String repository; public String branch; - public Date lastRefresh; + public Date lastRefreshDate; + public Date currentRefreshDate; public boolean subscribed; @@ -42,7 +43,8 @@ public class FeedModel implements Serializable, Comparable { public FeedModel(String definition) { subscribed = true; - lastRefresh = new Date(0); + lastRefreshDate = new Date(0); + currentRefreshDate = new Date(0); String[] fields = definition.split(":"); repository = fields[0]; @@ -76,7 +78,7 @@ public class FeedModel implements Serializable, Comparable { @Override public int hashCode() { - return (repository + (StringUtils.isEmpty(branch) ? "" : branch)).toLowerCase().hashCode(); + return toString().toLowerCase().hashCode(); } @Override