mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Update message encoder and RemoteWipeManager for the new api for RemoteWipeMessageHeader
This commit is contained in:
@@ -7,8 +7,8 @@ import org.briarproject.briar.api.remotewipe.MessageEncoder;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.SETUP;
|
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
||||||
|
|
||||||
public class MessageEncoderImpl implements MessageEncoder {
|
public class MessageEncoderImpl implements MessageEncoder {
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.briarproject.briar.api.remotewipe.RemoteWipeManager;
|
|||||||
import org.briarproject.briar.api.remotewipe.RemoteWipeMessageHeader;
|
import org.briarproject.briar.api.remotewipe.RemoteWipeMessageHeader;
|
||||||
import org.briarproject.briar.api.remotewipe.RemoteWipeReceivedEvent;
|
import org.briarproject.briar.api.remotewipe.RemoteWipeReceivedEvent;
|
||||||
import org.briarproject.briar.client.ConversationClientImpl;
|
import org.briarproject.briar.client.ConversationClientImpl;
|
||||||
|
import org.briarproject.briar.api.remotewipe.MessageType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -45,8 +46,8 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.SETUP;
|
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_CONTACT_ID;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_CONTACT_ID;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_RECEIVED_WIPE;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_RECEIVED_WIPE;
|
||||||
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_WIPERS;
|
import static org.briarproject.briar.remotewipe.RemoteWipeConstants.GROUP_KEY_WIPERS;
|
||||||
@@ -121,7 +122,8 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
protected boolean incomingMessage(Transaction txn, Message m, BdfList body,
|
||||||
BdfDictionary meta) throws DbException, FormatException {
|
BdfDictionary meta) throws DbException, FormatException {
|
||||||
System.out.println("Incoming remote wipe message");
|
System.out.println("Incoming remote wipe message");
|
||||||
MessageType type = MessageType.fromValue(body.getLong(0).intValue());
|
MessageType type = MessageType
|
||||||
|
.fromValue(body.getLong(0).intValue());
|
||||||
if (type == SETUP) {
|
if (type == SETUP) {
|
||||||
messageTracker.trackIncomingMessage(txn, m);
|
messageTracker.trackIncomingMessage(txn, m);
|
||||||
ContactId contactId = getContactId(txn, m.getGroupId());
|
ContactId contactId = getContactId(txn, m.getGroupId());
|
||||||
@@ -129,7 +131,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
MessageStatus status = db.getMessageStatus(txn, contactId,
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
m.getId());
|
m.getId());
|
||||||
txn.attach(new RemoteWipeReceivedEvent(
|
txn.attach(new RemoteWipeReceivedEvent(
|
||||||
createMessageHeader(m, meta, status), contactId));
|
createMessageHeader(m, meta, status, type), contactId));
|
||||||
} else if (type == WIPE) {
|
} else if (type == WIPE) {
|
||||||
if (!remoteWipeIsSetup(txn)) return false;
|
if (!remoteWipeIsSetup(txn)) return false;
|
||||||
if (clock.currentTimeMillis() - m.getTimestamp() > MAX_MESSAGE_AGE)
|
if (clock.currentTimeMillis() - m.getTimestamp() > MAX_MESSAGE_AGE)
|
||||||
@@ -308,7 +310,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
MessageStatus status = db.getMessageStatus(txn, contactId,
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
messageEntry.getKey());
|
messageEntry.getKey());
|
||||||
headers.add(
|
headers.add(
|
||||||
createMessageHeader(message, meta, status));
|
createMessageHeader(message, meta, status, SETUP));
|
||||||
} else if (meta.getLong(MSG_KEY_MESSAGE_TYPE).intValue() ==
|
} else if (meta.getLong(MSG_KEY_MESSAGE_TYPE).intValue() ==
|
||||||
WIPE.getValue()) {
|
WIPE.getValue()) {
|
||||||
Message message = clientHelper
|
Message message = clientHelper
|
||||||
@@ -316,7 +318,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
MessageStatus status = db.getMessageStatus(txn, contactId,
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
messageEntry.getKey());
|
messageEntry.getKey());
|
||||||
headers.add(
|
headers.add(
|
||||||
createMessageHeader(message, meta, status));
|
createMessageHeader(message, meta, status, WIPE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return headers;
|
return headers;
|
||||||
@@ -326,7 +328,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RemoteWipeMessageHeader createMessageHeader(
|
private RemoteWipeMessageHeader createMessageHeader(
|
||||||
Message message, BdfDictionary meta, MessageStatus status
|
Message message, BdfDictionary meta, MessageStatus status, MessageType type
|
||||||
)
|
)
|
||||||
throws FormatException {
|
throws FormatException {
|
||||||
|
|
||||||
@@ -343,7 +345,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
return new RemoteWipeMessageHeader(
|
return new RemoteWipeMessageHeader(
|
||||||
message.getId(), message.getGroupId(), timestamp,
|
message.getId(), message.getGroupId(), timestamp,
|
||||||
isLocal, read, status.isSent(), status.isSeen(),
|
isLocal, read, status.isSent(), status.isSeen(),
|
||||||
attachmentHeaders);
|
attachmentHeaders, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -414,7 +416,7 @@ public class RemoteWipeManagerImpl extends ConversationClientImpl
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Pair<MessageId, BdfDictionary> findMessage(Transaction txn,
|
private Pair<MessageId, BdfDictionary> findMessage(Transaction txn,
|
||||||
GroupId g, MessageType type, boolean local)
|
GroupId g, org.briarproject.briar.api.remotewipe.MessageType type, boolean local)
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
BdfDictionary query = BdfDictionary.of(
|
BdfDictionary query = BdfDictionary.of(
|
||||||
new BdfEntry(MSG_KEY_MESSAGE_TYPE, type.getValue()),
|
new BdfEntry(MSG_KEY_MESSAGE_TYPE, type.getValue()),
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.SETUP;
|
import static org.briarproject.briar.api.remotewipe.MessageType.SETUP;
|
||||||
import static org.briarproject.briar.remotewipe.MessageType.WIPE;
|
import static org.briarproject.briar.api.remotewipe.MessageType.WIPE;
|
||||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_LOCAL;
|
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_LOCAL;
|
||||||
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_MESSAGE_TYPE;
|
import static org.briarproject.briar.socialbackup.SocialBackupConstants.MSG_KEY_MESSAGE_TYPE;
|
||||||
|
|
||||||
@@ -35,7 +35,8 @@ class RemoteWipeValidator extends BdfMessageValidator {
|
|||||||
@Override
|
@Override
|
||||||
protected BdfMessageContext validateMessage(Message m, Group g,
|
protected BdfMessageContext validateMessage(Message m, Group g,
|
||||||
BdfList body) throws FormatException {
|
BdfList body) throws FormatException {
|
||||||
MessageType type = MessageType
|
org.briarproject.briar.api.remotewipe.MessageType
|
||||||
|
type = org.briarproject.briar.api.remotewipe.MessageType
|
||||||
.fromValue(body.getLong(0).intValue());
|
.fromValue(body.getLong(0).intValue());
|
||||||
if (type == SETUP) return validateSetupMessage(body);
|
if (type == SETUP) return validateSetupMessage(body);
|
||||||
else if (type == WIPE) return validateWipeMessage(body);
|
else if (type == WIPE) return validateWipeMessage(body);
|
||||||
|
|||||||
Reference in New Issue
Block a user