]> source.dussan.org Git - gitblit.git/commitdiff
Differentiate new activity on feeds panel
authorJames Moger <james.moger@gitblit.com>
Thu, 3 Nov 2011 11:46:10 +0000 (07:46 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 3 Nov 2011 11:46:10 +0000 (07:46 -0400)
src/com/gitblit/client/FeedsPanel.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/GitblitManager.java
src/com/gitblit/client/GitblitRegistration.java
src/com/gitblit/client/SyndicatedEntryTableModel.java
src/com/gitblit/models/FeedModel.java

index 60d2d5f0f7969c8dcececb882f73a9ecbf9d9031..a9a24731b62243908a9e5420a2af8881f4c2af9d 100644 (file)
@@ -130,7 +130,7 @@ public abstract class FeedsPanel extends JPanel {
                controls.add(viewTree);\r
 \r
                NameRenderer nameRenderer = new NameRenderer();\r
-               tableModel = new SyndicatedEntryTableModel();\r
+               tableModel = new SyndicatedEntryTableModel(gitblit);\r
                header = new HeaderPanel(Translation.get("gb.timeline"), "feed_16x16.png");\r
                table = Utils.newTable(tableModel, Utils.DATE_FORMAT);\r
                defaultSorter = new TableRowSorter<SyndicatedEntryTableModel>(tableModel);\r
@@ -264,7 +264,10 @@ public abstract class FeedsPanel extends JPanel {
        }\r
 \r
        private void updateAuthors() {\r
-               String repository = repositorySelector.getSelectedItem().toString();\r
+               String repository = ALL;\r
+               if (repositorySelector.getSelectedIndex() > -1) {\r
+                       repository = repositorySelector.getSelectedItem().toString();\r
+               }\r
 \r
                // determine unique repositories and authors\r
                Set<String> uniqueAuthors = new HashSet<String>();\r
index 2a08b85c1d990ecc0b97bd289e4c95159ec4ef52..cc2b45849a4f7e52b0fc7d4148b27d77206df266 100644 (file)
@@ -51,6 +51,8 @@ public class GitblitClient implements Serializable {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       private static final Date NEVER = new Date(0);\r
+\r
        protected final GitblitRegistration reg;\r
 \r
        public final String url;\r
@@ -213,12 +215,14 @@ public class GitblitClient implements Serializable {
                Set<SyndicatedEntryModel> allEntries = new HashSet<SyndicatedEntryModel>();\r
                if (reg.feeds.size() > 0) {\r
                        for (FeedModel feed : reg.feeds) {\r
-                               feed.lastRefresh = new Date();\r
+                               feed.lastRefreshDate = feed.currentRefreshDate;\r
+                               feed.currentRefreshDate = new Date();\r
                                List<SyndicatedEntryModel> entries = SyndicationUtils.readFeed(url,\r
                                                feed.repository, feed.branch, -1, account, password);\r
                                allEntries.addAll(entries);\r
                        }\r
                }\r
+               reg.cacheFeeds();\r
                syndicatedEntries.clear();\r
                syndicatedEntries.addAll(allEntries);\r
                Collections.sort(syndicatedEntries);\r
@@ -241,6 +245,18 @@ public class GitblitClient implements Serializable {
                }\r
        }\r
 \r
+       public Date getLastFeedRefresh(String repository, String branch) {\r
+               FeedModel feed = new FeedModel();\r
+               feed.repository = repository;\r
+               feed.branch = branch;\r
+               if (reg.feeds.contains(feed)) {\r
+                       int idx = reg.feeds.indexOf(feed);\r
+                       feed = reg.feeds.get(idx);\r
+                       return feed.lastRefreshDate;\r
+               }\r
+               return NEVER;\r
+       }\r
+\r
        public boolean isSubscribed(RepositoryModel repository) {\r
                return subscribedRepositories.contains(repository.name.toLowerCase());\r
        }\r
index 22f98eb648b8096ab49bda4020c2003d2213acb6..a16cfe64bce229a8147a57884830ba20fd45b6cf 100644 (file)
@@ -25,7 +25,10 @@ import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;\r
 import java.awt.event.WindowAdapter;\r
 import java.awt.event.WindowEvent;\r
+import java.io.BufferedReader;\r
 import java.io.File;\r
+import java.io.FileReader;\r
+import java.io.FileWriter;\r
 import java.io.IOException;\r
 import java.net.ConnectException;\r
 import java.text.MessageFormat;\r
@@ -34,6 +37,7 @@ import java.util.ArrayList;
 import java.util.Collections;\r
 import java.util.Comparator;\r
 import java.util.Date;\r
+import java.util.HashMap;\r
 import java.util.LinkedHashMap;\r
 import java.util.List;\r
 import java.util.Locale;\r
@@ -310,7 +314,13 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                } else {\r
                                        password = new String(Base64.decode(pw)).toCharArray();\r
                                }\r
-                               GitblitRegistration reg = new GitblitRegistration(server, url, account, password);\r
+                               GitblitRegistration reg = new GitblitRegistration(server, url, account, password) {\r
+                                       private static final long serialVersionUID = 1L;\r
+\r
+                                       protected void cacheFeeds() {\r
+                                               writeFeedCache(this);\r
+                                       }\r
+                               };\r
                                String[] feeds = config.getStringList(SERVER, server, FEED);\r
                                if (feeds != null) {\r
                                        // deserialize the field definitions\r
@@ -320,6 +330,7 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                                        }\r
                                }\r
                                reg.lastLogin = lastLogin;\r
+                               loadFeedCache(reg);\r
                                registrations.put(reg.name, reg);\r
                        }\r
                } catch (Throwable t) {\r
@@ -388,6 +399,49 @@ public class GitblitManager extends JFrame implements RegistrationsDialog.Regist
                return config;\r
        }\r
 \r
