Commit 2d9345c0 authored by Torsten Grote's avatar Torsten Grote

Remove unnecessary information from private message classes

parent 817df9c7
......@@ -36,7 +36,6 @@ import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.keyagreement.ContactExchangeActivity;
import org.briarproject.briar.android.view.BriarRecyclerView;
import org.briarproject.briar.api.android.AndroidNotificationManager;
import org.briarproject.briar.api.client.BaseMessageHeader;
import org.briarproject.briar.api.client.MessageTracker.GroupCount;
import org.briarproject.briar.api.introduction.IntroductionRequest;
import org.briarproject.briar.api.introduction.IntroductionResponse;
......@@ -283,7 +282,7 @@ public class ContactListFragment extends BaseFragment implements EventListener {
}
}
private void updateItem(ContactId c, BaseMessageHeader h) {
private void updateItem(ContactId c, PrivateMessageHeader h) {
runOnUiThreadUnlessDestroyed(() -> {
adapter.incrementRevision();
int position = adapter.findItemPosition(c);
......
......@@ -11,7 +11,6 @@ import org.briarproject.briar.R;
import org.briarproject.briar.android.contact.ConversationRequestItem.RequestType;
import org.briarproject.briar.api.blog.BlogInvitationRequest;
import org.briarproject.briar.api.blog.BlogInvitationResponse;
import org.briarproject.briar.api.client.BaseMessageHeader;
import org.briarproject.briar.api.forum.ForumInvitationRequest;
import org.briarproject.briar.api.forum.ForumInvitationResponse;
import org.briarproject.briar.api.introduction.IntroductionRequest;
......@@ -92,7 +91,7 @@ abstract class ConversationItem {
if (ir.isLocal()) {
String text = ctx.getString(R.string.introduction_request_sent,
contactName, ir.getName());
return new ConversationNoticeOutItem(ir.getMessageId(),
return new ConversationNoticeOutItem(ir.getId(),
ir.getGroupId(), text, ir.getMessage(), ir.getTimestamp(),
ir.isSent(), ir.isSeen());
} else {
......@@ -109,7 +108,7 @@ abstract class ConversationItem {
text = ctx.getString(R.string.introduction_request_received,
contactName, ir.getName());
}
return new ConversationRequestItem(ir.getMessageId(),
return new ConversationRequestItem(ir.getId(),
ir.getGroupId(), INTRODUCTION, ir.getSessionId(), text,
ir.getMessage(), ir.getTimestamp(), ir.isRead(), null,
ir.wasAnswered(), false);
......@@ -132,9 +131,8 @@ abstract class ConversationItem {
R.string.introduction_response_declined_sent,
ir.getName());
}
return new ConversationNoticeOutItem(ir.getMessageId(),
ir.getGroupId(), text, null, ir.getTimestamp(), ir.isSent(),
ir.isSeen());
return new ConversationNoticeOutItem(ir.getId(), ir.getGroupId(),
text, null, ir.getTimestamp(), ir.isSent(), ir.isSeen());
} else {
String text;
if (ir.wasAccepted()) {
......@@ -152,9 +150,8 @@ abstract class ConversationItem {
contactName, ir.getName());
}
}
return new ConversationNoticeInItem(ir.getMessageId(),
ir.getGroupId(), text, null, ir.getTimestamp(),
ir.isRead());
return new ConversationNoticeInItem(ir.getId(), ir.getGroupId(),
text, null, ir.getTimestamp(), ir.isRead());
}
}
......@@ -272,12 +269,10 @@ abstract class ConversationItem {
/**
* This method should not be used to display the resulting ConversationItem
* in the UI, but only to update list information based on the
* BaseMessageHeader.
* PrivateMessageHeader.
**/
static ConversationItem from(Context ctx, BaseMessageHeader h) {
if (h instanceof PrivateMessageHeader) {
return from((PrivateMessageHeader) h);
} else if(h instanceof IntroductionRequest) {
static ConversationItem from(Context ctx, PrivateMessageHeader h) {
if(h instanceof IntroductionRequest) {
return from(ctx, "", (IntroductionRequest) h);
} else if(h instanceof IntroductionResponse) {
return from(ctx, "", (IntroductionResponse) h);
......@@ -286,7 +281,7 @@ abstract class ConversationItem {
} else if(h instanceof InvitationResponse) {
return from(ctx, "", (InvitationResponse) h);
} else {
throw new IllegalArgumentException("Unknown message header");
return from(h);
}
}
......
......@@ -88,7 +88,7 @@ class ForumControllerImpl extends
(ForumInvitationResponse) f.getResponse();
if (r.getShareableId().equals(getGroupId()) && r.wasAccepted()) {
LOG.info("Forum invitation was accepted");
onForumInvitationAccepted(r.getContactId());
onForumInvitationAccepted(f.getContactId());
}
} else if (e instanceof ContactLeftShareableEvent) {
ContactLeftShareableEvent c = (ContactLeftShareableEvent) e;
......
......@@ -103,7 +103,7 @@ class GroupControllerImpl extends
(GroupInvitationResponse) g.getResponse();
if (getGroupId().equals(r.getShareableId()) && r.wasAccepted()) {
listener.runOnUiThreadUnlessDestroyed(
() -> listener.onInvitationAccepted(r.getContactId()));
() -> listener.onInvitationAccepted(g.getContactId()));
}
} else if (e instanceof GroupDissolvedEvent) {
GroupDissolvedEvent g = (GroupDissolvedEvent) e;
......
......@@ -17,7 +17,7 @@ public class BlogInvitationRequest extends InvitationRequest<Blog> {
SessionId sessionId, Blog blog, ContactId contactId,
@Nullable String message, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, blog,
contactId, message, available, canBeOpened);
message, available, canBeOpened);
}
public String getBlogAuthorName() {
......
package org.briarproject.briar.api.blog;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -12,10 +11,9 @@ public class BlogInvitationResponse extends InvitationResponse {
public BlogInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, GroupId blogId, ContactId contactId,
boolean accept) {
SessionId sessionId, GroupId blogId, boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId, blogId,
contactId, accept);
accept);
}
}
package org.briarproject.briar.api.client;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public abstract class BaseMessageHeader {
private final MessageId id;
private final GroupId groupId;
private final long timestamp;
private final boolean local, sent, seen, read;
public BaseMessageHeader(MessageId id, GroupId groupId, long timestamp,
boolean local, boolean sent, boolean seen, boolean read) {
this.id = id;
this.groupId = groupId;
this.timestamp = timestamp;
this.local = local;
this.sent = sent;
this.seen = seen;
this.read = read;
}
public MessageId getId() {
return id;
}
public GroupId getGroupId() {
return groupId;
}
public long getTimestamp() {
return timestamp;
}
public boolean isLocal() {
return local;
}
public boolean isSent() {
return sent;
}
public boolean isSeen() {
return seen;
}
public boolean isRead() {
return read;
}
}
......@@ -19,7 +19,7 @@ public class ForumInvitationRequest extends InvitationRequest<Forum> {
SessionId sessionId, Forum forum, ContactId contactId,
@Nullable String message, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, forum,
contactId, message, available, canBeOpened);
message, available, canBeOpened);
}
public String getForumName() {
......
package org.briarproject.briar.api.forum;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -15,10 +14,9 @@ public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, GroupId forumId, ContactId contactId,
boolean accept) {
SessionId sessionId, GroupId forumId, boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId, forumId,
contactId, accept);
accept);
}
}
......@@ -3,41 +3,26 @@ package org.briarproject.briar.api.introduction;
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.BaseMessageHeader;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
@Immutable
@NotNullByDefault
public class IntroductionMessage extends BaseMessageHeader {
public abstract class IntroductionMessage extends PrivateMessageHeader {
private final SessionId sessionId;
private final MessageId messageId;
private final Role role;
IntroductionMessage(SessionId sessionId, MessageId messageId,
GroupId groupId, Role role, long time, boolean local, boolean sent,
GroupId groupId, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(messageId, groupId, time, local, sent, seen, read);
this.sessionId = sessionId;
this.messageId = messageId;
this.role = role;
}
public SessionId getSessionId() {
return sessionId;
}
public MessageId getMessageId() {
return messageId;
}
public boolean isIntroducer() {
return role == INTRODUCER;
}
}
package org.briarproject.briar.api.introduction;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -10,25 +11,28 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class IntroductionRequest extends IntroductionResponse {
public class IntroductionRequest extends IntroductionMessage {
private final Author introducedAuthor;
@Nullable
private final String message;
private final boolean answered, exists;
public IntroductionRequest(SessionId sessionId, MessageId messageId,
GroupId groupId, Role role, long time, boolean local, boolean sent,
boolean seen, boolean read, String name, boolean accepted,
GroupId groupId, long time, boolean local, boolean sent,
boolean seen, boolean read, Author introducedAuthor,
@Nullable String message, boolean answered, boolean exists) {
super(sessionId, messageId, groupId, role, time, local, sent, seen,
read, name, accepted);
super(sessionId, messageId, groupId, time, local, sent, seen, read);
this.introducedAuthor = introducedAuthor;
this.message = message;
this.answered = answered;
this.exists = exists;
}
public String getName() {
return introducedAuthor.getName();
}
@Nullable
public String getMessage() {
return message;
......
......@@ -7,20 +7,22 @@ import org.briarproject.briar.api.client.SessionId;
import javax.annotation.concurrent.Immutable;
import static org.briarproject.briar.api.introduction.Role.INTRODUCER;
@Immutable
@NotNullByDefault
public class IntroductionResponse extends IntroductionMessage {
private final String name;
private final Role role;
private final boolean accepted;
public IntroductionResponse(SessionId sessionId, MessageId messageId,
GroupId groupId, Role role, long time, boolean local, boolean sent,
boolean seen, boolean read, String name, boolean accepted) {
super(sessionId, messageId, groupId, role, time, local, sent, seen,
read);
super(sessionId, messageId, groupId, time, local, sent, seen, read);
this.name = name;
this.role = role;
this.accepted = accepted;
}
......@@ -28,6 +30,10 @@ public class IntroductionResponse extends IntroductionMessage {
return name;
}
public boolean isIntroducer() {
return role == INTRODUCER;
}
public boolean wasAccepted() {
return accepted;
}
......
......@@ -3,18 +3,55 @@ package org.briarproject.briar.api.messaging;
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.BaseMessageHeader;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class PrivateMessageHeader extends BaseMessageHeader {
public class PrivateMessageHeader {
private final MessageId id;
private final GroupId groupId;
private final long timestamp;
private final boolean local, sent, seen, read;
public PrivateMessageHeader(MessageId id, GroupId groupId, long timestamp,
boolean local, boolean read, boolean sent, boolean seen) {
this.id = id;
this.groupId = groupId;
this.timestamp = timestamp;
this.local = local;
this.sent = sent;
this.seen = seen;
this.read = read;
}
public MessageId getId() {
return id;
}
public GroupId getGroupId() {
return groupId;
}
public long getTimestamp() {
return timestamp;
}
public boolean isLocal() {
return local;
}
public boolean isSent() {
return sent;
}
public boolean isSeen() {
return seen;
}
super(id, groupId, timestamp, local, sent, seen, read);
public boolean isRead() {
return read;
}
}
......@@ -20,7 +20,7 @@ public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
SessionId sessionId, PrivateGroup shareable, ContactId contactId,
@Nullable String message, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, shareable,
contactId, message, available, canBeOpened);
message, available, canBeOpened);
}
}
package org.briarproject.briar.api.privategroup.invitation;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -15,10 +14,9 @@ public class GroupInvitationResponse extends InvitationResponse {
public GroupInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, GroupId shareableId, ContactId contactId,
boolean accept) {
SessionId sessionId, GroupId shareableId, boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId,
shareableId, contactId, accept);
shareableId, accept);
}
}
package org.briarproject.briar.api.sharing;
import org.briarproject.bramble.api.contact.ContactId;
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.BaseMessageHeader;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class InvitationMessage extends BaseMessageHeader {
public abstract class InvitationMessage extends PrivateMessageHeader {
private final SessionId sessionId;
private final ContactId contactId;
public InvitationMessage(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, ContactId contactId) {
SessionId sessionId) {
super(id, groupId, time, local, sent, seen, read);
this.sessionId = sessionId;
this.contactId = contactId;
}
public SessionId getSessionId() {
return sessionId;
}
public ContactId getContactId() {
return contactId;
}
}
package org.briarproject.briar.api.sharing;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -11,7 +10,8 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class InvitationRequest<S extends Shareable> extends InvitationMessage {
public abstract class InvitationRequest<S extends Shareable>
extends InvitationMessage {
private final S shareable;
@Nullable
......@@ -20,9 +20,9 @@ public class InvitationRequest<S extends Shareable> extends InvitationMessage {
public InvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, S shareable, ContactId contactId,
SessionId sessionId, S shareable,
@Nullable String message, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, contactId);
super(id, groupId, time, local, sent, seen, read, sessionId);
this.shareable = shareable;
this.message = message;
this.available = available;
......
package org.briarproject.briar.api.sharing;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
......@@ -10,7 +9,7 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class InvitationResponse extends InvitationMessage {
public abstract class InvitationResponse extends InvitationMessage {
private final GroupId shareableId;
private final boolean accept;
......@@ -18,8 +17,8 @@ public class InvitationResponse extends InvitationMessage {
public InvitationResponse(MessageId id, GroupId groupId,
long time, boolean local, boolean sent, boolean seen,
boolean read, SessionId sessionId, GroupId shareableId,
ContactId contactId, boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId, contactId);
boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId);
this.shareableId = shareableId;
this.accept = accept;
}
......
package org.briarproject.briar.api.sharing;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
@NotNullByDefault
......@@ -9,8 +8,6 @@ public interface Shareable {
GroupId getId();
Group getGroup();
String getName();
}
......@@ -41,7 +41,6 @@ import javax.inject.Inject;
import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.briar.api.introduction.Role.INTRODUCEE;
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_AUTH;
import static org.briarproject.briar.introduction.IntroduceeState.AWAIT_RESPONSES;
import static org.briarproject.briar.introduction.IntroduceeState.LOCAL_ACCEPTED;
......@@ -255,11 +254,10 @@ class IntroduceeProtocolEngine
localAuthor.getId());
boolean contactExists = contactManager
.contactExists(txn, m.getAuthor().getId(), localAuthor.getId());
IntroductionRequest request =
new IntroductionRequest(s.getSessionId(), m.getMessageId(),
m.getGroupId(), INTRODUCEE, m.getTimestamp(), false,
false, false, false, m.getAuthor().getName(), false,
m.getMessage(), false, contactExists);
IntroductionRequest request = new IntroductionRequest(s.getSessionId(),
m.getMessageId(), m.getGroupId(), m.getTimestamp(), false,
false, false, false, m.getAuthor(), m.getMessage(), false,
contactExists);
IntroductionRequestReceivedEvent e =
new IntroductionRequestReceivedEvent(c.getId(), request);
txn.attach(e);
......
......@@ -472,10 +472,9 @@ class IntroductionManagerImpl extends ConversationClientImpl
localAuthor.getId());
return new IntroductionRequest(sessionId, m, contactGroupId,
role, meta.getTimestamp(), meta.isLocal(),
status.isSent(), status.isSeen(), meta.isRead(),
author.getName(), false, message, !meta.isAvailableToAnswer(),
contactExists);
meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), author, message,
!meta.isAvailableToAnswer(), contactExists);
}
private IntroductionResponse parseInvitationResponse(GroupId contactGroupId,
......
......@@ -258,6 +258,6 @@ class CreatorProtocolEngine extends AbstractProtocolEngine<CreatorSession> {
SessionId sessionId = new SessionId(m.getPrivateGroupId().getBytes());
return new GroupInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false, sessionId,
m.getPrivateGroupId(), c, accept);
m.getPrivateGroupId(), accept);
}
}
......@@ -434,7 +434,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
return new GroupInvitationResponse(m, contactGroupId,
meta.getTimestamp(), meta.isLocal(), status.isSent(),
status.isSeen(), meta.isRead(), sessionId,
meta.getPrivateGroupId(), c, accept);
meta.getPrivateGroupId(), accept);
}
@Override
......
......@@ -30,11 +30,10 @@ public class BlogInvitationFactoryImpl
@Override
public BlogInvitationResponse createInvitationResponse(MessageId id,
GroupId contactGroupId, long time, boolean local, boolean sent,
boolean seen, boolean read, GroupId shareableId,
ContactId contactId, boolean accept) {
boolean seen, boolean read, GroupId shareableId, boolean accept) {
SessionId sessionId = new SessionId(shareableId.getBytes());
return new BlogInvitationResponse(id, contactGroupId, time, local,
sent, seen, read, sessionId, shareableId, contactId, accept);
sent, seen, read, sessionId, shareableId, accept);
}
}
......@@ -63,7 +63,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false,
m.getShareableId(), contactId, true);
m.getShareableId(), true);
return new BlogInvitationResponseReceivedEvent(contactId, response);
}
......@@ -73,7 +73,7 @@ class BlogProtocolEngineImpl extends ProtocolEngineImpl<Blog> {
BlogInvitationResponse response = invitationFactory
.createInvitationResponse(m.getId(), m.getContactGroupId(),
m.getTimestamp(), false, false, true, false,
m.getShareableId(), contactId, true);
m.getShareableId(), true);
return new BlogInvitationResponseReceivedEvent(contactId, response);
}
......
......@@ -80,8 +80,8 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
// Pre-share both blogs, if they have not been shared already
try {
preShareShareable(txn, c, ourBlog);
preShareShareable(txn, c, theirBlog);
preShareGroup(txn, c, ourBlog.getGroup());
preShareGroup(txn, c, theirBlog.getGroup());
} catch (FormatException e) {
throw new DbException(e);
}
...