3.1.0.alpha5
Pre-releaseSupport for Persistent Messages in Discussion Components
Messages added to a CollaborationMessageList can now be persisted on an external backend to retain them when the application restarts. You can set a CollaborationMessagePersister on the list and implement your logic to e.g. save messages to a database.
CollaborationMessagePersister persister = CollaborationMessagePersister.fromCallbacks(
fetchQuery -> messageRepository
.findAllByTopicSince(fetchQuery.getTopicId(), fetchQuery.getSince())
.stream().map(entity -> new CollaborationMessage(
new UserInfo(entity.getAuthor().getId()),
entity.getText(),
entity.getTime()
)),
persistRequest -> {
CollaborationMessage message = persistRequest.getMessage();
MessageEntity entity = new MessageEntity(
message.getText(),
persistRequest.getTopicId(),
userRepository.findById(message.getUser().getId());
);
messageRepository.save(entity);
});
CollaborationMessageList list = new CollaborationMessageList(user, topic, persister);Submitter API for custom input components
CollaborationMessageInput is the provided component to submit messages to a CollaborationMessageList. Now you can connect a custom component to the list and configure it via a CollaborationMessageSubmitter which will be activated when the list connects to the topic.
CollaborationMessageList list = new CollaborationMessageList(user, topic);
TextField field = new TextField();
Button button = new Button();
button.setEnabled(false);
list.setSubmitter(activationContext -> {
button.setEnabled(true);
Registration registration = button.addClickListener(event ->
activationContext.appendMessage(field.getValue()));
return () -> {
registration.remove();
button.setEnabled(false);
};
});
add(list, field, button);New CollaborationList
CollaborationList is a collaborative list of item you can obtain via TopicConnection::getNamedList. The list supports getting its items, appending new ones, and subscribing to list changes:
CollaborationEngine.getInstance().openTopicConnection(this, "topic", user, connection -> {
CollaborationList list = connection.getNamedList("notifications");
list.subscribe(event -> {
event.getAddedItem(String.class).ifPresent(Notification::show);
});
return () -> {};
});Other Changes
- Fixed field highlight inside
Dialog. - Providing images as stream resources with
CollaborationMessageList::setImageProvider. CollaborationMessageInputnow takesCollaborationMessageListas a constructor argument.
Compatibility
This version is targeted for Vaadin 20, and will be included in the following Vaadin 20 pre-release.