Collaboration Engine 3.1.0
What's new in 3.1
Collaboration Engine 3.1 introduced the Discuss feature, to create a chat with only a few lines of code by automatically synchronizing the messages for all users connected to the same topic. The implementation includes two components: CollaborationMessageList and CollaborationMessageInput.
Example to set it up:
User userEntity = userService.getCurrentUser();
UserInfo userInfo = new UserInfo(userEntity.getId(),
userEntity.getName(), userEntity.getImageUrl());
String topicId = "general";
CollaborationMessageList messageList = new CollaborationMessageList(
userInfo, topicId);
CollaborationMessageInput messageInput = new CollaborationMessageInput(
messageList);
layout.add(messageList, messageInput);
Support for Persistent Messages in Discussion Components
Messages added to a CollaborationMessageList
can 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
. You can connect a custom component to submit to the message 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("Send");
button.setEnabled(false);
list.setSubmitter(activationContext -> {
button.setEnabled(true);
Registration clickRegistration = button.addClickListener(event -> {
activationContext.appendMessage(field.getValue());
field.setValue("");
});
return () -> {
clickRegistration.remove();
button.setEnabled(false);
};
});
layout.add(list, field, button);
Other Noteworthy Changes Since 3.0
- Make Collaboration Engine OSGi compatible
CollaborationList
as a new low-level data type- Expiration timeout for
CollaborationBinder
- Configure Collaboration Engine by defining a subclass of
CollaborationEngineConfiguration
as a Spring or CDI bean. - Fixed field highlight inside
Dialog
. - Providing images as stream resources with
CollaborationMessageList::setImageProvider
. - Trying to use an inactive topic connection now throws an exception. Trying to subscribe to data changes or update the data in Collaboration Engine while the topic connection is not active does not work. Now this is explicitly forbidden by throwing an exception. This affects only the low-level API usage (
CollaborationEngine::openTopicConnection
) userInfo.setColorIndex(-1)
now means that the Collaboration Engine should manage the user's color index and keep it consistent across topics and components. -1 is now the default value for the color index.CollaborationEngine
has now a public method,getUserColorIndex(UserInfo userInfo)
. It returns the user's color index that is explicitly defined. When the color index is -1, it will assign a color index automatically. It is useful when you build custom collaborative experiences and want to user colors which are consistent with other features, likeCollaborationBinder
andCollaborationAvatarGroup
.
- Removed the Vaadin BOM, now the Flow dependencies are scoped as provided.
UserInfo
can now be created outside the UI thread.
Compatibility
This version is part of Vaadin 20, and will also be compatible with the upcoming Vaadin 14.7 release.