vaadin / collaboration-engine

The simplest way to build real-time collaboration into web apps
https://vaadin.com/collaboration
Other
3 stars 1 forks source link

[Avatar] Provide API for UserInfo #61

Closed stefanuebe closed 2 years ago

stefanuebe commented 2 years ago

The CE uses the "UserInfo" type to provide the info about the current user to the CE. This sample shows how to create a separate Avatar. It would be nice to directly use the UserInfo here instead of needing to extract the information manually from it.

This sample code shows some potential alternatives on how to combine UserInfo and Avatar in API form.

UserInfo userInfo = getUserInfo(); //... from somewhere

CollaborationAvatarGroup group = new CollaborationAvatarGroup(userInfo, getTopicId());
group.setOwnAvatarVisible(false); // Exclude own avatar from the group:

Avatar avatar = new Avatar(userInfo);

avatar.setUserInfo(userInfo); // alternative way 1
avatar = Avatar.of(userInfo); // alternative way 2
avatar = userInfo.createAvatar(); // alternative way 3
avatar = group.createOwnAvatar(); // alternative way 4

add(group, avatar);
Legioth commented 2 years ago

Avatar is defined by the reusable component. UserInfo is defined by Collaboration Engine. We don't want to make the component depend on CE, which means that the API would have to be in CE. That would be alternative 3 or 4 from the suggestions.

heruan commented 2 years ago

I would go with alternative 4, i.e. avatarGroup.createLocalUserAvatar(). This way we don't create a dependency on the component for UserInfo either, in case we want to extract the component in a separate module.