+       private void loadFeedCache(GitblitRegistration reg) {\r
+               File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url)\r
+                               + ".cache");\r
+               if (!feedCache.exists()) {\r
+                       // no cache for this registration\r
+                       return;\r
+               }\r
+               try {\r
+                       BufferedReader reader = new BufferedReader(new FileReader(feedCache));\r
+                       Map<String, Date> cache = new HashMap<String, Date>();\r
+                       SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");\r
+                       String line = null;\r
+                       while ((line = reader.readLine()) != null) {\r
+                               String[] kvp = line.split("=");\r
+                               cache.put(kvp[0], df.parse(kvp[1]));\r
+                       }\r
+                       reader.close();\r
+                       for (FeedModel feed : reg.feeds) {\r
+                               String name = feed.toString();\r
+                               if (cache.containsKey(name)) {\r
+                                       feed.currentRefreshDate = cache.get(name);\r
+                               }\r
+                       }\r
+               } catch (Exception e) {\r
+                       Utils.showException(GitblitManager.this, e);\r
+               }\r
+       }\r
+\r
+       private void writeFeedCache(GitblitRegistration reg) {\r
+               try {\r
+                       File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.url)\r
+                                       + ".cache");\r
+                       FileWriter writer = new FileWriter(feedCache);\r
+                       for (FeedModel feed : reg.feeds) {\r
+                               writer.append(MessageFormat.format("{0}={1,date,yyyy-MM-dd'T'HH:mm:ss}\n",\r
+                                               feed.toString(), feed.currentRefreshDate));\r
+                       }\r
+                       writer.close();\r
+               } catch (Exception e) {\r
+                       Utils.showException(GitblitManager.this, e);\r
+               }\r
+       }\r
+\r
        public static void main(String[] args) {\r
                EventQueue.invokeLater(new Runnable() {\r
                        public void run() {\r
index 05b23d015886f0c76775807fc7d4a0da6e43149c..33399b1636b6a6a735323dc1def0028f3b791f53 100644 (file)
@@ -75,4 +75,7 @@ public class GitblitRegistration implements Serializable, Comparable<GitblitRegi
        public int compareTo(GitblitRegistration o) {\r
                return name.toLowerCase().compareTo(o.name.toLowerCase());\r
        }\r
+\r
+       protected void cacheFeeds() {\r
+       }\r
 }\r
index 73783a5de41f24410d678d07380972ca9ee0ab1e..93177a8f14f3aa2b151592f416836edfb5d7d0b6 100644 (file)
@@ -34,10 +34,12 @@ public class SyndicatedEntryTableModel extends AbstractTableModel {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
+       private final GitblitClient gitblit;\r
+\r
        List<SyndicatedEntryModel> entries;\r
 \r
        enum Columns {\r
-               Date, Repository,Author, Message, Branch;\r
+               Date, Repository, Author, Message, Branch;\r
 \r
                @Override\r
                public String toString() {\r
@@ -45,12 +47,9 @@ public class SyndicatedEntryTableModel extends AbstractTableModel {
                }\r
        }\r
 \r
-       public SyndicatedEntryTableModel() {\r
-               this(new ArrayList<SyndicatedEntryModel>());\r
-       }\r
-\r
-       public SyndicatedEntryTableModel(List<SyndicatedEntryModel> entries) {\r
-               setEntries(entries);\r
+       public SyndicatedEntryTableModel(GitblitClient gitblit) {\r
+               this.gitblit = gitblit;\r
+               this.entries = new ArrayList<SyndicatedEntryModel>();\r
        }\r
 \r
        public void setEntries(List<SyndicatedEntryModel> entries) {\r
@@ -114,6 +113,10 @@ public class SyndicatedEntryTableModel extends AbstractTableModel {
                case Author:\r
                        return entry.author;\r
                case Message:\r
+                       Date lastRefresh = gitblit.getLastFeedRefresh(entry.repository, entry.branch);\r
+                       if (entry.published.after(lastRefresh)) {\r
+                               return "<html><body><b>" + entry.title;\r
+                       }\r
                        return entry.title;\r
                }\r
                return null;\r
index d5535850a4af73db088cb2d7512a8e916d750494..08f9e48ec71ccee82e14a26d96293233b4d3ea0f 100644 (file)
@@ -29,7 +29,8 @@ public class FeedModel implements Serializable, Comparable<FeedModel> {
 \r
        public String repository;\r
        public String branch;\r
-       public Date lastRefresh;\r
+       public Date lastRefreshDate;\r
+       public Date currentRefreshDate;\r
 \r
        public boolean subscribed;\r
 \r
@@ -42,7 +43,8 @@ public class FeedModel implements Serializable, Comparable<FeedModel> {
 \r
        public FeedModel(String definition) {\r
                subscribed = true;\r
-               lastRefresh = new Date(0);\r
+               lastRefreshDate = new Date(0);\r
+               currentRefreshDate = new Date(0);\r
 \r
                String[] fields = definition.split(":");\r
                repository = fields[0];\r
@@ -76,7 +78,7 @@ public class FeedModel implements Serializable, Comparable<FeedModel> {
 \r
        @Override\r
        public int hashCode() {\r
-               return (repository + (StringUtils.isEmpty(branch) ? "" : branch)).toLowerCase().hashCode();\r
+               return toString().toLowerCase().hashCode();\r
        }\r
 \r
        @Override\r