implemented otp login
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -24,6 +24,7 @@ import jakarta.mail.internet.MimeMultipart;
|
||||
import jakarta.mail.util.ByteArrayDataSource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageSystem implements PostBox {
|
||||
@@ -113,9 +114,9 @@ public class MessageSystem implements PostBox {
|
||||
var date = new Date();
|
||||
|
||||
for (var receiver : dueRecipients){
|
||||
Function<String,String> translateFunction = receiver instanceof UmbrellaUser uu ? text -> translator.translate(uu.language(),text) : text -> text;
|
||||
// combine messages for user
|
||||
var combined = new CombinedMessage(translateFunction);
|
||||
BiFunction<String,Map<String,String>,String> translateFunction = (text,fills) -> translator.translate(receiver.language(),text,fills);
|
||||
|
||||
var combined = new CombinedMessage("Collected messages",translateFunction);
|
||||
var envelopes = queue.stream().filter(env -> env.isFor(receiver)).toList();
|
||||
for (var envelope : envelopes) combined.merge(envelope.message());
|
||||
|
||||
|
||||
@@ -6,43 +6,46 @@ import static java.lang.System.Logger.Level.TRACE;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CombinedMessage {
|
||||
private static final System.Logger LOG = System.getLogger(CombinedMessage.class.getSimpleName());
|
||||
|
||||
private final Set<Attachment> attachments = new HashSet<>();
|
||||
private final StringBuilder body = new StringBuilder();
|
||||
private final StringBuilder combinedBody = new StringBuilder();
|
||||
private String combinedSubject = null;
|
||||
private final List<Message> mergedMessages = new ArrayList<>();
|
||||
private final Function<String, String> translate;
|
||||
private final String subjectForCombinedMessage;
|
||||
private final BiFunction<String,Map<String,String>,String> translate;
|
||||
private UmbrellaUser sender = null;
|
||||
private String subject = null;
|
||||
|
||||
public CombinedMessage(Function<String,String> translate){
|
||||
public CombinedMessage(String subjectForCombinedMessage, BiFunction<String, Map<String,String>,String> translateFunction){
|
||||
LOG.log(DEBUG,"Creating combined message…");
|
||||
this.translate = translate;
|
||||
this.subjectForCombinedMessage = subjectForCombinedMessage;
|
||||
translate = translateFunction;
|
||||
}
|
||||
|
||||
public void merge(Message message) {
|
||||
LOG.log(TRACE,"Merging {0} into combined message…",message);
|
||||
var body = translate.apply(message.body(),message.fills());
|
||||
var subject = translate.apply(message.subject(),message.fills());
|
||||
switch (mergedMessages.size()){
|
||||
case 0:
|
||||
body.append(message.body());
|
||||
combinedBody.append(body);
|
||||
sender = message.sender();
|
||||
subject = message.subject();
|
||||
combinedSubject = subject;
|
||||
break;
|
||||
case 1:
|
||||
body.insert(0,format("# {0}:\n# {1}:\n\n",sender,subject)); // insert sender and subject of first message right before the body of the first message
|
||||
subject = translate.apply("Collected messages");
|
||||
combinedBody.insert(0,format("# {0}:\n# {1}:\n\n",sender,subject)); // insert sender and subject of first message right before the body of the first message
|
||||
combinedSubject = subjectForCombinedMessage;
|
||||
// no break here, we need to append the subject and content
|
||||
default:
|
||||
body.append("\n\n# ").append(message.sender()).append(":\n");
|
||||
body.append("# ").append(message.subject()).append(":\n\n");
|
||||
body.append(message.body());
|
||||
combinedBody.append("\n\n# ").append(message.sender()).append(":\n");
|
||||
combinedBody.append("# ").append(subject).append(":\n\n");
|
||||
combinedBody.append(body);
|
||||
}
|
||||
if (message.attachments() != null) attachments.addAll(message.attachments());
|
||||
mergedMessages.add(message);
|
||||
@@ -53,7 +56,7 @@ public class CombinedMessage {
|
||||
}
|
||||
|
||||
public String body() {
|
||||
return body.toString();
|
||||
return combinedBody.toString();
|
||||
}
|
||||
|
||||
public UmbrellaUser sender() {
|
||||
@@ -61,7 +64,7 @@ public class CombinedMessage {
|
||||
}
|
||||
|
||||
public String subject() {
|
||||
return subject;
|
||||
return combinedSubject;
|
||||
}
|
||||
|
||||
public List<Message> messages() {
|
||||
|
||||
Reference in New Issue
Block a user