Улученный decline устройств, теперь не требуется рвать сокет
This commit is contained in:
@@ -7,10 +7,14 @@ import jakarta.persistence.Entity;
|
|||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Index;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "devices")
|
@Table(name = "devices", indexes = {
|
||||||
|
@Index(name = "idx_public_key", columnList = "publicKey, deviceId", unique = true)
|
||||||
|
})
|
||||||
|
|
||||||
public class Device extends CreateUpdateEntity {
|
public class Device extends CreateUpdateEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.rosetta.im.packet.Packet0Handshake;
|
|||||||
import com.rosetta.im.packet.Packet24DeviceResolve;
|
import com.rosetta.im.packet.Packet24DeviceResolve;
|
||||||
import com.rosetta.im.packet.runtime.DeviceSolution;
|
import com.rosetta.im.packet.runtime.DeviceSolution;
|
||||||
import com.rosetta.im.packet.runtime.HandshakeStage;
|
import com.rosetta.im.packet.runtime.HandshakeStage;
|
||||||
|
import com.rosetta.im.service.dispatch.DeviceDispatcher;
|
||||||
|
|
||||||
import io.orprotocol.ProtocolException;
|
import io.orprotocol.ProtocolException;
|
||||||
import io.orprotocol.client.Client;
|
import io.orprotocol.client.Client;
|
||||||
@@ -24,10 +25,12 @@ public class Executor24DeviceResolve extends PacketExecutor<Packet24DeviceResolv
|
|||||||
private final ClientManager clientManager;
|
private final ClientManager clientManager;
|
||||||
private final EventManager eventManager;
|
private final EventManager eventManager;
|
||||||
private final DeviceRepository deviceRepository = new DeviceRepository();
|
private final DeviceRepository deviceRepository = new DeviceRepository();
|
||||||
|
private final DeviceDispatcher deviceDispatcher;
|
||||||
|
|
||||||
public Executor24DeviceResolve(ClientManager clientManager, EventManager eventManager) {
|
public Executor24DeviceResolve(ClientManager clientManager, EventManager eventManager) {
|
||||||
this.clientManager = clientManager;
|
this.clientManager = clientManager;
|
||||||
this.eventManager = eventManager;
|
this.eventManager = eventManager;
|
||||||
|
this.deviceDispatcher = new DeviceDispatcher(clientManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,7 +108,16 @@ public class Executor24DeviceResolve extends PacketExecutor<Packet24DeviceResolv
|
|||||||
* Отклонено, отправляем отклонение
|
* Отклонено, отправляем отклонение
|
||||||
*/
|
*/
|
||||||
c.send(packet);
|
c.send(packet);
|
||||||
c.disconnect(Failures.HANDSHAKE_NOT_COMPLETED);
|
/**
|
||||||
|
* И удаляем теги аутентификации и устройства, так как клиент в момент отклонения
|
||||||
|
* должен поймать разлогин
|
||||||
|
*/
|
||||||
|
c.clearTags();
|
||||||
|
/**
|
||||||
|
* Отправяем всем устройствам этого пользователя информацию о том, что устройство было отключено (чтобы клиент мог скрыть уведомление
|
||||||
|
* о присоединении нового устройства)
|
||||||
|
*/
|
||||||
|
this.deviceDispatcher.sendDevices(eciAuthentificate.getPublicKey());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,27 @@ public class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Очищает все ECI теги клиента и удаляет его из индекса клиентов.
|
||||||
|
*/
|
||||||
|
public void clearTags() {
|
||||||
|
for (Class<? extends ECITag> tagClass : this.eciTags.keySet()) {
|
||||||
|
if (this.clientIndexer != null) {
|
||||||
|
this.clientIndexer.removeTagIndex(this, tagClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.eciTags.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Удаляет данные клиента по указанному ключу.
|
||||||
|
* @param <T> Тип данных.
|
||||||
|
* @param tagClass Класс данных для удаления.
|
||||||
|
*/
|
||||||
|
public <T extends ECITag> void removeTag(Class<T> tagClass) {
|
||||||
|
this.addTag(tagClass, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Переиндексирует тег клиента в индексе клиентов.
|
* Переиндексирует тег клиента в индексе клиентов.
|
||||||
* @param tagClass
|
* @param tagClass
|
||||||
|
|||||||
Reference in New Issue
Block a user