mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Added active flag to contacts.
This commit is contained in:
@@ -125,7 +125,7 @@ public class ContactListFragment extends BaseEventFragment {
|
||||
long now = System.currentTimeMillis();
|
||||
List<ContactListItem> contacts =
|
||||
new ArrayList<ContactListItem>();
|
||||
for (Contact c : contactManager.getContacts()) {
|
||||
for (Contact c : contactManager.getActiveContacts()) {
|
||||
try {
|
||||
ContactId id = c.getId();
|
||||
GroupId groupId =
|
||||
|
||||
@@ -138,7 +138,7 @@ SelectContactsDialog.Listener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
contacts = contactManager.getContacts();
|
||||
contacts = contactManager.getActiveContacts();
|
||||
selected = forumSharingManager.getSharedWith(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if (LOG.isLoggable(INFO))
|
||||
|
||||
@@ -8,11 +8,14 @@ public class Contact {
|
||||
private final ContactId id;
|
||||
private final Author author;
|
||||
private final AuthorId localAuthorId;
|
||||
private final boolean active;
|
||||
|
||||
public Contact(ContactId id, Author author, AuthorId localAuthorId) {
|
||||
public Contact(ContactId id, Author author, AuthorId localAuthorId,
|
||||
boolean active) {
|
||||
this.id = id;
|
||||
this.author = author;
|
||||
this.localAuthorId = localAuthorId;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public ContactId getId() {
|
||||
@@ -27,6 +30,10 @@ public class Contact {
|
||||
return localAuthorId;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
|
||||
@@ -19,17 +19,21 @@ public interface ContactManager {
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* and returns an ID for the contact.
|
||||
*/
|
||||
ContactId addContact(Author remote, AuthorId local) throws DbException;
|
||||
ContactId addContact(Author remote, AuthorId local, boolean active)
|
||||
throws DbException;
|
||||
|
||||
/** Returns the contact with the given ID. */
|
||||
Contact getContact(ContactId c) throws DbException;
|
||||
|
||||
/** Returns all contacts. */
|
||||
Collection<Contact> getContacts() throws DbException;
|
||||
/** Returns all active contacts. */
|
||||
Collection<Contact> getActiveContacts() throws DbException;
|
||||
|
||||
/** Removes a contact and all associated state. */
|
||||
void removeContact(ContactId c) throws DbException;
|
||||
|
||||
/** Marks a contact as active or inactive. */
|
||||
void setContactActive(ContactId c, boolean active) throws DbException;
|
||||
|
||||
interface AddContactHook {
|
||||
void addingContact(Transaction txn, Contact c) throws DbException;
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ public interface DatabaseComponent {
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* and returns an ID for the contact.
|
||||
*/
|
||||
ContactId addContact(Transaction txn, Author remote, AuthorId local)
|
||||
throws DbException;
|
||||
ContactId addContact(Transaction txn, Author remote, AuthorId local,
|
||||
boolean active) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a group.
|
||||
@@ -317,6 +317,12 @@ public interface DatabaseComponent {
|
||||
*/
|
||||
void removeTransport(Transaction txn, TransportId t) throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given contact as active or inactive.
|
||||
*/
|
||||
void setContactActive(Transaction txn, ContactId c, boolean active)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given message as shared or unshared.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.briarproject.api.event;
|
||||
|
||||
import org.briarproject.api.contact.ContactId;
|
||||
|
||||
/** An event that is broadcast when a contact is marked active or inactive. */
|
||||
public class ContactStatusChangedEvent extends Event {
|
||||
|
||||
private final ContactId contactId;
|
||||
private final boolean active;
|
||||
|
||||
public ContactStatusChangedEvent(ContactId contactId, boolean active) {
|
||||
this.contactId = contactId;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public ContactId getContactId() {
|
||||
return contactId;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,9 @@ import org.briarproject.api.identity.AuthorId;
|
||||
import org.briarproject.api.identity.IdentityManager.RemoveIdentityHook;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -41,12 +43,12 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Author remote, AuthorId local)
|
||||
public ContactId addContact(Author remote, AuthorId local, boolean active)
|
||||
throws DbException {
|
||||
ContactId c;
|
||||
Transaction txn = db.startTransaction();
|
||||
try {
|
||||
c = db.addContact(txn, remote, local);
|
||||
c = db.addContact(txn, remote, local, active);
|
||||
Contact contact = db.getContact(txn, c);
|
||||
for (AddContactHook hook : addHooks)
|
||||
hook.addingContact(txn, contact);
|
||||
@@ -71,7 +73,7 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Contact> getContacts() throws DbException {
|
||||
public Collection<Contact> getActiveContacts() throws DbException {
|
||||
Collection<Contact> contacts;
|
||||
Transaction txn = db.startTransaction();
|
||||
try {
|
||||
@@ -80,7 +82,9 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return contacts;
|
||||
List<Contact> active = new ArrayList<Contact>(contacts.size());
|
||||
for (Contact c : contacts) if (c.isActive()) active.add(c);
|
||||
return Collections.unmodifiableList(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +98,18 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContactActive(ContactId c, boolean active)
|
||||
throws DbException {
|
||||
Transaction txn = db.startTransaction();
|
||||
try {
|
||||
db.setContactActive(txn, c, active);
|
||||
txn.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeContact(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
|
||||
@@ -64,7 +64,7 @@ interface Database<T> {
|
||||
* Stores a contact associated with the given local and remote pseudonyms,
|
||||
* and returns an ID for the contact.
|
||||
*/
|
||||
ContactId addContact(T txn, Author remote, AuthorId local)
|
||||
ContactId addContact(T txn, Author remote, AuthorId local, boolean active)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
@@ -446,6 +446,12 @@ interface Database<T> {
|
||||
*/
|
||||
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given contact as active or inactive.
|
||||
*/
|
||||
void setContactActive(T txn, ContactId c, boolean active)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Marks the given message as shared or unshared.
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.briarproject.api.db.NoSuchTransportException;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.event.ContactAddedEvent;
|
||||
import org.briarproject.api.event.ContactRemovedEvent;
|
||||
import org.briarproject.api.event.ContactStatusChangedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.GroupAddedEvent;
|
||||
@@ -136,13 +137,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
}
|
||||
|
||||
public ContactId addContact(Transaction transaction, Author remote,
|
||||
AuthorId local) throws DbException {
|
||||
AuthorId local, boolean active) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsLocalAuthor(txn, local))
|
||||
throw new NoSuchLocalAuthorException();
|
||||
if (db.containsContact(txn, remote.getId(), local))
|
||||
throw new ContactExistsException();
|
||||
ContactId c = db.addContact(txn, remote, local);
|
||||
ContactId c = db.addContact(txn, remote, local, active);
|
||||
transaction.attach(new ContactAddedEvent(c));
|
||||
return c;
|
||||
}
|
||||
@@ -580,6 +581,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
transaction.attach(new TransportRemovedEvent(t));
|
||||
}
|
||||
|
||||
public void setContactActive(Transaction transaction, ContactId c,
|
||||
boolean active) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsContact(txn, c))
|
||||
throw new NoSuchContactException();
|
||||
db.setContactActive(txn, c, active);
|
||||
transaction.attach(new ContactStatusChangedEvent(c, active));
|
||||
}
|
||||
|
||||
public void setMessageShared(Transaction transaction, Message m,
|
||||
boolean shared) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
|
||||
@@ -89,6 +89,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " name VARCHAR NOT NULL,"
|
||||
+ " publicKey BINARY NOT NULL,"
|
||||
+ " localAuthorId HASH NOT NULL,"
|
||||
+ " active BOOLEAN NOT NULL,"
|
||||
+ " PRIMARY KEY (contactId),"
|
||||
+ " FOREIGN KEY (localAuthorId)"
|
||||
+ " REFERENCES localAuthors (authorId)"
|
||||
@@ -441,20 +442,21 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
return new DeviceId(StringUtils.fromHexString(s.get(DEVICE_ID_KEY)));
|
||||
}
|
||||
|
||||
public ContactId addContact(Connection txn, Author remote, AuthorId local)
|
||||
throws DbException {
|
||||
public ContactId addContact(Connection txn, Author remote, AuthorId local,
|
||||
boolean active) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
// Create a contact row
|
||||
String sql = "INSERT INTO contacts"
|
||||
+ " (authorId, name, publicKey, localAuthorId)"
|
||||
+ " VALUES (?, ?, ?, ?)";
|
||||
+ " (authorId, name, publicKey, localAuthorId, active)"
|
||||
+ " VALUES (?, ?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, remote.getId().getBytes());
|
||||
ps.setString(2, remote.getName());
|
||||
ps.setBytes(3, remote.getPublicKey());
|
||||
ps.setBytes(4, local.getBytes());
|
||||
ps.setBoolean(5, active);
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected != 1) throw new DbStateException();
|
||||
ps.close();
|
||||
@@ -926,7 +928,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT authorId, name, publicKey, localAuthorId"
|
||||
String sql = "SELECT authorId, name, publicKey,"
|
||||
+ " localAuthorId, active"
|
||||
+ " FROM contacts"
|
||||
+ " WHERE contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
@@ -937,10 +940,11 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String name = rs.getString(2);
|
||||
byte[] publicKey = rs.getBytes(3);
|
||||
AuthorId localAuthorId = new AuthorId(rs.getBytes(4));
|
||||
boolean active = rs.getBoolean(5);
|
||||
rs.close();
|
||||
ps.close();
|
||||
Author author = new Author(authorId, name, publicKey);
|
||||
return new Contact(c, author, localAuthorId);
|
||||
return new Contact(c, author, localAuthorId, active);
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs);
|
||||
tryToClose(ps);
|
||||
@@ -954,7 +958,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT contactId, authorId, name, publicKey,"
|
||||
+ " localAuthorId"
|
||||
+ " localAuthorId, active"
|
||||
+ " FROM contacts";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
@@ -966,7 +970,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
byte[] publicKey = rs.getBytes(4);
|
||||
Author author = new Author(authorId, name, publicKey);
|
||||
AuthorId localAuthorId = new AuthorId(rs.getBytes(5));
|
||||
contacts.add(new Contact(contactId, author, localAuthorId));
|
||||
boolean active = rs.getBoolean(6);
|
||||
contacts.add(new Contact(contactId, author, localAuthorId,
|
||||
active));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -2013,6 +2019,23 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
public void setContactActive(Connection txn, ContactId c, boolean active)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "UPDATE contacts SET active = ? WHERE contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBoolean(1, active);
|
||||
ps.setInt(2, c.getInt());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(ps);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessageShared(Connection txn, MessageId m, boolean shared)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
@@ -2022,7 +2045,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setBoolean(1, shared);
|
||||
ps.setBytes(2, m.getBytes());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected < 0) throw new DbStateException();
|
||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(ps);
|
||||
@@ -2039,7 +2062,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, valid ? VALID.getValue() : INVALID.getValue());
|
||||
ps.setBytes(2, m.getBytes());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected < 0) throw new DbStateException();
|
||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
tryToClose(ps);
|
||||
|
||||
@@ -219,7 +219,7 @@ abstract class Connector extends Thread {
|
||||
long timestamp, boolean alice) throws DbException {
|
||||
// Add the contact to the database
|
||||
contactId = contactManager.addContact(remoteAuthor,
|
||||
localAuthor.getId());
|
||||
localAuthor.getId(), true);
|
||||
// Derive transport keys
|
||||
keyManager.addContact(contactId, master, timestamp, alice);
|
||||
return contactId;
|
||||
|
||||
@@ -107,7 +107,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
transportId = new TransportId("id");
|
||||
maxLatency = Integer.MAX_VALUE;
|
||||
contactId = new ContactId(234);
|
||||
contact = new Contact(contactId, author, localAuthorId);
|
||||
contact = new Contact(contactId, author, localAuthorId, true);
|
||||
}
|
||||
|
||||
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
||||
@@ -143,7 +143,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsContact(txn, authorId, localAuthorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addContact(txn, author, localAuthorId);
|
||||
oneOf(database).addContact(txn, author, localAuthorId, true);
|
||||
will(returnValue(contactId));
|
||||
oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
|
||||
// getContacts()
|
||||
@@ -193,7 +193,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
try {
|
||||
db.addLocalAuthor(transaction, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(transaction, author, localAuthorId));
|
||||
db.addContact(transaction, author, localAuthorId, true));
|
||||
assertEquals(Collections.singletonList(contact),
|
||||
db.getContacts(transaction));
|
||||
db.addGroup(transaction, group); // First time - listeners called
|
||||
@@ -294,11 +294,11 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
final EventBus eventBus = context.mock(EventBus.class);
|
||||
context.checking(new Expectations() {{
|
||||
// Check whether the contact is in the DB (which it's not)
|
||||
exactly(17).of(database).startTransaction();
|
||||
exactly(18).of(database).startTransaction();
|
||||
will(returnValue(txn));
|
||||
exactly(17).of(database).containsContact(txn, contactId);
|
||||
exactly(18).of(database).containsContact(txn, contactId);
|
||||
will(returnValue(false));
|
||||
exactly(17).of(database).abortTransaction(txn);
|
||||
exactly(18).of(database).abortTransaction(txn);
|
||||
}});
|
||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||
shutdown);
|
||||
@@ -456,6 +456,16 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
db.endTransaction(transaction);
|
||||
}
|
||||
|
||||
transaction = db.startTransaction();
|
||||
try {
|
||||
db.setContactActive(transaction, contactId, true);
|
||||
fail();
|
||||
} catch (NoSuchContactException expected) {
|
||||
// Expected
|
||||
} finally {
|
||||
db.endTransaction(transaction);
|
||||
}
|
||||
|
||||
transaction = db.startTransaction();
|
||||
try {
|
||||
db.setReorderingWindow(transaction, contactId, transportId, 0, 0,
|
||||
@@ -501,7 +511,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
|
||||
Transaction transaction = db.startTransaction();
|
||||
try {
|
||||
db.addContact(transaction, author, localAuthorId);
|
||||
db.addContact(transaction, author, localAuthorId, true);
|
||||
fail();
|
||||
} catch (NoSuchLocalAuthorException expected) {
|
||||
// Expected
|
||||
@@ -755,7 +765,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
will(returnValue(true));
|
||||
oneOf(database).containsContact(txn, authorId, localAuthorId);
|
||||
will(returnValue(false));
|
||||
oneOf(database).addContact(txn, author, localAuthorId);
|
||||
oneOf(database).addContact(txn, author, localAuthorId, true);
|
||||
will(returnValue(contactId));
|
||||
oneOf(eventBus).broadcast(with(any(ContactAddedEvent.class)));
|
||||
// endTransaction()
|
||||
@@ -776,7 +786,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
||||
try {
|
||||
db.addLocalAuthor(transaction, localAuthor);
|
||||
assertEquals(contactId,
|
||||
db.addContact(transaction, author, localAuthorId));
|
||||
db.addContact(transaction, author, localAuthorId, true));
|
||||
transaction.setComplete();
|
||||
} finally {
|
||||
db.endTransaction(transaction);
|
||||
|
||||
@@ -108,7 +108,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
Connection txn = db.startTransaction();
|
||||
assertFalse(db.containsContact(txn, contactId));
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
assertTrue(db.containsContact(txn, contactId));
|
||||
assertFalse(db.containsGroup(txn, groupId));
|
||||
db.addGroup(txn, group);
|
||||
@@ -170,7 +171,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, VALID, true);
|
||||
@@ -207,7 +209,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and an unvalidated message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, UNKNOWN, true);
|
||||
@@ -245,7 +248,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and an unshared message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, VALID, false);
|
||||
@@ -283,7 +287,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, VALID, true);
|
||||
@@ -309,7 +314,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact and a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
|
||||
@@ -345,7 +351,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, VALID, true);
|
||||
@@ -508,7 +515,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact and a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
|
||||
@@ -527,7 +535,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
|
||||
// The group is not in the database
|
||||
assertFalse(db.containsVisibleMessage(txn, contactId, messageId));
|
||||
@@ -544,7 +553,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addMessage(txn, message, VALID, true);
|
||||
db.addStatus(txn, contactId, messageId, false, false);
|
||||
@@ -563,7 +573,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact and a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
|
||||
// The group should not be visible to the contact
|
||||
@@ -598,7 +609,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact and the groups
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
for (Group g : groups) db.addGroup(txn, g);
|
||||
|
||||
// Make the groups visible to the contact
|
||||
@@ -630,7 +642,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add the contact, the transport and the transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
db.addTransportKeys(txn, contactId, keys);
|
||||
|
||||
@@ -691,7 +704,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
db.updateTransportKeys(txn, Collections.singletonMap(contactId, keys));
|
||||
|
||||
@@ -726,7 +740,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add the contact, transport and transport keys
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addTransport(txn, transportId, 123);
|
||||
db.updateTransportKeys(txn, Collections.singletonMap(contactId, keys));
|
||||
|
||||
@@ -762,7 +777,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
assertEquals(Collections.emptyList(), contacts);
|
||||
|
||||
// Add a contact associated with the local author
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
contacts = db.getContacts(txn, localAuthorId);
|
||||
assertEquals(Collections.singletonList(contactId), contacts);
|
||||
|
||||
@@ -783,7 +799,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact - initially there should be no offered messages
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
||||
|
||||
// Add some offered messages and count them
|
||||
@@ -921,7 +938,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
|
||||
// Add a group and make it visible to the contact
|
||||
db.addGroup(txn, group);
|
||||
@@ -997,7 +1015,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact and a group
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
|
||||
// The group should not be visible to the contact
|
||||
@@ -1030,8 +1049,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
db.addLocalAuthor(txn, localAuthor1);
|
||||
|
||||
// Add the same contact for each local pseudonym
|
||||
ContactId contactId = db.addContact(txn, author, localAuthorId);
|
||||
ContactId contactId1 = db.addContact(txn, author, localAuthorId1);
|
||||
ContactId contactId = db.addContact(txn, author, localAuthorId, true);
|
||||
ContactId contactId1 = db.addContact(txn, author, localAuthorId1, true);
|
||||
|
||||
// The contacts should be distinct
|
||||
assertNotEquals(contactId, contactId1);
|
||||
@@ -1050,7 +1069,8 @@ public class H2DatabaseTest extends BriarTestCase {
|
||||
|
||||
// Add a contact, a group and a message
|
||||
db.addLocalAuthor(txn, localAuthor);
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId));
|
||||
assertEquals(contactId, db.addContact(txn, author, localAuthorId,
|
||||
true));
|
||||
db.addGroup(txn, group);
|
||||
db.addVisibility(txn, contactId, groupId);
|
||||
db.addMessage(txn, message, VALID, true);
|
||||
|
||||
@@ -134,7 +134,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Add Bob as a contact
|
||||
Author bobAuthor = new Author(bobId, "Bob",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
ContactId contactId = contactManager.addContact(bobAuthor, aliceId);
|
||||
ContactId contactId = contactManager.addContact(bobAuthor, aliceId,
|
||||
true);
|
||||
// Derive and store the transport keys
|
||||
keyManager.addContact(contactId, master, timestamp, true);
|
||||
|
||||
@@ -204,7 +205,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
// Add Alice as a contact
|
||||
Author aliceAuthor = new Author(aliceId, "Alice",
|
||||
new byte[MAX_PUBLIC_KEY_LENGTH]);
|
||||
ContactId contactId = contactManager.addContact(aliceAuthor, bobId);
|
||||
ContactId contactId = contactManager.addContact(aliceAuthor, bobId,
|
||||
true);
|
||||
// Derive and store the transport keys
|
||||
keyManager.addContact(contactId, master, timestamp, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user