Новый протокол регистрации токенов
All checks were successful
Build rosetta-wss / build (push) Successful in 1m48s

This commit is contained in:
RoyceDa
2026-03-31 17:44:09 +02:00
parent 1e00105d87
commit d2263c6b9a
14 changed files with 391 additions and 169 deletions

View File

@@ -1,40 +1,51 @@
package im.rosetta.database.entity;
import im.rosetta.database.CreateUpdateEntity;
import java.util.ArrayList;
import java.util.List;
import im.rosetta.database.CreateUpdateEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
@Entity
@Table(name = "devices", indexes = {
@Index(name = "idx_public_key", columnList = "publicKey, deviceId", unique = true)
})
public class Device extends CreateUpdateEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "publicKey", nullable = false)
private String publicKey;
@Column(name = "deviceId", nullable = false)
private String deviceId;
@Column(name = "deviceName", nullable = false)
private String deviceName;
@Column(name = "deviceOs", nullable = false)
private String deviceOs;
/**
* Время завершения сессии устройства
*/
@Column(name = "syncTime", nullable = true, columnDefinition = "bigint default 0")
private Long syncTime;
@OneToMany(mappedBy = "device", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<PushToken> tokens = new ArrayList<>();
public Long getId() {
return id;
}
@@ -59,6 +70,10 @@ public class Device extends CreateUpdateEntity {
return syncTime;
}
public List<PushToken> getTokens() {
return tokens;
}
public void setSyncTime(Long syncTime) {
this.syncTime = syncTime;
}
@@ -79,4 +94,24 @@ public class Device extends CreateUpdateEntity {
this.deviceOs = deviceOs;
}
}
public void setTokens(List<PushToken> tokens) {
this.tokens = tokens;
}
public void addToken(PushToken token) {
if (token == null) {
return;
}
this.tokens.add(token);
token.setDevice(this);
}
public void removeToken(PushToken token) {
if (token == null) {
return;
}
this.tokens.remove(token);
token.setDevice(null);
}
}