mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-19 13:38:03 +01:00
Simplify Device entity
This commit is contained in:
@@ -7,15 +7,12 @@ package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -46,7 +43,7 @@ public class Account {
|
||||
private String username;
|
||||
|
||||
@JsonProperty
|
||||
private Set<Device> devices = new HashSet<>();
|
||||
private List<Device> devices = new ArrayList<>();
|
||||
|
||||
@JsonProperty
|
||||
private String identityKey;
|
||||
@@ -84,17 +81,6 @@ public class Account {
|
||||
@JsonIgnore
|
||||
private boolean canonicallyDiscoverable;
|
||||
|
||||
public Account() {}
|
||||
|
||||
@VisibleForTesting
|
||||
public Account(String number, UUID uuid, final UUID phoneNumberIdentifier, Set<Device> devices, byte[] unidentifiedAccessKey) {
|
||||
this.number = number;
|
||||
this.uuid = uuid;
|
||||
this.phoneNumberIdentifier = phoneNumberIdentifier;
|
||||
this.devices = devices;
|
||||
this.unidentifiedAccessKey = unidentifiedAccessKey;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
// this is the one method that may be called on a stale account
|
||||
return uuid;
|
||||
@@ -150,17 +136,17 @@ public class Account {
|
||||
public void addDevice(Device device) {
|
||||
requireNotStale();
|
||||
|
||||
this.devices.remove(device);
|
||||
removeDevice(device.getId());
|
||||
this.devices.add(device);
|
||||
}
|
||||
|
||||
public void removeDevice(long deviceId) {
|
||||
requireNotStale();
|
||||
|
||||
this.devices.remove(new Device(deviceId, null, null, null, null, null, null, false, 0, null, 0, 0, "NA", 0, null));
|
||||
this.devices.removeIf(device -> device.getId() == deviceId);
|
||||
}
|
||||
|
||||
public Set<Device> getDevices() {
|
||||
public List<Device> getDevices() {
|
||||
requireNotStale();
|
||||
|
||||
return devices;
|
||||
@@ -175,13 +161,7 @@ public class Account {
|
||||
public Optional<Device> getDevice(long deviceId) {
|
||||
requireNotStale();
|
||||
|
||||
for (Device device : devices) {
|
||||
if (device.getId() == deviceId) {
|
||||
return Optional.of(device);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
return devices.stream().filter(device -> device.getId() == deviceId).findFirst();
|
||||
}
|
||||
|
||||
public boolean isGroupsV2Supported() {
|
||||
|
||||
@@ -67,31 +67,6 @@ public class Device {
|
||||
@JsonProperty
|
||||
private DeviceCapabilities capabilities;
|
||||
|
||||
public Device() {}
|
||||
|
||||
public Device(long id, String name, String authToken, String salt,
|
||||
String gcmId, String apnId,
|
||||
String voipApnId, boolean fetchesMessages,
|
||||
int registrationId, SignedPreKey signedPreKey,
|
||||
long lastSeen, long created, String userAgent,
|
||||
long uninstalledFeedback, DeviceCapabilities capabilities) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.authToken = authToken;
|
||||
this.salt = salt;
|
||||
this.gcmId = gcmId;
|
||||
this.apnId = apnId;
|
||||
this.voipApnId = voipApnId;
|
||||
this.fetchesMessages = fetchesMessages;
|
||||
this.registrationId = registrationId;
|
||||
this.signedPreKey = signedPreKey;
|
||||
this.lastSeen = lastSeen;
|
||||
this.created = created;
|
||||
this.userAgent = userAgent;
|
||||
this.uninstalledFeedback = uninstalledFeedback;
|
||||
this.capabilities = capabilities;
|
||||
}
|
||||
|
||||
public String getApnId() {
|
||||
return apnId;
|
||||
}
|
||||
@@ -251,16 +226,6 @@ public class Device {
|
||||
return groupsV2Supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (other instanceof Device that) && this.id == that.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int)this.id;
|
||||
}
|
||||
|
||||
public static class DeviceCapabilities {
|
||||
@JsonProperty
|
||||
private boolean gv2;
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.SharedMetricRegistries;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.whispersystems.textsecuregcm.util.Constants;
|
||||
@@ -41,8 +40,7 @@ public class PushFeedbackProcessor extends AccountDatabaseCrawlerListener {
|
||||
for (Account account : chunkAccounts) {
|
||||
boolean update = false;
|
||||
|
||||
final Set<Device> devices = account.getDevices();
|
||||
for (Device device : devices) {
|
||||
for (Device device : account.getDevices()) {
|
||||
if (deviceNeedsUpdate(device)) {
|
||||
if (deviceExpired(device)) {
|
||||
if (device.isEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user