Do not require an entire Message for the MessageSharedEvent

This commit is contained in:
Torsten Grote
2016-08-16 10:56:51 -03:00
parent eb3da2aac9
commit 743fc7dd1f
8 changed files with 16 additions and 16 deletions

View File

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

View File

@@ -437,7 +437,7 @@ public interface DatabaseComponent {
/** /**
* Marks the given message as shared or unshared. * Marks the given message as shared or unshared.
*/ */
void setMessageShared(Transaction txn, Message m, boolean shared) void setMessageShared(Transaction txn, MessageId m, boolean shared)
throws DbException; throws DbException;
/** /**

View File

@@ -1,17 +1,17 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import org.briarproject.api.sync.Message; import org.briarproject.api.sync.MessageId;
/** An event that is broadcast when a message is shared. */ /** An event that is broadcast when a message is shared. */
public class MessageSharedEvent extends Event { public class MessageSharedEvent extends Event {
private final Message message; private final MessageId messageId;
public MessageSharedEvent(Message message) { public MessageSharedEvent(MessageId message) {
this.message = message; this.messageId = message;
} }
public Message getMessage() { public MessageId getMessageId() {
return message; return messageId;
} }
} }

View File

@@ -240,7 +240,7 @@ class ClientHelperImpl implements ClientHelper {
} }
@Override @Override
public void setMessageShared(Transaction txn, Message m, boolean shared) public void setMessageShared(Transaction txn, MessageId m, boolean shared)
throws DbException { throws DbException {
db.setMessageShared(txn, m, shared); db.setMessageShared(txn, m, shared);
} }

View File

@@ -199,7 +199,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
transaction.attach(new MessageAddedEvent(m, null)); transaction.attach(new MessageAddedEvent(m, null));
transaction.attach(new MessageStateChangedEvent(m, c, true, transaction.attach(new MessageStateChangedEvent(m, c, true,
DELIVERED)); DELIVERED));
if (shared) transaction.attach(new MessageSharedEvent(m)); if (shared) transaction.attach(new MessageSharedEvent(m.getId()));
} }
db.mergeMessageMetadata(txn, m.getId(), meta); db.mergeMessageMetadata(txn, m.getId(), meta);
} }
@@ -704,13 +704,13 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
transaction.attach(new ContactStatusChangedEvent(c, active)); transaction.attach(new ContactStatusChangedEvent(c, active));
} }
public void setMessageShared(Transaction transaction, Message m, public void setMessageShared(Transaction transaction, MessageId m,
boolean shared) throws DbException { boolean shared) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException(); if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsMessage(txn, m.getId())) if (!db.containsMessage(txn, m))
throw new NoSuchMessageException(); throw new NoSuchMessageException();
db.setMessageShared(txn, m.getId(), shared); db.setMessageShared(txn, m, shared);
if (shared) transaction.attach(new MessageSharedEvent(m)); if (shared) transaction.attach(new MessageSharedEvent(m));
} }

View File

@@ -78,7 +78,7 @@ 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); clientHelper.setMessageShared(txn, m.getId(), true);
ForumPostHeader post = getForumPostHeader(txn, m.getId(), meta); ForumPostHeader post = getForumPostHeader(txn, m.getId(), meta);
ForumPostReceivedEvent event = ForumPostReceivedEvent event =

View File

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

View File

@@ -751,7 +751,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
transaction = db.startTransaction(false); transaction = db.startTransaction(false);
try { try {
db.setMessageShared(transaction, message, true); db.setMessageShared(transaction, message.getId(), true);
fail(); fail();
} catch (NoSuchMessageException expected) { } catch (NoSuchMessageException expected) {
// Expected // Expected