diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java index 8acf6e9..fa350c9 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Link.java @@ -7,9 +7,10 @@ import lombok.ToString; @Getter @Setter -@EqualsAndHashCode(callSuper = true) @ToString +@EqualsAndHashCode(callSuper = true) public class Link extends Attachment { + private String url; public Link() { diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java index bd1a504..45e8c05 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java @@ -1,11 +1,11 @@ package dev.struchkov.godfather.context.service.impl; +import dev.struchkov.godfather.context.domain.content.Mail; import dev.struchkov.godfather.context.repository.ContentRepository; +import dev.struchkov.godfather.context.service.MailService; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import dev.struchkov.godfather.context.domain.content.Mail; -import dev.struchkov.godfather.context.service.MailService; import java.time.Clock; import java.time.LocalDateTime; @@ -24,6 +24,7 @@ public class MailServiceImpl implements MailService { private boolean newMessage = false; private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())); + //TODO [13.04.2022]: Подобная реализация с newMessage вызовет проблемы с несколькими инстансами. @Override public void add(Mail mail) { mailRepository.add(mail); @@ -40,9 +41,9 @@ public class MailServiceImpl implements MailService { @Override public List getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); - List mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo); + final List mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo); if (mails != null && !mails.isEmpty()) { - return getReturnMails(mails); + return findLastMailEachUser(mails); } else { return Collections.emptyList(); } @@ -51,9 +52,9 @@ public class MailServiceImpl implements MailService { @Override public List getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); - List mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo); + final List mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo); if (mails != null && !mails.isEmpty()) { - return getReturnMails(mails); + return findLastMailEachUser(mails); } else { return Collections.emptyList(); } @@ -61,14 +62,14 @@ public class MailServiceImpl implements MailService { @Override public List getNewMessage() { - LocalDateTime newData = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())).plusNanos(999999999); - List lastEventByAddDateTime = Collections.emptyList(); + final LocalDateTime newData = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())).plusNanos(999999999); if (newMessage) { - lastEventByAddDateTime = getLastEventByAddDateTime(oldDateTime, newData); + final List lastEventByAddDateTime = getLastEventByAddDateTime(oldDateTime, newData); newMessage = false; oldDateTime = newData; + return lastEventByAddDateTime; } - return lastEventByAddDateTime; + return Collections.emptyList(); } @Override @@ -86,9 +87,12 @@ public class MailServiceImpl implements MailService { mailRepository.deleteAllByAddDateAfter(date); } - private List getReturnMails(List mails) { - Set people = new HashSet<>(); - List returnMails = new ArrayList<>(); + /** + * Возвращает только последнее сообщение каждого пользователя переданного из списка. + */ + private List findLastMailEachUser(List mails) { + final Set people = new HashSet<>(); + final List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { if (!people.contains(mails.get(i).getPersonId())) { returnMails.add(mails.get(i));