Add support for revealing contacts to the PrivateGroupManager

This also adds two integration tests and improves some small details
This commit is contained in:
Torsten Grote
2016-11-08 22:26:56 -02:00
parent b20c107010
commit ec8982438a
13 changed files with 402 additions and 156 deletions

View File

@@ -12,12 +12,12 @@ public class GroupMember {
private final Author author;
private final Status status;
private final boolean shared;
private final Visibility visibility;
public GroupMember(Author author, Status status, boolean shared) {
public GroupMember(Author author, Status status, Visibility visibility) {
this.author = author;
this.status = status;
this.shared = shared;
this.visibility = visibility;
}
public Author getAuthor() {
@@ -28,8 +28,8 @@ public class GroupMember {
return status;
}
public boolean isShared() {
return shared;
public Visibility getVisibility() {
return visibility;
}
}

View File

@@ -12,20 +12,22 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class PrivateGroup extends NamedGroup implements Shareable {
private final Author author;
private final Author creator;
public PrivateGroup(Group group, String name, Author author, byte[] salt) {
public PrivateGroup(Group group, String name, Author creator, byte[] salt) {
super(group, name, salt);
this.author = author;
this.creator = creator;
}
public Author getAuthor() {
return author;
public Author getCreator() {
return creator;
}
@Override
public boolean equals(Object o) {
return o instanceof PrivateGroup && super.equals(o);
return o instanceof PrivateGroup &&
creator.equals(((PrivateGroup) o).getCreator()) &&
super.equals(o);
}
}

View File

@@ -1,9 +1,11 @@
package org.briarproject.api.privategroup;
import org.briarproject.api.FormatException;
import org.briarproject.api.clients.MessageTracker;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorId;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.GroupId;
@@ -20,16 +22,16 @@ public interface PrivateGroupManager extends MessageTracker {
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.privategroup");
/**
* Adds a new private group and joins it.
* Adds a new private group and joins it as the creator.
*
* @param group The private group to add
* @param joinMsg The new member's join message
* @param joinMsg The creators's join message
*/
void addPrivateGroup(PrivateGroup group, GroupMessage joinMsg)
throws DbException;
/**
* Adds a new private group and joins it.
* Adds a new private group and joins it as a member.
*
* @param group The private group to add
* @param joinMsg The new member's join message
@@ -103,6 +105,17 @@ public interface PrivateGroupManager extends MessageTracker {
*/
boolean isMember(Transaction txn, GroupId g, Author a) throws DbException;
/**
* This method needs to be called when a contact relationship
* has been revealed between you and the Author with AuthorId a
* in the Group identified by the GroupId g.
*
* @param byContact true if the remote contact has revealed
* the relationship first. Otherwise false.
*/
void relationshipRevealed(Transaction txn, GroupId g, AuthorId a,
boolean byContact) throws FormatException, DbException;
/**
* Registers a hook to be called when members are added
* or groups are removed.

View File

@@ -0,0 +1,25 @@
package org.briarproject.api.privategroup;
public enum Visibility {
INVISIBLE(0),
VISIBLE(1),
REVEALED_BY_YOU(2),
REVEALED_BY_CONTACT(3);
int value;
Visibility(int value) {
this.value = value;
}
public static Visibility valueOf(int value) {
for (Visibility v : values()) if (v.value == value) return v;
throw new IllegalArgumentException();
}
public int getInt() {
return value;
}
}