New Forum Sharing Client

This commit is contained in:
Torsten Grote
2016-12-16 11:30:09 -02:00
parent 409e0fb5a5
commit 694e662028
64 changed files with 3168 additions and 1655 deletions

View File

@@ -1,7 +1,10 @@
package org.briarproject.briar.api.blog;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupId;
import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.SessionId;
@@ -10,7 +13,7 @@ import org.briarproject.briar.api.sharing.InvitationRequest;
import javax.annotation.Nullable;
@NotNullByDefault
public class BlogInvitationRequest extends InvitationRequest {
public class BlogInvitationRequest extends InvitationRequest<Blog> {
private final String blogAuthorName;
@@ -19,9 +22,12 @@ public class BlogInvitationRequest extends InvitationRequest {
@Nullable String message, GroupId blogId,
boolean available, boolean canBeOpened, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, blogId, available,
canBeOpened, time, local, sent, seen, read);
// TODO pass a proper blog here when redoing the BlogSharingManager
super(id, groupId, time, local, sent, seen, read, sessionId,
new Blog(new Group(blogId, BlogManager.CLIENT_ID, new byte[0]),
new Author(new AuthorId(new byte[AuthorId.LENGTH]),
blogAuthorName, new byte[0])), contactId,
message, available, canBeOpened);
this.blogAuthorName = blogAuthorName;
}

View File

@@ -14,9 +14,8 @@ public class BlogInvitationResponse extends InvitationResponse {
GroupId groupId, ContactId contactId, GroupId blogId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, blogId, accept, time, local,
sent, seen, read);
super(id, groupId, time, local, sent, seen, read, sessionId, blogId,
contactId, accept);
}
}

View File

@@ -12,23 +12,18 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class ForumInvitationRequest extends InvitationRequest {
public class ForumInvitationRequest extends InvitationRequest<Forum> {
private final String forumName;
public ForumInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, GroupId forumId,
String forumName, @Nullable String message, boolean available,
boolean canBeOpened, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, forumId, available,
canBeOpened, time, local, sent, seen, read);
this.forumName = forumName;
public ForumInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
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);
}
public String getForumName() {
return forumName;
return getShareable().getName();
}
}

View File

@@ -13,13 +13,12 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, GroupId forumId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, forumId, accept, time, local,
sent, seen, read);
public ForumInvitationResponse(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, GroupId forumId, ContactId contactId,
boolean accept) {
super(id, groupId, time, local, sent, seen, read, sessionId, forumId,
contactId, accept);
}
}

View File

@@ -27,6 +27,11 @@ public interface ForumManager {
*/
Forum addForum(String name) throws DbException;
/**
* Subscribes to a forum within the given {@link Transaction}.
*/
void addForum(Transaction txn, Forum f) throws DbException;
/**
* Unsubscribes from a forum.
*/

View File

@@ -1,21 +1,20 @@
package org.briarproject.briar.api.forum.event;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.forum.ForumInvitationResponse;
import org.briarproject.briar.api.sharing.event.InvitationResponseReceivedEvent;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class ForumInvitationResponseReceivedEvent extends
InvitationResponseReceivedEvent {
private final String forumName;
public ForumInvitationResponseReceivedEvent(String forumName,
ContactId contactId, ForumInvitationResponse response) {
public ForumInvitationResponseReceivedEvent(ContactId contactId,
ForumInvitationResponse response) {
super(contactId, response);
this.forumName = forumName;
}
public String getForumName() {
return forumName;
}
}

View File

@@ -1,11 +1,11 @@
package org.briarproject.briar.api.privategroup.invitation;
import org.briarproject.bramble.api.contact.ContactId;
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;
import org.briarproject.briar.api.client.SessionId;
import org.briarproject.briar.api.privategroup.PrivateGroup;
import org.briarproject.briar.api.sharing.InvitationRequest;
import javax.annotation.Nullable;
@@ -13,28 +13,14 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class GroupInvitationRequest extends InvitationRequest {
public class GroupInvitationRequest extends InvitationRequest<PrivateGroup> {
private final String groupName;
private final Author creator;
public GroupInvitationRequest(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, @Nullable String message,
GroupId privateGroupId, String groupName, Author creator,
boolean available, boolean canBeOpened, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, message, privateGroupId,
available, canBeOpened, time, local, sent, seen, read);
this.groupName = groupName;
this.creator = creator;
}
public String getGroupName() {
return groupName;
}
public Author getCreator() {
return creator;
public GroupInvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
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);
}
}

View File

@@ -13,11 +13,12 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class GroupInvitationResponse extends InvitationResponse {
public GroupInvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, GroupId privateGroupId,
boolean accept, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, privateGroupId, accept, time,
local, sent, seen, read);
public GroupInvitationResponse(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,
shareableId, contactId, accept);
}
}

