code clean

This commit is contained in:
Patrick Haßel 2024-06-17 15:25:18 +02:00
parent a4e5b7980c
commit d52865e54e

View File

@ -31,7 +31,6 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Slf4j
@Service
@ -71,14 +70,11 @@ public class TelegramService {
final List<MessageDto> existingMessages = messageService.findAllDtoByOfferDto(offer);
final List<ChatDto> chats = chatService.findAllEnabled();
for (final ChatDto chat : chats) {
final Optional<MessageDto> existing = existingMessages.stream().filter(m -> m.getChat().getId() == chat.getId()).findFirst();
if (existing.isPresent()) {
log.info("Found existing message: {}", existing);
update(existing.get());
} else {
log.info("Creating new message for chat={}", chat.getId());
send(offer, chat);
}
existingMessages
.stream()
.filter(m -> m.getChat().getId() == chat.getId())
.findFirst()
.ifPresentOrElse(this::update, () -> send(offer, chat));
}
}
@ -181,7 +177,7 @@ public class TelegramService {
null
);
edit.setParseMode("Markdown");
log.info("Editing Offer: {}", messageDto);
log.info("Editing Message: {}", messageDto);
bot.execute(edit);
} catch (TelegramApiException | JsonProcessingException e) {
if (e.toString().endsWith("Bad Request: message to edit not found")) {