Removed the ability to star messages (unused in UI).

This commit is contained in:
akwizgran
2013-09-27 18:15:43 +01:00
parent 0a153acd02
commit 7b01e42da8
8 changed files with 22 additions and 184 deletions

View File

@@ -213,9 +213,6 @@ public interface DatabaseComponent {
/** Returns all temporary secrets. */ /** Returns all temporary secrets. */
Collection<TemporarySecret> getSecrets() throws DbException; Collection<TemporarySecret> getSecrets() throws DbException;
/** Returns true if the given message has been starred. */
boolean getStarredFlag(MessageId m) throws DbException;
/** Returns the set of groups to which the user subscribes. */ /** Returns the set of groups to which the user subscribes. */
Collection<Group> getSubscriptions() throws DbException; Collection<Group> getSubscriptions() throws DbException;
@@ -325,12 +322,6 @@ public interface DatabaseComponent {
/** Records the given messages as having been seen by the given contact. */ /** Records the given messages as having been seen by the given contact. */
void setSeen(ContactId c, Collection<MessageId> seen) throws DbException; void setSeen(ContactId c, Collection<MessageId> seen) throws DbException;
/**
* Marks the given message starred or unstarred and returns true if it was
* previously starred.
*/
boolean setStarredFlag(MessageId m, boolean starred) throws DbException;
/** /**
* Makes the given group visible to the given set of contacts and invisible * Makes the given group visible to the given set of contacts and invisible
* to any other current or future contacts. * to any other current or future contacts.

View File

@@ -10,9 +10,8 @@ public class GroupMessageHeader extends MessageHeader {
public GroupMessageHeader(MessageId id, MessageId parent, Author author, public GroupMessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read, String contentType, String subject, long timestamp, boolean read,
boolean starred, GroupId groupId) { GroupId groupId) {
super(id, parent, author, contentType, subject, timestamp, read, super(id, parent, author, contentType, subject, timestamp, read);
starred);
this.groupId = groupId; this.groupId = groupId;
} }

View File

@@ -9,11 +9,10 @@ public abstract class MessageHeader {
private final Author author; private final Author author;
private final String contentType, subject; private final String contentType, subject;
private final long timestamp; private final long timestamp;
private final boolean read, starred; private final boolean read;
protected MessageHeader(MessageId id, MessageId parent, Author author, protected MessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read, String contentType, String subject, long timestamp, boolean read) {
boolean starred) {
this.id = id; this.id = id;
this.parent = parent; this.parent = parent;
this.author = author; this.author = author;
@@ -21,7 +20,6 @@ public abstract class MessageHeader {
this.subject = subject; this.subject = subject;
this.timestamp = timestamp; this.timestamp = timestamp;
this.read = read; this.read = read;
this.starred = starred;
} }
/** Returns the message's unique identifier. */ /** Returns the message's unique identifier. */
@@ -63,9 +61,4 @@ public abstract class MessageHeader {
public boolean isRead() { public boolean isRead() {
return read; return read;
} }
/** Returns true if the message has been starred. */
public boolean isStarred() {
return starred;
}
} }

View File

@@ -11,9 +11,8 @@ public class PrivateMessageHeader extends MessageHeader {
public PrivateMessageHeader(MessageId id, MessageId parent, Author author, public PrivateMessageHeader(MessageId id, MessageId parent, Author author,
String contentType, String subject, long timestamp, boolean read, String contentType, String subject, long timestamp, boolean read,
boolean starred, ContactId contactId, boolean incoming) { ContactId contactId, boolean incoming) {
super(id, parent, author, contentType, subject, timestamp, read, super(id, parent, author, contentType, subject, timestamp, read);
starred);
this.contactId = contactId; this.contactId = contactId;
this.incoming = incoming; this.incoming = incoming;
} }

View File

@@ -435,13 +435,6 @@ interface Database<T> {
Collection<MessageId> getSendableMessages(T txn, ContactId c, int maxLength) Collection<MessageId> getSendableMessages(T txn, ContactId c, int maxLength)
throws DbException; throws DbException;
/**
* Returns true if the given message has been starred.
* <p>
* Locking: message read.
*/
boolean getStarredFlag(T txn, MessageId m) throws DbException;
/** /**
* Returns the groups to which the user subscribes. * Returns the groups to which the user subscribes.
* <p> * <p>
@@ -682,15 +675,6 @@ interface Database<T> {
boolean setRetentionTime(T txn, ContactId c, long retention, long version) boolean setRetentionTime(T txn, ContactId c, long retention, long version)
throws DbException; throws DbException;
/**
* Marks the given message starred or unstarred and returns true if it was
* previously starred.
* <p>
* Locking: message write.
*/
boolean setStarredFlag(T txn, MessageId m, boolean starred)
throws DbException;
/** /**
* If the database contains the given message and it belongs to a group * If the database contains the given message and it belongs to a group
* that is visible to the given contact, marks the message as seen by the * that is visible to the given contact, marks the message as seen by the

View File

@@ -1113,25 +1113,6 @@ DatabaseCleaner.Callback {
} }
} }
public boolean getStarredFlag(MessageId m) throws DbException {
messageLock.readLock().lock();
try {
T txn = db.startTransaction();
try {
if(!db.containsMessage(txn, m))
throw new NoSuchMessageException();
boolean starred = db.getStarredFlag(txn, m);
db.commitTransaction(txn);
return starred;
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
messageLock.readLock().unlock();
}
}
public Collection<Group> getSubscriptions() throws DbException { public Collection<Group> getSubscriptions() throws DbException {
subscriptionLock.readLock().lock(); subscriptionLock.readLock().lock();
try { try {
@@ -1795,26 +1776,6 @@ DatabaseCleaner.Callback {
} }
} }
public boolean setStarredFlag(MessageId m, boolean starred)
throws DbException {
messageLock.writeLock().lock();
try {
T txn = db.startTransaction();
try {
if(!db.containsMessage(txn, m))
throw new NoSuchMessageException();
boolean wasStarred = db.setStarredFlag(txn, m, starred);
db.commitTransaction(txn);
return wasStarred;
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
messageLock.writeLock().unlock();
}
}
public void setVisibility(GroupId g, Collection<ContactId> visible) public void setVisibility(GroupId g, Collection<ContactId> visible)
throws DbException { throws DbException {
Collection<ContactId> affected = new ArrayList<ContactId>(); Collection<ContactId> affected = new ArrayList<ContactId>();

View File

@@ -154,7 +154,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " incoming BOOLEAN NOT NULL," + " incoming BOOLEAN NOT NULL,"
+ " contactId INT UNSIGNED," // Null for group messages + " contactId INT UNSIGNED," // Null for group messages
+ " read BOOLEAN NOT NULL," + " read BOOLEAN NOT NULL,"
+ " starred BOOLEAN NOT NULL,"
+ " PRIMARY KEY (messageId)," + " PRIMARY KEY (messageId),"
+ " FOREIGN KEY (groupId)" + " FOREIGN KEY (groupId)"
+ " REFERENCES groups (groupId)" + " REFERENCES groups (groupId)"
@@ -662,9 +661,9 @@ abstract class JdbcDatabase implements Database<Connection> {
String sql = "INSERT INTO messages (messageId, parentId, groupId," String sql = "INSERT INTO messages (messageId, parentId, groupId,"
+ " authorId, authorName, authorKey, contentType, subject," + " authorId, authorName, authorKey, contentType, subject,"
+ " timestamp, length, bodyStart, bodyLength, raw," + " timestamp, length, bodyStart, bodyLength, raw,"
+ " incoming, read, starred)" + " incoming, read)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?," + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,"
+ " FALSE, FALSE)"; + " FALSE)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getId().getBytes()); ps.setBytes(1, m.getId().getBytes());
if(m.getParent() == null) ps.setNull(2, BINARY); if(m.getParent() == null) ps.setNull(2, BINARY);
@@ -760,8 +759,8 @@ abstract class JdbcDatabase implements Database<Connection> {
try { try {
String sql = "INSERT INTO messages (messageId, parentId," String sql = "INSERT INTO messages (messageId, parentId,"
+ " contentType, subject, timestamp, length, bodyStart," + " contentType, subject, timestamp, length, bodyStart,"
+ " bodyLength, raw, incoming, contactId, read, starred)" + " bodyLength, raw, incoming, contactId, read)"
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE, FALSE)"; + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getId().getBytes()); ps.setBytes(1, m.getId().getBytes());
if(m.getParent() == null) ps.setNull(2, BINARY); if(m.getParent() == null) ps.setNull(2, BINARY);
@@ -1289,8 +1288,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT messageId, parentId, authorId, authorName," String sql = "SELECT messageId, parentId, authorId, authorName,"
+ " authorKey, contentType, subject, timestamp, read," + " authorKey, contentType, subject, timestamp, read"
+ " starred"
+ " FROM messages" + " FROM messages"
+ " WHERE groupId = ?"; + " WHERE groupId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
@@ -1316,9 +1314,8 @@ abstract class JdbcDatabase implements Database<Connection> {
String subject = rs.getString(7); String subject = rs.getString(7);
long timestamp = rs.getLong(8); long timestamp = rs.getLong(8);
boolean read = rs.getBoolean(9); boolean read = rs.getBoolean(9);
boolean starred = rs.getBoolean(10);
headers.add(new GroupMessageHeader(id, parent, author, headers.add(new GroupMessageHeader(id, parent, author,
contentType, subject, timestamp, read, starred, g)); contentType, subject, timestamp, read, g));
} }
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1651,7 +1648,7 @@ abstract class JdbcDatabase implements Database<Connection> {
try { try {
// Get the incoming message headers // Get the incoming message headers
String sql = "SELECT m.messageId, parentId, contentType, subject," String sql = "SELECT m.messageId, parentId, contentType, subject,"
+ " timestamp, read, starred, c.authorId, name, publicKey" + " timestamp, read, c.authorId, name, publicKey"
+ " FROM messages AS m" + " FROM messages AS m"
+ " JOIN contacts AS c" + " JOIN contacts AS c"
+ " ON m.contactId = c.contactId" + " ON m.contactId = c.contactId"
@@ -1671,20 +1668,18 @@ abstract class JdbcDatabase implements Database<Connection> {
String subject = rs.getString(4); String subject = rs.getString(4);
long timestamp = rs.getLong(5); long timestamp = rs.getLong(5);
boolean read = rs.getBoolean(6); boolean read = rs.getBoolean(6);
boolean starred = rs.getBoolean(7); AuthorId authorId = new AuthorId(rs.getBytes(7));
AuthorId authorId = new AuthorId(rs.getBytes(8)); String authorName = rs.getString(8);
String authorName = rs.getString(9); byte[] authorKey = rs.getBytes(9);
byte[] authorKey = rs.getBytes(10);
Author author = new Author(authorId, authorName, authorKey); Author author = new Author(authorId, authorName, authorKey);
headers.add(new PrivateMessageHeader(id, parent, author, headers.add(new PrivateMessageHeader(id, parent, author,
contentType, subject, timestamp, read, starred, c, contentType, subject, timestamp, read, c, true));
true));
} }
rs.close(); rs.close();
ps.close(); ps.close();
// Get the outgoing message headers // Get the outgoing message headers
sql = "SELECT m.messageId, parentId, contentType, subject," sql = "SELECT m.messageId, parentId, contentType, subject,"
+ " timestamp, read, starred, a.authorId, a.name," + " timestamp, read, a.authorId, a.name,"
+ " a.publicKey" + " a.publicKey"
+ " FROM messages AS m" + " FROM messages AS m"
+ " JOIN contacts AS c" + " JOIN contacts AS c"
@@ -1705,14 +1700,12 @@ abstract class JdbcDatabase implements Database<Connection> {
String subject = rs.getString(4); String subject = rs.getString(4);
long timestamp = rs.getLong(5); long timestamp = rs.getLong(5);
boolean read = rs.getBoolean(6); boolean read = rs.getBoolean(6);
boolean starred = rs.getBoolean(7); AuthorId authorId = new AuthorId(rs.getBytes(7));
AuthorId authorId = new AuthorId(rs.getBytes(8)); String authorName = rs.getString(8);
String authorName = rs.getString(9); byte[] authorKey = rs.getBytes(9);
byte[] authorKey = rs.getBytes(10);
Author author = new Author(authorId, authorName, authorKey); Author author = new Author(authorId, authorName, authorKey);
headers.add(new PrivateMessageHeader(id, parent, author, headers.add(new PrivateMessageHeader(id, parent, author,
contentType, subject, timestamp, read, starred, c, contentType, subject, timestamp, read, c, false));
false));
} }
rs.close(); rs.close();
ps.close(); ps.close();
@@ -2049,28 +2042,6 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
public boolean getStarredFlag(Connection txn, MessageId m)
throws DbException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT starred FROM messages WHERE messageId = ?";
ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes());
rs = ps.executeQuery();
boolean starred = false;
if(rs.next()) starred = rs.getBoolean(1);
if(rs.next()) throw new DbStateException();
rs.close();
ps.close();
return starred;
} catch(SQLException e) {
tryToClose(rs);
tryToClose(ps);
throw new DbException(e);
}
}
public Collection<Group> getSubscriptions(Connection txn) public Collection<Group> getSubscriptions(Connection txn)
throws DbException { throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
@@ -3017,36 +2988,6 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
public boolean setStarredFlag(Connection txn, MessageId m, boolean starred)
throws DbException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT starred FROM messages WHERE messageId = ?";
ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes());
rs = ps.executeQuery();
if(!rs.next()) throw new DbStateException();
boolean wasStarred = rs.getBoolean(1);
if(rs.next()) throw new DbStateException();
rs.close();
ps.close();
if(wasStarred == starred) return starred;
sql = "UPDATE messages SET starred = ? WHERE messageId = ?";
ps = txn.prepareStatement(sql);
ps.setBoolean(1, starred);
ps.setBytes(2, m.getBytes());
int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();
ps.close();
return !starred;
} catch(SQLException e) {
tryToClose(rs);
tryToClose(ps);
throw new DbException(e);
}
}
public boolean setStatusSeenIfVisible(Connection txn, ContactId c, public boolean setStatusSeenIfVisible(Connection txn, ContactId c,
MessageId m) throws DbException { MessageId m) throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;

View File

@@ -1202,12 +1202,10 @@ public class H2DatabaseTest extends BriarTestCase {
if(messageId.equals(header.getId())) { if(messageId.equals(header.getId())) {
assertHeadersMatch(message, header); assertHeadersMatch(message, header);
assertTrue(header.isRead()); assertTrue(header.isRead());
assertFalse(header.isStarred());
messageFound = true; messageFound = true;
} else if(messageId1.equals(header.getId())) { } else if(messageId1.equals(header.getId())) {
assertHeadersMatch(message1, header); assertHeadersMatch(message1, header);
assertFalse(header.isRead()); assertFalse(header.isRead());
assertFalse(header.isStarred());
message1Found = true; message1Found = true;
} else { } else {
fail(); fail();
@@ -1218,12 +1216,10 @@ public class H2DatabaseTest extends BriarTestCase {
if(messageId.equals(header.getId())) { if(messageId.equals(header.getId())) {
assertHeadersMatch(message, header); assertHeadersMatch(message, header);
assertTrue(header.isRead()); assertTrue(header.isRead());
assertFalse(header.isStarred());
messageFound = true; messageFound = true;
} else if(messageId1.equals(header.getId())) { } else if(messageId1.equals(header.getId())) {
assertHeadersMatch(message1, header); assertHeadersMatch(message1, header);
assertFalse(header.isRead()); assertFalse(header.isRead());
assertFalse(header.isStarred());
message1Found = true; message1Found = true;
} else { } else {
fail(); fail();
@@ -1275,32 +1271,6 @@ public class H2DatabaseTest extends BriarTestCase {
db.close(); db.close();
} }
@Test
public void testStarredFlag() throws Exception {
Database<Connection> db = open(false);
Connection txn = db.startTransaction();
// Subscribe to a group and store a message
db.addSubscription(txn, group);
db.addGroupMessage(txn, message, false);
// The message should be unstarred by default
assertFalse(db.getStarredFlag(txn, messageId));
// Starring the message should return the old value
assertFalse(db.setStarredFlag(txn, messageId, true));
assertTrue(db.setStarredFlag(txn, messageId, true));
// The message should be starred
assertTrue(db.getStarredFlag(txn, messageId));
// Unstarring the message should return the old value
assertTrue(db.setStarredFlag(txn, messageId, false));
assertFalse(db.setStarredFlag(txn, messageId, false));
// Unsubscribe from the group
db.removeSubscription(txn, groupId);
db.commitTransaction(txn);
db.close();
}
@Test @Test
public void testGetUnreadMessageCounts() throws Exception { public void testGetUnreadMessageCounts() throws Exception {
Database<Connection> db = open(false); Database<Connection> db = open(false);