Unify introduction response methods and handle ProtocolStateException

It is possible that a remote DECLINE message arrives short before the
user responds to the introduction.
This will cause a ProtocolStateException which (for now) is just caught
and a generic (existing) error message will be shown.
This commit is contained in:
Torsten Grote
2018-04-26 18:18:31 -03:00
parent f8f98ed95d
commit 337f7e7b8f
4 changed files with 22 additions and 46 deletions

View File

@@ -339,18 +339,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
}
@Override
public void acceptIntroduction(ContactId contactId, SessionId sessionId,
long timestamp) throws DbException {
respondToRequest(contactId, sessionId, timestamp, true);
}
@Override
public void declineIntroduction(ContactId contactId, SessionId sessionId,
long timestamp) throws DbException {
respondToRequest(contactId, sessionId, timestamp, false);
}
private void respondToRequest(ContactId contactId, SessionId sessionId,
public void respondToIntroduction(ContactId contactId, SessionId sessionId,
long timestamp, boolean accept) throws DbException {
Transaction txn = db.startTransaction(false);
try {

View File

@@ -445,7 +445,8 @@ public class IntroductionIntegrationTest
// answer request manually
introductionManager2
.acceptIntroduction(contactId0From2, listener2.sessionId, time);
.respondToIntroduction(contactId0From2, listener2.sessionId, time,
true);
// sync second response and ACK and make sure there is no abort
sync2To0(2, true);
@@ -1003,25 +1004,13 @@ public class IntroductionIntegrationTest
long time = clock.currentTimeMillis();
try {
if (introducee == 1 && answerRequests) {
if (accept) {
introductionManager1
.acceptIntroduction(contactId, sessionId,
time);
} else {
introductionManager1
.declineIntroduction(contactId, sessionId,
time);
}
introductionManager1
.respondToIntroduction(contactId, sessionId,
time, accept);
} else if (introducee == 2 && answerRequests) {
if (accept) {
introductionManager2
.acceptIntroduction(contactId, sessionId,
time);
} else {
introductionManager2
.declineIntroduction(contactId, sessionId,
time);
}
introductionManager2
.respondToIntroduction(contactId, sessionId,
time, accept);
}
} catch (DbException exception) {
eventWaiter.rethrow(exception);