Add support for @mentions by implementing the IMentionableContentType plugin type so users can direct readers attention to content in the community.
Why should I make my content mentionable?
Being able to mention content can provide users with easy access to your content. Keep in mind, you should be able to provide unique titles or it may be difficult for the user to find your content.
Creating an IMentionableContentType plugin
Adding support for @mentions is done by implementing the IMentionableContentType interface defined in the Telligent.Evolution.Extensibility.Content.Version2 namespace. For this example, we'll add the IMentionableContentType to the existing content type plugin defined in the Content Type Example , updating the LinkItemContentType definition to:
public class LinkItemContentType : IContentType, ITranslatablePlugin, IMentionableContentType
IMentionableContentType requires three methods: GetMentionables(), GetMentionPreviewHtml(), and GetMentionViewHtml(). GetMentionables() is used to load mention suggestions for a provided text query and optional filtering parameters. GetMentionPreviewHtml() provides the HTML rendering when listing mention suggestions when adding mentions. GetMentionViewHtml() provides the HTML when rendering a mention embedded in content. The following implementation of IMentionableContentType can be added to the LinkItemContentType implementation:
#region IMentionableContentType
public IEnumerable<IContent> GetMentionables(string queryText, MentionableContext filter)
{
var links = new List<IContent>();
IEnumerable<LinksApplication> applications;
if (filter?.ApplicationId != null)
applications = LinksData.ListApplications().Where(a => a.ApplicationId == filter.ApplicationId.Value);
else if (filter?.ApplicationTypeId != null)
applications = LinksData.ListApplications().Where(a => a.ApplicationTypeId == filter.ApplicationTypeId.Value);
else
applications = LinksData.ListApplications();
foreach (var application in applications)
{
links.AddRange(LinksData.ListLinks(application.ApplicationId)
.Where(r => r.Name.Contains(queryText, StringComparison.OrdinalIgnoreCase))
);
}
return links;
}
public string GetMentionPreviewHtml(Guid contentId, MentionPreviewOptions options)
{
if (!string.IsNullOrEmpty(options.LabelHtml))
return options.LabelHtml;
var content = LinksData.GetLink(contentId);
if (content != null)
return content.HtmlName("Web");
return null;
}
public string GetMentionViewHtml(Guid contentId, MentionViewOptions options)
{
var content = LinksData.GetLink(contentId);
if (content != null)
{
if (!string.IsNullOrEmpty(content.Url))
{
return $"<a href=\"{Apis.Get<IHtml>().EncodeAttribute(content.Url)}\">{options.LabelHtml ?? content.Name}</a>";
}
return options.LabelHtml ?? content.Name;
}
return null;
}
#endregion
Once the project is rebuilt and the plugin is , link content will be included when adding a @mention to other content supporting embedded mentions.
Shortcut for Indexed Content Types
If the content type already supports being indexed by search by implementing ISearchableContentType , mention support can be added easier by implementing IIndexedMentionableContentType (v2) . The only difference between IMentionableContentType and IIndexedMentionableContentType is that IIndexedMentionableContentType does not require the implementation of a method to retrieve mention suggestions--because the content is already in the search index, Verint Community will generate a query to find mentionable content of this type directly from the search index.