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

@@ -435,13 +435,6 @@ interface Database<T> {
Collection<MessageId> getSendableMessages(T txn, ContactId c, int maxLength)
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.
* <p>
@@ -682,15 +675,6 @@ interface Database<T> {
boolean setRetentionTime(T txn, ContactId c, long retention, long version)
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
* 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 {
subscriptionLock.readLock().lock();
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)
throws DbException {
Collection<ContactId> affected = new ArrayList<ContactId>();

View File

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