Новый протокол регистрации токенов
All checks were successful
Build rosetta-wss / build (push) Successful in 1m48s
All checks were successful
Build rosetta-wss / build (push) Successful in 1m48s
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
85
src/main/java/im/rosetta/database/entity/PushToken.java
Normal file
85
src/main/java/im/rosetta/database/entity/PushToken.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package im.rosetta.database.entity;
|
||||
|
||||
import im.rosetta.database.CreateUpdateEntity;
|
||||
import im.rosetta.packet.runtime.TokenType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
|
||||
@Entity
|
||||
@Table(
|
||||
name = "device_tokens",
|
||||
uniqueConstraints = {
|
||||
@UniqueConstraint(name = "uq_device_token", columnNames = {"device_id", "type", "token"})
|
||||
},
|
||||
indexes = {
|
||||
@Index(name = "idx_device_token_type", columnList = "type"),
|
||||
@Index(name = "idx_device_token_token", columnList = "token")
|
||||
}
|
||||
)
|
||||
public class PushToken extends CreateUpdateEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "device_id", nullable = false)
|
||||
private Device device;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "type", nullable = false, length = 32)
|
||||
private TokenType type;
|
||||
|
||||
@Column(name = "token", nullable = false, columnDefinition = "TEXT")
|
||||
private String token;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public TokenType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setDevice(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
public void setType(TokenType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PushToken pushToken = (PushToken) o;
|
||||
|
||||
if (!device.equals(pushToken.device)) return false;
|
||||
if (type != pushToken.type) return false;
|
||||
return token.equals(pushToken.token);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package im.rosetta.database.entity;
|
||||
|
||||
import im.rosetta.database.CreateUpdateEntity;
|
||||
import im.rosetta.database.converters.StringListConverter;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
@@ -12,9 +10,6 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "users", indexes = {
|
||||
@Index(name = "idx_users_publickey", columnList = "publicKey", unique = true)
|
||||
@@ -40,10 +35,6 @@ public class User extends CreateUpdateEntity {
|
||||
@Column(name = "publicKey", nullable = false, unique = true)
|
||||
private String publicKey;
|
||||
|
||||
@Convert(converter = StringListConverter.class)
|
||||
@Column(name = "notificationsTokens", nullable = false, columnDefinition = "TEXT")
|
||||
private List<String> notificationsTokens = new ArrayList<>();
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -89,12 +80,4 @@ public class User extends CreateUpdateEntity {
|
||||
this.verified = verified;
|
||||
}
|
||||
|
||||
public List<String> getNotificationsTokens() {
|
||||
return notificationsTokens;
|
||||
}
|
||||
|
||||
public void setNotificationsTokens(List<String> notificationsTokens) {
|
||||
this.notificationsTokens = notificationsTokens;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user