mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Only allow one private group (the inbox) to be shared with each contact.
This commit is contained in:
@@ -208,8 +208,8 @@ SelectContactsDialog.Listener {
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if(subscribe) {
|
if(subscribe) {
|
||||||
if(!wasSubscribed) db.addGroup(group);
|
if(!wasSubscribed) db.addGroup(group);
|
||||||
db.setVisibleToAll(group.getId(), all);
|
db.setVisibleToAll(group, all);
|
||||||
if(!all) db.setVisibility(group.getId(), visible);
|
if(!all) db.setVisibility(group, visible);
|
||||||
} else if(wasSubscribed) {
|
} else if(wasSubscribed) {
|
||||||
db.removeGroup(group);
|
db.removeGroup(group);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ SelectContactsDialog.Listener {
|
|||||||
Group g = groupFactory.createGroup(name, false);
|
Group g = groupFactory.createGroup(name, false);
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
if(all) db.setVisibleToAll(g.getId(), true);
|
if(all) db.setVisibleToAll(g, true);
|
||||||
else db.setVisibility(g.getId(), visible);
|
else db.setVisibility(g, visible);
|
||||||
long duration = System.currentTimeMillis() - now;
|
long duration = System.currentTimeMillis() - now;
|
||||||
if(LOG.isLoggable(INFO))
|
if(LOG.isLoggable(INFO))
|
||||||
LOG.info("Storing group took " + duration + " ms");
|
LOG.info("Storing group took " + duration + " ms");
|
||||||
|
|||||||
@@ -348,16 +348,15 @@ public interface DatabaseComponent {
|
|||||||
void setSeen(ContactId c, Collection<MessageId> seen) throws DbException;
|
void setSeen(ContactId c, Collection<MessageId> seen) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group visible to the given set of contacts and invisible
|
* Makes a public group visible to the given set of contacts and invisible
|
||||||
* to any other current or future contacts.
|
* to any other current or future contacts.
|
||||||
*/
|
*/
|
||||||
void setVisibility(GroupId g, Collection<ContactId> visible)
|
void setVisibility(Group g, Collection<ContactId> visible)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group visible or invisible to future contacts by default.
|
* Makes a public group visible to all current and future contacts, or
|
||||||
* If <tt>visible</tt> is true, the group is also made visible to all
|
* invisible to future contacts.
|
||||||
* current contacts.
|
|
||||||
*/
|
*/
|
||||||
void setVisibleToAll(GroupId g, boolean all) throws DbException;
|
void setVisibleToAll(Group g, boolean all) throws DbException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,11 +152,11 @@ interface Database<T> {
|
|||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group visible to the given contact.
|
* Makes a public group visible to the given contact.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: subscription write.
|
* Locking: subscription write.
|
||||||
*/
|
*/
|
||||||
void addVisibility(T txn, ContactId c, GroupId g) throws DbException;
|
void addVisibility(T txn, ContactId c, Group g) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the database contains the given contact.
|
* Returns true if the database contains the given contact.
|
||||||
@@ -616,11 +616,11 @@ interface Database<T> {
|
|||||||
void removeTransport(T txn, TransportId t) throws DbException;
|
void removeTransport(T txn, TransportId t) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group invisible to the given contact.
|
* Makes a public group invisible to the given contact.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: subscription write.
|
* Locking: subscription write.
|
||||||
*/
|
*/
|
||||||
void removeVisibility(T txn, ContactId c, GroupId g) throws DbException;
|
void removeVisibility(T txn, ContactId c, Group g) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the connection reordering window for the given endpoint in the
|
* Sets the connection reordering window for the given endpoint in the
|
||||||
@@ -732,11 +732,11 @@ interface Database<T> {
|
|||||||
long version) throws DbException;
|
long version) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes the given group visible or invisible to future contacts by default.
|
* Makes a public group visible or invisible to future contacts by default.
|
||||||
* <p>
|
* <p>
|
||||||
* Locking: subscription write.
|
* Locking: subscription write.
|
||||||
*/
|
*/
|
||||||
void setVisibleToAll(T txn, GroupId g, boolean all) throws DbException;
|
void setVisibleToAll(T txn, Group g, boolean all) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the expiry times of the given messages with respect to the given
|
* Updates the expiry times of the given messages with respect to the given
|
||||||
|
|||||||
@@ -1871,8 +1871,9 @@ DatabaseCleaner.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibility(GroupId g, Collection<ContactId> visible)
|
public void setVisibility(Group g, Collection<ContactId> visible)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
if(g.isPrivate()) throw new IllegalArgumentException();
|
||||||
Collection<ContactId> affected = new ArrayList<ContactId>();
|
Collection<ContactId> affected = new ArrayList<ContactId>();
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -1880,11 +1881,12 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
if(!db.containsGroup(txn, g))
|
if(!db.containsGroup(txn, g.getId()))
|
||||||
throw new NoSuchSubscriptionException();
|
throw new NoSuchSubscriptionException();
|
||||||
// Use HashSets for O(1) lookups, O(n) overall running time
|
// Use HashSets for O(1) lookups, O(n) overall running time
|
||||||
HashSet<ContactId> now = new HashSet<ContactId>(visible);
|
HashSet<ContactId> now = new HashSet<ContactId>(visible);
|
||||||
Collection<ContactId> before = db.getVisibility(txn, g);
|
Collection<ContactId> before =
|
||||||
|
db.getVisibility(txn, g.getId());
|
||||||
before = new HashSet<ContactId>(before);
|
before = new HashSet<ContactId>(before);
|
||||||
// Set the group's visibility for each current contact
|
// Set the group's visibility for each current contact
|
||||||
for(ContactId c : db.getContactIds(txn)) {
|
for(ContactId c : db.getContactIds(txn)) {
|
||||||
@@ -1915,7 +1917,8 @@ DatabaseCleaner.Callback {
|
|||||||
callListeners(new LocalSubscriptionsUpdatedEvent(affected));
|
callListeners(new LocalSubscriptionsUpdatedEvent(affected));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibleToAll(GroupId g, boolean all) throws DbException {
|
public void setVisibleToAll(Group g, boolean all) throws DbException {
|
||||||
|
if(g.isPrivate()) throw new IllegalArgumentException();
|
||||||
Collection<ContactId> affected = new ArrayList<ContactId>();
|
Collection<ContactId> affected = new ArrayList<ContactId>();
|
||||||
contactLock.readLock().lock();
|
contactLock.readLock().lock();
|
||||||
try {
|
try {
|
||||||
@@ -1923,13 +1926,14 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
if(!db.containsGroup(txn, g))
|
if(!db.containsGroup(txn, g.getId()))
|
||||||
throw new NoSuchSubscriptionException();
|
throw new NoSuchSubscriptionException();
|
||||||
// Make the group visible or invisible to future contacts
|
// Make the group visible or invisible to future contacts
|
||||||
db.setVisibleToAll(txn, g, all);
|
db.setVisibleToAll(txn, g, all);
|
||||||
if(all) {
|
if(all) {
|
||||||
// Make the group visible to all current contacts
|
// Make the group visible to all current contacts
|
||||||
Collection<ContactId> before = db.getVisibility(txn, g);
|
Collection<ContactId> before =
|
||||||
|
db.getVisibility(txn, g.getId());
|
||||||
before = new HashSet<ContactId>(before);
|
before = new HashSet<ContactId>(before);
|
||||||
for(ContactId c : db.getContactIds(txn)) {
|
for(ContactId c : db.getContactIds(txn)) {
|
||||||
if(!before.contains(c)) {
|
if(!before.contains(c)) {
|
||||||
|
|||||||
@@ -900,8 +900,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addVisibility(Connection txn, ContactId c, GroupId g)
|
public void addVisibility(Connection txn, ContactId c, Group g)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
if(g.isPrivate()) throw new IllegalArgumentException();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "INSERT INTO groupVisibilities"
|
String sql = "INSERT INTO groupVisibilities"
|
||||||
@@ -909,7 +910,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
+ " VALUES (?, ?, FALSE)";
|
+ " VALUES (?, ?, FALSE)";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setBytes(2, g.getBytes());
|
ps.setBytes(2, g.getId().getBytes());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -2633,15 +2634,16 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeVisibility(Connection txn, ContactId c, GroupId g)
|
public void removeVisibility(Connection txn, ContactId c, Group g)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
if(g.isPrivate()) throw new IllegalArgumentException();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "DELETE FROM groupVisibilities"
|
String sql = "DELETE FROM groupVisibilities"
|
||||||
+ " WHERE contactId = ? AND groupId = ?";
|
+ " WHERE contactId = ? AND groupId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setInt(1, c.getInt());
|
ps.setInt(1, c.getInt());
|
||||||
ps.setBytes(2, g.getBytes());
|
ps.setBytes(2, g.getId().getBytes());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected != 1) throw new DbStateException();
|
if(affected != 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
@@ -3074,14 +3076,15 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibleToAll(Connection txn, GroupId g, boolean all)
|
public void setVisibleToAll(Connection txn, Group g, boolean all)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
if(g.isPrivate()) throw new IllegalArgumentException();
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE groups SET visibleToAll = ? WHERE groupId = ?";
|
String sql = "UPDATE groups SET visibleToAll = ? WHERE groupId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBoolean(1, all);
|
ps.setBoolean(1, all);
|
||||||
ps.setBytes(2, g.getBytes());
|
ps.setBytes(2, g.getId().getBytes());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if(affected > 1) throw new DbStateException();
|
if(affected > 1) throw new DbStateException();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
|
|
||||||
public DatabaseComponentTest() {
|
public DatabaseComponentTest() {
|
||||||
groupId = new GroupId(TestUtils.getRandomId());
|
groupId = new GroupId(TestUtils.getRandomId());
|
||||||
group = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH], true);
|
group = new Group(groupId, "Group", new byte[GROUP_SALT_LENGTH], false);
|
||||||
authorId = new AuthorId(TestUtils.getRandomId());
|
authorId = new AuthorId(TestUtils.getRandomId());
|
||||||
author = new Author(authorId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]);
|
author = new Author(authorId, "Alice", new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||||
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
localAuthorId = new AuthorId(TestUtils.getRandomId());
|
||||||
@@ -465,7 +465,9 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setInboxGroup(contactId, group);
|
Group privateGroup = new Group(groupId, "Group",
|
||||||
|
new byte[GROUP_SALT_LENGTH], true);
|
||||||
|
db.setInboxGroup(contactId, privateGroup);
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchContactException expected) {}
|
} catch(NoSuchContactException expected) {}
|
||||||
|
|
||||||
@@ -557,7 +559,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
} catch(NoSuchSubscriptionException expected) {}
|
} catch(NoSuchSubscriptionException expected) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setVisibility(groupId, Collections.<ContactId>emptyList());
|
db.setVisibility(group, Collections.<ContactId>emptyList());
|
||||||
fail();
|
fail();
|
||||||
} catch(NoSuchSubscriptionException expected) {}
|
} catch(NoSuchSubscriptionException expected) {}
|
||||||
|
|
||||||
@@ -1337,8 +1339,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).getContactIds(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).removeVisibility(txn, contactId1, groupId);
|
oneOf(database).removeVisibility(txn, contactId1, group);
|
||||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
oneOf(database).setVisibleToAll(txn, group, false);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(listener).eventOccurred(with(any(
|
oneOf(listener).eventOccurred(with(any(
|
||||||
LocalSubscriptionsUpdatedEvent.class)));
|
LocalSubscriptionsUpdatedEvent.class)));
|
||||||
@@ -1347,7 +1349,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setVisibility(groupId, Arrays.asList(contactId));
|
db.setVisibility(group, Arrays.asList(contactId));
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1372,14 +1374,14 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).getContactIds(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
oneOf(database).setVisibleToAll(txn, group, false);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
DatabaseComponent db = createDatabaseComponent(database, cleaner,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setVisibility(groupId, both);
|
db.setVisibility(group, both);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1405,8 +1407,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(Collections.emptyList()));
|
will(returnValue(Collections.emptyList()));
|
||||||
oneOf(database).getContactIds(txn);
|
oneOf(database).getContactIds(txn);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).addVisibility(txn, contactId, groupId);
|
oneOf(database).addVisibility(txn, contactId, group);
|
||||||
oneOf(database).setVisibleToAll(txn, groupId, false);
|
oneOf(database).setVisibleToAll(txn, group, false);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(listener).eventOccurred(with(any(
|
oneOf(listener).eventOccurred(with(any(
|
||||||
LocalSubscriptionsUpdatedEvent.class)));
|
LocalSubscriptionsUpdatedEvent.class)));
|
||||||
@@ -1415,12 +1417,12 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
oneOf(database).containsGroup(txn, groupId);
|
oneOf(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).setVisibleToAll(txn, groupId, true);
|
oneOf(database).setVisibleToAll(txn, group, true);
|
||||||
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);
|
||||||
will(returnValue(both));
|
will(returnValue(both));
|
||||||
oneOf(database).addVisibility(txn, contactId1, groupId);
|
oneOf(database).addVisibility(txn, contactId1, group);
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(listener).eventOccurred(with(any(
|
oneOf(listener).eventOccurred(with(any(
|
||||||
LocalSubscriptionsUpdatedEvent.class)));
|
LocalSubscriptionsUpdatedEvent.class)));
|
||||||
@@ -1429,8 +1431,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
|
|||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
db.addListener(listener);
|
db.addListener(listener);
|
||||||
db.setVisibility(groupId, Arrays.asList(contactId));
|
db.setVisibility(group, Arrays.asList(contactId));
|
||||||
db.setVisibleToAll(groupId, true);
|
db.setVisibleToAll(group, true);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, false);
|
||||||
db.addStatus(txn, contactId, messageId, false);
|
db.addStatus(txn, contactId, messageId, false);
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
db.addStatus(txn, contactId, messageId, false);
|
db.addStatus(txn, contactId, messageId, false);
|
||||||
@@ -283,7 +283,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertFalse(it.hasNext());
|
assertFalse(it.hasNext());
|
||||||
|
|
||||||
// Making the subscription visible should make the message sendable
|
// Making the subscription visible should make the message sendable
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, group);
|
||||||
assertTrue(db.containsSendableMessages(txn, contactId));
|
assertTrue(db.containsSendableMessages(txn, contactId));
|
||||||
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
it = db.getSendableMessages(txn, contactId, ONE_MEGABYTE).iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
@@ -356,7 +356,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
db.addStatus(txn, contactId, messageId, false);
|
db.addStatus(txn, contactId, messageId, false);
|
||||||
@@ -654,7 +654,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, group);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// The message is not in the database
|
// The message is not in the database
|
||||||
@@ -673,7 +673,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
|
|
||||||
@@ -697,7 +697,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, group);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
db.setRetentionTime(txn, contactId, timestamp + 1, 1);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, false);
|
||||||
@@ -721,7 +721,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
|
|
||||||
@@ -746,7 +746,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, group);
|
||||||
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
db.setGroups(txn, contactId, Arrays.asList(group), 1);
|
||||||
|
|
||||||
// The message is not in the database
|
// The message is not in the database
|
||||||
@@ -784,7 +784,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, group);
|
||||||
db.addMessage(txn, message, false);
|
db.addMessage(txn, message, false);
|
||||||
db.addStatus(txn, contactId, messageId, false);
|
db.addStatus(txn, contactId, messageId, false);
|
||||||
|
|
||||||
@@ -826,7 +826,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
|
|
||||||
@@ -849,7 +849,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
db.addLocalAuthor(txn, localAuthor);
|
db.addLocalAuthor(txn, localAuthor);
|
||||||
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, 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, false);
|
||||||
|
|
||||||
@@ -876,11 +876,11 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||||
|
|
||||||
// Make the group visible to the contact
|
// Make the group visible to the contact
|
||||||
db.addVisibility(txn, contactId, groupId);
|
db.addVisibility(txn, contactId, group);
|
||||||
assertEquals(Arrays.asList(contactId), db.getVisibility(txn, groupId));
|
assertEquals(Arrays.asList(contactId), db.getVisibility(txn, groupId));
|
||||||
|
|
||||||
// Make the group invisible again
|
// Make the group invisible again
|
||||||
db.removeVisibility(txn, contactId, groupId);
|
db.removeVisibility(txn, contactId, group);
|
||||||
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
assertEquals(Collections.emptyList(), db.getVisibility(txn, groupId));
|
||||||
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
@@ -1201,13 +1201,12 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Make the groups visible to the contact
|
// Make the groups visible to the contact
|
||||||
Collections.shuffle(groups);
|
Collections.shuffle(groups);
|
||||||
for(Group g : groups) db.addVisibility(txn, contactId, g.getId());
|
for(Group g : groups) db.addVisibility(txn, contactId, g);
|
||||||
|
|
||||||
// Make some of the groups invisible to the contact and remove them all
|
// Make some of the groups invisible to the contact and remove them all
|
||||||
Collections.shuffle(groups);
|
Collections.shuffle(groups);
|
||||||
for(Group g : groups) {
|
for(Group g : groups) {
|
||||||
if(Math.random() < 0.5)
|
if(Math.random() < 0.5) db.removeVisibility(txn, contactId, g);
|
||||||
db.removeVisibility(txn, contactId, g.getId());
|
|
||||||
db.removeGroup(txn, g.getId());
|
db.removeGroup(txn, g.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1572,7 +1571,7 @@ public class H2DatabaseTest extends BriarTestCase {
|
|||||||
|
|
||||||
// Make the group visible to all contacts - it should be available,
|
// Make the group visible to all contacts - it should be available,
|
||||||
// subscribed, visible to all
|
// subscribed, visible to all
|
||||||
db.setVisibleToAll(txn, groupId, true);
|
db.setVisibleToAll(txn, group, true);
|
||||||
assertEquals(Arrays.asList(group), db.getGroups(txn));
|
assertEquals(Arrays.asList(group), db.getGroups(txn));
|
||||||
it = db.getAvailableGroups(txn).iterator();
|
it = db.getAvailableGroups(txn).iterator();
|
||||||
assertTrue(it.hasNext());
|
assertTrue(it.hasNext());
|
||||||
|
|||||||
Reference in New Issue
Block a user