Issue
- When users send messages or create threads in the discussion forum, certain information about them (name + surname) is displayed. This article covers the need to change this behavior through a customization and display the user's screen name instead of their full name.
Environment
- 2023.Q4
Resolution
- To change the behavior, a fragment type customization would need to be implemented.(https://help.liferay.com/hc/es/articles/360017881152-JSP-Overrides-Using-OSGi-Fragments).
- The JSP to be modified would be the following retrieving the User object associated with the userId available in that JSP through the UserLocalServiceUtil API and subsequently obtaining the screenName. -> Code github
<%
String messageUserName = "anonymous";
if (thread.getLastPostByUserId() != 0) {
messageUserName = HtmlUtil.escape(PortalUtil.getUserName(thread.getLastPostByUserId(), StringPool.BLANK));
if (Validator.isNull(messageUserName)) {
MBMessage lastThreadMessage = MBMessageLocalServiceUtil.getLastThreadMessage(thread.getThreadId(), thread.getStatus());
messageUserName = HtmlUtil.escape(PortalUtil.getUserName(lastThreadMessage.getUserId(), lastThreadMessage.getUserName()));
}
}
Date lastPostDate = thread.getLastPostDate();
String lastPostDateDescription = LanguageUtil.getTimeDescription(request, System.currentTimeMillis() - lastPostDate.getTime(), true);
%>
<p class="list-group-subtext">
<liferay-ui:message arguments="<%= new String[] {messageUserName, lastPostDateDescription} %>" key="x-replied-x-ago" />
</p>
NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.