mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Removed the ability to star messages (unused in UI).
This commit is contained in:
@@ -213,9 +213,6 @@ public interface DatabaseComponent {
|
||||
/** Returns all temporary secrets. */
|
||||
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. */
|
||||
Collection<Group> getSubscriptions() throws DbException;
|
||||
|
||||
@@ -325,12 +322,6 @@ public interface DatabaseComponent {
|
||||
/** Records the given messages as having been seen by the given contact. */
|
||||
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
|
||||
* to any other current or future contacts.
|
||||
|
||||
@@ -10,9 +10,8 @@ public class GroupMessageHeader extends MessageHeader {
|
||||
|
||||
public GroupMessageHeader(MessageId id, MessageId parent, Author author,
|
||||
String contentType, String subject, long timestamp, boolean read,
|
||||
boolean starred, GroupId groupId) {
|
||||
super(id, parent, author, contentType, subject, timestamp, read,
|
||||
starred);
|
||||
GroupId groupId) {
|
||||
super(id, parent, author, contentType, subject, timestamp, read);
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,10 @@ public abstract class MessageHeader {
|
||||
private final Author author;
|
||||
private final String contentType, subject;
|
||||
private final long timestamp;
|
||||
private final boolean read, starred;
|
||||
private final boolean read;
|
||||
|
||||
protected MessageHeader(MessageId id, MessageId parent, Author author,
|
||||
String contentType, String subject, long timestamp, boolean read,
|
||||
boolean starred) {
|
||||
String contentType, String subject, long timestamp, boolean read) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
this.author = author;
|
||||
@@ -21,7 +20,6 @@ public abstract class MessageHeader {
|
||||
this.subject = subject;
|
||||
this.timestamp = timestamp;
|
||||
this.read = read;
|
||||
this.starred = starred;
|
||||
}
|
||||
|
||||
/** Returns the message's unique identifier. */
|
||||
@@ -63,9 +61,4 @@ public abstract class MessageHeader {
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
/** Returns true if the message has been starred. */
|
||||
public boolean isStarred() {
|
||||
return starred;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,8 @@ public class PrivateMessageHeader extends MessageHeader {
|
||||
|
||||
public PrivateMessageHeader(MessageId id, MessageId parent, Author author,
|
||||
String contentType, String subject, long timestamp, boolean read,
|
||||
boolean starred, ContactId contactId, boolean incoming) {
|
||||
super(id, parent, author, contentType, subject, timestamp, read,
|
||||
starred);
|
||||
ContactId contactId, boolean incoming) {
|
||||
super(id, parent, author, contentType, subject, timestamp, read);
|
||||
this.contactId = contactId;
|
||||
this.incoming = incoming;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1202,12 +1202,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
if(messageId.equals(header.getId())) {
|
||||
assertHeadersMatch(message, header);
|
||||
assertTrue(header.isRead());
|
||||
assertFalse(header.isStarred());
|
||||
messageFound = true;
|
||||
} else if(messageId1.equals(header.getId())) {
|
||||
assertHeadersMatch(message1, header);
|
||||
assertFalse(header.isRead());
|
||||
assertFalse(header.isStarred());
|
||||
message1Found = true;
|
||||
} else {
|
||||
fail();
|
||||
@@ -1218,12 +1216,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
if(messageId.equals(header.getId())) {
|
||||
assertHeadersMatch(message, header);
|
||||
assertTrue(header.isRead());
|
||||
assertFalse(header.isStarred());
|
||||
messageFound = true;
|
||||
} else if(messageId1.equals(header.getId())) {
|
||||
assertHeadersMatch(message1, header);
|
||||
assertFalse(header.isRead());
|
||||
assertFalse(header.isStarred());
|
||||
message1Found = true;
|
||||
} else {
|
||||
fail();
|
||||
@@ -1275,32 +1271,6 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
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
|
||||
public void testGetUnreadMessageCounts() throws Exception {
|
||||
Database<Connection> db = open(false);
|
||||
|
||||
Reference in New Issue
Block a user