mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Create PrivateGroupManager Facade and stub implementation
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.forum.ForumPost;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Message;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GroupMessage extends ForumPost {
|
||||
|
||||
public GroupMessage(@NotNull Message message, @Nullable MessageId parent,
|
||||
@NotNull Author author) {
|
||||
super(message, parent, author);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.crypto.PrivateKey;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
public interface GroupMessageFactory {
|
||||
|
||||
@NotNull
|
||||
GroupMessage createGroupMessage(GroupId groupId, long timestamp,
|
||||
MessageId parent, LocalAuthor author, String body)
|
||||
throws FormatException, GeneralSecurityException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.PostHeader;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
|
||||
public class GroupMessageHeader extends PostHeader {
|
||||
|
||||
public GroupMessageHeader(MessageId id, MessageId parentId, long timestamp,
|
||||
Author author, Author.Status authorStatus, boolean read) {
|
||||
super(id, parentId, timestamp, author, authorStatus, read);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.clients.BaseGroup;
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.briarproject.api.sync.Group;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PrivateGroup extends BaseGroup {
|
||||
|
||||
private final Author author;
|
||||
|
||||
public PrivateGroup(@NotNull Group group, @NotNull String name,
|
||||
@NotNull Author author, @NotNull byte[] salt) {
|
||||
super(group, name, salt);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public Author getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof PrivateGroup && super.equals(o);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface PrivateGroupConstants {
|
||||
|
||||
/**
|
||||
* The maximum length of a group's name in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_GROUP_NAME_LENGTH = 100;
|
||||
|
||||
/**
|
||||
* The length of a group's random salt in bytes.
|
||||
*/
|
||||
int GROUP_SALT_LENGTH = 32;
|
||||
|
||||
/**
|
||||
* The maximum length of a group post's body in bytes.
|
||||
*/
|
||||
int MAX_GROUP_POST_BODY_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.identity.Author;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PrivateGroupFactory {
|
||||
|
||||
/**
|
||||
* Creates a private group with the given name and author.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup createPrivateGroup(String name, Author author);
|
||||
|
||||
/**
|
||||
* Creates a private group with the given name, author and salt.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.briarproject.api.privategroup;
|
||||
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.db.Transaction;
|
||||
import org.briarproject.api.sync.ClientId;
|
||||
import org.briarproject.api.sync.GroupId;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface PrivateGroupManager {
|
||||
|
||||
/** Returns the unique ID of the private group client. */
|
||||
@NotNull
|
||||
ClientId getClientId();
|
||||
|
||||
/** Stores (and sends) a local group message. */
|
||||
void addLocalMessage(GroupMessage p) throws DbException;
|
||||
|
||||
/** Returns the private group with the given ID. */
|
||||
@NotNull
|
||||
PrivateGroup getPrivateGroup(GroupId g) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the private group with the given ID within the given transaction.
|
||||
*/
|
||||
@NotNull
|
||||
PrivateGroup getPrivateGroup(Transaction txn, GroupId g) throws DbException;
|
||||
|
||||
/** Returns all private groups the user is a member of. */
|
||||
@NotNull
|
||||
Collection<PrivateGroup> getPrivateGroups() throws DbException;
|
||||
|
||||
/** Returns the body of the group message with the given ID. */
|
||||
@NotNull
|
||||
String getMessageBody(MessageId m) throws DbException;
|
||||
|
||||
/** Returns the headers of all group messages in the given group. */
|
||||
@NotNull
|
||||
Collection<GroupMessageHeader> getHeaders(GroupId g) throws DbException;
|
||||
|
||||
/** Marks a group message as read or unread. */
|
||||
void setReadFlag(MessageId m, boolean read) throws DbException;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user