Commit 5f6af4e4 authored by Torsten Grote's avatar Torsten Grote

Fix introduction response messages in UI and some minor fixes

parent 55a329a8
......@@ -124,6 +124,9 @@ abstract class ConversationItem {
text = ctx.getString(
R.string.introduction_response_accepted_sent,
ir.getName());
text += "\n\n" + ctx.getString(
R.string.introduction_response_accepted_sent_info,
ir.getName());
} else {
text = ctx.getString(
R.string.introduction_response_declined_sent,
......
......@@ -156,6 +156,7 @@
<string name="introduction_request_exists_received">%1$s has asked to introduce you to %2$s, but %2$s is already in your contact list. Since %1$s might not know that, you can still respond:</string>
<string name="introduction_request_answered_received">%1$s has asked to introduce you to %2$s.</string>
<string name="introduction_response_accepted_sent">You accepted the introduction to %1$s.</string>
<string name="introduction_response_accepted_sent_info">Before %1$s gets added to your contacts, they need to accept the introduction as well. This might take some time.</string>
<string name="introduction_response_declined_sent">You declined the introduction to %1$s.</string>
<string name="introduction_response_accepted_received">%1$s accepted the introduction to %2$s.</string>
<string name="introduction_response_declined_received">%1$s declined the introduction to %2$s.</string>
......
......@@ -25,6 +25,9 @@ public interface IntroductionManager extends ConversationClient {
*/
int CLIENT_VERSION = 1;
/**
* Returns true if both contacts can be introduced at this moment.
*/
boolean canIntroduce(Contact c1, Contact c2) throws DbException;
/**
......
......@@ -144,15 +144,15 @@ abstract class AbstractProtocolEngine<S extends Session>
}
}
void broadcastIntroductionResponseReceivedEvent(Transaction txn,
Session s, AuthorId sender, AbstractIntroductionMessage m)
void broadcastIntroductionResponseReceivedEvent(Transaction txn, Session s,
AuthorId sender, Author otherAuthor, AbstractIntroductionMessage m)
throws DbException {
AuthorId localAuthorId = identityManager.getLocalAuthor(txn).getId();
Contact c = contactManager.getContact(txn, sender, localAuthorId);
IntroductionResponse response =
new IntroductionResponse(s.getSessionId(), m.getMessageId(),
m.getGroupId(), s.getRole(), m.getTimestamp(), false,
false, false, false, c.getAuthor().getName(),
false, false, false, otherAuthor.getName(),
m instanceof AcceptMessage);
IntroductionResponseReceivedEvent e =
new IntroductionResponseReceivedEvent(c.getId(), response);
......
......@@ -355,7 +355,7 @@ class IntroduceeProtocolEngine
// Broadcast IntroductionResponseReceivedEvent
broadcastIntroductionResponseReceivedEvent(txn, s,
s.getIntroducer().getId(), m);
s.getIntroducer().getId(), s.getRemote().author, m);
if (s.getState() == AWAIT_RESPONSES) {
// Mark the request message unavailable to answer
......
......@@ -261,19 +261,24 @@ class IntroducerProtocolEngine
// Create the next state
IntroducerState state = AWAIT_AUTHS;
Introducee introduceeA, introduceeB;
Author sender, other;
if (senderIsAlice) {
if (s.getState() == AWAIT_RESPONSES) state = AWAIT_RESPONSE_B;
introduceeA = new Introducee(s.getIntroduceeA(), m.getMessageId());
introduceeB = new Introducee(s.getIntroduceeB(), sent);
sender = introduceeA.author;
other = introduceeB.author;
} else {
if (s.getState() == AWAIT_RESPONSES) state = AWAIT_RESPONSE_A;
introduceeA = new Introducee(s.getIntroduceeA(), sent);
introduceeB = new Introducee(s.getIntroduceeB(), m.getMessageId());
sender = introduceeB.author;
other = introduceeA.author;
}
// Broadcast IntroductionResponseReceivedEvent
Author sender = senderIsAlice ? introduceeA.author : introduceeB.author;
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(), m);
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(),
other, m);
// Move to the next state
return new IntroducerSession(s.getSessionId(), state,
......@@ -313,17 +318,22 @@ class IntroducerProtocolEngine
m.getTransportProperties(), false);
Introducee introduceeA, introduceeB;
Author sender, other;
if (senderIsAlice) {
introduceeA = new Introducee(s.getIntroduceeA(), m.getMessageId());
introduceeB = new Introducee(s.getIntroduceeB(), sent);
sender = introduceeA.author;
other = introduceeB.author;
} else {
introduceeA = new Introducee(s.getIntroduceeA(), sent);
introduceeB = new Introducee(s.getIntroduceeB(), m.getMessageId());
sender = introduceeB.author;
other = introduceeA.author;
}
// Broadcast IntroductionResponseReceivedEvent
Author sender = senderIsAlice ? introduceeA.author : introduceeB.author;
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(), m);
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(),
other, m);
return new IntroducerSession(s.getSessionId(), START,
s.getRequestTimestamp(), introduceeA, introduceeB);
......@@ -360,19 +370,24 @@ class IntroducerProtocolEngine
// Create the next state
IntroducerState state = START;
Introducee introduceeA, introduceeB;
Author sender, other;
if (senderIsAlice) {
if (s.getState() == AWAIT_RESPONSES) state = A_DECLINED;
introduceeA = new Introducee(s.getIntroduceeA(), m.getMessageId());
introduceeB = new Introducee(s.getIntroduceeB(), sent);
sender = introduceeA.author;
other = introduceeB.author;
} else {
if (s.getState() == AWAIT_RESPONSES) state = B_DECLINED;
introduceeA = new Introducee(s.getIntroduceeA(), sent);
introduceeB = new Introducee(s.getIntroduceeB(), m.getMessageId());
sender = introduceeB.author;
other = introduceeA.author;
}
// Broadcast IntroductionResponseReceivedEvent
Author sender = senderIsAlice ? introduceeA.author : introduceeB.author;
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(), m);
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(),
other, m);
return new IntroducerSession(s.getSessionId(), state,
s.getRequestTimestamp(), introduceeA, introduceeB);
......@@ -405,17 +420,22 @@ class IntroducerProtocolEngine
Message sent = sendDeclineMessage(txn, i, timestamp, false);
Introducee introduceeA, introduceeB;
Author sender, other;
if (senderIsAlice) {
introduceeA = new Introducee(s.getIntroduceeA(), m.getMessageId());
introduceeB = new Introducee(s.getIntroduceeB(), sent);
sender = introduceeA.author;
other = introduceeB.author;
} else {
introduceeA = new Introducee(s.getIntroduceeA(), sent);
introduceeB = new Introducee(s.getIntroduceeB(), m.getMessageId());
sender = introduceeB.author;
other = introduceeA.author;
}
// Broadcast IntroductionResponseReceivedEvent
Author sender = senderIsAlice ? introduceeA.author : introduceeB.author;
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(), m);
broadcastIntroductionResponseReceivedEvent(txn, s, sender.getId(),
other, m);
return new IntroducerSession(s.getSessionId(), START,
s.getRequestTimestamp(), introduceeA, introduceeB);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment