User Mentions API
API to support the mention of users |
Type | JAR |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Bundled With | XWiki Standard |
Table of contents
Description
The User Mentions API allows to configure how the mentions are sent, and to registers new kinds of mentionable actors.
Configuration
The MentionsConfiguration provides the shared constants and configurable values used for the mentions:
- USER_MENTION_TYPE: the default type of mentions
- getMentionsColor(): the default background color of the mentions
- getSelfMentionsColor() the default background color of the mentions to the current user
- isQuoteActivated() returns true of a quote of the text surrounding a mentions must be generated when sending a notification
Integrating a new mention type
Declaring a new mention type is made in three steps
Declaring a formatter
The formatter is used to display the mentioned actor in a textual form according to its type.
Three display styles can be asked for:
- full name (first and last names)
- first name only
- login
Declaring a provider is done by declaring a component with the role org.xwiki.mentions.MentionsFormatter.
For instance:
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.mentions.DisplayStyle;
import org.xwiki.mentions.MentionsFormatter;
@Singleton
@Component
@Named("example") // the hint must match the type of actor
public class ExampleMentionsFormatter implements MentionsFormatter
{
@Override
public String formatMention(String actorReference, DisplayStyle style)
{
switch (style) {
case FULL_NAME:
return "...full name...";
case FIRST_NAME:
return "...first name...";
case LOGIN:
return "...login...";
default:
return null;
}
}
}
Declaring a listener
When
Declaring an actor provider
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).
You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.
Dependencies
Dependencies for this extension (org.xwiki.platform:xwiki-platform-mentions-api 12.9):
- org.xwiki.platform:xwiki-platform-eventstream-api 12.9
- org.xwiki.platform:xwiki-platform-model-api 12.9
- org.xwiki.rendering:xwiki-rendering-api 12.9