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