View File

@@ -7,25 +7,22 @@ import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.briar.api.client.BaseMessageHeader;
import org.briarproject.briar.api.client.SessionId;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public abstract class InvitationMessage extends BaseMessageHeader {
public class InvitationMessage extends BaseMessageHeader {
private final SessionId sessionId;
private final ContactId contactId;
private final GroupId invitedGroupId;
public InvitationMessage(MessageId id, SessionId sessionId, GroupId groupId,
ContactId contactId, GroupId invitedGroupId, long time,
boolean local, boolean sent, boolean seen, boolean read) {
public InvitationMessage(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, ContactId contactId) {
super(id, groupId, time, local, read, sent, seen);
this.sessionId = sessionId;
this.contactId = contactId;
this.invitedGroupId = invitedGroupId;
}
public SessionId getSessionId() {
@@ -36,9 +33,4 @@ public abstract class InvitationMessage extends BaseMessageHeader {
return contactId;
}
@Nullable
public GroupId getInvitedGroupId() {
return invitedGroupId;
}
}

View File

@@ -11,20 +11,19 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public abstract class InvitationRequest extends InvitationMessage {
public class InvitationRequest<S extends Shareable> extends InvitationMessage {
private final S shareable;
@Nullable
private final String message;
private final boolean available, canBeOpened;
public InvitationRequest(MessageId id, SessionId sessionId, GroupId groupId,
ContactId contactId, @Nullable String message,
GroupId invitedGroupId, boolean available,
boolean canBeOpened, long time, boolean local, boolean sent,
boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, invitedGroupId, time, local,
sent, seen, read);
if (available && canBeOpened) throw new IllegalArgumentException();
public InvitationRequest(MessageId id, GroupId groupId, long time,
boolean local, boolean sent, boolean seen, boolean read,
SessionId sessionId, S shareable, ContactId contactId,
@Nullable String message, boolean available, boolean canBeOpened) {
super(id, groupId, time, local, sent, seen, read, sessionId, contactId);
this.shareable = shareable;
this.message = message;
this.available = available;
this.canBeOpened = canBeOpened;
@@ -43,4 +42,8 @@ public abstract class InvitationRequest extends InvitationMessage {
return canBeOpened;
}
public S getShareable() {
return shareable;
}
}

View File

@@ -10,21 +10,26 @@ import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public abstract class InvitationResponse extends InvitationMessage {
public class InvitationResponse extends InvitationMessage {
private final GroupId shareableId;
private final boolean accept;
public InvitationResponse(MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId,
GroupId invitedGroupId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, invitedGroupId, time, local,
sent, seen, read);
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);
this.shareableId = shareableId;
this.accept = accept;
}
public boolean wasAccepted() {
return accept;
}
public GroupId getShareableId() {
return shareableId;
}
}

View File

@@ -20,8 +20,8 @@ public interface SharingManager<S extends Shareable>
* Sends an invitation to share the given group with the given contact
* and sends an optional message along with it.
*/
void sendInvitation(GroupId groupId, ContactId contactId,
@Nullable String message) throws DbException;
void sendInvitation(GroupId shareableId, ContactId contactId,
@Nullable String message, long timestamp) throws DbException;
/**
* Responds to a pending group invitation
@@ -32,7 +32,7 @@ public interface SharingManager<S extends Shareable>
/**
* Responds to a pending group invitation
*/
void respondToInvitation(SessionId id, boolean accept)
void respondToInvitation(ContactId c, SessionId id, boolean accept)
throws DbException;
/**