Небольшой рефакторинг
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-02-26 22:21:38 +03:00
parent 607e50cb12
commit dcdb1d1747
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
5 changed files with 38 additions and 7 deletions

View File

@ -100,5 +100,14 @@ public class Discussion {
return Optional.empty(); return Optional.empty();
} }
public Optional<Note> 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();
}
} }

View File

@ -321,6 +321,7 @@ public class DiscussionServiceImpl implements DiscussionService {
if (NOTIFY_WITH_CONTEXT.equals(discussionLevel)) { if (NOTIFY_WITH_CONTEXT.equals(discussionLevel)) {
final Optional<Note> prevLastNote = discussion.getPrevLastNote(); final Optional<Note> prevLastNote = discussion.getPrevLastNote();
if (prevLastNote.isPresent()) { if (prevLastNote.isPresent()) {
final Note prevNote = prevLastNote.get(); final Note prevNote = prevLastNote.get();
notifyBuilder.previousMessage(prevNote.getBody()); notifyBuilder.previousMessage(prevNote.getBody());

View File

@ -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.context.service.MessageSendService;
import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator; import dev.struchkov.bot.gitlab.telegram.service.notify.NotifyBoxAnswerGenerator;
import dev.struchkov.godfather.simple.domain.BoxAnswer; 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 dev.struchkov.godfather.telegram.simple.context.service.TelegramSending;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -43,6 +44,7 @@ public class MessageSendTelegramService implements MessageSendService {
.map(generator -> { .map(generator -> {
final BoxAnswer answer = generator.generate(notify); final BoxAnswer answer = generator.generate(notify);
answer.setRecipientIfNull(personInformation.getTelegramId()); answer.setRecipientIfNull(personInformation.getTelegramId());
answer.setPayload(BoxAnswerPayload.DISABLE_WEB_PAGE_PREVIEW, true);
return answer; return answer;
}) })
.ifPresent(sending::send); .ifPresent(sending::send);

View File

@ -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.simple.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; 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.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.Checker.checkNotNull;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@ -23,8 +24,15 @@ public class NewCommentNotifyGenerator implements NotifyBoxAnswerGenerator<NewCo
@Override @Override
public BoxAnswer generate(NewCommentNotify notify) { public BoxAnswer generate(NewCommentNotify notify) {
final StringBuilder builder = new StringBuilder(Icons.COMMENT).append(" *New answer in Thread*") final StringBuilder builder = new StringBuilder(Icons.COMMENT).append(" *New answer in Thread*");
.append("\n-- -- -- merge request -- -- --\n")
if (checkNotBlank(notify.getDiscussionMessage()) || checkNotNull(notify.getPreviousMessage()) || checkNotNull(notify.getMessage())) {
builder.append("\n -- -- -- merge request name -- -- --\n");
} else {
builder.append(Icons.HR);
}
builder
.append(Icons.link(escapeMarkdown(notify.getMergeRequestName()), notify.getUrl())); .append(Icons.link(escapeMarkdown(notify.getMergeRequestName()), notify.getUrl()));
if (checkNotNull(notify.getDiscussionMessage())) { if (checkNotNull(notify.getDiscussionMessage())) {

View File

@ -17,6 +17,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.simple.domain.BoxAnswer.boxAnswer;
import static dev.struchkov.godfather.telegram.domain.keyboard.InlineKeyBoard.inlineKeyBoard; 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.godfather.telegram.domain.keyboard.button.UrlButton.urlButton;
import static dev.struchkov.haiti.utils.Checker.checkNotBlank;
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
import static dev.struchkov.haiti.utils.Strings.escapeMarkdown; import static dev.struchkov.haiti.utils.Strings.escapeMarkdown;
@ -25,11 +26,21 @@ public class NewThreadNotifyGenerator implements NotifyBoxAnswerGenerator<Discus
@Override @Override
public BoxAnswer generate(DiscussionNewNotify notify) { public BoxAnswer generate(DiscussionNewNotify notify) {
final StringBuilder builder = new StringBuilder(Icons.THREAD).append(" *New Thread in your MR*") final StringBuilder builder = new StringBuilder(Icons.THREAD).append(" *New Thread in your MR*");
.append("\n -- -- -- merge request -- -- --\n")
.append(Icons.link(escapeMarkdown(notify.getMergeRequestName()), notify.getUrl())) if (checkNotBlank(notify.getMessageTask())) {
.append("\n\n -- -- -- thread message -- -- --\n") builder.append("\n -- -- -- merge request name -- -- --\n");
} else {
builder.append(Icons.HR);
}
builder
.append(Icons.link(escapeMarkdown(notify.getMergeRequestName()), notify.getUrl()));
if (checkNotBlank(notify.getMessageTask())) {
builder.append("\n\n -- -- -- thread first message -- -- --\n")
.append("*").append(notify.getAuthorName()).append("*: ").append(escapeMarkdown(notify.getMessageTask())); .append("*").append(notify.getAuthorName()).append("*: ").append(escapeMarkdown(notify.getMessageTask()));
}
final List<Pair<String, String>> notes = notify.getNotes(); final List<Pair<String, String>> notes = notify.getNotes();
if (checkNotEmpty(notes)) { if (checkNotEmpty(notes)) {