package envoy.data; import java.time.Instant; import java.util.*; /** * @author Maximilian Käfer * @since Envoy Common v0.1-beta */ public final class GroupMessage extends Message { private final Map memberStatuses; private static final long serialVersionUID = 1L; /** * Initializes a {@link GroupMessage} with values for all of its properties. The * use * of this constructor is only intended for the {@link MessageBuilder} class, as * this class provides {@code null} checks and default values for all * properties. * * @param id unique ID * @param senderID the ID of the user who sends the message * @param groupID the ID of the group which receives the message * @param creationDate the creation date of the message * @param receivedDate the received date of the message * @param readDate the read date of the message * @param text the text content of the message * @param attachment the attachment of the message, if present * @param status the current {@link Message.MessageStatus} of the * message * @param forwarded whether this message was forwarded * @param memberStatuses a map of all members and their status according to this * {@link GroupMessage} * @since Envoy Common v0.2-beta */ GroupMessage(long id, long senderID, long groupID, Instant creationDate, Instant receivedDate, Instant readDate, String text, Attachment attachment, MessageStatus status, boolean forwarded, Map memberStatuses) { super(id, senderID, groupID, creationDate, receivedDate, readDate, text, attachment, status, forwarded); this.memberStatuses = memberStatuses; } /** * Sets the status to be the minimum of all members. * * @since Envoy Common v0.1-beta */ public void updateStatus() { setStatus(Collections.min(memberStatuses.values())); switch (getStatus()) { case RECEIVED: setReceivedDate(Instant.now()); break; case READ: setReadDate(Instant.now()); break; } } /** * @return the map of all statuses in this {@link GroupMessage} * @since Envoy Common v0.1-beta */ public Map getMemberStatuses() { return memberStatuses; } }