Update blog backend to match current usage

parent a18317e9
......@@ -538,7 +538,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
author0 = authorFactory
.createLocalAuthor(AUTHOR1, publicKey0, privateKey0);
identityManager0.addLocalAuthor(author0);
blog0 = blogFactory.createPersonalBlog(author0);
blog0 = blogFactory.createBlog(author0);
KeyPair keyPair1 = crypto.generateSignatureKeyPair();
byte[] publicKey1 = keyPair1.getPublic().getEncoded();
......@@ -546,7 +546,7 @@ public class BlogManagerTest extends BriarIntegrationTest {
author1 = authorFactory
.createLocalAuthor(AUTHOR2, publicKey1, privateKey1);
identityManager1.addLocalAuthor(author1);
blog1 = blogFactory.createPersonalBlog(author1);
blog1 = blogFactory.createBlog(author1);
}
private void addDefaultContacts() throws DbException {
......
......@@ -72,12 +72,12 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
private BlogManager blogManager0, blogManager1;
private ContactManager contactManager0, contactManager1, contactManager2;
private Contact contact1, contact2, contact01, contact02;
private ContactId contactId1, contactId2, contactId01, contactId02;
private ContactId contactId1, contactId01;
private IdentityManager identityManager0, identityManager1,
identityManager2;
private LocalAuthor author0, author1, author2;
private Blog blog0, blog1, blog2;
private SharerListener listener0, listener2;
private SharerListener listener0;
private InviteeListener listener1;
@Inject
......@@ -670,7 +670,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
);
contact1 = contactManager0.getContact(contactId1);
// sharer adds second contact
contactId2 = contactManager0.addContact(author2,
ContactId contactId2 = contactManager0.addContact(author2,
author0.getId(), master, clock.currentTimeMillis(), true,
true, true
);
......@@ -681,7 +681,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
true, true
);
contact01 = contactManager1.getContact(contactId01);
contactId02 = contactManager2.addContact(author0,
ContactId contactId02 = contactManager2.addContact(author0,
author2.getId(), master, clock.currentTimeMillis(), true,
true, true
);
......@@ -699,7 +699,7 @@ public class BlogSharingIntegrationTest extends BriarIntegrationTest {
t0.getEventBus().addListener(listener0);
listener1 = new InviteeListener(accept);
t1.getEventBus().addListener(listener1);
listener2 = new SharerListener();
SharerListener listener2 = new SharerListener();
t2.getEventBus().addListener(listener2);
}
......
......@@ -41,7 +41,6 @@
<dimen name="message_bubble_timestamp_margin">7dp</dimen>
<dimen name="forum_nested_line_width">2dp</dimen>
<dimen name="forum_nested_indicator">24dp</dimen>
<dimen name="forum_avatar_size">20dp</dimen>
<dimen name="blogs_avatar_normal_size">30dp</dimen>
<dimen name="blogs_avatar_icon_size">15dp</dimen>
......
......@@ -240,25 +240,14 @@
<string name="nobody">Nobody</string>
<!-- Blogs -->
<string name="blogs_my_blogs_create">Create Blog</string>
<string name="blogs_my_blogs_label">Add new Blog</string>
<string name="blogs_my_blogs_create_hint_title">Blog title (cannot be changed later)</string>
<string name="blogs_my_blogs_create_hint_desc">A short description of your new blog</string>
<string name="blogs_my_blogs_create_hint_desc_explanation">Potential readers may or may not subscribe to your blog based on the content of the description.</string>
<string name="blogs_my_blogs_created">Blog created</string>
<string name="blogs_blog_is_empty">This blog is empty</string>
<string name="blogs_other_blog_empty_state">This blog is currently empty.\n\nEither the author hasn\'t written anything yet, or the person who shared this blog with you needs to come online, so posts can be synchronized.</string>
<string name="tag_new">NEW</string>
<string name="read_more">read more</string>
<string name="blogs_write_blog_post">Write Blog Post</string>
<string name="blogs_write_blog_post_title_hint">Add a title (optional)</string>
<string name="blogs_write_blog_post_body_hint">Type your blog post here</string>
<string name="blogs_publish_blog_post">Publish</string>
<string name="blogs_blog_post_created">Blog Post Created</string>
<string name="blogs_blog_post_received">New Blog Post Received</string>
<string name="blogs_blog_post_scroll_to">Scroll To</string>
<string name="blogs_blog_failed_to_load">Blog failed to load</string>
<string name="blogs_blog_post_failed_to_load">Blog post failed to load</string>
<string name="blogs_feed_empty_state">This is the global blog feed.\n\nIt looks like nobody blogged anything, yet.\n\nBe the first and tap the pen icon to write a new blog post.</string>
<string name="blogs_personal_blog">%s\'s Personal Blog</string>
<string name="blogs_remove_blog">Remove Blog</string>
......@@ -268,9 +257,6 @@
<string name="blogs_reblog_comment_hint">Add an optional comment</string>
<string name="blogs_reblog_button">Reblog</string>
<string name="blogs_blog_list">Blog List</string>
<string name="blogs_available_blogs">Available Blogs</string>
<!-- Blog Sharing -->
<string name="blogs_sharing_share">Share Blog</string>
<string name="blogs_sharing_error">There was an error sharing this blog.</string>
......@@ -353,12 +339,6 @@
<string name="link_warning_text">This can be used to identify you. Think about whether you trust the person that sent you this link and consider opening it with Orfox.</string>
<string name="link_warning_open_link">Open Link</string>
<!-- Multiple Identities -->
<string name="anonymous">Anonymous</string>
<string name="new_identity_title">New Identity</string>
<string name="create_identity_button">Create Identity</string>
<string name="identity_created_toast">Identity created</string>
<!-- Crash Reporter -->
<string name="crash_report_title">Briar Crash Report</string>
<string name="briar_crashed">Sorry, Briar has crashed.</string>
......
......@@ -59,17 +59,6 @@
<item name="android:textColor">@android:color/primary_text_light</item>
</style>
<style name="BriarTag">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginRight">@dimen/margin_medium</item>
<item name="android:paddingLeft">3dp</item>
<item name="android:paddingRight">3dp</item>
<item name="android:background">@color/briar_primary</item>
<item name="android:textSize">@dimen/text_size_tiny</item>
<item name="android:textColor">@color/briar_text_primary_inverse</item>
</style>
<style name="Divider">
<item name="android:background">@color/divider</item>
</style>
......
......@@ -2,7 +2,6 @@ package org.briarproject.android.blogs;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ProgressBar;
import org.briarproject.R;
import org.briarproject.android.ActivityComponent;
......@@ -18,8 +17,6 @@ public class BlogActivity extends BriarActivity implements
static final int REQUEST_WRITE_POST = 1;
static final int REQUEST_SHARE = 2;
static final String BLOG_NAME = "briar.BLOG_NAME";
static final String IS_NEW_BLOG = "briar.IS_NEW_BLOG";
@Inject
BlogController blogController;
......@@ -35,17 +32,10 @@ public class BlogActivity extends BriarActivity implements
GroupId groupId = new GroupId(b);
blogController.setGroupId(groupId);
// Name of the blog
String blogName = i.getStringExtra(BLOG_NAME);
if (blogName != null) setTitle(blogName);
// Was this blog just created?
boolean isNew = i.getBooleanExtra(IS_NEW_BLOG, false);
setContentView(R.layout.activity_fragment_container);
if (state == null) {
BlogFragment f = BlogFragment.newInstance(groupId, blogName, isNew);
BlogFragment f = BlogFragment.newInstance(groupId);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, f, f.getUniqueTag())
.commit();
......
......@@ -38,12 +38,9 @@ import javax.inject.Inject;
import static android.app.Activity.RESULT_OK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
import static android.widget.Toast.LENGTH_SHORT;
import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.blogs.BlogActivity.BLOG_NAME;
import static org.briarproject.android.blogs.BlogActivity.IS_NEW_BLOG;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_SHARE;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST;
......@@ -56,21 +53,17 @@ public class BlogFragment extends BaseFragment implements
BlogController blogController;
private GroupId groupId;
private String blogName;
private BlogPostAdapter adapter;
private BriarRecyclerView list;
private MenuItem writeButton, deleteButton;
private boolean isMyBlog = false, canDeleteBlog = false;
static BlogFragment newInstance(GroupId groupId, @Nullable String name,
boolean isNew) {
static BlogFragment newInstance(GroupId groupId) {
BlogFragment f = new BlogFragment();
Bundle bundle = new Bundle();
bundle.putByteArray(GROUP_ID, groupId.getBytes());
bundle.putString(BLOG_NAME, name);
bundle.putBoolean(IS_NEW_BLOG, isNew);
f.setArguments(bundle);
return f;
......@@ -84,8 +77,6 @@ public class BlogFragment extends BaseFragment implements
byte[] b = args.getByteArray(GROUP_ID);
if (b == null) throw new IllegalStateException("No group ID in args");
groupId = new GroupId(b);
blogName = args.getString(BLOG_NAME);
boolean isNew = args.getBoolean(IS_NEW_BLOG);
View v = inflater.inflate(R.layout.fragment_blog, container, false);
......@@ -97,16 +88,6 @@ public class BlogFragment extends BaseFragment implements
list.showProgressBar();
list.setEmptyText(getString(R.string.blogs_other_blog_empty_state));
// show snackbar if this blog was just created
if (isNew) {
Snackbar s = Snackbar.make(list, R.string.blogs_my_blogs_created,
LENGTH_LONG);
s.getView().setBackgroundResource(R.color.briar_primary);
s.show();
// show only once
args.putBoolean(IS_NEW_BLOG, false);
}
return v;
}
......@@ -152,7 +133,6 @@ public class BlogFragment extends BaseFragment implements
Intent i = new Intent(getActivity(),
WriteBlogPostActivity.class);
i.putExtra(GROUP_ID, groupId.getBytes());
i.putExtra(BLOG_NAME, blogName);
startActivityForResult(i, REQUEST_WRITE_POST,
options.toBundle());
return true;
......@@ -266,10 +246,6 @@ public class BlogFragment extends BaseFragment implements
private void setToolbarTitle(Author a) {
String title = getString(R.string.blogs_personal_blog, a.getName());
getActivity().setTitle(title);
// safe title in intent, so it can be restored automatically
Intent intent = getActivity().getIntent();
intent.putExtra(BLOG_NAME, title);
}
private void showWriteButton() {
......
......@@ -17,10 +17,6 @@ class BlogItem {
return blog;
}
String getName() {
return blog.getName();
}
boolean isOurs() {
return ours;
}
......
......@@ -35,7 +35,6 @@ import static android.app.Activity.RESULT_OK;
import static android.support.design.widget.Snackbar.LENGTH_LONG;
import static android.support.v4.app.ActivityOptionsCompat.makeCustomAnimation;
import static org.briarproject.android.BriarActivity.GROUP_ID;
import static org.briarproject.android.blogs.BlogActivity.BLOG_NAME;
import static org.briarproject.android.blogs.BlogActivity.REQUEST_WRITE_POST;
public class FeedFragment extends BaseFragment implements
......@@ -171,7 +170,6 @@ public class FeedFragment extends BaseFragment implements
Intent i1 =
new Intent(getActivity(), WriteBlogPostActivity.class);
i1.putExtra(GROUP_ID, personalBlog.getId().getBytes());
i1.putExtra(BLOG_NAME, personalBlog.getName());
startActivityForResult(i1, REQUEST_WRITE_POST,
options.toBundle());
return true;
......
......@@ -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();
}
}
......@@ -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";
......
......@@ -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;
}
......@@ -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;
......
......@@ -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() {
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -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;
}
}
......@@ -7,14 +7,14 @@ import org.briarproject.api.clients.ClientHelper;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.AuthorFactory;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory;
import org.jetbrains.annotations.NotNull;
import javax.inject.Inject;
import static org.briarproject.api.blogs.BlogConstants.PERSONAL_BLOG_NAME;
@NotNullByDefault
class BlogFactoryImpl implements BlogFactory {
private final GroupFactory groupFactory;
......@@ -31,39 +31,29 @@ class BlogFactoryImpl implements BlogFactory {
}
@Override
public Blog createPersonalBlog(@NotNull Author a) {
return createBlog(PERSONAL_BLOG_NAME, "", a);
}
@Override
public Blog createBlog(@NotNull String name, @NotNull String description,
@NotNull Author author) {
public Blog createBlog(Author a) {
try {
BdfList blog = BdfList.of(
name,
author.getName(),
author.getPublicKey()
a.getName(),
a.getPublicKey()
);
byte[] descriptor = clientHelper.toByteArray(blog);
Group g = groupFactory
.createGroup(BlogManagerImpl.CLIENT_ID, descriptor);
return new Blog(g, name, description, author);
return new Blog(g, a);
} catch (FormatException e) {
throw new RuntimeException(e);
}
}
@Override
public Blog parseBlog(@NotNull Group g, @NotNull String description)
throws FormatException {
public Blog parseBlog(@NotNull Group g) throws FormatException {