diff options
author | James Moger <james.moger@gitblit.com> | 2011-11-03 07:46:10 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-11-03 07:46:10 -0400 |
commit | bab9c96e0f4730d52415469c45b92798e03f0733 (patch) | |
tree | baee46c34e121fce10ed0b7d9fc4b834c09c1aff /src | |
parent | 6477ce2aa8540fedbec7ebba5656cd3968e78019 (diff) | |
download | gitblit-bab9c96e0f4730d52415469c45b92798e03f0733.tar.gz gitblit-bab9c96e0f4730d52415469c45b92798e03f0733.zip |
Differentiate new activity on feeds panel
Diffstat (limited to 'src')
-rw-r--r-- | src/com/gitblit/client/FeedsPanel.java | 7 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitClient.java | 18 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitManager.java | 56 | ||||
-rw-r--r-- | src/com/gitblit/client/GitblitRegistration.java | 3 | ||||
-rw-r--r-- | src/com/gitblit/client/SyndicatedEntryTableModel.java | 17 | ||||
-rw-r--r-- | src/com/gitblit/models/FeedModel.java | 8 |
6 files changed, 95 insertions, 14 deletions
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<SyndicatedEntryTableModel>(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<String> uniqueAuthors = new HashSet<String>();
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<SyndicatedEntryModel> allEntries = new HashSet<SyndicatedEntryModel>();
if (reg.feeds.size() > 0) {
for (FeedModel feed : reg.feeds) {
- feed.lastRefresh = new Date();
+ feed.lastRefreshDate = feed.currentRefreshDate;
+ feed.currentRefreshDate = new Date();
List<SyndicatedEntryModel> 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<String, Date> cache = new HashMap<String, Date>();
+ 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<GitblitRegi public int compareTo(GitblitRegistration o) {
return name.toLowerCase().compareTo(o.name.toLowerCase());
}
+
+ protected void cacheFeeds() {
+ }
}
diff --git a/src/com/gitblit/client/SyndicatedEntryTableModel.java b/src/com/gitblit/client/SyndicatedEntryTableModel.java index 73783a5d..93177a8f 100644 --- a/src/com/gitblit/client/SyndicatedEntryTableModel.java +++ b/src/com/gitblit/client/SyndicatedEntryTableModel.java @@ -34,10 +34,12 @@ public class SyndicatedEntryTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L;
+ private final GitblitClient gitblit;
+
List<SyndicatedEntryModel> 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<SyndicatedEntryModel>());
- }
-
- public SyndicatedEntryTableModel(List<SyndicatedEntryModel> entries) {
- setEntries(entries);
+ public SyndicatedEntryTableModel(GitblitClient gitblit) {
+ this.gitblit = gitblit;
+ this.entries = new ArrayList<SyndicatedEntryModel>();
}
public void setEntries(List<SyndicatedEntryModel> 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 "<html><body><b>" + 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<FeedModel> { 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<FeedModel> { 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<FeedModel> { @Override
public int hashCode() {
- return (repository + (StringUtils.isEmpty(branch) ? "" : branch)).toLowerCase().hashCode();
+ return toString().toLowerCase().hashCode();
}
@Override
|