mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 07:09:56 +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 {
|
public class MailboxUpdate {
|
||||||
|
|
||||||
boolean hasMailbox;
|
boolean hasMailbox;
|
||||||
private final List<MailboxVersion> clientSupports;
|
private List<MailboxVersion> clientSupports;
|
||||||
|
|
||||||
public MailboxUpdate(List<MailboxVersion> clientSupports) {
|
public MailboxUpdate(List<MailboxVersion> clientSupports) {
|
||||||
this.hasMailbox = false;
|
this.hasMailbox = false;
|
||||||
@@ -22,6 +22,10 @@ public class MailboxUpdate {
|
|||||||
return clientSupports;
|
return clientSupports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setClientSupports(List<MailboxVersion> clientSupports) {
|
||||||
|
this.clientSupports = clientSupports;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasMailbox() {
|
public boolean hasMailbox() {
|
||||||
return hasMailbox;
|
return hasMailbox;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
@Override
|
@Override
|
||||||
public void onDatabaseOpened(Transaction txn) throws DbException {
|
public void onDatabaseOpened(Transaction txn) throws DbException {
|
||||||
if (db.containsGroup(txn, localGroup.getId())) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
db.addGroup(txn, localGroup);
|
db.addGroup(txn, localGroup);
|
||||||
@@ -123,8 +131,7 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mailboxPaired(Transaction txn, String ownOnion,
|
public void mailboxPaired(Transaction txn, String ownOnion,
|
||||||
List<MailboxVersion> serverSupports)
|
List<MailboxVersion> serverSupports) throws DbException {
|
||||||
throws DbException {
|
|
||||||
for (Contact c : db.getContacts(txn)) {
|
for (Contact c : db.getContacts(txn)) {
|
||||||
createAndSendUpdateWithMailbox(txn, c, serverSupports, ownOnion);
|
createAndSendUpdateWithMailbox(txn, c, serverSupports, ownOnion);
|
||||||
}
|
}
|
||||||
@@ -192,8 +199,8 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public MailboxUpdate getRemoteUpdate(Transaction txn, ContactId c) throws
|
public MailboxUpdate getRemoteUpdate(Transaction txn, ContactId c)
|
||||||
DbException {
|
throws DbException {
|
||||||
return getUpdate(txn, db.getContact(txn, c), false);
|
return getUpdate(txn, db.getContact(txn, c), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,8 +314,7 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
|||||||
return supports;
|
return supports;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MailboxUpdate parseUpdate(BdfList body)
|
private MailboxUpdate parseUpdate(BdfList body) throws FormatException {
|
||||||
throws FormatException {
|
|
||||||
BdfList clientSupports = body.getList(1);
|
BdfList clientSupports = body.getList(1);
|
||||||
BdfList serverSupports = body.getList(2);
|
BdfList serverSupports = body.getList(2);
|
||||||
BdfDictionary dict = body.getDictionary(3);
|
BdfDictionary dict = body.getDictionary(3);
|
||||||
|
|||||||
@@ -214,16 +214,74 @@ public class MailboxUpdateManagerImplTest extends BrambleMockTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDoesNotCreateGroupsAtStartupIfAlreadyCreated()
|
public void testChecksForCurrentClientSupportsInLatestUpdateOnSecondStartup()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Transaction txn = new Transaction(null, false);
|
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() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(db).containsGroup(txn, localGroup.getId());
|
oneOf(db).containsGroup(txn, localGroup.getId());
|
||||||
will(returnValue(true));
|
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);
|
t.onDatabaseOpened(txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user