Class MessageListUser

java.lang.Object
com.vaadin.flow.component.messages.MessageListUser
All Implemented Interfaces:
Serializable

public class MessageListUser extends Object implements Serializable
A user of a MessageList, rendered as an avatar with a name in the typing indicator of the list.

Use a separate instance for each message list. An avatar image that is set with setImageHandler(DownloadHandler) is served as a resource of the message list that the user was added to last.

Since:
25.3
Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • MessageListUser

      public MessageListUser()
      Creates an empty user. Use the setter methods to configure what is displayed in the avatar.
    • MessageListUser

      public MessageListUser(String name)
      Creates a user with the given name.
      Parameters:
      name - the name of the user
      See Also:
    • MessageListUser

      public MessageListUser(String name, String imageUrl)
      Creates a user with the given name and image URL.
      Parameters:
      name - the name of the user
      imageUrl - the URL of the avatar image
      See Also:
  • Method Details

    • getName

      public String getName()
      Gets the name of the user.
      Returns:
      the name of the user, or null if no name has been set
    • setName

      public void setName(String name)
      Sets the name of the user. The name is displayed next to the avatar, and identifies the user within the message list.
      Parameters:
      name - the name of the user, or null to remove the name
    • getAbbreviation

      public String getAbbreviation()
      Gets the abbreviation of the user.
      Returns:
      the abbreviation, or null if no abbreviation has been set
    • setAbbreviation

      public void setAbbreviation(String abbreviation)
      Sets the abbreviation of the user. The abbreviation is displayed in the avatar when no image has been set. By default, the abbreviation is deduced from the name.
      Parameters:
      abbreviation - the abbreviation, or null to remove the abbreviation
    • getImage

      public String getImage()
      Gets the URL of the avatar image.

      When the image is set with setImageHandler(DownloadHandler), this returns the URL that the handler is served from, or null while the user does not belong to an attached message list.

      Returns:
      the image URL, or null if no image has been set
    • setImage

      public void setImage(String imageUrl)
      Sets the URL of the avatar image. The image is displayed in the avatar even when a name or an abbreviation has been set.

      This removes an image set with setImageHandler(DownloadHandler).

      Parameters:
      imageUrl - the image URL, or null to remove the image
    • getImageHandler

      public DownloadHandler getImageHandler()
      Gets the download handler that serves the avatar image.
      Returns:
      the download handler, or null if the image has not been set with setImageHandler(DownloadHandler)
    • setImageHandler

      public void setImageHandler(DownloadHandler downloadHandler)
      Sets a download handler that serves the avatar image. The handler is registered as a resource of the message list that the user belongs to, and is unregistered when the user is removed from the list or the list is detached.

      The Content-Disposition header is set to inline for the handlers created by the factory methods in DownloadHandler, as well as for other AbstractDownloadHandler implementations.

      This removes an image URL set with setImage(String).

      Parameters:
      downloadHandler - the download handler, or null to remove the image
    • getColorIndex

      public Integer getColorIndex()
      Gets the color index of the user.
      Returns:
      the color index, or null if no color index has been set
    • setColorIndex

      public void setColorIndex(Integer colorIndex)
      Sets the color index of the user. Color index N applies the CSS variable --vaadin-user-color-N to the border of the avatar.
      Parameters:
      colorIndex - the color index, or null to remove the color index
    • addClassNames

      public void addClassNames(String... classNames)
      Adds one or more class names to the avatar of this user.
      Parameters:
      classNames - the class names to add
    • removeClassNames

      public void removeClassNames(String... classNames)
      Removes one or more class names from the avatar of this user.
      Parameters:
      classNames - the class names to remove
    • getClassName

      public String getClassName()
      Gets the class names set on the avatar of this user.
      Returns:
      a space-delimited list of class names, or null if no class names have been set