fi.evolver.ai.vaadin.component.ChatAvatarTextItem Maven / Gradle / Ivy
package fi.evolver.ai.vaadin.component;
import java.io.Serial;
import java.time.LocalDateTime;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasText.WhiteSpace;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.html.Div;
import fi.evolver.ai.vaadin.util.ChatUtils;
public class ChatAvatarTextItem extends ChatAvatarItem {
@Serial
private static final long serialVersionUID = 1L;
public ChatAvatarTextItem(LocalDateTime sendTime, String message, String user, boolean convertToHtml) {
super(sendTime, user, generateMessage(message, convertToHtml));
}
protected static Component generateMessage(String message, boolean convertToHtml) {
if (convertToHtml)
return new Html(ChatUtils.convertToHtml(message));
Div div = new Div(message);
div.setWhiteSpace(WhiteSpace.PRE_WRAP);
return div;
}
}