mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Add a new event that is broadcasted when a contact is verified
Also, don't support unverifying contacts.
This commit is contained in:
@@ -424,10 +424,9 @@ public interface DatabaseComponent {
|
|||||||
void removeTransport(Transaction txn, TransportId t) throws DbException;
|
void removeTransport(Transaction txn, TransportId t) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as verified or unverified.
|
* Marks the given contact as verified.
|
||||||
*/
|
*/
|
||||||
void setContactVerified(Transaction txn, ContactId c, boolean verified)
|
void setContactVerified(Transaction txn, ContactId c) throws DbException;
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as active or inactive.
|
* Marks the given contact as active or inactive.
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.briarproject.api.event;
|
||||||
|
|
||||||
|
import org.briarproject.api.contact.ContactId;
|
||||||
|
|
||||||
|
/** An event that is broadcast when a contact is verified. */
|
||||||
|
public class ContactVerifiedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
|
||||||
|
public ContactVerifiedEvent(ContactId contactId) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -576,10 +576,9 @@ interface Database<T> {
|
|||||||
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
void resetExpiryTime(T txn, ContactId c, MessageId m) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as verified or unverified.
|
* Marks the given contact as verified.
|
||||||
*/
|
*/
|
||||||
void setContactVerified(T txn, ContactId c, boolean verified)
|
void setContactVerified(T txn, ContactId c) throws DbException;
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the given contact as active or inactive.
|
* Marks the given contact as active or inactive.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.briarproject.api.db.Transaction;
|
|||||||
import org.briarproject.api.event.ContactAddedEvent;
|
import org.briarproject.api.event.ContactAddedEvent;
|
||||||
import org.briarproject.api.event.ContactRemovedEvent;
|
import org.briarproject.api.event.ContactRemovedEvent;
|
||||||
import org.briarproject.api.event.ContactStatusChangedEvent;
|
import org.briarproject.api.event.ContactStatusChangedEvent;
|
||||||
|
import org.briarproject.api.event.ContactVerifiedEvent;
|
||||||
import org.briarproject.api.event.Event;
|
import org.briarproject.api.event.Event;
|
||||||
import org.briarproject.api.event.EventBus;
|
import org.briarproject.api.event.EventBus;
|
||||||
import org.briarproject.api.event.GroupAddedEvent;
|
import org.briarproject.api.event.GroupAddedEvent;
|
||||||
@@ -683,14 +684,14 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
db.removeTransport(txn, t);
|
db.removeTransport(txn, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactVerified(Transaction transaction, ContactId c,
|
public void setContactVerified(Transaction transaction, ContactId c)
|
||||||
boolean verified) throws DbException {
|
throws DbException {
|
||||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||||
T txn = unbox(transaction);
|
T txn = unbox(transaction);
|
||||||
if (!db.containsContact(txn, c))
|
if (!db.containsContact(txn, c))
|
||||||
throw new NoSuchContactException();
|
throw new NoSuchContactException();
|
||||||
db.setContactVerified(txn, c, verified);
|
db.setContactVerified(txn, c);
|
||||||
transaction.attach(new ContactStatusChangedEvent(c, verified));
|
transaction.attach(new ContactVerifiedEvent(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactActive(Transaction transaction, ContactId c,
|
public void setContactActive(Transaction transaction, ContactId c,
|
||||||
|
|||||||
@@ -2249,13 +2249,13 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContactVerified(Connection txn, ContactId c,
|
public void setContactVerified(Connection txn, ContactId c)
|
||||||
boolean verified) throws DbException {
|
throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
try {
|
try {
|
||||||
String sql = "UPDATE contacts SET verified = ? WHERE contactId = ?";
|
String sql = "UPDATE contacts SET verified = ? WHERE contactId = ?";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBoolean(1, verified);
|
ps.setBoolean(1, true);
|
||||||
ps.setInt(2, c.getInt());
|
ps.setInt(2, c.getInt());
|
||||||
int affected = ps.executeUpdate();
|
int affected = ps.executeUpdate();
|
||||||
if (affected < 0 || affected > 1) throw new DbStateException();
|
if (affected < 0 || affected > 1) throw new DbStateException();
|
||||||
|
|||||||
Reference in New Issue
Block a user