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