Merge branch '595-clients-should-decide-whether-to-share-messages' into 'master'

Let clients decide whether to share messages or not

Before this MR, the `ValidationManager` was sharing all messages after they had been delivered. Now, it is within the client's responsibility whether to share messages or not. So far, only the Blog and the Forum client are sharing incoming messages.

Closes #595

See merge request !283
This commit is contained in:
akwizgran
2016-08-15 15:03:59 +00:00
7 changed files with 17 additions and 11 deletions

View File

@@ -69,6 +69,12 @@ public interface ClientHelper {
void mergeMessageMetadata(Transaction txn, MessageId m, void mergeMessageMetadata(Transaction txn, MessageId m,
BdfDictionary metadata) throws DbException, FormatException; BdfDictionary metadata) throws DbException, FormatException;
/**
* Marks the given message as shared or unshared with other contacts.
*/
void setMessageShared(Transaction txn, Message m, boolean shared)
throws DbException;
byte[] toByteArray(BdfDictionary dictionary) throws FormatException; byte[] toByteArray(BdfDictionary dictionary) throws FormatException;
byte[] toByteArray(BdfList list) throws FormatException; byte[] toByteArray(BdfList list) throws FormatException;

View File

@@ -162,6 +162,8 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
protected void incomingMessage(Transaction txn, Message m, BdfList list, protected void incomingMessage(Transaction txn, Message m, BdfList list,
BdfDictionary meta) throws DbException, FormatException { BdfDictionary meta) throws DbException, FormatException {
clientHelper.setMessageShared(txn, m, true);
GroupId groupId = m.getGroupId(); GroupId groupId = m.getGroupId();
BlogPostHeader h = getPostHeaderFromMetadata(txn, m.getId(), meta); BlogPostHeader h = getPostHeaderFromMetadata(txn, m.getId(), meta);
BlogPostAddedEvent event = BlogPostAddedEvent event =

View File

@@ -239,6 +239,12 @@ class ClientHelperImpl implements ClientHelper {
db.mergeMessageMetadata(txn, m, metadataEncoder.encode(metadata)); db.mergeMessageMetadata(txn, m, metadataEncoder.encode(metadata));
} }
@Override
public void setMessageShared(Transaction txn, Message m, boolean shared)
throws DbException {
db.setMessageShared(txn, m, shared);
}
@Override @Override
public byte[] toByteArray(BdfDictionary dictionary) throws FormatException { public byte[] toByteArray(BdfDictionary dictionary) throws FormatException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();

View File

@@ -78,6 +78,8 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
protected void incomingMessage(Transaction txn, Message m, BdfList body, protected void incomingMessage(Transaction txn, Message m, BdfList body,
BdfDictionary meta) throws DbException, FormatException { BdfDictionary meta) throws DbException, FormatException {
clientHelper.setMessageShared(txn, m, true);
ForumPostHeader post = getForumPostHeader(txn, m.getId(), meta); ForumPostHeader post = getForumPostHeader(txn, m.getId(), meta);
ForumPostReceivedEvent event = ForumPostReceivedEvent event =
new ForumPostReceivedEvent(post, m.getGroupId()); new ForumPostReceivedEvent(post, m.getGroupId());

View File

@@ -358,8 +358,6 @@ class ValidationManagerImpl implements ValidationManager, Service,
throw new InvalidMessageException( throw new InvalidMessageException(
"Deleted by Client"); "Deleted by Client");
} }
db.setMessageShared(txn, m, true);
db.setMessageState(txn, m, c, DELIVERED); db.setMessageState(txn, m, c, DELIVERED);
// deliver pending dependents // deliver pending dependents

View File

@@ -192,6 +192,7 @@ public class BlogManagerImplTest extends BriarTestCase {
); );
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(clientHelper).setMessageShared(txn, message, true);
oneOf(identityManager) oneOf(identityManager)
.getAuthorStatus(txn, blog1.getAuthor().getId()); .getAuthorStatus(txn, blog1.getAuthor().getId());
will(returnValue(VERIFIED)); will(returnValue(VERIFIED));

View File

@@ -119,7 +119,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Async delivery // Async delivery
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn2b)); will(returnValue(txn2b));
oneOf(db).setMessageShared(txn2b, message, true);
// Call the hook for the first message // Call the hook for the first message
oneOf(hook).incomingMessage(txn2b, message, metadata); oneOf(hook).incomingMessage(txn2b, message, metadata);
oneOf(db).getRawMessage(txn2b, messageId); oneOf(db).getRawMessage(txn2b, messageId);
@@ -209,7 +208,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver message in a new transaction // Deliver message in a new transaction
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn3)); will(returnValue(txn3));
oneOf(db).setMessageShared(txn3, message, true);
oneOf(db).setMessageState(txn3, message, clientId, DELIVERED); oneOf(db).setMessageState(txn3, message, clientId, DELIVERED);
oneOf(hook).incomingMessage(txn3, message, metadata); oneOf(hook).incomingMessage(txn3, message, metadata);
oneOf(db).getRawMessage(txn3, messageId); oneOf(db).getRawMessage(txn3, messageId);
@@ -233,7 +231,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver the dependent in a new transaction // Deliver the dependent in a new transaction
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn5)); will(returnValue(txn5));
oneOf(db).setMessageShared(txn5, message1, true);
oneOf(db).setMessageState(txn5, message1, clientId, DELIVERED); oneOf(db).setMessageState(txn5, message1, clientId, DELIVERED);
oneOf(hook).incomingMessage(txn5, message1, metadata); oneOf(hook).incomingMessage(txn5, message1, metadata);
oneOf(db).getRawMessage(txn5, messageId1); oneOf(db).getRawMessage(txn5, messageId1);
@@ -299,7 +296,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver the pending message // Deliver the pending message
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn3)); will(returnValue(txn3));
oneOf(db).setMessageShared(txn3, message, true);
oneOf(db).setMessageState(txn3, message, clientId, DELIVERED); oneOf(db).setMessageState(txn3, message, clientId, DELIVERED);
oneOf(hook).incomingMessage(txn3, message, metadata); oneOf(hook).incomingMessage(txn3, message, metadata);
oneOf(db).getRawMessage(txn3, messageId); oneOf(db).getRawMessage(txn3, messageId);
@@ -499,7 +495,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// async delivery // async delivery
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).setMessageShared(txn2, message, true);
// Call the hook // Call the hook
oneOf(hook).incomingMessage(txn2, message, metadata); oneOf(hook).incomingMessage(txn2, message, metadata);
oneOf(db).getRawMessage(txn2, messageId); oneOf(db).getRawMessage(txn2, messageId);
@@ -627,7 +622,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// async delivery // async delivery
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).setMessageShared(txn2, message, true);
// Call the hook // Call the hook
oneOf(hook).incomingMessage(txn2, message, metadata); oneOf(hook).incomingMessage(txn2, message, metadata);
oneOf(db).getRawMessage(txn2, messageId); oneOf(db).getRawMessage(txn2, messageId);
@@ -761,7 +755,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver first message // Deliver first message
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).setMessageShared(txn2, message, true);
oneOf(hook).incomingMessage(txn2, message, metadata); oneOf(hook).incomingMessage(txn2, message, metadata);
oneOf(db).getRawMessage(txn2, messageId); oneOf(db).getRawMessage(txn2, messageId);
will(returnValue(raw)); will(returnValue(raw));
@@ -784,7 +777,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver the pending message // Deliver the pending message
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn4)); will(returnValue(txn4));
oneOf(db).setMessageShared(txn4, message1, true);
oneOf(hook).incomingMessage(txn4, message1, metadata); oneOf(hook).incomingMessage(txn4, message1, metadata);
oneOf(db).getRawMessage(txn4, messageId1); oneOf(db).getRawMessage(txn4, messageId1);
will(returnValue(raw)); will(returnValue(raw));
@@ -842,7 +834,6 @@ public class ValidationManagerImplTest extends BriarTestCase {
// Deliver first message // Deliver first message
oneOf(db).startTransaction(false); oneOf(db).startTransaction(false);
will(returnValue(txn2)); will(returnValue(txn2));
oneOf(db).setMessageShared(txn2, message, true);
oneOf(hook).incomingMessage(txn2, message, metadata); oneOf(hook).incomingMessage(txn2, message, metadata);
oneOf(db).getRawMessage(txn2, messageId); oneOf(db).getRawMessage(txn2, messageId);
will(returnValue(raw)); will(returnValue(raw));