mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Implement deleteMessages in SocialBackupManagerImpl
This commit is contained in:
@@ -44,15 +44,15 @@ import org.briarproject.briar.api.conversation.ConversationMessageHeader;
|
|||||||
import org.briarproject.briar.api.conversation.DeletionResult;
|
import org.briarproject.briar.api.conversation.DeletionResult;
|
||||||
import org.briarproject.briar.api.socialbackup.BackupExistsException;
|
import org.briarproject.briar.api.socialbackup.BackupExistsException;
|
||||||
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
import org.briarproject.briar.api.socialbackup.BackupMetadata;
|
||||||
|
import org.briarproject.briar.api.socialbackup.BackupPayload;
|
||||||
|
import org.briarproject.briar.api.socialbackup.ContactData;
|
||||||
import org.briarproject.briar.api.socialbackup.DarkCrystal;
|
import org.briarproject.briar.api.socialbackup.DarkCrystal;
|
||||||
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
import org.briarproject.briar.api.socialbackup.ReturnShardPayload;
|
||||||
import org.briarproject.briar.api.socialbackup.Shard;
|
import org.briarproject.briar.api.socialbackup.Shard;
|
||||||
import org.briarproject.briar.api.socialbackup.BackupPayload;
|
|
||||||
import org.briarproject.briar.api.socialbackup.ShardMessageHeader;
|
import org.briarproject.briar.api.socialbackup.ShardMessageHeader;
|
||||||
import org.briarproject.briar.api.socialbackup.ShardReceivedEvent;
|
import org.briarproject.briar.api.socialbackup.ShardReceivedEvent;
|
||||||
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
import org.briarproject.briar.api.socialbackup.SocialBackupManager;
|
||||||
import org.briarproject.briar.client.ConversationClientImpl;
|
import org.briarproject.briar.client.ConversationClientImpl;
|
||||||
import org.briarproject.briar.api.socialbackup.ContactData;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -234,18 +234,24 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReturnShardPayload getReturnShardPayload(Transaction txn, ContactId contactId) throws DbException {
|
public ReturnShardPayload getReturnShardPayload(Transaction txn,
|
||||||
GroupId groupId = getContactGroup(db.getContact(txn, contactId)).getId();
|
ContactId contactId) throws DbException {
|
||||||
return new ReturnShardPayload(getRemoteShard(txn, groupId), getRemoteBackup(txn, groupId));
|
GroupId groupId =
|
||||||
|
getContactGroup(db.getContact(txn, contactId)).getId();
|
||||||
|
return new ReturnShardPayload(getRemoteShard(txn, groupId),
|
||||||
|
getRemoteBackup(txn, groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getReturnShardPayloadBytes(Transaction txn, ContactId contactId) throws DbException {
|
public byte[] getReturnShardPayloadBytes(Transaction txn,
|
||||||
return messageEncoder.encodeReturnShardPayload(getReturnShardPayload(txn, contactId));
|
ContactId contactId) throws DbException {
|
||||||
|
return messageEncoder.encodeReturnShardPayload(
|
||||||
|
getReturnShardPayload(txn, contactId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean amCustodian(Transaction txn, ContactId contactId) {
|
public boolean amCustodian(Transaction txn, ContactId contactId) {
|
||||||
try {
|
try {
|
||||||
GroupId groupId = getContactGroup(db.getContact(txn, contactId)).getId();
|
GroupId groupId =
|
||||||
|
getContactGroup(db.getContact(txn, contactId)).getId();
|
||||||
return findMessage(txn, groupId, SHARD, false) != null;
|
return findMessage(txn, groupId, SHARD, false) != null;
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -356,7 +362,8 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
.getMessage(txn, messageEntry.getKey());
|
.getMessage(txn, messageEntry.getKey());
|
||||||
MessageStatus status = db.getMessageStatus(txn, contactId,
|
MessageStatus status = db.getMessageStatus(txn, contactId,
|
||||||
messageEntry.getKey());
|
messageEntry.getKey());
|
||||||
headers.add(createShardMessageHeader(message, meta, status));
|
headers.add(
|
||||||
|
createShardMessageHeader(message, meta, status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return headers;
|
return headers;
|
||||||
@@ -395,6 +402,11 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
public DeletionResult deleteMessages(Transaction txn, ContactId c,
|
public DeletionResult deleteMessages(Transaction txn, ContactId c,
|
||||||
Set<MessageId> messageIds) throws DbException {
|
Set<MessageId> messageIds) throws DbException {
|
||||||
DeletionResult result = new DeletionResult();
|
DeletionResult result = new DeletionResult();
|
||||||
|
GroupId g = getContactGroup(db.getContact(txn, c)).getId();
|
||||||
|
for (MessageId m : messageIds) {
|
||||||
|
db.deleteMessage(txn, m);
|
||||||
|
db.deleteMessageMetadata(txn, m);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,7 +433,9 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private BackupPayload createBackupPayload(Transaction txn,
|
private BackupPayload createBackupPayload(Transaction txn,
|
||||||
SecretKey secret, List<org.briarproject.briar.api.socialbackup.ContactData> contactData, int version)
|
SecretKey secret,
|
||||||
|
List<org.briarproject.briar.api.socialbackup.ContactData> contactData,
|
||||||
|
int version)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Identity identity = identityManager.getIdentity(txn);
|
Identity identity = identityManager.getIdentity(txn);
|
||||||
return backupPayloadEncoder.encodeBackupPayload(secret, identity,
|
return backupPayloadEncoder.encodeBackupPayload(secret, identity,
|
||||||
@@ -431,7 +445,8 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
private List<ContactData> loadContactData(Transaction txn)
|
private List<ContactData> loadContactData(Transaction txn)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Collection<Contact> contacts = contactManager.getContacts(txn);
|
Collection<Contact> contacts = contactManager.getContacts(txn);
|
||||||
List<org.briarproject.briar.api.socialbackup.ContactData> contactData = new ArrayList<>();
|
List<org.briarproject.briar.api.socialbackup.ContactData> contactData =
|
||||||
|
new ArrayList<>();
|
||||||
for (Contact c : contacts) {
|
for (Contact c : contacts) {
|
||||||
// Skip contacts that are in the process of being removed
|
// Skip contacts that are in the process of being removed
|
||||||
Group contactGroup = getContactGroup(c);
|
Group contactGroup = getContactGroup(c);
|
||||||
@@ -439,7 +454,9 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
Map<TransportId, TransportProperties> props =
|
Map<TransportId, TransportProperties> props =
|
||||||
getTransportProperties(txn, c.getId());
|
getTransportProperties(txn, c.getId());
|
||||||
Shard shard = getRemoteShard(txn, contactGroup.getId());
|
Shard shard = getRemoteShard(txn, contactGroup.getId());
|
||||||
contactData.add(new org.briarproject.briar.api.socialbackup.ContactData(c, props, shard));
|
contactData
|
||||||
|
.add(new org.briarproject.briar.api.socialbackup.ContactData(
|
||||||
|
c, props, shard));
|
||||||
}
|
}
|
||||||
return contactData;
|
return contactData;
|
||||||
}
|
}
|
||||||
@@ -519,7 +536,9 @@ class SocialBackupManagerImpl extends ConversationClientImpl
|
|||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void updateBackup(Transaction txn, List<org.briarproject.briar.api.socialbackup.ContactData> contactData)
|
|
||||||
|
private void updateBackup(Transaction txn,
|
||||||
|
List<org.briarproject.briar.api.socialbackup.ContactData> contactData)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
BackupMetadata backupMetadata = requireNonNull(getBackupMetadata(txn));
|
BackupMetadata backupMetadata = requireNonNull(getBackupMetadata(txn));
|
||||||
int newVersion = backupMetadata.getVersion() + 1;
|
int newVersion = backupMetadata.getVersion() + 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user