mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Always replace pending contacts no matter their state when link is re-entered
This commit is contained in:
@@ -141,12 +141,6 @@ public interface ContactManager {
|
|||||||
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the state of the given {@link PendingContact}.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
PendingContactState getPendingContactState(PendingContactId p);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a {@link PendingContact}.
|
* Removes a {@link PendingContact}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -172,12 +172,6 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
|||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public PendingContactState getPendingContactState(PendingContactId p) {
|
|
||||||
return states.get(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removePendingContact(PendingContactId p) throws DbException {
|
public void removePendingContact(PendingContactId p) throws DbException {
|
||||||
db.transaction(false, txn -> db.removePendingContact(txn, p));
|
db.transaction(false, txn -> db.removePendingContact(txn, p));
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
|||||||
import org.briarproject.bramble.api.contact.PendingContact;
|
import org.briarproject.bramble.api.contact.PendingContact;
|
||||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.db.NoSuchPendingContactException;
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
import org.briarproject.briar.android.viewmodel.LiveEvent;
|
||||||
import org.briarproject.briar.android.viewmodel.LiveResult;
|
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||||
@@ -26,7 +27,6 @@ import javax.inject.Inject;
|
|||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
import static java.util.logging.Logger.getLogger;
|
import static java.util.logging.Logger.getLogger;
|
||||||
import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX;
|
import static org.briarproject.bramble.api.contact.HandshakeLinkConstants.LINK_REGEX;
|
||||||
import static org.briarproject.bramble.api.contact.PendingContactState.FAILED;
|
|
||||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -122,14 +122,15 @@ public class AddContactViewModel extends AndroidViewModel {
|
|||||||
|
|
||||||
public void updatePendingContact(String name, PendingContact p) {
|
public void updatePendingContact(String name, PendingContact p) {
|
||||||
dbExecutor.execute(() -> {
|
dbExecutor.execute(() -> {
|
||||||
if (contactManager.getPendingContactState(p.getId()) == FAILED) {
|
try {
|
||||||
try {
|
contactManager.removePendingContact(p.getId());
|
||||||
contactManager.removePendingContact(p.getId());
|
|
||||||
} catch (DbException e) {
|
|
||||||
logException(LOG, WARNING, e);
|
|
||||||
addContactResult.postValue(new LiveResult<>(e));
|
|
||||||
}
|
|
||||||
addContact(name);
|
addContact(name);
|
||||||
|
} catch(NoSuchPendingContactException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
// no error in UI as pending contact was converted into contact
|
||||||
|
} catch (DbException e) {
|
||||||
|
logException(LOG, WARNING, e);
|
||||||
|
addContactResult.postValue(new LiveResult<>(e));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user