mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 04:39:54 +01:00
Refactor doesExist() method.
This commit is contained in:
@@ -114,13 +114,14 @@ abstract class ConversationItem {
|
|||||||
} else {
|
} else {
|
||||||
String text;
|
String text;
|
||||||
RequestType type;
|
RequestType type;
|
||||||
|
boolean canBeOpened;
|
||||||
if (ir instanceof IntroductionRequest) {
|
if (ir instanceof IntroductionRequest) {
|
||||||
type = INTRODUCTION;
|
type = INTRODUCTION;
|
||||||
if (ir.wasAnswered()) {
|
if (ir.wasAnswered()) {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.introduction_request_answered_received,
|
R.string.introduction_request_answered_received,
|
||||||
contactName, ir.getName());
|
contactName, ir.getName());
|
||||||
} else if (ir.doesExist()) {
|
} else if (((IntroductionRequest) ir).isContact()) {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.introduction_request_exists_received,
|
R.string.introduction_request_exists_received,
|
||||||
contactName, ir.getName());
|
contactName, ir.getName());
|
||||||
@@ -136,15 +137,18 @@ abstract class ConversationItem {
|
|||||||
text = ctx.getString(R.string.forum_invitation_received,
|
text = ctx.getString(R.string.forum_invitation_received,
|
||||||
contactName, ir.getName());
|
contactName, ir.getName());
|
||||||
type = FORUM;
|
type = FORUM;
|
||||||
|
canBeOpened = ((ForumInvitationRequest) ir).canBeOpened();
|
||||||
} else if (ir instanceof BlogInvitationRequest) {
|
} else if (ir instanceof BlogInvitationRequest) {
|
||||||
text = ctx.getString(R.string.blogs_sharing_invitation_received,
|
text = ctx.getString(R.string.blogs_sharing_invitation_received,
|
||||||
contactName, ir.getName());
|
contactName, ir.getName());
|
||||||
type = BLOG;
|
type = BLOG;
|
||||||
|
canBeOpened = ((BlogInvitationRequest) ir).canBeOpened();
|
||||||
} else if (ir instanceof GroupInvitationRequest) {
|
} else if (ir instanceof GroupInvitationRequest) {
|
||||||
text = ctx.getString(
|
text = ctx.getString(
|
||||||
R.string.groups_invitations_invitation_received,
|
R.string.groups_invitations_invitation_received,
|
||||||
contactName, ir.getName());
|
contactName, ir.getName());
|
||||||
type = GROUP;
|
type = GROUP;
|
||||||
|
canBeOpened = ((GroupInvitationRequest) ir).canBeOpened();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unknown PrivateRequest");
|
throw new IllegalArgumentException("Unknown PrivateRequest");
|
||||||
}
|
}
|
||||||
@@ -152,7 +156,7 @@ abstract class ConversationItem {
|
|||||||
ir.getGroupId(), type, ir.getSessionId(), text,
|
ir.getGroupId(), type, ir.getSessionId(), text,
|
||||||
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
|
ir.getMessage(), ir.getTimestamp(), ir.isRead(),
|
||||||
((Shareable) ir.getNameable()).getId(), !ir.wasAnswered(),
|
((Shareable) ir.getNameable()).getId(), !ir.wasAnswered(),
|
||||||
ir.doesExist());
|
canBeOpened);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class BlogInvitationRequest extends PrivateRequest<Blog> {
|
public class BlogInvitationRequest extends InvitationRequest<Blog> {
|
||||||
|
|
||||||
public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
|
public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||||
boolean local, boolean sent, boolean seen, boolean read,
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, Blog blog,
|
SessionId sessionId, Blog blog, @Nullable String message,
|
||||||
@Nullable String message, boolean available, boolean canBeOpened) {
|
boolean available, boolean canBeOpened) {
|
||||||
super(id, groupId, time, local, sent, seen, read, sessionId, blog,
|
super(id, groupId, time, local, sent, seen, read, sessionId, blog,
|
||||||
message, available, canBeOpened);
|
message, available, canBeOpened);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,19 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class ForumInvitationRequest extends PrivateRequest<Forum> {
|
public class ForumInvitationRequest extends InvitationRequest<Forum> {
|
||||||
|
|
||||||
public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
|
public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||||
boolean local, boolean sent, boolean seen, boolean read,
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, Forum forum,
|
SessionId sessionId, Forum forum, @Nullable String message,
|
||||||
@Nullable String message, boolean available, boolean canBeOpened) {
|
boolean available, boolean canBeOpened) {
|
||||||
super(id, groupId, time, local, sent, seen, read, sessionId, forum,
|
super(id, groupId, time, local, sent, seen, read, sessionId, forum,
|
||||||
message, available, canBeOpened);
|
message, available, canBeOpened);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,18 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class IntroductionRequest extends PrivateRequest<Introduction> {
|
public class IntroductionRequest extends PrivateRequest<Introduction> {
|
||||||
|
|
||||||
|
private final boolean contact;
|
||||||
|
|
||||||
public IntroductionRequest(MessageId messageId, GroupId groupId,
|
public IntroductionRequest(MessageId messageId, GroupId groupId,
|
||||||
long time, boolean local, boolean sent, boolean seen, boolean read,
|
long time, boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, Introduction introduction,
|
SessionId sessionId, Introduction introduction,
|
||||||
@Nullable String message, boolean answered, boolean exists) {
|
@Nullable String message, boolean answered, boolean contact) {
|
||||||
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||||
introduction, message, answered, exists);
|
introduction, message, answered);
|
||||||
|
this.contact = contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isContact() {
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,18 +16,17 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
|
|||||||
private final N nameable;
|
private final N nameable;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final String message;
|
private final String message;
|
||||||
private final boolean answered, exists;
|
private final boolean answered;
|
||||||
|
|
||||||
public PrivateRequest(MessageId messageId, GroupId groupId, long time,
|
public PrivateRequest(MessageId messageId, GroupId groupId, long time,
|
||||||
boolean local, boolean sent, boolean seen, boolean read,
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
SessionId sessionId, N nameable, @Nullable String message,
|
SessionId sessionId, N nameable, @Nullable String message,
|
||||||
boolean answered, boolean exists) {
|
boolean answered) {
|
||||||
super(messageId, groupId, time, local, sent, seen, read);
|
super(messageId, groupId, time, local, sent, seen, read);
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
this.nameable = nameable;
|
this.nameable = nameable;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.answered = answered;
|
this.answered = answered;
|
||||||
this.exists = exists;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionId getSessionId() {
|
public SessionId getSessionId() {
|
||||||
@@ -50,8 +49,4 @@ public class PrivateRequest<N extends Nameable> extends PrivateMessageHeader {
|
|||||||
public boolean wasAnswered() {
|
public boolean wasAnswered() {
|
||||||
return answered;
|
return answered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doesExist() {
|
|
||||||
return exists;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
|||||||
import org.briarproject.bramble.api.sync.GroupId;
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
import org.briarproject.bramble.api.sync.MessageId;
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
import org.briarproject.briar.api.messaging.PrivateRequest;
|
|
||||||
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
import org.briarproject.briar.api.privategroup.PrivateGroup;
|
||||||
|
import org.briarproject.briar.api.sharing.InvitationRequest;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.concurrent.Immutable;
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class GroupInvitationRequest extends PrivateRequest<PrivateGroup> {
|
public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
|
||||||
|
|
||||||
public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
|
public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||||
boolean local, boolean sent, boolean seen, boolean read,
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.briarproject.briar.api.sharing;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateRequest;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public abstract class InvitationRequest<S extends Shareable> extends
|
||||||
|
PrivateRequest<S> {
|
||||||
|
|
||||||
|
private final boolean canBeOpened;
|
||||||
|
|
||||||
|
public InvitationRequest(MessageId messageId, GroupId groupId, long time,
|
||||||
|
boolean local, boolean sent, boolean seen, boolean read,
|
||||||
|
SessionId sessionId, S object, @Nullable String message,
|
||||||
|
boolean answered, boolean canBeOpened) {
|
||||||
|
super(messageId, groupId, time, local, sent, seen, read, sessionId,
|
||||||
|
object, message, answered);
|
||||||
|
this.canBeOpened = canBeOpened;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canBeOpened() {
|
||||||
|
return canBeOpened;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -613,10 +613,10 @@ public class IntroductionIntegrationTest
|
|||||||
// assert that introducees get notified about the existing contact
|
// assert that introducees get notified about the existing contact
|
||||||
IntroductionRequest ir1 = getIntroductionRequest(db1,
|
IntroductionRequest ir1 = getIntroductionRequest(db1,
|
||||||
introductionManager1, contactId0From1);
|
introductionManager1, contactId0From1);
|
||||||
assertTrue(ir1.doesExist());
|
assertTrue(ir1.isContact());
|
||||||
IntroductionRequest ir2 = getIntroductionRequest(db2,
|
IntroductionRequest ir2 = getIntroductionRequest(db2,
|
||||||
introductionManager2, contactId0From2);
|
introductionManager2, contactId0From2);
|
||||||
assertTrue(ir2.doesExist());
|
assertTrue(ir2.isContact());
|
||||||
|
|
||||||
// sync ACCEPT messages back to introducer
|
// sync ACCEPT messages back to introducer
|
||||||
sync1To0(1, true);
|
sync1To0(1, true);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
assertEquals(privateGroup0.getName(), request.getNameable().getName());
|
assertEquals(privateGroup0.getName(), request.getNameable().getName());
|
||||||
assertFalse(request.isLocal());
|
assertFalse(request.isLocal());
|
||||||
assertFalse(request.isRead());
|
assertFalse(request.isRead());
|
||||||
assertFalse(request.doesExist());
|
assertFalse(request.canBeOpened());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -182,7 +182,7 @@ public class GroupInvitationIntegrationTest
|
|||||||
} else {
|
} else {
|
||||||
GroupInvitationRequest request = (GroupInvitationRequest) m;
|
GroupInvitationRequest request = (GroupInvitationRequest) m;
|
||||||
assertEquals(privateGroup0, request.getNameable());
|
assertEquals(privateGroup0, request.getNameable());
|
||||||
assertTrue(request.doesExist());
|
assertTrue(request.canBeOpened());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(foundResponse);
|
assertTrue(foundResponse);
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public class ForumSharingIntegrationTest
|
|||||||
assertEquals(forum0.getName(), invitation.getName());
|
assertEquals(forum0.getName(), invitation.getName());
|
||||||
assertEquals(forum0, invitation.getNameable());
|
assertEquals(forum0, invitation.getNameable());
|
||||||
assertEquals("Hi!", invitation.getMessage());
|
assertEquals("Hi!", invitation.getMessage());
|
||||||
assertTrue(invitation.doesExist());
|
assertTrue(invitation.canBeOpened());
|
||||||
} else {
|
} else {
|
||||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||||
assertEquals(forum0, response.getNameable());
|
assertEquals(forum0, response.getNameable());
|
||||||
@@ -195,7 +195,7 @@ public class ForumSharingIntegrationTest
|
|||||||
assertFalse(invitation.wasAnswered());
|
assertFalse(invitation.wasAnswered());
|
||||||
assertEquals(forum0.getName(), invitation.getName());
|
assertEquals(forum0.getName(), invitation.getName());
|
||||||
assertEquals(null, invitation.getMessage());
|
assertEquals(null, invitation.getMessage());
|
||||||
assertFalse(invitation.doesExist());
|
assertFalse(invitation.canBeOpened());
|
||||||
} else {
|
} else {
|
||||||
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
ForumInvitationResponse response = (ForumInvitationResponse) m;
|
||||||
assertEquals(forum0, response.getNameable());
|
assertEquals(forum0, response.getNameable());
|
||||||
|
|||||||
Reference in New Issue
Block a user