mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Migrate blog sharing to new sharing client infrastructure
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
|
||||
public interface BlogConstants {
|
||||
@@ -7,12 +8,7 @@ public interface BlogConstants {
|
||||
/**
|
||||
* The maximum length of a blogs's name in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_BLOG_TITLE_LENGTH = 100;
|
||||
|
||||
/**
|
||||
* The length of a blogs's description in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_BLOG_DESC_LENGTH = 240;
|
||||
int MAX_BLOG_NAME_LENGTH = MAX_AUTHOR_NAME_LENGTH;
|
||||
|
||||
/**
|
||||
* The maximum length of a blog post's body in bytes.
|
||||
@@ -24,13 +20,8 @@ public interface BlogConstants {
|
||||
*/
|
||||
int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH;
|
||||
|
||||
/* Blog Sharing Constants */
|
||||
String BLOG_AUTHOR_NAME = "blogAuthorName";
|
||||
String BLOG_PUBLIC_KEY = "blogPublicKey";
|
||||
|
||||
// Metadata keys
|
||||
String KEY_TYPE = "type";
|
||||
String KEY_DESCRIPTION = "description";
|
||||
String KEY_TIMESTAMP = "timestamp";
|
||||
String KEY_TIME_RECEIVED = "timeReceived";
|
||||
String KEY_AUTHOR_ID = "id";
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
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;
|
||||
@@ -15,24 +12,16 @@ import javax.annotation.Nullable;
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationRequest extends InvitationRequest<Blog> {
|
||||
|
||||
private final String blogAuthorName;
|
||||
|
||||
public BlogInvitationRequest(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, String blogAuthorName,
|
||||
@Nullable String message, GroupId blogId,
|
||||
boolean available, boolean canBeOpened, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean 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;
|
||||
public BlogInvitationRequest(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read,
|
||||
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);
|
||||
}
|
||||
|
||||
public String getBlogAuthorName() {
|
||||
return blogAuthorName;
|
||||
return getShareable().getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import org.briarproject.briar.api.sharing.InvitationResponse;
|
||||
@NotNullByDefault
|
||||
public class BlogInvitationResponse extends InvitationResponse {
|
||||
|
||||
public BlogInvitationResponse(MessageId id, SessionId sessionId,
|
||||
GroupId groupId, ContactId contactId, GroupId blogId,
|
||||
boolean accept, long time, boolean local, boolean sent,
|
||||
boolean seen, boolean read) {
|
||||
public BlogInvitationResponse(MessageId id, GroupId groupId, long time,
|
||||
boolean local, boolean sent, boolean seen, boolean read,
|
||||
SessionId sessionId, GroupId blogId, ContactId contactId,
|
||||
boolean accept) {
|
||||
super(id, groupId, time, local, sent, seen, read, sessionId, blogId,
|
||||
contactId, accept);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,16 @@ public interface BlogManager {
|
||||
*/
|
||||
ClientId CLIENT_ID = new ClientId("org.briarproject.briar.blog");
|
||||
|
||||
/**
|
||||
* Adds a blog from the given author.
|
||||
*/
|
||||
Blog addBlog(Author author) throws DbException;
|
||||
|
||||
/**
|
||||
* Adds the given {@link Blog} within the given {@link Transaction}.
|
||||
*/
|
||||
void addBlog(Transaction txn, Blog b) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns true if a blog can be removed.
|
||||
*/
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.briarproject.briar.api.blog;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.SharingMessage.Invitation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.BLOG_AUTHOR_NAME;
|
||||
import static org.briarproject.briar.api.blog.BlogConstants.BLOG_PUBLIC_KEY;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface BlogSharingMessage {
|
||||
|
||||
class BlogInvitation extends Invitation {
|
||||
|
||||
private final String blogAuthorName;
|
||||
private final byte[] blogPublicKey;
|
||||
|
||||
public BlogInvitation(GroupId groupId, SessionId sessionId,
|
||||
String blogAuthorName, byte[] blogPublicKey, long time,
|
||||
@Nullable String message) {
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
this.blogAuthorName = blogAuthorName;
|
||||
this.blogPublicKey = blogPublicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfList toBdfList() {
|
||||
BdfList list = super.toBdfList();
|
||||
list.add(BdfList.of(blogAuthorName, blogPublicKey));
|
||||
if (message != null) list.add(message);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfDictionary toBdfDictionary() {
|
||||
BdfDictionary d = toBdfDictionaryHelper();
|
||||
d.put(BLOG_AUTHOR_NAME, blogAuthorName);
|
||||
d.put(BLOG_PUBLIC_KEY, blogPublicKey);
|
||||
if (message != null) d.put(INVITATION_MSG, message);
|
||||
return d;
|
||||
}
|
||||
|
||||
public static BlogInvitation from(GroupId groupId, BdfDictionary d)
|
||||
throws FormatException {
|
||||
|
||||
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
|
||||
String blogAuthorName = d.getString(BLOG_AUTHOR_NAME);
|
||||
byte[] blogPublicKey = d.getRaw(BLOG_PUBLIC_KEY);
|
||||
String message = d.getOptionalString(INVITATION_MSG);
|
||||
long time = d.getLong(TIME);
|
||||
|
||||
return new BlogInvitation(groupId, sessionId, blogAuthorName,
|
||||
blogPublicKey, time, message);
|
||||
}
|
||||
|
||||
public String getBlogAuthorName() {
|
||||
return blogAuthorName;
|
||||
}
|
||||
|
||||
public byte[] getBlogPublicKey() {
|
||||
return blogPublicKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package org.briarproject.briar.api.forum;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
import org.briarproject.briar.api.sharing.SharingMessage.Invitation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_NAME;
|
||||
import static org.briarproject.briar.api.forum.ForumConstants.FORUM_SALT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.INVITATION_MSG;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
|
||||
@NotNullByDefault
|
||||
public interface ForumSharingMessage {
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class ForumInvitation extends Invitation {
|
||||
|
||||
private final String forumName;
|
||||
private final byte[] forumSalt;
|
||||
|
||||
public ForumInvitation(GroupId groupId, SessionId sessionId,
|
||||
String forumName, byte[] forumSalt, long time,
|
||||
@Nullable String message) {
|
||||
|
||||
super(groupId, sessionId, time, message);
|
||||
|
||||
this.forumName = forumName;
|
||||
this.forumSalt = forumSalt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfList toBdfList() {
|
||||
BdfList list = super.toBdfList();
|
||||
list.add(forumName);
|
||||
list.add(forumSalt);
|
||||
if (message != null) list.add(message);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfDictionary toBdfDictionary() {
|
||||
BdfDictionary d = toBdfDictionaryHelper();
|
||||
d.put(FORUM_NAME, forumName);
|
||||
d.put(FORUM_SALT, forumSalt);
|
||||
if (message != null) d.put(INVITATION_MSG, message);
|
||||
return d;
|
||||
}
|
||||
|
||||
public static ForumInvitation from(GroupId groupId, BdfDictionary d)
|
||||
throws FormatException {
|
||||
|
||||
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
|
||||
String forumName = d.getString(FORUM_NAME);
|
||||
byte[] forumSalt = d.getRaw(FORUM_SALT);
|
||||
String message = d.getOptionalString(INVITATION_MSG);
|
||||
long time = d.getLong(TIME);
|
||||
|
||||
return new ForumInvitation(groupId, sessionId, forumName, forumSalt,
|
||||
time, message);
|
||||
}
|
||||
|
||||
public String getForumName() {
|
||||
return forumName;
|
||||
}
|
||||
|
||||
public byte[] getForumSalt() {
|
||||
return forumSalt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
|
||||
@Deprecated
|
||||
public interface InvitationFactory<I extends SharingMessage.Invitation> {
|
||||
|
||||
I build(GroupId groupId, BdfDictionary d) throws FormatException;
|
||||
}
|
||||
@@ -4,74 +4,10 @@ import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_L
|
||||
|
||||
public interface SharingConstants {
|
||||
|
||||
/**
|
||||
* The length of a sharing session's random salt in bytes.
|
||||
*/
|
||||
int SHARING_SALT_LENGTH = 32;
|
||||
|
||||
/**
|
||||
* The maximum length of the optional message from the inviter to the
|
||||
* invitee in UTF-8 bytes.
|
||||
*/
|
||||
int MAX_INVITATION_MESSAGE_LENGTH = MAX_MESSAGE_BODY_LENGTH - 1024;
|
||||
|
||||
@Deprecated
|
||||
String CONTACT_ID = "contactId";
|
||||
@Deprecated
|
||||
String GROUP_ID = "groupId";
|
||||
@Deprecated
|
||||
String TO_BE_SHARED_BY_US = "toBeSharedByUs";
|
||||
@Deprecated
|
||||
String SHARED_BY_US = "sharedByUs";
|
||||
@Deprecated
|
||||
String SHARED_WITH_US = "sharedWithUs";
|
||||
@Deprecated
|
||||
String TYPE = "type";
|
||||
@Deprecated
|
||||
String SESSION_ID = "sessionId";
|
||||
@Deprecated
|
||||
String STORAGE_ID = "storageId";
|
||||
@Deprecated
|
||||
String STATE = "state";
|
||||
@Deprecated
|
||||
String LOCAL = "local";
|
||||
@Deprecated
|
||||
String TIME = "time";
|
||||
@Deprecated
|
||||
String IS_SHARER = "isSharer";
|
||||
@Deprecated
|
||||
String SHAREABLE_ID = "shareableId";
|
||||
@Deprecated
|
||||
String INVITATION_MSG = "invitationMsg";
|
||||
@Deprecated
|
||||
String INVITATION_ID = "invitationId";
|
||||
@Deprecated
|
||||
String RESPONSE_ID = "responseId";
|
||||
@Deprecated
|
||||
int SHARE_MSG_TYPE_INVITATION = 1;
|
||||
@Deprecated
|
||||
int SHARE_MSG_TYPE_ACCEPT = 2;
|
||||
@Deprecated
|
||||
int SHARE_MSG_TYPE_DECLINE = 3;
|
||||
@Deprecated
|
||||
int SHARE_MSG_TYPE_LEAVE = 4;
|
||||
@Deprecated
|
||||
int SHARE_MSG_TYPE_ABORT = 5;
|
||||
@Deprecated
|
||||
int TASK_ADD_SHAREABLE_TO_LIST_SHARED_WITH_US = 0;
|
||||
@Deprecated
|
||||
int TASK_REMOVE_SHAREABLE_FROM_LIST_SHARED_WITH_US = 1;
|
||||
@Deprecated
|
||||
int TASK_ADD_SHARED_SHAREABLE = 2;
|
||||
@Deprecated
|
||||
int TASK_ADD_SHAREABLE_TO_LIST_TO_BE_SHARED_BY_US = 3;
|
||||
@Deprecated
|
||||
int TASK_REMOVE_SHAREABLE_FROM_LIST_TO_BE_SHARED_BY_US = 4;
|
||||
@Deprecated
|
||||
int TASK_SHARE_SHAREABLE = 5;
|
||||
@Deprecated
|
||||
int TASK_UNSHARE_SHAREABLE_SHARED_BY_US = 6;
|
||||
@Deprecated
|
||||
int TASK_UNSHARE_SHAREABLE_SHARED_WITH_US = 7;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
package org.briarproject.briar.api.sharing;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.data.BdfDictionary;
|
||||
import org.briarproject.bramble.api.data.BdfEntry;
|
||||
import org.briarproject.bramble.api.data.BdfList;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.GROUP_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SESSION_ID;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_ACCEPT;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_DECLINE;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_INVITATION;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.SHARE_MSG_TYPE_LEAVE;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TIME;
|
||||
import static org.briarproject.briar.api.sharing.SharingConstants.TYPE;
|
||||
|
||||
@Deprecated
|
||||
@NotNullByDefault
|
||||
public interface SharingMessage {
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
abstract class BaseMessage {
|
||||
|
||||
private final GroupId groupId;
|
||||
private final SessionId sessionId;
|
||||
private final long time;
|
||||
|
||||
BaseMessage(GroupId groupId, SessionId sessionId, long time) {
|
||||
this.groupId = groupId;
|
||||
this.sessionId = sessionId;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public BdfList toBdfList() {
|
||||
return BdfList.of(getType(), getSessionId());
|
||||
}
|
||||
|
||||
public abstract BdfDictionary toBdfDictionary();
|
||||
|
||||
protected BdfDictionary toBdfDictionaryHelper() {
|
||||
return BdfDictionary.of(
|
||||
new BdfEntry(TYPE, getType()),
|
||||
new BdfEntry(GROUP_ID, groupId),
|
||||
new BdfEntry(SESSION_ID, sessionId)
|
||||
);
|
||||
}
|
||||
|
||||
public static BaseMessage from(InvitationFactory invitationFactory,
|
||||
GroupId groupId, BdfDictionary d)
|
||||
throws FormatException {
|
||||
|
||||
long type = d.getLong(TYPE);
|
||||
|
||||
if (type == SHARE_MSG_TYPE_INVITATION)
|
||||
return invitationFactory.build(groupId, d);
|
||||
else
|
||||
return SimpleMessage.from(type, groupId, d);
|
||||
}
|
||||
|
||||
public abstract long getType();
|
||||
|
||||
public GroupId getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public SessionId getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
abstract class Invitation extends BaseMessage {
|
||||
|
||||
@Nullable
|
||||
protected final String message;
|
||||
|
||||
public Invitation(GroupId groupId, SessionId sessionId, long time,
|
||||
@Nullable String message) {
|
||||
|
||||
super(groupId, sessionId, time);
|
||||
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getType() {
|
||||
return SHARE_MSG_TYPE_INVITATION;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class SimpleMessage extends BaseMessage {
|
||||
|
||||
private final long type;
|
||||
|
||||
public SimpleMessage(long type, GroupId groupId, SessionId sessionId,
|
||||
long time) {
|
||||
super(groupId, sessionId, time);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BdfDictionary toBdfDictionary() {
|
||||
return toBdfDictionaryHelper();
|
||||
}
|
||||
|
||||
public static SimpleMessage from(long type, GroupId groupId,
|
||||
BdfDictionary d) throws FormatException {
|
||||
|
||||
if (type != SHARE_MSG_TYPE_ACCEPT &&
|
||||
type != SHARE_MSG_TYPE_DECLINE &&
|
||||
type != SHARE_MSG_TYPE_LEAVE &&
|
||||
type != SHARE_MSG_TYPE_ABORT) throw new FormatException();
|
||||
|
||||
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
|
||||
long time = d.getLong(TIME);
|
||||
return new SimpleMessage(type, groupId, sessionId, time);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user