Update blog backend to match current usage

This commit is contained in:
Torsten Grote
2016-10-27 12:55:54 -02:00
parent a18317e912
commit 9e553ef9c8
28 changed files with 154 additions and 386 deletions

View File

@@ -5,7 +5,6 @@ import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sharing.Shareable;
import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable;
@@ -13,21 +12,13 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public class Blog extends BaseGroup implements Shareable {
private final String description;
private final Author author;
public Blog(Group group, String name, String description, Author author) {
super(group, name);
this.description = description;
public Blog(Group group, Author author) {
super(group);
this.author = author;
}
@NotNull
public String getDescription() {
return description;
}
@NotNull
public Author getAuthor() {
return author;
}
@@ -36,4 +27,13 @@ public class Blog extends BaseGroup implements Shareable {
public boolean equals(Object o) {
return o instanceof Blog && super.equals(o);
}
/**
* Returns the blog's author's name, not the name as shown in the UI.
*/
@Override
public String getName() {
return author.getName();
}
}

View File

@@ -16,12 +16,7 @@ public interface BlogConstants {
/** The maximum length of a blog comment in bytes. */
int MAX_BLOG_COMMENT_LENGTH = MAX_BLOG_POST_BODY_LENGTH;
/** The internal name of personal blogs that are created automatically */
String PERSONAL_BLOG_NAME = "briar.PERSONAL_BLOG_NAME";
/* Blog Sharing Constants */
String BLOG_TITLE = "blogTitle";
String BLOG_DESC = "blogDescription";
String BLOG_AUTHOR_NAME = "blogAuthorName";
String BLOG_PUBLIC_KEY = "blogPublicKey";

View File

@@ -2,19 +2,17 @@ package org.briarproject.api.blogs;
import org.briarproject.api.FormatException;
import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
@NotNullByDefault
public interface BlogFactory {
/** Creates a blog with the given name, description and author. */
Blog createBlog(@NotNull String name, @NotNull String description,
@NotNull Author author);
/** Creates a personal blog for a given author. */
Blog createPersonalBlog(@NotNull Author author);
Blog createBlog(Author author);
/** Parses a blog with the given Group */
Blog parseBlog(@NotNull Group g) throws FormatException;
/** Parses a blog with the given Group and description */
Blog parseBlog(@NotNull Group g, @NotNull String description)
throws FormatException;
}

View File

@@ -16,10 +16,6 @@ public interface BlogManager {
/** Returns the unique ID of the blog client. */
ClientId getClientId();
/** Creates a new Blog. */
Blog addBlog(LocalAuthor localAuthor, String name, String description)
throws DbException;
/** Returns true if a blog can be removed. */
boolean canBeRemoved(GroupId g) throws DbException;

View File

@@ -8,9 +8,7 @@ import org.briarproject.api.sharing.SharingMessage.Invitation;
import org.briarproject.api.sync.GroupId;
import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME;
import static org.briarproject.api.blogs.BlogConstants.BLOG_DESC;
import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY;
import static org.briarproject.api.blogs.BlogConstants.BLOG_TITLE;
import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG;
import static org.briarproject.api.sharing.SharingConstants.SESSION_ID;
import static org.briarproject.api.sharing.SharingConstants.TIME;
@@ -19,19 +17,14 @@ public interface BlogSharingMessage {
class BlogInvitation extends Invitation {
private final String blogTitle;
private final String blogDesc;
private final String blogAuthorName;
private final byte[] blogPublicKey;
public BlogInvitation(GroupId groupId, SessionId sessionId,
String blogTitle, String blogDesc, String blogAuthorName,
byte[] blogPublicKey, long time, String message) {
String blogAuthorName, byte[] blogPublicKey, long time,
String message) {
super(groupId, sessionId, time, message);
this.blogTitle = blogTitle;
this.blogDesc = blogDesc;
this.blogAuthorName = blogAuthorName;
this.blogPublicKey = blogPublicKey;
}
@@ -39,8 +32,6 @@ public interface BlogSharingMessage {
@Override
public BdfList toBdfList() {
BdfList list = super.toBdfList();
list.add(blogTitle);
list.add(blogDesc);
list.add(BdfList.of(blogAuthorName, blogPublicKey));
if (message != null) list.add(message);
return list;
@@ -49,8 +40,6 @@ public interface BlogSharingMessage {
@Override
public BdfDictionary toBdfDictionary() {
BdfDictionary d = toBdfDictionaryHelper();
d.put(BLOG_TITLE, blogTitle);
d.put(BLOG_DESC, blogDesc);
d.put(BLOG_AUTHOR_NAME, blogAuthorName);
d.put(BLOG_PUBLIC_KEY, blogPublicKey);
if (message != null) d.put(INVITATION_MSG, message);
@@ -61,23 +50,13 @@ public interface BlogSharingMessage {
throws FormatException {
SessionId sessionId = new SessionId(d.getRaw(SESSION_ID));
String blogTitle = d.getString(BLOG_TITLE);
String blogDesc = d.getString(BLOG_DESC);
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, blogTitle,
blogDesc, blogAuthorName, blogPublicKey, time, message);
}
public String getBlogTitle() {
return blogTitle;
}
public String getBlogDesc() {
return blogDesc;
return new BlogInvitation(groupId, sessionId, blogAuthorName,
blogPublicKey, time, message);
}
public String getBlogAuthorName() {

View File

@@ -3,7 +3,6 @@ package org.briarproject.api.clients;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable;
@@ -12,28 +11,19 @@ import javax.annotation.concurrent.Immutable;
public abstract class BaseGroup {
private final Group group;
private final String name;
public BaseGroup(Group group, String name) {
public BaseGroup(Group group) {
this.group = group;
this.name = name;
}
@NotNull
public GroupId getId() {
return group.getId();
}
@NotNull
public Group getGroup() {
return group;
}
@NotNull
public String getName() {
return name;
}
@Override
public int hashCode() {
return group.hashCode();

View File

@@ -10,13 +10,19 @@ import javax.annotation.concurrent.Immutable;
@NotNullByDefault
public abstract class NamedGroup extends BaseGroup {
private final String name;
private final byte[] salt;
public NamedGroup(@NotNull Group group, @NotNull String name, byte[] salt) {
super(group, name);
super(group);
this.name = name;
this.salt = salt;
}
public String getName() {
return name;
}
public byte[] getSalt() {
return salt;
}

View File

@@ -3,17 +3,12 @@ package org.briarproject.api.event;
import org.briarproject.api.blogs.BlogInvitationResponse;
import org.briarproject.api.contact.ContactId;
public class BlogInvitationResponseReceivedEvent extends InvitationResponseReceivedEvent {
public class BlogInvitationResponseReceivedEvent
extends InvitationResponseReceivedEvent {
private final String blogTitle;
public BlogInvitationResponseReceivedEvent(String blogTitle,
ContactId contactId, BlogInvitationResponse response) {
public BlogInvitationResponseReceivedEvent(ContactId contactId,
BlogInvitationResponse response) {
super(contactId, response);
this.blogTitle = blogTitle;
}
public String getBlogTitle() {
return blogTitle;
}
}