implemented otp login
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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