Синхронизация сообщений для офлайн пользователей в группах
This commit is contained in:
@@ -8,6 +8,7 @@ import im.rosetta.client.tags.ECIAuthentificate;
|
||||
import im.rosetta.database.QuerySession;
|
||||
import im.rosetta.database.entity.Buffer;
|
||||
import im.rosetta.database.repository.BufferRepository;
|
||||
import im.rosetta.database.repository.GroupRepository;
|
||||
import im.rosetta.exception.UnauthorizedExeception;
|
||||
import im.rosetta.packet.Packet7Read;
|
||||
import im.rosetta.service.Service;
|
||||
@@ -20,6 +21,7 @@ import io.orprotocol.packet.PacketManager;
|
||||
public class BufferService extends Service<BufferRepository> {
|
||||
|
||||
private PacketManager packetManager;
|
||||
private GroupRepository groupRepository = new GroupRepository();
|
||||
|
||||
public BufferService(BufferRepository repository, PacketManager packetManager) {
|
||||
super(repository);
|
||||
@@ -41,10 +43,24 @@ public class BufferService extends Service<BufferRepository> {
|
||||
*/
|
||||
throw new UnauthorizedExeception("Unauthorized client cannot get packets from buffer");
|
||||
}
|
||||
/**
|
||||
* Получаем группы клиента, и исходя из этого формируем список каких пакетов нам нужно взять из базы
|
||||
*/
|
||||
List<String> clientGroups = this.groupRepository.findGroupsByMember(eciAuthentificate.getPublicKey());
|
||||
List<String> toValue = new ArrayList<>();
|
||||
/**
|
||||
* Добавляем публичный ключ клиента, так как ему нужны пакеты, которые были отправлены ему напрямую, а не в группу
|
||||
*/
|
||||
toValue.add(eciAuthentificate.getPublicKey());
|
||||
/**
|
||||
* Добавляем группы клиента, так как ему нужны пакеты, которые были отправлены в эти группы
|
||||
*/
|
||||
toValue.addAll(clientGroups);
|
||||
|
||||
String toPublicKey = eciAuthentificate.getPublicKey();
|
||||
String hql = "FROM Buffer WHERE (to = :to OR from = :from) AND timestamp > :timestamp ORDER BY timestamp ASC";
|
||||
String hql = "FROM Buffer WHERE (to IN (:to) OR from = :from) AND timestamp > :timestamp ORDER BY timestamp ASC";
|
||||
HashMap<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("to", toPublicKey);
|
||||
parameters.put("to", toValue);
|
||||
parameters.put("from", toPublicKey);
|
||||
parameters.put("timestamp", fromTimestampMs);
|
||||
List<Packet> packets = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user