mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Allow multiple identities to have the same contact. #224
This commit is contained in:
@@ -155,11 +155,13 @@ interface Database<T> {
|
||||
void addVisibility(T txn, ContactId c, GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact.
|
||||
* Returns true if the database contains the given contact for the given
|
||||
* local pseudonym.
|
||||
* <p>
|
||||
* Locking: read.
|
||||
*/
|
||||
boolean containsContact(T txn, AuthorId a) throws DbException;
|
||||
boolean containsContact(T txn, AuthorId remote, AuthorId local)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if the database contains the given contact.
|
||||
|
||||
@@ -144,10 +144,10 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
try {
|
||||
T txn = db.startTransaction();
|
||||
try {
|
||||
if (db.containsContact(txn, remote.getId()))
|
||||
throw new ContactExistsException();
|
||||
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);
|
||||
db.commitTransaction(txn);
|
||||
return c;
|
||||
|
||||
@@ -871,14 +871,16 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsContact(Connection txn, AuthorId a)
|
||||
throws DbException {
|
||||
public boolean containsContact(Connection txn, AuthorId remote,
|
||||
AuthorId local) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT NULL FROM contacts WHERE authorId = ?";
|
||||
String sql = "SELECT NULL FROM contacts"
|
||||
+ " WHERE authorId = ? AND localAuthorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, a.getBytes());
|
||||
ps.setBytes(1, remote.getBytes());
|
||||
ps.setBytes(2, local.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
boolean found = rs.next();
|
||||
if (rs.next()) throw new DbStateException();
|
||||
|
||||
Reference in New Issue
Block a user