diff --git a/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java b/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java index 0339413b1..758a94595 100644 --- a/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/BlogManagerTest.java @@ -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 { diff --git a/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java b/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java index 2cc0340bc..0dc2e877c 100644 --- a/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java +++ b/briar-android-tests/src/test/java/org/briarproject/BlogSharingIntegrationTest.java @@ -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); } diff --git a/briar-android/res/values/dimens.xml b/briar-android/res/values/dimens.xml index cc465f1ea..fc0531ab6 100644 --- a/briar-android/res/values/dimens.xml +++ b/briar-android/res/values/dimens.xml @@ -41,7 +41,6 @@ 7dp 2dp 24dp - 20dp 30dp 15dp diff --git a/briar-android/res/values/strings.xml b/briar-android/res/values/strings.xml index f69c03741..02df65bc4 100644 --- a/briar-android/res/values/strings.xml +++ b/briar-android/res/values/strings.xml @@ -240,25 +240,14 @@ Nobody - Create Blog - Add new Blog - Blog title (cannot be changed later) - A short description of your new blog - Potential readers may or may not subscribe to your blog based on the content of the description. - Blog created - This blog is empty 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. - NEW read more Write Blog Post - Add a title (optional) Type your blog post here Publish Blog Post Created New Blog Post Received Scroll To - Blog failed to load - Blog post failed to load 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. %s\'s Personal Blog Remove Blog @@ -268,9 +257,6 @@ Add an optional comment Reblog - Blog List - Available Blogs - Share Blog There was an error sharing this blog. @@ -353,12 +339,6 @@ 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. Open Link - - Anonymous - New Identity - Create Identity - Identity created - Briar Crash Report Sorry, Briar has crashed. diff --git a/briar-android/res/values/styles.xml b/briar-android/res/values/styles.xml index 2056a57c7..71b6c910c 100644 --- a/briar-android/res/values/styles.xml +++ b/briar-android/res/values/styles.xml @@ -59,17 +59,6 @@ @android:color/primary_text_light - - diff --git a/briar-android/src/org/briarproject/android/blogs/BlogActivity.java b/briar-android/src/org/briarproject/android/blogs/BlogActivity.java index 5f4fc731d..116fc8ac8 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogActivity.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogActivity.java @@ -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(); diff --git a/briar-android/src/org/briarproject/android/blogs/BlogFragment.java b/briar-android/src/org/briarproject/android/blogs/BlogFragment.java index ac8e28166..d93aa0563 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogFragment.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogFragment.java @@ -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() { diff --git a/briar-android/src/org/briarproject/android/blogs/BlogItem.java b/briar-android/src/org/briarproject/android/blogs/BlogItem.java index 163840ae2..691f9cb75 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogItem.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogItem.java @@ -17,10 +17,6 @@ class BlogItem { return blog; } - String getName() { - return blog.getName(); - } - boolean isOurs() { return ours; } diff --git a/briar-android/src/org/briarproject/android/blogs/FeedFragment.java b/briar-android/src/org/briarproject/android/blogs/FeedFragment.java index 4be0bc541..5c7bd3949 100644 --- a/briar-android/src/org/briarproject/android/blogs/FeedFragment.java +++ b/briar-android/src/org/briarproject/android/blogs/FeedFragment.java @@ -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; diff --git a/briar-api/src/org/briarproject/api/blogs/Blog.java b/briar-api/src/org/briarproject/api/blogs/Blog.java index 153eb6e27..3de97f5ea 100644 --- a/briar-api/src/org/briarproject/api/blogs/Blog.java +++ b/briar-api/src/org/briarproject/api/blogs/Blog.java @@ -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(); + } + } diff --git a/briar-api/src/org/briarproject/api/blogs/BlogConstants.java b/briar-api/src/org/briarproject/api/blogs/BlogConstants.java index e88fb182c..19adcefbd 100644 --- a/briar-api/src/org/briarproject/api/blogs/BlogConstants.java +++ b/briar-api/src/org/briarproject/api/blogs/BlogConstants.java @@ -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"; diff --git a/briar-api/src/org/briarproject/api/blogs/BlogFactory.java b/briar-api/src/org/briarproject/api/blogs/BlogFactory.java index 585d0700c..f730f4367 100644 --- a/briar-api/src/org/briarproject/api/blogs/BlogFactory.java +++ b/briar-api/src/org/briarproject/api/blogs/BlogFactory.java @@ -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; } diff --git a/briar-api/src/org/briarproject/api/blogs/BlogManager.java b/briar-api/src/org/briarproject/api/blogs/BlogManager.java index 2637779d4..62e4349dd 100644 --- a/briar-api/src/org/briarproject/api/blogs/BlogManager.java +++ b/briar-api/src/org/briarproject/api/blogs/BlogManager.java @@ -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; diff --git a/briar-api/src/org/briarproject/api/blogs/BlogSharingMessage.java b/briar-api/src/org/briarproject/api/blogs/BlogSharingMessage.java index 1465225e6..f97799ac5 100644 --- a/briar-api/src/org/briarproject/api/blogs/BlogSharingMessage.java +++ b/briar-api/src/org/briarproject/api/blogs/BlogSharingMessage.java @@ -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() { diff --git a/briar-api/src/org/briarproject/api/clients/BaseGroup.java b/briar-api/src/org/briarproject/api/clients/BaseGroup.java index f101106e3..f4f7636e1 100644 --- a/briar-api/src/org/briarproject/api/clients/BaseGroup.java +++ b/briar-api/src/org/briarproject/api/clients/BaseGroup.java @@ -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(); diff --git a/briar-api/src/org/briarproject/api/clients/NamedGroup.java b/briar-api/src/org/briarproject/api/clients/NamedGroup.java index f4b95fdc5..ed4589cae 100644 --- a/briar-api/src/org/briarproject/api/clients/NamedGroup.java +++ b/briar-api/src/org/briarproject/api/clients/NamedGroup.java @@ -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; } diff --git a/briar-api/src/org/briarproject/api/event/BlogInvitationResponseReceivedEvent.java b/briar-api/src/org/briarproject/api/event/BlogInvitationResponseReceivedEvent.java index fc4c04be2..6043885ad 100644 --- a/briar-api/src/org/briarproject/api/event/BlogInvitationResponseReceivedEvent.java +++ b/briar-api/src/org/briarproject/api/event/BlogInvitationResponseReceivedEvent.java @@ -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; - } } diff --git a/briar-core/src/org/briarproject/blogs/BlogFactoryImpl.java b/briar-core/src/org/briarproject/blogs/BlogFactoryImpl.java index 7853ec403..aed543f53 100644 --- a/briar-core/src/org/briarproject/blogs/BlogFactoryImpl.java +++ b/briar-core/src/org/briarproject/blogs/BlogFactoryImpl.java @@ -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 { byte[] descriptor = g.getDescriptor(); - // Blog Name, Author Name, Public Key + // Author Name, Public Key BdfList blog = clientHelper.toList(descriptor); - String name = blog.getString(0); Author a = - authorFactory.createAuthor(blog.getString(1), blog.getRaw(2)); - return new Blog(g, name, description, a); + authorFactory.createAuthor(blog.getString(0), blog.getRaw(1)); + return new Blog(g, a); } } diff --git a/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java b/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java index d31023c44..29fb1b5d1 100644 --- a/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java +++ b/briar-core/src/org/briarproject/blogs/BlogManagerImpl.java @@ -58,7 +58,6 @@ import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME; import static org.briarproject.api.blogs.BlogConstants.KEY_COMMENT; -import static org.briarproject.api.blogs.BlogConstants.KEY_DESCRIPTION; import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_MSG_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_PARENT_MSG_ID; @@ -113,16 +112,14 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, @Override public void createLocalState(Transaction txn) throws DbException { - // Ensure every identity does have its own personal blog - // TODO this can probably be removed once #446 is resolved and all users migrated to a new version - for (LocalAuthor a : db.getLocalAuthors(txn)) { - Blog b = blogFactory.createPersonalBlog(a); - Group g = b.getGroup(); - if (!db.containsGroup(txn, g.getId())) { - db.addGroup(txn, g); - for (ContactId c : db.getContacts(txn, a.getId())) { - db.setVisibleToContact(txn, c, g.getId(), true); - } + // Ensure that the local identity has its own personal blog + LocalAuthor la = identityManager.getLocalAuthor(txn); + Blog b = blogFactory.createBlog(la); + Group g = b.getGroup(); + if (!db.containsGroup(txn, g.getId())) { + db.addGroup(txn, g); + for (ContactId c : db.getContacts(txn, la.getId())) { + db.setVisibleToContact(txn, c, g.getId(), true); } } // Ensure that we have the personal blogs of all pre-existing contacts @@ -132,7 +129,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, @Override public void addingContact(Transaction txn, Contact c) throws DbException { // get personal blog of the contact - Blog b = blogFactory.createPersonalBlog(c.getAuthor()); + Blog b = blogFactory.createBlog(c.getAuthor()); Group g = b.getGroup(); if (!db.containsGroup(txn, g.getId())) { // add the personal blog of the contact @@ -141,7 +138,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, // share our personal blog with the new contact LocalAuthor a = db.getLocalAuthor(txn, c.getLocalAuthorId()); - Blog b2 = blogFactory.createPersonalBlog(a); + Blog b2 = blogFactory.createBlog(a); db.setVisibleToContact(txn, c.getId(), b2.getId(), true); } } @@ -149,7 +146,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, @Override public void removingContact(Transaction txn, Contact c) throws DbException { if (c != null) { - Blog b = blogFactory.createPersonalBlog(c.getAuthor()); + Blog b = blogFactory.createBlog(c.getAuthor()); db.removeGroup(txn, b.getGroup()); } } @@ -160,7 +157,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, // add a personal blog for the new identity LOG.info("New Personal Blog Added."); - Blog b = blogFactory.createPersonalBlog(a); + Blog b = blogFactory.createBlog(a); db.addGroup(txn, b.getGroup()); } @@ -169,7 +166,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, throws DbException { // remove the personal blog of that identity - Blog b = blogFactory.createPersonalBlog(a); + Blog b = blogFactory.createBlog(a); db.removeGroup(txn, b.getGroup()); } @@ -219,29 +216,6 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, return false; } - @Override - public Blog addBlog(LocalAuthor localAuthor, String name, - String description) throws DbException { - - Blog b = blogFactory - .createBlog(name, description, localAuthor); - BdfDictionary metadata = BdfDictionary.of( - new BdfEntry(KEY_DESCRIPTION, b.getDescription()) - ); - - Transaction txn = db.startTransaction(false); - try { - db.addGroup(txn, b.getGroup()); - clientHelper.mergeGroupMetadata(txn, b.getId(), metadata); - txn.setComplete(); - } catch (FormatException e) { - throw new DbException(e); - } finally { - db.endTransaction(txn); - } - return b; - } - @Override public boolean canBeRemoved(GroupId g) throws DbException { Transaction txn = db.startTransaction(true); @@ -453,8 +427,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, public Blog getBlog(Transaction txn, GroupId g) throws DbException { try { Group group = db.getGroup(txn, g); - String description = getBlogDescription(txn, g); - return blogFactory.parseBlog(group, description); + return blogFactory.parseBlog(group); } catch (FormatException e) { throw new DbException(e); } @@ -476,7 +449,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, @Override public Blog getPersonalBlog(Author author) { - return blogFactory.createPersonalBlog(author); + return blogFactory.createBlog(author); } @Override @@ -488,8 +461,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, try { groups = db.getGroups(txn, CLIENT_ID); for (Group g : groups) { - String description = getBlogDescription(txn, g.getId()); - blogs.add(blogFactory.parseBlog(g, description)); + blogs.add(blogFactory.parseBlog(g)); } txn.setComplete(); } finally { @@ -613,12 +585,6 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager, removeHooks.add(hook); } - private String getBlogDescription(Transaction txn, GroupId g) - throws DbException, FormatException { - BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g); - return d.getString(KEY_DESCRIPTION, ""); - } - private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, GroupId groupId, MessageId id) throws DbException, FormatException { BdfDictionary meta = diff --git a/briar-core/src/org/briarproject/blogs/BlogPostValidator.java b/briar-core/src/org/briarproject/blogs/BlogPostValidator.java index cd2347bc6..dfbe77098 100644 --- a/briar-core/src/org/briarproject/blogs/BlogPostValidator.java +++ b/briar-core/src/org/briarproject/blogs/BlogPostValidator.java @@ -100,7 +100,7 @@ class BlogPostValidator extends BdfMessageValidator { byte[] sig = body.getRaw(1); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), postBody); - Blog b = blogFactory.parseBlog(g, ""); // description doesn't matter + Blog b = blogFactory.parseBlog(g); Author a = b.getAuthor(); try { clientHelper.verifySignature(sig, a.getPublicKey(), signed); @@ -145,7 +145,7 @@ class BlogPostValidator extends BdfMessageValidator { BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), comment, pOriginalId, currentId); - Blog b = blogFactory.parseBlog(g, ""); // description doesn't matter + Blog b = blogFactory.parseBlog(g); Author a = b.getAuthor(); try { clientHelper.verifySignature(sig, a.getPublicKey(), signed); diff --git a/briar-core/src/org/briarproject/sharing/BlogInviteeSessionState.java b/briar-core/src/org/briarproject/sharing/BlogInviteeSessionState.java index 58ab24a0e..8298333ff 100644 --- a/briar-core/src/org/briarproject/sharing/BlogInviteeSessionState.java +++ b/briar-core/src/org/briarproject/sharing/BlogInviteeSessionState.java @@ -3,53 +3,40 @@ package org.briarproject.sharing; import org.briarproject.api.clients.SessionId; import org.briarproject.api.contact.ContactId; import org.briarproject.api.data.BdfDictionary; +import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.MessageId; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; + +import javax.annotation.concurrent.NotThreadSafe; 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; +@NotThreadSafe +@NotNullByDefault public class BlogInviteeSessionState extends InviteeSessionState { - private final String blogTitle; - private final String blogDesc; private final String blogAuthorName; private final byte[] blogPublicKey; public BlogInviteeSessionState(SessionId sessionId, MessageId storageId, GroupId groupId, State state, ContactId contactId, GroupId blogId, - String blogTitle, String blogDesc, String blogAuthorName, - byte[] blogPublicKey, @NotNull MessageId invitationId) { + String blogAuthorName, byte[] blogPublicKey, + @NotNull MessageId invitationId) { super(sessionId, storageId, groupId, state, contactId, blogId, invitationId); - - this.blogTitle = blogTitle; - this.blogDesc = blogDesc; this.blogAuthorName = blogAuthorName; this.blogPublicKey = blogPublicKey; } public BdfDictionary toBdfDictionary() { BdfDictionary d = super.toBdfDictionary(); - d.put(BLOG_TITLE, getBlogTitle()); - d.put(BLOG_DESC, getBlogDesc()); d.put(BLOG_AUTHOR_NAME, getBlogAuthorName()); d.put(BLOG_PUBLIC_KEY, getBlogPublicKey()); return d; } - public String getBlogTitle() { - return blogTitle; - } - - public String getBlogDesc() { - return blogDesc; - } - public String getBlogAuthorName() { return blogAuthorName; } diff --git a/briar-core/src/org/briarproject/sharing/BlogSharerSessionState.java b/briar-core/src/org/briarproject/sharing/BlogSharerSessionState.java index 5dd365cae..aa48bf498 100644 --- a/briar-core/src/org/briarproject/sharing/BlogSharerSessionState.java +++ b/briar-core/src/org/briarproject/sharing/BlogSharerSessionState.java @@ -3,52 +3,41 @@ package org.briarproject.sharing; import org.briarproject.api.clients.SessionId; import org.briarproject.api.contact.ContactId; import org.briarproject.api.data.BdfDictionary; +import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.MessageId; import org.jetbrains.annotations.Nullable; -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 javax.annotation.concurrent.NotThreadSafe; +import static org.briarproject.api.blogs.BlogConstants.BLOG_AUTHOR_NAME; +import static org.briarproject.api.blogs.BlogConstants.BLOG_PUBLIC_KEY; + +@NotThreadSafe +@NotNullByDefault public class BlogSharerSessionState extends SharerSessionState { - private final String blogTitle; - private final String blogDesc; private final String blogAuthorName; private final byte[] blogPublicKey; public BlogSharerSessionState(SessionId sessionId, MessageId storageId, GroupId groupId, State state, ContactId contactId, GroupId blogId, - String blogTitle, String blogDesc, String blogAuthorName, - byte[] blogPublicKey, @Nullable MessageId responseId) { + String blogAuthorName,byte[] blogPublicKey, + @Nullable MessageId responseId) { super(sessionId, storageId, groupId, state, contactId, blogId, responseId); - this.blogTitle = blogTitle; - this.blogDesc = blogDesc; this.blogAuthorName = blogAuthorName; this.blogPublicKey = blogPublicKey; } public BdfDictionary toBdfDictionary() { BdfDictionary d = super.toBdfDictionary(); - d.put(BLOG_TITLE, getBlogTitle()); - d.put(BLOG_DESC, getBlogDesc()); d.put(BLOG_AUTHOR_NAME, getBlogAuthorName()); d.put(BLOG_PUBLIC_KEY, getBlogPublicKey()); return d; } - public String getBlogTitle() { - return blogTitle; - } - - public String getBlogDesc() { - return blogDesc; - } - public String getBlogAuthorName() { return blogAuthorName; } diff --git a/briar-core/src/org/briarproject/sharing/BlogSharingManagerImpl.java b/briar-core/src/org/briarproject/sharing/BlogSharingManagerImpl.java index 9248393b3..5429ef96d 100644 --- a/briar-core/src/org/briarproject/sharing/BlogSharingManagerImpl.java +++ b/briar-core/src/org/briarproject/sharing/BlogSharingManagerImpl.java @@ -40,9 +40,7 @@ import java.security.SecureRandom; import javax.inject.Inject; 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_ID; import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID; @@ -54,8 +52,7 @@ class BlogSharingManagerImpl extends "bee438b5de0b3a685badc4e49d76e72d" + "21e01c4b569a775112756bdae267a028")); - @Inject - IdentityManager identityManager; + private final IdentityManager identityManager; private final BlogManager blogManager; private final SFactory sFactory; @@ -70,12 +67,14 @@ class BlogSharingManagerImpl extends BlogManager blogManager, ClientHelper clientHelper, Clock clock, DatabaseComponent db, MessageQueueManager messageQueueManager, MetadataEncoder metadataEncoder, MetadataParser metadataParser, - ContactGroupFactory contactGroupFactory, SecureRandom random) { + ContactGroupFactory contactGroupFactory, SecureRandom random, + IdentityManager identityManager) { super(db, messageQueueManager, clientHelper, metadataParser, metadataEncoder, random, contactGroupFactory, clock); this.blogManager = blogManager; + this.identityManager = identityManager; sFactory = new SFactory(authorFactory, blogFactory, blogManager); iFactory = new IFactory(); isFactory = new ISFactory(); @@ -175,9 +174,12 @@ class BlogSharingManagerImpl extends @Override public BdfList encode(Blog f) { - return BdfList.of(f.getName(), f.getDescription(), - BdfList.of(f.getAuthor().getName(), - f.getAuthor().getPublicKey())); + return BdfList.of( + BdfList.of( + f.getAuthor().getName(), + f.getAuthor().getPublicKey() + ) + ); } @Override @@ -189,19 +191,16 @@ class BlogSharingManagerImpl extends @Override public Blog parse(BdfList shareable) throws FormatException { Author author = authorFactory - .createAuthor(shareable.getList(2).getString(0), - shareable.getList(2).getRaw(1)); - return blogFactory - .createBlog(shareable.getString(0), shareable.getString(1), - author); + .createAuthor(shareable.getList(0).getString(0), + shareable.getList(0).getRaw(1)); + return blogFactory.createBlog(author); } @Override public Blog parse(BlogInvitation msg) { Author author = authorFactory.createAuthor(msg.getBlogAuthorName(), msg.getBlogPublicKey()); - return blogFactory - .createBlog(msg.getBlogTitle(), msg.getBlogDesc(), author); + return blogFactory.createBlog(author); } @Override @@ -209,9 +208,7 @@ class BlogSharingManagerImpl extends Author author = authorFactory .createAuthor(state.getBlogAuthorName(), state.getBlogPublicKey()); - return blogFactory - .createBlog(state.getBlogTitle(), state.getBlogDesc(), - author); + return blogFactory.createBlog(author); } @Override @@ -219,9 +216,7 @@ class BlogSharingManagerImpl extends Author author = authorFactory .createAuthor(state.getBlogAuthorName(), state.getBlogPublicKey()); - return blogFactory - .createBlog(state.getBlogTitle(), state.getBlogDesc(), - author); + return blogFactory.createBlog(author); } } @@ -237,8 +232,7 @@ class BlogSharingManagerImpl extends public BlogInvitation build(BlogSharerSessionState localState, long time) { return new BlogInvitation(localState.getGroupId(), - localState.getSessionId(), localState.getBlogTitle(), - localState.getBlogDesc(), localState.getBlogAuthorName(), + localState.getSessionId(), localState.getBlogAuthorName(), localState.getBlogPublicKey(), time, localState.getMessage()); } @@ -251,14 +245,12 @@ class BlogSharingManagerImpl extends MessageId storageId, GroupId groupId, InviteeSessionState.State state, ContactId contactId, GroupId blogId, BdfDictionary d) throws FormatException { - 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); MessageId invitationId = new MessageId(d.getRaw(INVITATION_ID)); return new BlogInviteeSessionState(sessionId, storageId, - groupId, state, contactId, blogId, blogTitle, blogDesc, - blogAuthorName, blogPublicKey, invitationId); + groupId, state, contactId, blogId, blogAuthorName, + blogPublicKey, invitationId); } @Override @@ -267,9 +259,9 @@ class BlogSharingManagerImpl extends InviteeSessionState.State state, ContactId contactId, Blog blog, MessageId invitationId) { return new BlogInviteeSessionState(sessionId, storageId, - groupId, state, contactId, blog.getId(), blog.getName(), - blog.getDescription(), blog.getAuthor().getName(), - blog.getAuthor().getPublicKey(), invitationId); + groupId, state, contactId, blog.getId(), + blog.getAuthor().getName(), blog.getAuthor().getPublicKey(), + invitationId); } } @@ -280,8 +272,6 @@ class BlogSharingManagerImpl extends MessageId storageId, GroupId groupId, SharerSessionState.State state, ContactId contactId, GroupId blogId, BdfDictionary d) throws FormatException { - 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); MessageId responseId = null; @@ -289,8 +279,8 @@ class BlogSharingManagerImpl extends if (responseIdBytes != null) responseId = new MessageId(responseIdBytes); return new BlogSharerSessionState(sessionId, storageId, - groupId, state, contactId, blogId, blogTitle, blogDesc, - blogAuthorName, blogPublicKey, responseId); + groupId, state, contactId, blogId, blogAuthorName, + blogPublicKey, responseId); } @Override @@ -299,9 +289,9 @@ class BlogSharingManagerImpl extends SharerSessionState.State state, ContactId contactId, Blog blog) { return new BlogSharerSessionState(sessionId, storageId, - groupId, state, contactId, blog.getId(), blog.getName(), - blog.getDescription(), blog.getAuthor().getName(), - blog.getAuthor().getPublicKey(), null); + groupId, state, contactId, blog.getId(), + blog.getAuthor().getName(), blog.getAuthor().getPublicKey(), + null); } } @@ -333,7 +323,6 @@ class BlogSharingManagerImpl extends @Override public BlogInvitationResponseReceivedEvent build( BlogSharerSessionState localState, boolean accept, long time) { - String title = localState.getBlogTitle(); ContactId c = localState.getContactId(); MessageId responseId = localState.getResponseId(); if (responseId == null) @@ -343,7 +332,7 @@ class BlogSharingManagerImpl extends localState.getSessionId(), localState.getGroupId(), localState.getContactId(), accept, time, false, false, false, false); - return new BlogInvitationResponseReceivedEvent(title, c, response); + return new BlogInvitationResponseReceivedEvent(c, response); } } } diff --git a/briar-core/src/org/briarproject/sharing/BlogSharingValidator.java b/briar-core/src/org/briarproject/sharing/BlogSharingValidator.java index 5f0988254..781555917 100644 --- a/briar-core/src/org/briarproject/sharing/BlogSharingValidator.java +++ b/briar-core/src/org/briarproject/sharing/BlogSharingValidator.java @@ -15,11 +15,7 @@ import org.briarproject.clients.BdfMessageValidator; import javax.inject.Inject; 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.blogs.BlogConstants.MAX_BLOG_DESC_LENGTH; -import static org.briarproject.api.blogs.BlogConstants.MAX_BLOG_TITLE_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH; import static org.briarproject.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.sharing.SharingConstants.INVITATION_MSG; @@ -52,30 +48,22 @@ class BlogSharingValidator extends BdfMessageValidator { checkLength(id, SessionId.LENGTH); if (type == SHARE_MSG_TYPE_INVITATION) { - checkSize(body, 5, 6); + checkSize(body, 3, 4); - String name = body.getString(2); - checkLength(name, 1, MAX_BLOG_TITLE_LENGTH); - - String desc = body.getString(3); - checkLength(desc, 0, MAX_BLOG_DESC_LENGTH); - - BdfList author = body.getList(4); + BdfList author = body.getList(2); checkSize(author, 2); String authorName = author.getString(0); - checkLength(name, 1, MAX_AUTHOR_NAME_LENGTH); + checkLength(authorName, 1, MAX_AUTHOR_NAME_LENGTH); byte[] publicKey = author.getRaw(1); checkLength(publicKey, 1, MAX_PUBLIC_KEY_LENGTH); - d.put(BLOG_TITLE, name); - d.put(BLOG_DESC, desc); d.put(BLOG_AUTHOR_NAME, authorName); d.put(BLOG_PUBLIC_KEY, publicKey); - if (body.size() > 5) { - String msg = body.getString(5); + if (body.size() > 3) { + String msg = body.getString(3); checkLength(msg, 0, MAX_INVITATION_MESSAGE_LENGTH); d.put(INVITATION_MSG, msg); } diff --git a/briar-core/src/org/briarproject/sharing/InviteeSessionState.java b/briar-core/src/org/briarproject/sharing/InviteeSessionState.java index 1aa65b232..ec77dfe82 100644 --- a/briar-core/src/org/briarproject/sharing/InviteeSessionState.java +++ b/briar-core/src/org/briarproject/sharing/InviteeSessionState.java @@ -3,10 +3,13 @@ package org.briarproject.sharing; import org.briarproject.api.clients.SessionId; import org.briarproject.api.contact.ContactId; import org.briarproject.api.data.BdfDictionary; +import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.MessageId; import org.jetbrains.annotations.NotNull; +import javax.annotation.concurrent.NotThreadSafe; + import static org.briarproject.api.sharing.SharingConstants.INVITATION_ID; import static org.briarproject.api.sharing.SharingConstants.IS_SHARER; import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT; @@ -19,7 +22,8 @@ import static org.briarproject.sharing.InviteeSessionState.Action.LOCAL_LEAVE; import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_INVITATION; import static org.briarproject.sharing.InviteeSessionState.Action.REMOTE_LEAVE; -// This class is not thread-safe +@NotThreadSafe +@NotNullByDefault public abstract class InviteeSessionState extends SharingSessionState { private State state; diff --git a/briar-core/src/org/briarproject/sharing/SharerSessionState.java b/briar-core/src/org/briarproject/sharing/SharerSessionState.java index a56be9067..a7406f0b1 100644 --- a/briar-core/src/org/briarproject/sharing/SharerSessionState.java +++ b/briar-core/src/org/briarproject/sharing/SharerSessionState.java @@ -3,10 +3,13 @@ package org.briarproject.sharing; import org.briarproject.api.clients.SessionId; import org.briarproject.api.contact.ContactId; import org.briarproject.api.data.BdfDictionary; +import org.briarproject.api.nullsafety.NotNullByDefault; import org.briarproject.api.sync.GroupId; import org.briarproject.api.sync.MessageId; import org.jetbrains.annotations.Nullable; +import javax.annotation.concurrent.NotThreadSafe; + import static org.briarproject.api.sharing.SharingConstants.IS_SHARER; import static org.briarproject.api.sharing.SharingConstants.RESPONSE_ID; import static org.briarproject.api.sharing.SharingConstants.SHARE_MSG_TYPE_ABORT; @@ -20,7 +23,8 @@ import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_ACCEPT; import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_DECLINE; import static org.briarproject.sharing.SharerSessionState.Action.REMOTE_LEAVE; -// This class is not thread-safe +@NotThreadSafe +@NotNullByDefault public abstract class SharerSessionState extends SharingSessionState { private State state; @@ -58,6 +62,7 @@ public abstract class SharerSessionState extends SharingSessionState { this.msg = msg; } + @Nullable public String getMessage() { return this.msg; } diff --git a/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java b/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java index 736925ade..34c9749b5 100644 --- a/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java +++ b/briar-tests/src/org/briarproject/blogs/BlogManagerImplTest.java @@ -41,7 +41,6 @@ import static org.briarproject.TestUtils.getRandomId; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_ID; import static org.briarproject.api.blogs.BlogConstants.KEY_AUTHOR_NAME; -import static org.briarproject.api.blogs.BlogConstants.KEY_DESCRIPTION; import static org.briarproject.api.blogs.BlogConstants.KEY_PUBLIC_KEY; import static org.briarproject.api.blogs.BlogConstants.KEY_READ; import static org.briarproject.api.blogs.BlogConstants.KEY_TIMESTAMP; @@ -63,8 +62,6 @@ public class BlogManagerImplTest extends BriarTestCase { private final IdentityManager identityManager = context.mock(IdentityManager.class); private final ClientHelper clientHelper = context.mock(ClientHelper.class); - private final MetadataParser metadataParser = - context.mock(MetadataParser.class); private final ContactManager contactManager = context.mock(ContactManager.class); private final BlogFactory blogFactory = context.mock(BlogFactory.class); @@ -78,11 +75,12 @@ public class BlogManagerImplTest extends BriarTestCase { BlogPostFactory blogPostFactory; public BlogManagerImplTest() { + MetadataParser metadataParser = context.mock(MetadataParser.class); blogManager = new BlogManagerImpl(db, identityManager, clientHelper, metadataParser, contactManager, blogFactory, blogPostFactory); - blog1 = getBlog("Test Blog 1", "Test Description 1"); - blog2 = getBlog("Test Blog 2", "Test Description 2"); + blog1 = createBlog(); + blog2 = createBlog(); messageId = new MessageId(getRandomId()); message = new Message(messageId, blog1.getId(), 42, getRandomBytes(42)); } @@ -95,8 +93,7 @@ public class BlogManagerImplTest extends BriarTestCase { @Test public void testCreateLocalState() throws DbException { final Transaction txn = new Transaction(null, false); - final Collection localAuthors = - Collections.singletonList((LocalAuthor) blog1.getAuthor()); + final LocalAuthor localAuthor = (LocalAuthor) blog1.getAuthor(); final ContactId contactId = new ContactId(0); final Collection contactIds = @@ -107,9 +104,9 @@ public class BlogManagerImplTest extends BriarTestCase { final Collection contacts = Collections.singletonList(contact); context.checking(new Expectations() {{ - oneOf(db).getLocalAuthors(txn); - will(returnValue(localAuthors)); - oneOf(blogFactory).createPersonalBlog(blog1.getAuthor()); + oneOf(identityManager).getLocalAuthor(txn); + will(returnValue(localAuthor)); + oneOf(blogFactory).createBlog(blog1.getAuthor()); will(returnValue(blog1)); oneOf(db).containsGroup(txn, blog1.getId()); will(returnValue(false)); @@ -119,7 +116,7 @@ public class BlogManagerImplTest extends BriarTestCase { oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true); oneOf(db).getContacts(txn); will(returnValue(contacts)); - oneOf(blogFactory).createPersonalBlog(blog2.getAuthor()); + oneOf(blogFactory).createBlog(blog2.getAuthor()); will(returnValue(blog2)); oneOf(db).containsGroup(txn, blog2.getId()); will(returnValue(false)); @@ -127,7 +124,7 @@ public class BlogManagerImplTest extends BriarTestCase { oneOf(db).setVisibleToContact(txn, contactId, blog2.getId(), true); oneOf(db).getLocalAuthor(txn, blog1.getAuthor().getId()); will(returnValue(blog1.getAuthor())); - oneOf(blogFactory).createPersonalBlog(blog1.getAuthor()); + oneOf(blogFactory).createBlog(blog1.getAuthor()); will(returnValue(blog1)); oneOf(db).setVisibleToContact(txn, contactId, blog1.getId(), true); }}); @@ -145,7 +142,7 @@ public class BlogManagerImplTest extends BriarTestCase { blog1.getAuthor().getId(), true, true); context.checking(new Expectations() {{ - oneOf(blogFactory).createPersonalBlog(blog2.getAuthor()); + oneOf(blogFactory).createBlog(blog2.getAuthor()); will(returnValue(blog2)); oneOf(db).removeGroup(txn, blog2.getGroup()); }}); @@ -163,7 +160,7 @@ public class BlogManagerImplTest extends BriarTestCase { a.getPublicKey(), 0); context.checking(new Expectations() {{ - oneOf(blogFactory).createPersonalBlog(localAuthor); + oneOf(blogFactory).createBlog(localAuthor); will(returnValue(blog1)); oneOf(db).addGroup(txn, blog1.getGroup()); }}); @@ -181,7 +178,7 @@ public class BlogManagerImplTest extends BriarTestCase { a.getPublicKey(), 0); context.checking(new Expectations() {{ - oneOf(blogFactory).createPersonalBlog(localAuthor); + oneOf(blogFactory).createBlog(localAuthor); will(returnValue(blog1)); oneOf(db).removeGroup(txn, blog1.getGroup()); }}); @@ -226,35 +223,6 @@ public class BlogManagerImplTest extends BriarTestCase { assertEquals(blog1.getAuthor(), h.getAuthor()); } - @Test - public void testAddBlog() throws DbException, FormatException { - final Transaction txn = new Transaction(null, false); - Author a = blog1.getAuthor(); - final LocalAuthor localAuthor = - new LocalAuthor(a.getId(), a.getName(), a.getPublicKey(), - a.getPublicKey(), 0); - final BdfDictionary meta = BdfDictionary.of( - new BdfEntry(KEY_DESCRIPTION, blog1.getDescription()) - ); - - context.checking(new Expectations() {{ - oneOf(blogFactory) - .createBlog(blog1.getName(), blog1.getDescription(), - blog1.getAuthor()); - will(returnValue(blog1)); - oneOf(db).startTransaction(false); - will(returnValue(txn)); - oneOf(db).addGroup(txn, blog1.getGroup()); - oneOf(clientHelper).mergeGroupMetadata(txn, blog1.getId(), meta); - oneOf(db).endTransaction(txn); - }}); - - blogManager - .addBlog(localAuthor, blog1.getName(), blog1.getDescription()); - context.assertIsSatisfied(); - assertTrue(txn.isComplete()); - } - @Test public void testRemoveBlog() throws Exception { final Transaction txn = new Transaction(null, false); @@ -369,15 +337,12 @@ public class BlogManagerImplTest extends BriarTestCase { will(returnValue(txn)); oneOf(db).getGroup(txn, blog.getId()); will(returnValue(blog.getGroup())); - oneOf(clientHelper) - .getGroupMetadataAsDictionary(txn, blog.getId()); - will(returnValue(new BdfDictionary())); - oneOf(blogFactory).parseBlog(blog.getGroup(), ""); + oneOf(blogFactory).parseBlog(blog.getGroup()); will(returnValue(blog)); }}); } - private Blog getBlog(String name, String desc) { + private Blog createBlog() { final GroupId groupId = new GroupId(getRandomId()); final Group group = new Group(groupId, CLIENT_ID, getRandomBytes(42)); final AuthorId authorId = new AuthorId(getRandomId()); @@ -387,7 +352,7 @@ public class BlogManagerImplTest extends BriarTestCase { final LocalAuthor localAuthor = new LocalAuthor(authorId, "Author", publicKey, privateKey, created); - return new Blog(group, name, desc, localAuthor); + return new Blog(group, localAuthor); } private BdfDictionary authorToBdfDictionary(Author a) { diff --git a/briar-tests/src/org/briarproject/blogs/BlogPostValidatorTest.java b/briar-tests/src/org/briarproject/blogs/BlogPostValidatorTest.java index afb1b90b9..08943fc9f 100644 --- a/briar-tests/src/org/briarproject/blogs/BlogPostValidatorTest.java +++ b/briar-tests/src/org/briarproject/blogs/BlogPostValidatorTest.java @@ -50,23 +50,19 @@ public class BlogPostValidatorTest extends BriarTestCase { private final Mockery context = new Mockery(); private final Blog blog; - private final Author author; private final BdfDictionary authorDict; private final ClientId clientId; private final byte[] descriptor; private final Group group; private final Message message; private final BlogPostValidator validator; - private final CryptoComponent cryptoComponent = - context.mock(CryptoComponent.class); private final GroupFactory groupFactory = context.mock(GroupFactory.class); private final MessageFactory messageFactory = context.mock(MessageFactory.class); private final BlogFactory blogFactory = context.mock(BlogFactory.class); private final ClientHelper clientHelper = context.mock(ClientHelper.class); - private final Clock clock = new SystemClock(); + private final Author author; private final String body = TestUtils.getRandomString(42); - private final String contentType = "text/plain"; public BlogPostValidatorTest() { GroupId groupId = new GroupId(TestUtils.getRandomId()); @@ -82,7 +78,7 @@ public class BlogPostValidatorTest extends BriarTestCase { new BdfEntry(KEY_AUTHOR_NAME, author.getName()), new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey()) ); - blog = new Blog(group, "Test Blog", "", author); + blog = new Blog(group, author); MessageId messageId = new MessageId(TestUtils.getRandomId()); long timestamp = System.currentTimeMillis(); @@ -90,8 +86,10 @@ public class BlogPostValidatorTest extends BriarTestCase { message = new Message(messageId, group.getId(), timestamp, raw); MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class); - validator = new BlogPostValidator(groupFactory, messageFactory, - blogFactory, clientHelper, metadataEncoder, clock); + Clock clock = new SystemClock(); + validator = + new BlogPostValidator(groupFactory, messageFactory, blogFactory, + clientHelper, metadataEncoder, clock); context.assertIsSatisfied(); } @@ -115,7 +113,7 @@ public class BlogPostValidatorTest extends BriarTestCase { @Test(expected = FormatException.class) public void testValidateBlogPostWithoutAttachments() throws IOException, GeneralSecurityException { - BdfList content = BdfList.of(null, contentType, null, body); + BdfList content = BdfList.of(null, null, body); BdfList m = BdfList.of(POST.getInt(), content, null); validator.validateMessage(message, group, m).getDictionary(); @@ -124,7 +122,7 @@ public class BlogPostValidatorTest extends BriarTestCase { @Test(expected = FormatException.class) public void testValidateBlogPostWithoutSignature() throws IOException, GeneralSecurityException { - BdfList content = BdfList.of(null, contentType, null, body, null); + BdfList content = BdfList.of(null, null, body, null); BdfList m = BdfList.of(POST.getInt(), content, null); validator.validateMessage(message, group, m).getDictionary(); @@ -261,7 +259,7 @@ public class BlogPostValidatorTest extends BriarTestCase { private void expectCrypto(final BdfList signed, final byte[] sig) throws IOException, GeneralSecurityException { context.checking(new Expectations() {{ - oneOf(blogFactory).parseBlog(group, ""); + oneOf(blogFactory).parseBlog(group); will(returnValue(blog)); oneOf(clientHelper) .verifySignature(sig, author.getPublicKey(), signed);