From dcdb1d17475651c2dfa8fda3b973c74988d4f046 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 26 Feb 2023 22:21:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../context/domain/entity/Discussion.java | 9 ++++++++ .../service/impl/DiscussionServiceImpl.java | 1 + .../service/MessageSendTelegramService.java | 2 ++ .../notify/NewCommentNotifyGenerator.java | 12 +++++++++-- .../notify/NewThreadNotifyGenerator.java | 21 ++++++++++++++----- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java index 16b8cfd..dd07c32 100644 --- a/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java +++ b/bot-context/src/main/java/dev/struchkov/bot/gitlab/context/domain/entity/Discussion.java @@ -100,5 +100,14 @@ public class Discussion { return Optional.empty(); } + public Optional getLastNoteByUserId(Long personId) { + for (int i = notes.size() - 1; i >= 0; i--) { + final Note note = notes.get(i); + if (note.getAuthor().getId().equals(personId)) { + return Optional.of(note); + } + } + return Optional.empty(); + } } diff --git a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java index 9114814..f795710 100644 --- a/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java +++ b/bot-core/src/main/java/dev/struchkov/bot/gitlab/core/service/impl/DiscussionServiceImpl.java @@ -321,6 +321,7 @@ public class DiscussionServiceImpl implements DiscussionService { if (NOTIFY_WITH_CONTEXT.equals(discussionLevel)) { final Optional prevLastNote = discussion.getPrevLastNote(); + if (prevLastNote.isPresent()) { final Note prevNote = prevLastNote.get(); notifyBuilder.previousMessage(prevNote.getBody()); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java index b65404e..1e6d41b 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/MessageSendTelegramService.java @@ -5,6 +5,7 @@ import dev.struchkov.bot.gitlab.context.domain.notify.Notify; import dev.struchkov.bot.gitlab.context.service.MessageSendService; import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator; import dev.struchkov.godfather.simple.domain.BoxAnswer; +import dev.struchkov.godfather.telegram.main.context.BoxAnswerPayload; import dev.struchkov.godfather.telegram.simple.context.service.TelegramSending; import lombok.NonNull; import org.springframework.stereotype.Service; @@ -43,6 +44,7 @@ public class MessageSendTelegramService implements MessageSendService { .map(generator -> { final BoxAnswer answer = generator.generate(notify); answer.setRecipientIfNull(personInformation.getTelegramId()); + answer.setPayload(BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW, true); return answer; }) .ifPresent(sending::send); diff --git a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java index 4d082ce..c645927 100644 --- a/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java +++ b/telegram-bot/src/main/java/dev/struchkov/bot/gitlab/telegram/service/notify/NewCommentNotifyGenerator.java @@ -14,6 +14,7 @@ import static dev.struchkov.godfather.main.domain.keyboard.button.SimpleButton.s import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; import static dev.struchkov.godfather.telegram.domain.keyboard.button.UrlButton.urlButton; +import static dev.struchkov.haiti.utils.Checker.checkNotBlank; import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; @@ -23,8 +24,15 @@ public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator> notes = notify.getNotes(); if (checkNotEmpty(notes)) {