mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Send mailbox update to contacts if supported mailbox versions changed
This commit is contained in:
@@ -11,7 +11,7 @@ import javax.annotation.concurrent.Immutable;
|
||||
public class MailboxUpdate {
|
||||
|
||||
boolean hasMailbox;
|
||||
private final List<MailboxVersion> clientSupports;
|
||||
private List<MailboxVersion> clientSupports;
|
||||
|
||||
public MailboxUpdate(List<MailboxVersion> clientSupports) {
|
||||
this.hasMailbox = false;
|
||||
@@ -22,6 +22,10 @@ public class MailboxUpdate {
|
||||
return clientSupports;
|
||||
}
|
||||
|
||||
public void setClientSupports(List<MailboxVersion> clientSupports) {
|
||||
this.clientSupports = clientSupports;
|
||||
}
|
||||
|
||||
public boolean hasMailbox() {
|
||||
return hasMailbox;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,14 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
||||
@Override
|
||||
public void onDatabaseOpened(Transaction txn) throws DbException {
|
||||
if (db.containsGroup(txn, localGroup.getId())) {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
MailboxUpdate latest = getLocalUpdate(txn, c.getId());
|
||||
if (!latest.getClientSupports().equals(CLIENT_SUPPORTS)) {
|
||||
latest.setClientSupports(CLIENT_SUPPORTS);
|
||||
Group g = getContactGroup(c);
|
||||
storeMessageReplaceLatest(txn, g.getId(), latest);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
db.addGroup(txn, localGroup);
|
||||
@@ -123,8 +131,7 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
||||
|
||||
@Override
|
||||
public void mailboxPaired(Transaction txn, String ownOnion,
|
||||
List<MailboxVersion> serverSupports)
|
||||
throws DbException {
|
||||
List<MailboxVersion> serverSupports) throws DbException {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
createAndSendUpdateWithMailbox(txn, c, serverSupports, ownOnion);
|
||||
}
|
||||
@@ -192,8 +199,8 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public MailboxUpdate getRemoteUpdate(Transaction txn, ContactId c) throws
|
||||
DbException {
|
||||
public MailboxUpdate getRemoteUpdate(Transaction txn, ContactId c)
|
||||
throws DbException {
|
||||
return getUpdate(txn, db.getContact(txn, c), false);
|
||||
}
|
||||
|
||||
@@ -307,8 +314,7 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
||||
return supports;
|
||||
}
|
||||
|
||||
private MailboxUpdate parseUpdate(BdfList body)
|
||||
throws FormatException {
|
||||
private MailboxUpdate parseUpdate(BdfList body) throws FormatException {
|
||||
BdfList clientSupports = body.getList(1);
|
||||
BdfList serverSupports = body.getList(2);
|
||||
BdfDictionary dict = body.getDictionary(3);
|
||||
|
||||
@@ -214,16 +214,74 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotCreateGroupsAtStartupIfAlreadyCreated()
|
||||
public void testChecksForCurrentClientSupportsInLatestUpdateOnSecondStartup()
|
||||
throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
|
||||
Contact contact = getContact();
|
||||
List<Contact> contacts = singletonList(contact);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
Map<MessageId, BdfDictionary> emptyMessageMetadata =
|
||||
new LinkedHashMap<>();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn,
|
||||
contact.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
will(returnValue(SHARED));
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
contactGroup.getId(), SHARED);
|
||||
oneOf(clientHelper).setContactId(txn, contactGroup.getId(),
|
||||
contact.getId());
|
||||
oneOf(mailboxSettingsManager).getOwnMailboxProperties(txn);
|
||||
will(returnValue(null));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(emptyMessageMetadata));
|
||||
expectStoreMessage(txn, contactGroup.getId(), 1, realClientSupports,
|
||||
emptyServerSupports, emptyPropsDict, true);
|
||||
}});
|
||||
|
||||
MailboxUpdateManagerImpl t = createInstance();
|
||||
t.addingContact(txn, contact);
|
||||
|
||||
Message message = getMessage(contactGroup.getId());
|
||||
BdfList body = BdfList.of(1, realClientSupports, emptyServerSupports,
|
||||
emptyPropsDict);
|
||||
BdfDictionary metaDictionary = BdfDictionary.of(
|
||||
new BdfEntry(MSG_KEY_VERSION, 1),
|
||||
new BdfEntry(MSG_KEY_LOCAL, true)
|
||||
);
|
||||
Map<MessageId, BdfDictionary> messageMetadata = new LinkedHashMap<>();
|
||||
messageMetadata.put(message.getId(), metaDictionary);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).containsGroup(txn, localGroup.getId());
|
||||
will(returnValue(true));
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(contacts));
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(contactGroupFactory)
|
||||
.createContactGroup(CLIENT_ID, MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
will(returnValue(messageMetadata));
|
||||
oneOf(clientHelper).getMessageAsList(txn, message.getId());
|
||||
will(returnValue(body));
|
||||
oneOf(clientHelper).parseAndValidateMailboxUpdate(
|
||||
realClientSupports, emptyServerSupports, emptyPropsDict);
|
||||
will(returnValue(updateNoMailbox));
|
||||
}});
|
||||
|
||||
MailboxUpdateManagerImpl t = createInstance();
|
||||
t.onDatabaseOpened(txn);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user