mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Keep MailboxUpdate immutable
This commit is contained in:
@@ -9,23 +9,22 @@ import javax.annotation.concurrent.Immutable;
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
public class MailboxUpdate {
|
||||
|
||||
boolean hasMailbox;
|
||||
private List<MailboxVersion> clientSupports;
|
||||
private final boolean hasMailbox;
|
||||
private final List<MailboxVersion> clientSupports;
|
||||
|
||||
public MailboxUpdate(List<MailboxVersion> clientSupports) {
|
||||
this.hasMailbox = false;
|
||||
this(clientSupports, false);
|
||||
}
|
||||
|
||||
MailboxUpdate(List<MailboxVersion> clientSupports, boolean hasMailbox) {
|
||||
this.clientSupports = clientSupports;
|
||||
this.hasMailbox = hasMailbox;
|
||||
}
|
||||
|
||||
public List<MailboxVersion> getClientSupports() {
|
||||
return clientSupports;
|
||||
}
|
||||
|
||||
public void setClientSupports(List<MailboxVersion> clientSupports) {
|
||||
this.clientSupports = clientSupports;
|
||||
}
|
||||
|
||||
public boolean hasMailbox() {
|
||||
return hasMailbox;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ public class MailboxUpdateWithMailbox extends MailboxUpdate {
|
||||
MailboxAuthToken authToken, MailboxFolderId inboxId,
|
||||
MailboxFolderId outboxId
|
||||
) {
|
||||
super(clientSupports);
|
||||
this.hasMailbox = true;
|
||||
super(clientSupports, true);
|
||||
this.serverSupports = serverSupports;
|
||||
this.onion = onion;
|
||||
this.authToken = authToken;
|
||||
@@ -29,6 +28,12 @@ public class MailboxUpdateWithMailbox extends MailboxUpdate {
|
||||
this.outboxId = outboxId;
|
||||
}
|
||||
|
||||
public MailboxUpdateWithMailbox(MailboxUpdateWithMailbox o,
|
||||
List<MailboxVersion> newClientSupports) {
|
||||
this(newClientSupports, o.serverSupports, o.onion, o.authToken,
|
||||
o.inboxId, o.outboxId);
|
||||
}
|
||||
|
||||
public String getOnion() {
|
||||
return onion;
|
||||
}
|
||||
|
||||
@@ -87,9 +87,16 @@ class MailboxUpdateManagerImpl implements MailboxUpdateManager,
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
MailboxUpdate latest = getLocalUpdate(txn, c.getId());
|
||||
if (!latest.getClientSupports().equals(CLIENT_SUPPORTS)) {
|
||||
latest.setClientSupports(CLIENT_SUPPORTS);
|
||||
MailboxUpdate updated;
|
||||
if (latest.hasMailbox()) {
|
||||
updated = new MailboxUpdateWithMailbox(
|
||||
(MailboxUpdateWithMailbox) latest,
|
||||
CLIENT_SUPPORTS);
|
||||
} else {
|
||||
updated = new MailboxUpdate(CLIENT_SUPPORTS);
|
||||
}
|
||||
Group g = getContactGroup(c);
|
||||
storeMessageReplaceLatest(txn, g.getId(), latest);
|
||||
storeMessageReplaceLatest(txn, g.getId(), updated);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user