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