mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 23:29:52 +01:00
Set a flag in MessageHeader to indicate whether the message is local.
This commit is contained in:
@@ -12,11 +12,11 @@ public class MessageHeader {
|
|||||||
private final Author.Status authorStatus;
|
private final Author.Status authorStatus;
|
||||||
private final String contentType;
|
private final String contentType;
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final boolean read;
|
private final boolean local, read;
|
||||||
|
|
||||||
public MessageHeader(MessageId id, MessageId parent, GroupId groupId,
|
public MessageHeader(MessageId id, MessageId parent, GroupId groupId,
|
||||||
Author author, Author.Status authorStatus, String contentType,
|
Author author, Author.Status authorStatus, String contentType,
|
||||||
long timestamp, boolean read) {
|
long timestamp, boolean local, boolean read) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
@@ -24,6 +24,7 @@ public class MessageHeader {
|
|||||||
this.authorStatus = authorStatus;
|
this.authorStatus = authorStatus;
|
||||||
this.contentType = contentType;
|
this.contentType = contentType;
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
|
this.local = local;
|
||||||
this.read = read;
|
this.read = read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +70,11 @@ public class MessageHeader {
|
|||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true if the message was locally generated. */
|
||||||
|
public boolean isLocal() {
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns true if the message has been read. */
|
/** Returns true if the message has been read. */
|
||||||
public boolean isRead() {
|
public boolean isRead() {
|
||||||
return read;
|
return read;
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ interface Database<T> {
|
|||||||
* <p>
|
* <p>
|
||||||
* Locking: message write.
|
* Locking: message write.
|
||||||
*/
|
*/
|
||||||
void addMessage(T txn, Message m, boolean incoming) throws DbException;
|
void addMessage(T txn, Message m, boolean local) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records that a message has been offered by the given contact.
|
* Records that a message has been offered by the given contact.
|
||||||
|
|||||||
@@ -383,8 +383,12 @@ DatabaseCleaner.Callback {
|
|||||||
*/
|
*/
|
||||||
private void addMessage(T txn, Message m, ContactId sender)
|
private void addMessage(T txn, Message m, ContactId sender)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
db.addMessage(txn, m, sender != null);
|
if(sender == null) {
|
||||||
if(sender == null) db.setReadFlag(txn, m.getId(), true);
|
db.addMessage(txn, m, true);
|
||||||
|
db.setReadFlag(txn, m.getId(), true);
|
||||||
|
} else {
|
||||||
|
db.addMessage(txn, m, false);
|
||||||
|
}
|
||||||
Group g = m.getGroup();
|
Group g = m.getGroup();
|
||||||
Collection<ContactId> visibility = db.getVisibility(txn, g.getId());
|
Collection<ContactId> visibility = db.getVisibility(txn, g.getId());
|
||||||
visibility = new HashSet<ContactId>(visibility);
|
visibility = new HashSet<ContactId>(visibility);
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ import org.briarproject.api.transport.TemporarySecret;
|
|||||||
*/
|
*/
|
||||||
abstract class JdbcDatabase implements Database<Connection> {
|
abstract class JdbcDatabase implements Database<Connection> {
|
||||||
|
|
||||||
private static final int SCHEMA_VERSION = 3;
|
private static final int SCHEMA_VERSION = 4;
|
||||||
private static final int MIN_SCHEMA_VERSION = 3;
|
private static final int MIN_SCHEMA_VERSION = 4;
|
||||||
|
|
||||||
private static final String CREATE_SETTINGS =
|
private static final String CREATE_SETTINGS =
|
||||||
"CREATE TABLE settings"
|
"CREATE TABLE settings"
|
||||||
@@ -160,7 +160,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " bodyStart INT NOT NULL,"
|
+ " bodyStart INT NOT NULL,"
|
||||||
+ " bodyLength INT NOT NULL,"
|
+ " bodyLength INT NOT NULL,"
|
||||||
+ " raw BLOB NOT NULL,"
|
+ " raw BLOB NOT NULL,"
|
||||||
+ " incoming BOOLEAN NOT NULL,"
|
+ " local BOOLEAN NOT NULL,"
|
||||||
+ " read BOOLEAN NOT NULL,"
|
+ " read BOOLEAN NOT NULL,"
|
||||||
+ " PRIMARY KEY (messageId),"
|
+ " PRIMARY KEY (messageId),"
|
||||||
+ " FOREIGN KEY (groupId)"
|
+ " FOREIGN KEY (groupId)"
|
||||||
@@ -805,14 +805,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMessage(Connection txn, Message m, boolean incoming)
|
public void addMessage(Connection txn, Message m, boolean local)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "INSERT INTO messages (messageId, parentId, groupId,"
|
String sql = "INSERT INTO messages (messageId, parentId, groupId,"
|
||||||
+ " authorId, authorName, authorKey, contentType,"
|
+ " authorId, authorName, authorKey, contentType,"
|
||||||
+ " timestamp, length, bodyStart, bodyLength, raw,"
|
+ " timestamp, length, bodyStart, bodyLength, raw,"
|
||||||
+ " incoming, read)"
|
+ " local, read)"
|
||||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)";
|
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, FALSE)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, m.getId().getBytes());
|
ps.setBytes(1, m.getId().getBytes());
|
||||||
@@ -836,7 +836,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ps.setInt(10, m.getBodyStart());
|
ps.setInt(10, m.getBodyStart());
|
||||||
ps.setInt(11, m.getBodyLength());
|
ps.setInt(11, m.getBodyLength());
|
||||||
ps.setBytes(12, raw);
|
ps.setBytes(12, raw);
|
||||||
ps.setBoolean(13, incoming);
|
ps.setBoolean(13, local);
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -1517,7 +1517,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
if(rs.next()) throw new DbException();
|
if(rs.next()) throw new DbException();
|
||||||
// Get the message headers
|
// Get the message headers
|
||||||
sql = "SELECT messageId, parentId, m.groupId, contentType,"
|
sql = "SELECT messageId, parentId, m.groupId, contentType,"
|
||||||
+ " timestamp, incoming, read"
|
+ " timestamp, local, read"
|
||||||
+ " FROM messages AS m"
|
+ " FROM messages AS m"
|
||||||
+ " JOIN groups AS g"
|
+ " JOIN groups AS g"
|
||||||
+ " ON m.groupId = g.groupId"
|
+ " ON m.groupId = g.groupId"
|
||||||
@@ -1536,16 +1536,16 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
GroupId groupId = new GroupId(rs.getBytes(3));
|
GroupId groupId = new GroupId(rs.getBytes(3));
|
||||||
String contentType = rs.getString(4);
|
String contentType = rs.getString(4);
|
||||||
long timestamp = rs.getLong(5);
|
long timestamp = rs.getLong(5);
|
||||||
boolean incoming = rs.getBoolean(6);
|
boolean local = rs.getBoolean(6);
|
||||||
boolean read = rs.getBoolean(7);
|
boolean read = rs.getBoolean(7);
|
||||||
if(incoming) {
|
if(local) {
|
||||||
headers.add(new MessageHeader(id, parent, groupId,
|
|
||||||
remoteAuthor, VERIFIED, contentType, timestamp,
|
|
||||||
read));
|
|
||||||
} else {
|
|
||||||
headers.add(new MessageHeader(id, parent, groupId,
|
headers.add(new MessageHeader(id, parent, groupId,
|
||||||
localAuthor, VERIFIED, contentType, timestamp,
|
localAuthor, VERIFIED, contentType, timestamp,
|
||||||
read));
|
true, read));
|
||||||
|
} else {
|
||||||
|
headers.add(new MessageHeader(id, parent, groupId,
|
||||||
|
remoteAuthor, VERIFIED, contentType, timestamp,
|
||||||
|
false, read));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
@@ -1719,7 +1719,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT messageId, parentId, m.authorId, authorName,"
|
String sql = "SELECT messageId, parentId, m.authorId, authorName,"
|
||||||
+ " authorKey, contentType, timestamp, read,"
|
+ " authorKey, contentType, timestamp, local, read,"
|
||||||
+ " la.authorId IS NOT NULL, c.authorId IS NOT NULL"
|
+ " la.authorId IS NOT NULL, c.authorId IS NOT NULL"
|
||||||
+ " FROM messages AS m"
|
+ " FROM messages AS m"
|
||||||
+ " LEFT OUTER JOIN localAuthors AS la"
|
+ " LEFT OUTER JOIN localAuthors AS la"
|
||||||
@@ -1747,15 +1747,16 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
String contentType = rs.getString(6);
|
String contentType = rs.getString(6);
|
||||||
long timestamp = rs.getLong(7);
|
long timestamp = rs.getLong(7);
|
||||||
boolean read = rs.getBoolean(8);
|
boolean local = rs.getBoolean(8);
|
||||||
boolean isSelf = rs.getBoolean(9);
|
boolean read = rs.getBoolean(9);
|
||||||
boolean isContact = rs.getBoolean(10);
|
boolean isSelf = rs.getBoolean(10);
|
||||||
|
boolean isContact = rs.getBoolean(11);
|
||||||
Author.Status authorStatus;
|
Author.Status authorStatus;
|
||||||
if(author == null) authorStatus = ANONYMOUS;
|
if(author == null) authorStatus = ANONYMOUS;
|
||||||
else if(isSelf || isContact) authorStatus = VERIFIED;
|
else if(isSelf || isContact) authorStatus = VERIFIED;
|
||||||
else authorStatus = UNKNOWN;
|
else authorStatus = UNKNOWN;
|
||||||
headers.add(new MessageHeader(id, parent, g, author,
|
headers.add(new MessageHeader(id, parent, g, author,
|
||||||
authorStatus, contentType, timestamp, read));
|
authorStatus, contentType, timestamp, local, read));
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).containsGroup(txn, groupId);
|
oneOf(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addMessage(txn, message, false);
|
oneOf(database).addMessage(txn, message, true);
|
||||||
oneOf(database).setReadFlag(txn, messageId, true);
|
oneOf(database).setReadFlag(txn, messageId, true);
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).getVisibility(txn, groupId);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
@@ -1000,7 +1000,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).addMessage(txn, message, true);
|
oneOf(database).addMessage(txn, message, false);
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).getVisibility(txn, groupId);
|
||||||
will(returnValue(Arrays.asList(contactId)));
|
will(returnValue(Arrays.asList(contactId)));
|
||||||
oneOf(database).getContactIds(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Subscribe to a group and store a message
|
// Subscribe to a group and store a message
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
|
|
||||||
// Unsubscribing from the group should remove the message
|
// Unsubscribing from the group should remove the message
|
||||||
assertTrue(db.containsMessage(txn, messageId));
|
assertTrue(db.containsMessage(txn, messageId));
|
||||||
@@ -167,7 +167,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
|
|
||||||
// The message has no status yet, so it should not be sendable
|
// The message has no status yet, so it should not be sendable
|
||||||
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
Collection<MessageId> ids = db.getMessagesToSend(txn, contactId,
|
||||||
@@ -202,7 +202,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, false);
|
db.addStatus(txn, contactId, messageId, false, false);
|
||||||
|
|
||||||
// The contact is not subscribed, so the message should not be sendable
|
// The contact is not subscribed, so the message should not be sendable
|
||||||
@@ -239,7 +239,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, false);
|
db.addStatus(txn, contactId, messageId, false, false);
|
||||||
|
|
||||||
// The message is sendable, but too large to send
|
// The message is sendable, but too large to send
|
||||||
@@ -269,7 +269,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, false);
|
db.addStatus(txn, contactId, messageId, false, false);
|
||||||
|
|
||||||
// The subscription is not visible to the contact, so the message
|
// The subscription is not visible to the contact, so the message
|
||||||
@@ -306,10 +306,10 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message1 = new TestMessage(messageId1, null, group, author,
|
Message message1 = new TestMessage(messageId1, null, group, author,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, true);
|
db.addStatus(txn, contactId, messageId, false, true);
|
||||||
db.raiseAckFlag(txn, contactId, messageId);
|
db.raiseAckFlag(txn, contactId, messageId);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
db.addStatus(txn, contactId, messageId1, false, true);
|
db.addStatus(txn, contactId, messageId1, false, true);
|
||||||
db.raiseAckFlag(txn, contactId, messageId1);
|
db.raiseAckFlag(txn, contactId, messageId1);
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// Receive the same message twice
|
// Receive the same message twice
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, true);
|
db.addStatus(txn, contactId, messageId, false, true);
|
||||||
db.raiseAckFlag(txn, contactId, messageId);
|
db.raiseAckFlag(txn, contactId, messageId);
|
||||||
db.raiseAckFlag(txn, contactId, messageId);
|
db.raiseAckFlag(txn, contactId, messageId);
|
||||||
@@ -371,7 +371,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, groupId);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, false);
|
db.addStatus(txn, contactId, messageId, false, false);
|
||||||
|
|
||||||
// Retrieve the message from the database and mark it as sent
|
// Retrieve the message from the database and mark it as sent
|
||||||
@@ -407,8 +407,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Subscribe to a group and store two messages
|
// Subscribe to a group and store two messages
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
|
|
||||||
// Allowing enough capacity for one message should return the older one
|
// Allowing enough capacity for one message should return the older one
|
||||||
Iterator<MessageId> it = db.getOldMessages(txn, size).iterator();
|
Iterator<MessageId> it = db.getOldMessages(txn, size).iterator();
|
||||||
@@ -446,7 +446,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
// Storing a message should reduce the free space
|
// Storing a message should reduce the free space
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
assertTrue(db.getFreeSpace() < free);
|
assertTrue(db.getFreeSpace() < free);
|
||||||
|
|
||||||
@@ -705,7 +705,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addStatus(txn, contactId, messageId, false, false);
|
db.addStatus(txn, contactId, messageId, false, false);
|
||||||
|
|
||||||
// The subscription is not visible
|
// The subscription is not visible
|
||||||
@@ -752,7 +752,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId childId = new MessageId(TestUtils.getRandomId());
|
MessageId childId = new MessageId(TestUtils.getRandomId());
|
||||||
Message child = new TestMessage(childId, null, group, null, contentType,
|
Message child = new TestMessage(childId, null, group, null, contentType,
|
||||||
subject, timestamp, raw);
|
subject, timestamp, raw);
|
||||||
db.addMessage(txn, child, false);
|
db.addMessage(txn, child, true);
|
||||||
assertTrue(db.containsMessage(txn, childId));
|
assertTrue(db.containsMessage(txn, childId));
|
||||||
assertNull(db.getParent(txn, childId));
|
assertNull(db.getParent(txn, childId));
|
||||||
|
|
||||||
@@ -773,7 +773,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||||
Message child = new TestMessage(childId, parentId, group, null,
|
Message child = new TestMessage(childId, parentId, group, null,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, child, false);
|
db.addMessage(txn, child, true);
|
||||||
assertTrue(db.containsMessage(txn, childId));
|
assertTrue(db.containsMessage(txn, childId));
|
||||||
assertFalse(db.containsMessage(txn, parentId));
|
assertFalse(db.containsMessage(txn, parentId));
|
||||||
assertNull(db.getParent(txn, childId));
|
assertNull(db.getParent(txn, childId));
|
||||||
@@ -801,8 +801,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
Message parent = new TestMessage(parentId, null, group1, null,
|
Message parent = new TestMessage(parentId, null, group1, null,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, child, false);
|
db.addMessage(txn, child, true);
|
||||||
db.addMessage(txn, parent, false);
|
db.addMessage(txn, parent, true);
|
||||||
assertTrue(db.containsMessage(txn, childId));
|
assertTrue(db.containsMessage(txn, childId));
|
||||||
assertTrue(db.containsMessage(txn, parentId));
|
assertTrue(db.containsMessage(txn, parentId));
|
||||||
assertNull(db.getParent(txn, childId));
|
assertNull(db.getParent(txn, childId));
|
||||||
@@ -826,8 +826,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
Message parent = new TestMessage(parentId, null, group, null,
|
Message parent = new TestMessage(parentId, null, group, null,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, child, false);
|
db.addMessage(txn, child, true);
|
||||||
db.addMessage(txn, parent, false);
|
db.addMessage(txn, parent, true);
|
||||||
assertTrue(db.containsMessage(txn, childId));
|
assertTrue(db.containsMessage(txn, childId));
|
||||||
assertTrue(db.containsMessage(txn, parentId));
|
assertTrue(db.containsMessage(txn, parentId));
|
||||||
assertEquals(parentId, db.getParent(txn, childId));
|
assertEquals(parentId, db.getParent(txn, childId));
|
||||||
@@ -853,8 +853,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message1 = new TestMessage(messageId1, null, group, null,
|
Message message1 = new TestMessage(messageId1, null, group, null,
|
||||||
contentType, subject, timestamp, raw, 10, bodyLength);
|
contentType, subject, timestamp, raw, 10, bodyLength);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
|
|
||||||
// Calculate the expected message bodies
|
// Calculate the expected message bodies
|
||||||
byte[] expectedBody = new byte[bodyLength];
|
byte[] expectedBody = new byte[bodyLength];
|
||||||
@@ -887,13 +887,13 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
|
|
||||||
// Store a couple of messages
|
// Store a couple of messages
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
MessageId parentId = new MessageId(TestUtils.getRandomId());
|
||||||
long timestamp1 = System.currentTimeMillis();
|
long timestamp1 = System.currentTimeMillis();
|
||||||
Message message1 = new TestMessage(messageId1, parentId, group, author,
|
Message message1 = new TestMessage(messageId1, parentId, group, author,
|
||||||
contentType, subject, timestamp1, raw);
|
contentType, subject, timestamp1, raw);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
// Mark one of the messages read
|
// Mark one of the messages read
|
||||||
db.setReadFlag(txn, messageId, true);
|
db.setReadFlag(txn, messageId, true);
|
||||||
|
|
||||||
@@ -944,7 +944,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
|
|
||||||
// Store a message from the contact - status VERIFIED
|
// Store a message from the contact - status VERIFIED
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
AuthorId authorId1 = new AuthorId(TestUtils.getRandomId());
|
AuthorId authorId1 = new AuthorId(TestUtils.getRandomId());
|
||||||
// Store a message from an unknown author - status UNKNOWN
|
// Store a message from an unknown author - status UNKNOWN
|
||||||
Author author1 = new Author(authorId1, "Bob",
|
Author author1 = new Author(authorId1, "Bob",
|
||||||
@@ -952,12 +952,12 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message1 = new TestMessage(messageId1, null, group, author1,
|
Message message1 = new TestMessage(messageId1, null, group, author1,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
// Store an anonymous message - status ANONYMOUS
|
// Store an anonymous message - status ANONYMOUS
|
||||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message2 = new TestMessage(messageId2, null, group, null,
|
Message message2 = new TestMessage(messageId2, null, group, null,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, message2, false);
|
db.addMessage(txn, message2, true);
|
||||||
|
|
||||||
// Retrieve the message headers (order is undefined)
|
// Retrieve the message headers (order is undefined)
|
||||||
Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
|
Collection<MessageHeader> headers = db.getMessageHeaders(txn, groupId);
|
||||||
@@ -996,7 +996,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Subscribe to a group and store a message
|
// Subscribe to a group and store a message
|
||||||
db.addGroup(txn, group);
|
db.addGroup(txn, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
|
|
||||||
// The message should be unread by default
|
// The message should be unread by default
|
||||||
assertFalse(db.getReadFlag(txn, messageId));
|
assertFalse(db.getReadFlag(txn, messageId));
|
||||||
@@ -1026,17 +1026,17 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addGroup(txn, group1);
|
db.addGroup(txn, group1);
|
||||||
|
|
||||||
// Store two messages in the first group
|
// Store two messages in the first group
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId1 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message1 = new TestMessage(messageId1, null, group, author,
|
Message message1 = new TestMessage(messageId1, null, group, author,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, message1, false);
|
db.addMessage(txn, message1, true);
|
||||||
|
|
||||||
// Store one message in the second group
|
// Store one message in the second group
|
||||||
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||||
Message message2 = new TestMessage(messageId2, null, group1, author,
|
Message message2 = new TestMessage(messageId2, null, group1, author,
|
||||||
contentType, subject, timestamp, raw);
|
contentType, subject, timestamp, raw);
|
||||||
db.addMessage(txn, message2, false);
|
db.addMessage(txn, message2, true);
|
||||||
|
|
||||||
// Mark one of the messages in the first group read
|
// Mark one of the messages in the first group read
|
||||||
db.setReadFlag(txn, messageId, true);
|
db.setReadFlag(txn, messageId, true);
|
||||||
@@ -1531,7 +1531,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.getInboxMessageHeaders(txn, contactId));
|
db.getInboxMessageHeaders(txn, contactId));
|
||||||
|
|
||||||
// Add a message to the inbox group - the header should be returned
|
// Add a message to the inbox group - the header should be returned
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, true);
|
||||||
Collection<MessageHeader> headers =
|
Collection<MessageHeader> headers =
|
||||||
db.getInboxMessageHeaders(txn, contactId);
|
db.getInboxMessageHeaders(txn, contactId);
|
||||||
assertEquals(1, headers.size());
|
assertEquals(1, headers.size());
|
||||||
|
|||||||
Reference in New Issue
Block a user