ConversationManager: Address review issues

parent 2309e732
...@@ -70,34 +70,34 @@ class ConversationNoticeOutItem extends ConversationOutItem { ...@@ -70,34 +70,34 @@ class ConversationNoticeOutItem extends ConversationOutItem {
} }
private static String getText(Context ctx, String contactName, private static String getText(Context ctx, String contactName,
PrivateResponse ir) { PrivateResponse r) {
if (ir.wasAccepted()) { if (r.wasAccepted()) {
if (ir instanceof IntroductionResponse) { if (r instanceof IntroductionResponse) {
String name = ((IntroductionResponse) ir).getIntroducedAuthor() String name = ((IntroductionResponse) r).getIntroducedAuthor()
.getName(); .getName();
return ctx.getString( return ctx.getString(
R.string.introduction_response_accepted_sent, R.string.introduction_response_accepted_sent,
name) + "\n\n" + ctx.getString( name) + "\n\n" + ctx.getString(
R.string.introduction_response_accepted_sent_info, R.string.introduction_response_accepted_sent_info,
name); name);
} else if (ir instanceof ForumInvitationResponse) { } else if (r instanceof ForumInvitationResponse) {
return ctx.getString(R.string.forum_invitation_response_accepted_sent, contactName); return ctx.getString(R.string.forum_invitation_response_accepted_sent, contactName);
} else if (ir instanceof BlogInvitationResponse) { } else if (r instanceof BlogInvitationResponse) {
return ctx.getString(R.string.blogs_sharing_response_accepted_sent, contactName); return ctx.getString(R.string.blogs_sharing_response_accepted_sent, contactName);
} else if (ir instanceof GroupInvitationResponse) { } else if (r instanceof GroupInvitationResponse) {
return ctx.getString(R.string.groups_invitations_response_accepted_sent, contactName); return ctx.getString(R.string.groups_invitations_response_accepted_sent, contactName);
} }
} else { } else {
if (ir instanceof IntroductionResponse) { if (r instanceof IntroductionResponse) {
String name = ((IntroductionResponse) ir).getIntroducedAuthor() String name = ((IntroductionResponse) r).getIntroducedAuthor()
.getName(); .getName();
return ctx.getString( return ctx.getString(
R.string.introduction_response_declined_sent, name); R.string.introduction_response_declined_sent, name);
} else if (ir instanceof ForumInvitationResponse) { } else if (r instanceof ForumInvitationResponse) {
return ctx.getString(R.string.forum_invitation_response_declined_sent, contactName); return ctx.getString(R.string.forum_invitation_response_declined_sent, contactName);
} else if (ir instanceof BlogInvitationResponse) { } else if (r instanceof BlogInvitationResponse) {
return ctx.getString(R.string.blogs_sharing_response_declined_sent, contactName); return ctx.getString(R.string.blogs_sharing_response_declined_sent, contactName);
} else if (ir instanceof GroupInvitationResponse) { } else if (r instanceof GroupInvitationResponse) {
return ctx.getString(R.string.groups_invitations_response_declined_sent, contactName); return ctx.getString(R.string.groups_invitations_response_declined_sent, contactName);
} }
} }
......
...@@ -256,7 +256,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> { ...@@ -256,7 +256,7 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
GroupInvitationMessage m, boolean accept) { GroupInvitationMessage m, boolean accept) {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes()); SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationResponse(m.getId(), m.getContactGroupId(), return new GroupInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId, m.getTimestamp(), false, false, false, false, sessionId,
accept, m.getPrivateGroupId()); accept, m.getPrivateGroupId());
} }
} }
...@@ -61,7 +61,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> { ...@@ -61,7 +61,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
ContactId contactId) { ContactId contactId) {
BlogInvitationResponse response = invitationFactory BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, false, false,
true, m.getShareableId()); true, m.getShareableId());
return new BlogInvitationResponseReceivedEvent(response, contactId); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }
...@@ -71,8 +71,8 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> { ...@@ -71,8 +71,8 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
ContactId contactId) { ContactId contactId) {
BlogInvitationResponse response = invitationFactory BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, false, false,
true, m.getShareableId()); false, m.getShareableId());
return new BlogInvitationResponseReceivedEvent(response, contactId); return new BlogInvitationResponseReceivedEvent(response, contactId);
} }
......
...@@ -73,7 +73,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> { ...@@ -73,7 +73,7 @@ class ForumProtocolEngineImpl extends ProtocolEngineImpl<Forum> {
ForumInvitationResponse response = invitationFactory ForumInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(), .createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, m.getTimestamp(), false, false, true, false,
true, m.getShareableId()); false, m.getShareableId());
return new ForumInvitationResponseReceivedEvent(response, contactId); return new ForumInvitationResponseReceivedEvent(response, contactId);
} }
......
...@@ -368,13 +368,16 @@ public class IntroductionIntegrationTest ...@@ -368,13 +368,16 @@ public class IntroductionIntegrationTest
.getMessageHeaders(txn, contactId1From0)); .getMessageHeaders(txn, contactId1From0));
assertEquals(2, messages.size()); assertEquals(2, messages.size());
messages = withinTransactionReturns(db0, messages = withinTransactionReturns(db0,
txn -> introductionManager0.getMessageHeaders(txn, contactId2From0)); txn -> introductionManager0
.getMessageHeaders(txn, contactId2From0));
assertEquals(2, messages.size()); assertEquals(2, messages.size());
messages = withinTransactionReturns(db1, messages = withinTransactionReturns(db1,
txn -> introductionManager1.getMessageHeaders(txn, contactId0From1)); txn -> introductionManager1
assertEquals(3,messages.size()); .getMessageHeaders(txn, contactId0From1));
assertEquals(3, messages.size());
messages = withinTransactionReturns(db2, messages = withinTransactionReturns(db2,
txn -> introductionManager2.getMessageHeaders(txn, contactId0From2)); txn -> introductionManager2
.getMessageHeaders(txn, contactId0From2));
assertEquals(3, messages.size()); assertEquals(3, messages.size());
assertFalse(listener0.aborted); assertFalse(listener0.aborted);
assertFalse(listener1.aborted); assertFalse(listener1.aborted);
......
...@@ -408,7 +408,7 @@ public class PrivateGroupManagerIntegrationTest ...@@ -408,7 +408,7 @@ public class PrivateGroupManagerIntegrationTest
groupManager2.addPrivateGroup(txn, privateGroup0, joinMsg2, false); groupManager2.addPrivateGroup(txn, privateGroup0, joinMsg2, false);
// share the group with 0 // share the group with 0
db2.setGroupVisibility(txn, db2.setGroupVisibility(txn,
contactId0From1, privateGroup0.getId(), SHARED); // TODO contactId contactId0From2, privateGroup0.getId(), SHARED);
}); });
// sync join messages // sync join messages
......
...@@ -478,11 +478,11 @@ public class ForumSharingIntegrationTest ...@@ -478,11 +478,11 @@ public class ForumSharingIntegrationTest
.contains(contact0From1)); .contains(contact0From1));
// and both have each other's invitations (and no response) // and both have each other's invitations (and no response)
assertEquals(2, withinTransactionReturns(db0, txn2 -> assertEquals(2, withinTransactionReturns(db0, txn ->
forumSharingManager0.getMessageHeaders(txn2, contactId1From0)) forumSharingManager0.getMessageHeaders(txn, contactId1From0))
.size()); .size());
assertEquals(2, withinTransactionReturns(db1, txn2 -> assertEquals(2, withinTransactionReturns(db1, txn ->
forumSharingManager1.getMessageHeaders(txn2, contactId0From1)) forumSharingManager1.getMessageHeaders(txn, contactId0From1))
.size()); .size());
// there are no more open invitations // there are no more open invitations
...@@ -561,11 +561,11 @@ public class ForumSharingIntegrationTest ...@@ -561,11 +561,11 @@ public class ForumSharingIntegrationTest
withinTransaction(db2, txn -> db2.addGroup(txn, forum0.getGroup())); withinTransaction(db2, txn -> db2.addGroup(txn, forum0.getGroup()));
// add listeners // add listeners
listener0 = new SharerListener(); listener0 = new SharerListener(true);
c0.getEventBus().addListener(listener0); c0.getEventBus().addListener(listener0);
listener1 = new InviteeListener(true, false); listener1 = new InviteeListener(true, false);
c1.getEventBus().addListener(listener1); c1.getEventBus().addListener(listener1);
listener2 = new SharerListener(); listener2 = new SharerListener(true);
c2.getEventBus().addListener(listener2); c2.getEventBus().addListener(listener2);
// send invitation // send invitation
...@@ -790,13 +790,22 @@ public class ForumSharingIntegrationTest ...@@ -790,13 +790,22 @@ public class ForumSharingIntegrationTest
@NotNullByDefault @NotNullByDefault
private class SharerListener implements EventListener { private class SharerListener implements EventListener {
private final boolean accept;
private volatile boolean requestReceived = false; private volatile boolean requestReceived = false;
private volatile boolean responseReceived = false; private volatile boolean responseReceived = false;
private SharerListener(boolean accept) {
this.accept = accept;
}
@Override @Override
public void eventOccurred(Event e) { public void eventOccurred(Event e) {
if (e instanceof ForumInvitationResponseReceivedEvent) { if (e instanceof ForumInvitationResponseReceivedEvent) {
ForumInvitationResponseReceivedEvent event =
(ForumInvitationResponseReceivedEvent) e;
responseReceived = true; responseReceived = true;
eventWaiter.assertEquals(accept,
event.getMessageHeader().wasAccepted());
eventWaiter.resume(); eventWaiter.resume();
} }
// this is only needed for tests where a forum is re-shared // this is only needed for tests where a forum is re-shared
...@@ -868,17 +877,19 @@ public class ForumSharingIntegrationTest ...@@ -868,17 +877,19 @@ public class ForumSharingIntegrationTest
ForumInvitationResponseReceivedEvent event = ForumInvitationResponseReceivedEvent event =
(ForumInvitationResponseReceivedEvent) e; (ForumInvitationResponseReceivedEvent) e;
eventWaiter.assertEquals(contactId0From1, event.getContactId()); eventWaiter.assertEquals(contactId0From1, event.getContactId());
eventWaiter.assertEquals(accept,
event.getMessageHeader().wasAccepted());
eventWaiter.resume(); eventWaiter.resume();
} }
} }
} }
private void listenToEvents(boolean accept) throws DbException { private void listenToEvents(boolean accept) {
listener0 = new SharerListener(); listener0 = new SharerListener(accept);
c0.getEventBus().addListener(listener0); c0.getEventBus().addListener(listener0);
listener1 = new InviteeListener(accept); listener1 = new InviteeListener(accept);
c1.getEventBus().addListener(listener1); c1.getEventBus().addListener(listener1);
listener2 = new SharerListener(); listener2 = new SharerListener(accept);
c2.getEventBus().addListener(listener2); c2.getEventBus().addListener(listener2);
} }
......
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