diff --git a/briar-android/AndroidManifest.xml b/briar-android/AndroidManifest.xml
index fc8fcd528..ad48f4aea 100644
--- a/briar-android/AndroidManifest.xml
+++ b/briar-android/AndroidManifest.xml
@@ -42,15 +42,15 @@
+ android:label="@string/app_name" >
+ android:label="@string/app_name" >
+ android:label="@string/app_name" >
+ #FFFFFF
#FFFFFF
#FFFFFF
#CCCCCC
diff --git a/briar-android/res/values/strings.xml b/briar-android/res/values/strings.xml
index 14258e047..5881c29be 100644
--- a/briar-android/res/values/strings.xml
+++ b/briar-android/res/values/strings.xml
@@ -44,7 +44,8 @@
To: %1$s
New Message
To:
- Groups
(Anonymous)
+ Groups
New Post
+ Blogs
diff --git a/briar-android/src/net/sf/briar/android/HomeScreenActivity.java b/briar-android/src/net/sf/briar/android/HomeScreenActivity.java
index 02cea07ef..3cf515905 100644
--- a/briar-android/src/net/sf/briar/android/HomeScreenActivity.java
+++ b/briar-android/src/net/sf/briar/android/HomeScreenActivity.java
@@ -89,8 +89,12 @@ public class HomeScreenActivity extends BriarActivity {
groupsButton.setText(R.string.groups_button);
groupsButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
- startActivity(new Intent(HomeScreenActivity.this,
- GroupListActivity.class));
+ Intent i = new Intent(HomeScreenActivity.this,
+ GroupListActivity.class);
+ i.putExtra("net.sf.briar.RESTRICTED", false);
+ i.putExtra("net.sf.briar.TITLE",
+ getResources().getString(R.string.groups_title));
+ startActivity(i);
}
});
buttons.add(groupsButton);
@@ -99,11 +103,16 @@ public class HomeScreenActivity extends BriarActivity {
blogsButton.setLayoutParams(matchParent);
blogsButton.setBackgroundResource(0);
blogsButton.setCompoundDrawablesWithIntrinsicBounds(0,
- R.drawable.social_share, 0, 0);
+ R.drawable.social_blog, 0, 0);
blogsButton.setText(R.string.blogs_button);
blogsButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
- // FIXME: Hook this button up to an activity
+ Intent i = new Intent(HomeScreenActivity.this,
+ GroupListActivity.class);
+ i.putExtra("net.sf.briar.RESTRICTED", true);
+ i.putExtra("net.sf.briar.TITLE",
+ getResources().getString(R.string.blogs_title));
+ startActivity(i);
}
});
buttons.add(blogsButton);
@@ -138,6 +147,8 @@ public class HomeScreenActivity extends BriarActivity {
grid.setLayoutParams(matchParent);
grid.setGravity(CENTER);
grid.setPadding(5, 5, 5, 5);
+ grid.setBackgroundColor(getResources().getColor(
+ R.color.home_screen_background));
grid.setNumColumns(2);
grid.setAdapter(new BaseAdapter() {
diff --git a/briar-android/src/net/sf/briar/android/groups/GroupActivity.java b/briar-android/src/net/sf/briar/android/groups/GroupActivity.java
index deff171b8..43af87cf9 100644
--- a/briar-android/src/net/sf/briar/android/groups/GroupActivity.java
+++ b/briar-android/src/net/sf/briar/android/groups/GroupActivity.java
@@ -51,6 +51,7 @@ OnClickListener, OnItemClickListener {
private final BriarServiceConnection serviceConnection =
new BriarServiceConnection();
+ private boolean restricted = false;
private String groupName = null;
private GroupAdapter adapter = null;
private ListView list = null;
@@ -65,6 +66,7 @@ OnClickListener, OnItemClickListener {
super.onCreate(null);
Intent i = getIntent();
+ restricted = i.getBooleanExtra("net.sf.briar.RESTRICTED", false);
byte[] id = i.getByteArrayExtra("net.sf.briar.GROUP_ID");
if(id == null) throw new IllegalStateException();
groupId = new GroupId(id);
@@ -194,7 +196,8 @@ OnClickListener, OnItemClickListener {
public void eventOccurred(DatabaseEvent e) {
if(e instanceof GroupMessageAddedEvent) {
- if(((GroupMessageAddedEvent) e).getGroupId().equals(groupId)) {
+ GroupMessageAddedEvent g = (GroupMessageAddedEvent) e;
+ if(g.getGroup().getId().equals(groupId)) {
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
loadHeaders();
}
@@ -205,7 +208,8 @@ OnClickListener, OnItemClickListener {
if(LOG.isLoggable(INFO)) LOG.info("Rating changed, reloading");
loadHeaders();
} else if(e instanceof SubscriptionRemovedEvent) {
- if(((SubscriptionRemovedEvent) e).getGroupId().equals(groupId)) {
+ SubscriptionRemovedEvent s = (SubscriptionRemovedEvent) e;
+ if(s.getGroup().getId().equals(groupId)) {
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
finishOnUiThread();
}
@@ -214,6 +218,7 @@ OnClickListener, OnItemClickListener {
public void onClick(View view) {
Intent i = new Intent(this, WriteGroupMessageActivity.class);
+ i.putExtra("net.sf.briar.RESTRICTED", restricted);
i.putExtra("net.sf.briar.GROUP_ID", groupId.getBytes());
startActivity(i);
}
diff --git a/briar-android/src/net/sf/briar/android/groups/GroupListActivity.java b/briar-android/src/net/sf/briar/android/groups/GroupListActivity.java
index f1885f610..70d797bb3 100644
--- a/briar-android/src/net/sf/briar/android/groups/GroupListActivity.java
+++ b/briar-android/src/net/sf/briar/android/groups/GroupListActivity.java
@@ -1,6 +1,8 @@
package net.sf.briar.android.groups;
+import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
+import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -26,6 +28,7 @@ import net.sf.briar.android.BriarService;
import net.sf.briar.android.BriarService.BriarServiceConnection;
import net.sf.briar.android.widgets.CommonLayoutParams;
import net.sf.briar.android.widgets.HorizontalBorder;
+import net.sf.briar.android.widgets.HorizontalSpace;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.android.DatabaseUiExecutor;
import net.sf.briar.api.crypto.CryptoComponent;
@@ -67,6 +70,7 @@ implements OnClickListener, DatabaseListener {
private GroupListAdapter adapter = null;
private ListView list = null;
+ private ImageButton newGroupButton = null, composeButton = null;
// Fields that are accessed from DB threads must be volatile
@Inject private volatile CryptoComponent crypto;
@@ -76,6 +80,7 @@ implements OnClickListener, DatabaseListener {
@Inject private volatile AuthorFactory authorFactory;
@Inject private volatile GroupFactory groupFactory;
@Inject private volatile MessageFactory messageFactory;
+ private volatile boolean restricted = false;
@Override
public void onCreate(Bundle state) {
@@ -85,6 +90,12 @@ implements OnClickListener, DatabaseListener {
layout.setOrientation(VERTICAL);
layout.setGravity(CENTER_HORIZONTAL);
+ Intent i = getIntent();
+ restricted = i.getBooleanExtra("net.sf.briar.RESTRICTED", false);
+ String title = i.getStringExtra("net.sf.briar.TITLE");
+ if(title == null) throw new IllegalStateException();
+ setTitle(title);
+
adapter = new GroupListAdapter(this);
list = new ListView(this);
// Give me all the width and all the unused height
@@ -95,11 +106,28 @@ implements OnClickListener, DatabaseListener {
layout.addView(new HorizontalBorder(this));
- ImageButton newGroupButton = new ImageButton(this);
+ LinearLayout footer = new LinearLayout(this);
+ footer.setLayoutParams(CommonLayoutParams.MATCH_WRAP);
+ footer.setOrientation(HORIZONTAL);
+ footer.setGravity(CENTER);
+ footer.addView(new HorizontalSpace(this));
+
+ newGroupButton = new ImageButton(this);
newGroupButton.setBackgroundResource(0);
- newGroupButton.setImageResource(R.drawable.social_new_chat);
+ if(restricted)
+ newGroupButton.setImageResource(R.drawable.social_new_blog);
+ else newGroupButton.setImageResource(R.drawable.social_new_chat);
newGroupButton.setOnClickListener(this);
- layout.addView(newGroupButton);
+ footer.addView(newGroupButton);
+ footer.addView(new HorizontalSpace(this));
+
+ composeButton = new ImageButton(this);
+ composeButton.setBackgroundResource(0);
+ composeButton.setImageResource(R.drawable.content_new_email);
+ composeButton.setOnClickListener(this);
+ footer.addView(composeButton);
+ footer.addView(new HorizontalSpace(this));
+ layout.addView(footer);
setContentView(layout);
@@ -146,7 +174,11 @@ implements OnClickListener, DatabaseListener {
Group group1 = groupFactory.createGroup("Godwin's Lore");
db.subscribe(group1);
db.setVisibility(group1.getId(), Arrays.asList(contactId));
- // Insert some text messages to the groups
+ Group group2 = groupFactory.createGroup(
+ "All Kids Love Blog", publicKey);
+ db.subscribe(group2);
+ db.setVisibility(group2.getId(), Arrays.asList(contactId));
+ // Insert some text messages to the unrestricted groups
for(int i = 0; i < 20; i++) {
String body;
if(i % 3 == 0) {
@@ -197,6 +229,43 @@ implements OnClickListener, DatabaseListener {
m = messageFactory.createAnonymousMessage(m.getId(),
group1, "text/plain", body.getBytes("UTF-8"));
db.addLocalGroupMessage(m);
+ // Insert some text messages to the restricted group
+ for(int i = 0; i < 20; i++) {
+ if(i % 3 == 0) {
+ body = "Message " + i + " is short.";
+ } else {
+ body = "Message " + i + " is long enough to wrap"
+ + " onto a second line on some screens.";
+ }
+ now = System.currentTimeMillis();
+ if(i % 5 == 0) {
+ m = messageFactory.createAnonymousMessage(null,
+ group2, privateKey, "text/plain",
+ body.getBytes("UTF-8"));
+ } else if(i % 5 == 2) {
+ m = messageFactory.createPseudonymousMessage(null,
+ group2, privateKey, author, privateKey,
+ "text/plain", body.getBytes("UTF-8"));
+ } else {
+ m = messageFactory.createPseudonymousMessage(null,
+ group2, privateKey, author1, privateKey,
+ "text/plain", body.getBytes("UTF-8"));
+ }
+ duration = System.currentTimeMillis() - now;
+ if(LOG.isLoggable(INFO)) {
+ LOG.info("Message creation took " +
+ duration + " ms");
+ }
+ now = System.currentTimeMillis();
+ if(Math.random() < 0.5) db.addLocalGroupMessage(m);
+ else db.receiveMessage(contactId, m);
+ db.setReadFlag(m.getId(), i % 4 == 0);
+ duration = System.currentTimeMillis() - now;
+ if(LOG.isLoggable(INFO)) {
+ LOG.info("Message storage took " +
+ duration + " ms");
+ }
+ }
} catch(DbException e) {
if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
@@ -233,8 +302,8 @@ implements OnClickListener, DatabaseListener {
new ArrayList();
long now = System.currentTimeMillis();
for(Group g : db.getSubscriptions()) {
- // Filter out restricted groups
- if(g.getPublicKey() != null) continue;
+ // Filter out restricted/unrestricted groups
+ if(g.isRestricted() != restricted) continue;
try {
// Load the headers from the database
Collection headers =
@@ -322,41 +391,52 @@ implements OnClickListener, DatabaseListener {
}
public void onClick(View view) {
- startActivity(new Intent(this, WriteGroupMessageActivity.class));
+ if(view == newGroupButton) {
+ // FIXME: Hook this button up to an activity
+ } else if(view == composeButton) {
+ Intent i = new Intent(this, WriteGroupMessageActivity.class);
+ i.putExtra("net.sf.briar.RESTRICTED", restricted);
+ startActivity(i);
+ }
}
public void eventOccurred(DatabaseEvent e) {
if(e instanceof GroupMessageAddedEvent) {
- if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
- loadHeaders(((GroupMessageAddedEvent) e).getGroupId());
+ Group g = ((GroupMessageAddedEvent) e).getGroup();
+ if(g.isRestricted() == restricted) {
+ if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
+ loadHeaders(g);
+ }
} else if(e instanceof MessageExpiredEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
loadHeaders(); // FIXME: Don't reload everything
} else if(e instanceof SubscriptionRemovedEvent) {
// Reload the group, expecting NoSuchSubscriptionException
- if(LOG.isLoggable(INFO)) LOG.info("Group removed, reloading");
- loadHeaders(((SubscriptionRemovedEvent) e).getGroupId());
+ Group g = ((SubscriptionRemovedEvent) e).getGroup();
+ if(g.isRestricted() == restricted) {
+ if(LOG.isLoggable(INFO)) LOG.info("Group removed, reloading");
+ loadHeaders(g);
+ }
}
}
- private void loadHeaders(final GroupId g) {
+ private void loadHeaders(final Group g) {
dbUiExecutor.execute(new Runnable() {
public void run() {
try {
serviceConnection.waitForStartup();
long now = System.currentTimeMillis();
- Group group = db.getGroup(g);
Collection headers =
- db.getMessageHeaders(g);
+ db.getMessageHeaders(g.getId());
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
LOG.info("Partial load took " + duration + " ms");
CountDownLatch latch = new CountDownLatch(1);
- displayHeaders(latch, group, headers);
+ displayHeaders(latch, g, headers);
latch.await();
} catch(NoSuchSubscriptionException e) {
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
- removeGroup(g);
+ removeGroup(g.getId());
} catch(DbException e) {
if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
diff --git a/briar-android/src/net/sf/briar/android/groups/WriteGroupMessageActivity.java b/briar-android/src/net/sf/briar/android/groups/WriteGroupMessageActivity.java
index 6dd8792ea..38b8ce59d 100644
--- a/briar-android/src/net/sf/briar/android/groups/WriteGroupMessageActivity.java
+++ b/briar-android/src/net/sf/briar/android/groups/WriteGroupMessageActivity.java
@@ -53,6 +53,7 @@ implements OnClickListener, OnItemSelectedListener {
new BriarServiceConnection();
@Inject private BundleEncrypter bundleEncrypter;
+ private boolean restricted = false;
private GroupNameSpinnerAdapter adapter = null;
private Spinner spinner = null;
private ImageButton sendButton = null;
@@ -71,6 +72,7 @@ implements OnClickListener, OnItemSelectedListener {
super.onCreate(null);
Intent i = getIntent();
+ restricted = i.getBooleanExtra("net.sf.briar.RESTRICTED", false);
byte[] id = i.getByteArrayExtra("net.sf.briar.GROUP_ID");
if(id != null) groupId = new GroupId(id);
id = i.getByteArrayExtra("net.sf.briar.PARENT_ID");
@@ -123,6 +125,7 @@ implements OnClickListener, OnItemSelectedListener {
serviceConnection, 0);
}
+ // FIXME: If restricted, only load groups the user can post to
private void loadGroupList() {
dbExecutor.execute(new Runnable() {
public void run() {
@@ -144,6 +147,7 @@ implements OnClickListener, OnItemSelectedListener {
runOnUiThread(new Runnable() {
public void run() {
for(Group g : groups) {
+ if(g.isRestricted() != restricted) continue;
if(g.getId().equals(groupId)) {
group = g;
spinner.setSelection(adapter.getCount());
diff --git a/briar-api/src/net/sf/briar/api/db/DatabaseComponent.java b/briar-api/src/net/sf/briar/api/db/DatabaseComponent.java
index 3e466d191..add29d7ab 100644
--- a/briar-api/src/net/sf/briar/api/db/DatabaseComponent.java
+++ b/briar-api/src/net/sf/briar/api/db/DatabaseComponent.java
@@ -327,5 +327,5 @@ public interface DatabaseComponent {
* Unsubscribes from the given group. Any messages belonging to the group
* are deleted from the database.
*/
- void unsubscribe(GroupId g) throws DbException;
+ void unsubscribe(Group g) throws DbException;
}
diff --git a/briar-api/src/net/sf/briar/api/db/event/GroupMessageAddedEvent.java b/briar-api/src/net/sf/briar/api/db/event/GroupMessageAddedEvent.java
index 0a66d81f4..40c551030 100644
--- a/briar-api/src/net/sf/briar/api/db/event/GroupMessageAddedEvent.java
+++ b/briar-api/src/net/sf/briar/api/db/event/GroupMessageAddedEvent.java
@@ -1,20 +1,20 @@
package net.sf.briar.api.db.event;
-import net.sf.briar.api.messaging.GroupId;
+import net.sf.briar.api.messaging.Group;
/** An event that is broadcast when a group message is added to the database. */
public class GroupMessageAddedEvent extends DatabaseEvent {
- private final GroupId groupId;
+ private final Group group;
private final boolean incoming;
- public GroupMessageAddedEvent(GroupId groupId, boolean incoming) {
- this.groupId = groupId;
+ public GroupMessageAddedEvent(Group group, boolean incoming) {
+ this.group = group;
this.incoming = incoming;
}
- public GroupId getGroupId() {
- return groupId;
+ public Group getGroup() {
+ return group;
}
public boolean isIncoming() {
diff --git a/briar-api/src/net/sf/briar/api/db/event/SubscriptionRemovedEvent.java b/briar-api/src/net/sf/briar/api/db/event/SubscriptionRemovedEvent.java
index df7f5bf93..2957304ef 100644
--- a/briar-api/src/net/sf/briar/api/db/event/SubscriptionRemovedEvent.java
+++ b/briar-api/src/net/sf/briar/api/db/event/SubscriptionRemovedEvent.java
@@ -1,17 +1,17 @@
package net.sf.briar.api.db.event;
-import net.sf.briar.api.messaging.GroupId;
+import net.sf.briar.api.messaging.Group;
/** An event that is broadcast when the user unsubscribes from a group. */
public class SubscriptionRemovedEvent extends DatabaseEvent {
- private final GroupId groupId;
+ private final Group group;
- public SubscriptionRemovedEvent(GroupId groupId) {
- this.groupId = groupId;
+ public SubscriptionRemovedEvent(Group group) {
+ this.group = group;
}
- public GroupId getGroupId() {
- return groupId;
+ public Group getGroup() {
+ return group;
}
}
diff --git a/briar-api/src/net/sf/briar/api/messaging/Group.java b/briar-api/src/net/sf/briar/api/messaging/Group.java
index 3e1bf6466..71d260ac8 100644
--- a/briar-api/src/net/sf/briar/api/messaging/Group.java
+++ b/briar-api/src/net/sf/briar/api/messaging/Group.java
@@ -23,6 +23,11 @@ public class Group {
return name;
}
+ /** Returns true if the group is restricted. */
+ public boolean isRestricted() {
+ return publicKey != null;
+ }
+
/**
* If the group is restricted, returns the public key that is used to
* authorise all messages sent to the group. Otherwise returns null.
diff --git a/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java b/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java
index 99dc9c162..f5184749c 100644
--- a/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java
+++ b/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java
@@ -287,10 +287,8 @@ DatabaseCleaner.Callback {
} finally {
contactLock.readLock().unlock();
}
- if(added) {
- GroupId g = m.getGroup().getId();
- callListeners(new GroupMessageAddedEvent(g, false));
- }
+ if(added)
+ callListeners(new GroupMessageAddedEvent(m.getGroup(), false));
}
/**
@@ -1357,7 +1355,7 @@ DatabaseCleaner.Callback {
if(added) {
Group g = m.getGroup();
if(g == null) callListeners(new PrivateMessageAddedEvent(c, true));
- else callListeners(new GroupMessageAddedEvent(g.getId(), true));
+ else callListeners(new GroupMessageAddedEvent(g, true));
}
}
@@ -1855,7 +1853,7 @@ DatabaseCleaner.Callback {
return added;
}
- public void unsubscribe(GroupId g) throws DbException {
+ public void unsubscribe(Group g) throws DbException {
Collection affected;
messageLock.writeLock().lock();
try {
@@ -1863,10 +1861,11 @@ DatabaseCleaner.Callback {
try {
T txn = db.startTransaction();
try {
- if(!db.containsSubscription(txn, g))
+ GroupId id = g.getId();
+ if(!db.containsSubscription(txn, id))
throw new NoSuchSubscriptionException();
- affected = db.getVisibility(txn, g);
- db.removeSubscription(txn, g);
+ affected = db.getVisibility(txn, id);
+ db.removeSubscription(txn, id);
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);
diff --git a/briar-core/src/net/sf/briar/db/JdbcDatabase.java b/briar-core/src/net/sf/briar/db/JdbcDatabase.java
index 854fe74e7..c9834381a 100644
--- a/briar-core/src/net/sf/briar/db/JdbcDatabase.java
+++ b/briar-core/src/net/sf/briar/db/JdbcDatabase.java
@@ -823,7 +823,8 @@ abstract class JdbcDatabase implements Database {
ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getId().getBytes());
ps.setString(2, g.getName());
- ps.setBytes(3, g.getPublicKey());
+ if(g.isRestricted()) ps.setBytes(3, g.getPublicKey());
+ else ps.setNull(3, BINARY);
int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();
ps.close();
@@ -3029,9 +3030,8 @@ abstract class JdbcDatabase implements Database {
for(Group g : subs) {
ps.setBytes(2, g.getId().getBytes());
ps.setString(3, g.getName());
- byte[] key = g.getPublicKey();
- if(key == null) ps.setNull(4, BINARY);
- else ps.setBytes(4, key);
+ if(g.isRestricted()) ps.setBytes(4, g.getPublicKey());
+ else ps.setNull(4, BINARY);
ps.addBatch();
}
int[] affectedBatch = ps.executeBatch();
diff --git a/briar-core/src/net/sf/briar/messaging/MessageFactoryImpl.java b/briar-core/src/net/sf/briar/messaging/MessageFactoryImpl.java
index a66b3b6bf..a6c93b06e 100644
--- a/briar-core/src/net/sf/briar/messaging/MessageFactoryImpl.java
+++ b/briar-core/src/net/sf/briar/messaging/MessageFactoryImpl.java
@@ -99,8 +99,7 @@ class MessageFactoryImpl implements MessageFactory {
// Validate the arguments
if((author == null) != (authorKey == null))
throw new IllegalArgumentException();
- if((group == null || group.getPublicKey() == null)
- != (groupKey == null))
+ if((group == null || !group.isRestricted()) != (groupKey == null))
throw new IllegalArgumentException();
if(contentType.getBytes("UTF-8").length > MAX_CONTENT_TYPE_LENGTH)
throw new IllegalArgumentException();
@@ -182,9 +181,8 @@ class MessageFactoryImpl implements MessageFactory {
private void writeGroup(Writer w, Group g) throws IOException {
w.writeStructId(GROUP);
w.writeString(g.getName());
- byte[] publicKey = g.getPublicKey();
- if(publicKey == null) w.writeNull();
- else w.writeBytes(publicKey);
+ if(g.isRestricted()) w.writeBytes(g.getPublicKey());
+ else w.writeNull();
}
private void writeAuthor(Writer w, Author a) throws IOException {
diff --git a/briar-core/src/net/sf/briar/messaging/MessageReader.java b/briar-core/src/net/sf/briar/messaging/MessageReader.java
index de0bf74ac..73c055051 100644
--- a/briar-core/src/net/sf/briar/messaging/MessageReader.java
+++ b/briar-core/src/net/sf/briar/messaging/MessageReader.java
@@ -93,7 +93,7 @@ class MessageReader implements StructReader {
int signedByGroup = (int) counting.getCount();
// Read the group's signature, if there is one
byte[] groupSig = null;
- if(group == null || group.getPublicKey() == null) r.readNull();
+ if(group == null || !group.isRestricted()) r.readNull();
else groupSig = r.readBytes(MAX_SIGNATURE_LENGTH);
// That's all, folks
r.removeConsumer(counting);
diff --git a/briar-core/src/net/sf/briar/messaging/MessageVerifierImpl.java b/briar-core/src/net/sf/briar/messaging/MessageVerifierImpl.java
index 22abc2655..de57bbb3a 100644
--- a/briar-core/src/net/sf/briar/messaging/MessageVerifierImpl.java
+++ b/briar-core/src/net/sf/briar/messaging/MessageVerifierImpl.java
@@ -46,7 +46,7 @@ class MessageVerifierImpl implements MessageVerifier {
}
// Verify the group's signature, if there is one
Group group = m.getGroup();
- if(group != null && group.getPublicKey() != null) {
+ if(group != null && group.isRestricted()) {
PublicKey k = keyParser.parsePublicKey(group.getPublicKey());
signature.initVerify(k);
signature.update(raw, 0, m.getLengthSignedByGroup());
diff --git a/briar-core/src/net/sf/briar/messaging/PacketWriterImpl.java b/briar-core/src/net/sf/briar/messaging/PacketWriterImpl.java
index 0e54cec9b..067881cb5 100644
--- a/briar-core/src/net/sf/briar/messaging/PacketWriterImpl.java
+++ b/briar-core/src/net/sf/briar/messaging/PacketWriterImpl.java
@@ -133,9 +133,8 @@ class PacketWriterImpl implements PacketWriter {
for(Group g : u.getGroups()) {
w.writeStructId(GROUP);
w.writeString(g.getName());
- byte[] publicKey = g.getPublicKey();
- if(publicKey == null) w.writeNull();
- else w.writeBytes(publicKey);
+ if(g.isRestricted()) w.writeBytes(g.getPublicKey());
+ else w.writeNull();
}
w.writeListEnd();
w.writeInt64(u.getVersion());
diff --git a/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java b/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java
index e59726b0f..61bc729a9 100644
--- a/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java
+++ b/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java
@@ -204,8 +204,8 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
db.subscribe(group); // Second time - not called
assertEquals(Collections.emptyList(), db.getMessageHeaders(groupId));
assertEquals(Arrays.asList(groupId), db.getSubscriptions());
- db.unsubscribe(groupId); // Listeners called
- db.removeContact(contactId); // Listeners called
+ db.unsubscribe(group);
+ db.removeContact(contactId);
db.removeListener(listener);
db.close();
@@ -707,7 +707,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
} catch(NoSuchSubscriptionException expected) {}
try {
- db.unsubscribe(groupId);
+ db.unsubscribe(group);
fail();
} catch(NoSuchSubscriptionException expected) {}