Исправил SenderStorageService на SenderRepository
This commit is contained in:
parent
375ee3255b
commit
78cc771852
@ -1,8 +1,8 @@
|
|||||||
package dev.struchkov.godfather.telegram.quarkus.sender;
|
package dev.struchkov.godfather.telegram.quarkus.context.repository;
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
|
|
||||||
public interface SenderStorageService {
|
public interface SenderRepository {
|
||||||
|
|
||||||
Uni<Integer> getLastSendMessage(String telegramId);
|
Uni<Integer> getLastSendMessage(String telegramId);
|
||||||
|
|
@ -1,13 +0,0 @@
|
|||||||
package dev.struchkov.godfather.telegram.quarkus.context.service;
|
|
||||||
|
|
||||||
import io.smallrye.mutiny.Uni;
|
|
||||||
|
|
||||||
public interface SenderStorageService {
|
|
||||||
|
|
||||||
Uni<Integer> getLastSendMessage(Long telegramId);
|
|
||||||
|
|
||||||
Uni<Void> saveLastSendMessage(Long telegramId, Integer messageId);
|
|
||||||
|
|
||||||
Uni<Void> removeLastSendMessage(Long telegramId);
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
package dev.struchkov.godfather.telegram.simple.context.service;
|
package dev.struchkov.godfather.telegram.simple.context.repository;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface SenderStorageService {
|
public interface SenderRepository {
|
||||||
|
|
||||||
Optional<Integer> getLastSendMessage(String telegramId);
|
Optional<Integer> getLastSendMessage(String telegramId);
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package dev.struchkov.godfather.telegram.quarkus.core.service;
|
package dev.struchkov.godfather.telegram.quarkus.core.service;
|
||||||
|
|
||||||
import dev.struchkov.godfather.telegram.quarkus.context.service.SenderStorageService;
|
import dev.struchkov.godfather.telegram.quarkus.context.repository.SenderRepository;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||||
|
|
||||||
public class SenderMapStorageService implements SenderStorageService {
|
public class SenderMapRepository implements SenderRepository {
|
||||||
|
|
||||||
private final Map<Long, Integer> lastMessageId = new HashMap<>();
|
private final Map<Long, Integer> lastMessageId = new HashMap<>();
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package dev.struchkov.godfather.telegram.simple.core.service;
|
package dev.struchkov.godfather.telegram.simple.core.service;
|
||||||
|
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.SenderStorageService;
|
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -9,7 +9,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||||
|
|
||||||
public class SenderMapStorageService implements SenderStorageService {
|
public class SenderMapRepository implements SenderRepository {
|
||||||
|
|
||||||
private final Map<String, Integer> lastMessageId = new HashMap<>();
|
private final Map<String, Integer> lastMessageId = new HashMap<>();
|
||||||
|
|
@ -5,6 +5,7 @@ import dev.struchkov.godfather.main.domain.SendType;
|
|||||||
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
|
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
|
||||||
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
|
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
|
||||||
|
import dev.struchkov.godfather.telegram.quarkus.context.repository.SenderRepository;
|
||||||
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
|
import dev.struchkov.godfather.telegram.quarkus.context.service.TelegramSending;
|
||||||
import io.smallrye.mutiny.Uni;
|
import io.smallrye.mutiny.Uni;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -30,23 +31,23 @@ public class TelegramSender implements TelegramSending {
|
|||||||
private final AbsSender absSender;
|
private final AbsSender absSender;
|
||||||
|
|
||||||
private SendPreProcessing sendPreProcessing;
|
private SendPreProcessing sendPreProcessing;
|
||||||
private SenderStorageService senderStorageService;
|
private SenderRepository senderRepository;
|
||||||
|
|
||||||
public TelegramSender(TelegramConnect telegramConnect) {
|
public TelegramSender(TelegramConnect telegramConnect) {
|
||||||
this.absSender = telegramConnect.getAbsSender();
|
this.absSender = telegramConnect.getAbsSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelegramSender(TelegramConnect telegramConnect, SenderStorageService senderStorageService) {
|
public TelegramSender(TelegramConnect telegramConnect, SenderRepository senderRepository) {
|
||||||
this.absSender = telegramConnect.getAbsSender();
|
this.absSender = telegramConnect.getAbsSender();
|
||||||
this.senderStorageService = senderStorageService;
|
this.senderRepository = senderRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
|
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
|
||||||
this.sendPreProcessing = sendPreProcessing;
|
this.sendPreProcessing = sendPreProcessing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSenderRepository(SenderStorageService senderStorageService) {
|
public void setSenderRepository(SenderRepository senderStorageService) {
|
||||||
this.senderStorageService = senderStorageService;
|
this.senderRepository = senderRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -65,8 +66,8 @@ public class TelegramSender implements TelegramSending {
|
|||||||
v -> {
|
v -> {
|
||||||
isNotNull(telegramId, boxAnswer);
|
isNotNull(telegramId, boxAnswer);
|
||||||
|
|
||||||
if (boxAnswer.isReplace() && checkNotNull(senderStorageService)) {
|
if (boxAnswer.isReplace() && checkNotNull(senderRepository)) {
|
||||||
return senderStorageService.getLastSendMessage(telegramId)
|
return senderRepository.getLastSendMessage(telegramId)
|
||||||
.onItem().transformToUni(
|
.onItem().transformToUni(
|
||||||
lastId -> {
|
lastId -> {
|
||||||
if (checkNotNull(lastId)) {
|
if (checkNotNull(lastId)) {
|
||||||
@ -119,8 +120,8 @@ public class TelegramSender implements TelegramSending {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final Message execute = absSender.execute(sendMessage);
|
final Message execute = absSender.execute(sendMessage);
|
||||||
if (checkNotNull(senderStorageService) && saveMessageId) {
|
if (checkNotNull(senderRepository) && saveMessageId) {
|
||||||
return senderStorageService.saveLastSendMessage(telegramId, execute.getMessageId());
|
return senderRepository.saveLastSendMessage(telegramId, execute.getMessageId());
|
||||||
}
|
}
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
log.error(e.getApiResponse());
|
||||||
|
@ -5,7 +5,7 @@ import dev.struchkov.godfather.main.domain.SendType;
|
|||||||
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
import dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard;
|
||||||
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
|
import dev.struchkov.godfather.telegram.main.context.TelegramConnect;
|
||||||
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
|
import dev.struchkov.godfather.telegram.main.sender.util.KeyBoardConvert;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.SenderStorageService;
|
import dev.struchkov.godfather.telegram.simple.context.repository.SenderRepository;
|
||||||
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -31,23 +31,23 @@ public class TelegramSender implements TelegramSending {
|
|||||||
private final AbsSender absSender;
|
private final AbsSender absSender;
|
||||||
|
|
||||||
private SendPreProcessing sendPreProcessing;
|
private SendPreProcessing sendPreProcessing;
|
||||||
private SenderStorageService senderStorageService;
|
private SenderRepository senderRepository;
|
||||||
|
|
||||||
public TelegramSender(TelegramConnect telegramConnect) {
|
public TelegramSender(TelegramConnect telegramConnect) {
|
||||||
this.absSender = telegramConnect.getAbsSender();
|
this.absSender = telegramConnect.getAbsSender();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelegramSender(TelegramConnect telegramConnect, SenderStorageService senderStorageService) {
|
public TelegramSender(TelegramConnect telegramConnect, SenderRepository senderRepository) {
|
||||||
this.absSender = telegramConnect.getAbsSender();
|
this.absSender = telegramConnect.getAbsSender();
|
||||||
this.senderStorageService = senderStorageService;
|
this.senderRepository = senderRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
|
public void setSendPreProcessing(SendPreProcessing sendPreProcessing) {
|
||||||
this.sendPreProcessing = sendPreProcessing;
|
this.sendPreProcessing = sendPreProcessing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSenderRepository(SenderStorageService senderStorageService) {
|
public void setSenderRepository(SenderRepository senderRepository) {
|
||||||
this.senderStorageService = senderStorageService;
|
this.senderRepository = senderRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,8 +63,8 @@ public class TelegramSender implements TelegramSending {
|
|||||||
private void sendBoxAnswer(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, boolean saveMessageId) {
|
private void sendBoxAnswer(@NotNull String telegramId, @NotNull BoxAnswer boxAnswer, boolean saveMessageId) {
|
||||||
isNotNull(telegramId, boxAnswer);
|
isNotNull(telegramId, boxAnswer);
|
||||||
try {
|
try {
|
||||||
if (boxAnswer.isReplace() && checkNotNull(senderStorageService)) {
|
if (boxAnswer.isReplace() && checkNotNull(senderRepository)) {
|
||||||
final Optional<Integer> optLastId = senderStorageService.getLastSendMessage(telegramId);
|
final Optional<Integer> optLastId = senderRepository.getLastSendMessage(telegramId);
|
||||||
if (optLastId.isPresent()) {
|
if (optLastId.isPresent()) {
|
||||||
replaceMessage(telegramId, optLastId.get(), boxAnswer);
|
replaceMessage(telegramId, optLastId.get(), boxAnswer);
|
||||||
} else {
|
} else {
|
||||||
@ -105,8 +105,8 @@ public class TelegramSender implements TelegramSending {
|
|||||||
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
sendMessage.setReplyMarkup(KeyBoardConvert.convertKeyBoard(boxAnswer.getKeyBoard()));
|
||||||
try {
|
try {
|
||||||
final Message execute = absSender.execute(sendMessage);
|
final Message execute = absSender.execute(sendMessage);
|
||||||
if (checkNotNull(senderStorageService) && saveMessageId) {
|
if (checkNotNull(senderRepository) && saveMessageId) {
|
||||||
senderStorageService.saveLastSendMessage(telegramId, execute.getMessageId());
|
senderRepository.saveLastSendMessage(telegramId, execute.getMessageId());
|
||||||
}
|
}
|
||||||
} catch (TelegramApiRequestException e) {
|
} catch (TelegramApiRequestException e) {
|
||||||
log.error(e.getApiResponse());
|
log.error(e.getApiResponse());
|
||||||
|
Loading…
Reference in New Issue
Block a user