Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Fix/4.0.2/plf 5308 #348

Open
wants to merge 1 commit into
base: stable/4.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class User {

/** . */

private String position;
private String fullName;
private String position = "";
private String fullName = "";
private String id;
private String profileUrl;
private String activity;
private String userName;
private String activity = "";
private String userName = "";
/** . */

private String avatar;
private String status;
private String identity;
private String relationId;
private String status = "";
private String identity = "";
private String relationId = "";

public User(final String userName) {
this.userName = userName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package org.exoplatform.platform.portlet.juzu.whoisonline;

import org.apache.commons.lang.StringEscapeUtils;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.forum.service.ForumService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.social.common.RealtimeListAccess;
import org.exoplatform.social.core.activity.model.ExoSocialActivity;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.model.Profile;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
import org.exoplatform.social.core.manager.ActivityManager;
import org.exoplatform.social.core.manager.IdentityManager;
import org.exoplatform.social.core.manager.RelationshipManager;
import org.exoplatform.social.core.relationship.model.Relationship;
import org.exoplatform.social.core.service.LinkProvider;

import java.util.ArrayList;
Expand All @@ -25,81 +19,37 @@
* @date 07/12/12
*/
public class WhoIsOnlineImpl implements WhoIsOnline {

private static Log log = ExoLogger.getLogger(WhoIsOnlineImpl.class);
private static final String CONFIRMED = "confirmed";
private static final String PENDING = "pending";
private static final String RECEIVED = "received";
private static final String IGNORED = "ignored";
private static final String DEFAULT_ACTIVITY = "DEFAULT_ACTIVITY";
private static final String LINK_ACTIVITY = "LINK_ACTIVITY";
private static final String DOC_ACTIVITY = "DOC_ACTIVITY";
private static final int COUNT = 10;
private static final int MAX_CHAR = 115;
private static final int INDEX_CHAR = 110;
private static final String THREE_DOTS = "...";
private static final int MAX_USER = 17;
private static final int INDEX_USER = 18;
private static final int MAX_DOC_CHAR = 25;

public List<User> getFriends(String userId) {
List<User> userOnLineList = new ArrayList<User>();
if (userId == null) return userOnLineList;

try {
if (userId == null) {
return userOnLineList;
}
RelationshipManager relationshipManager = (RelationshipManager) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(RelationshipManager.class);
ForumService forumService = (ForumService) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(ForumService.class);
IdentityManager identityManager = (IdentityManager) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(IdentityManager.class);
Identity myIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, userId);
List<String> users = forumService.getOnlineUsers();
if (users.contains(userId)) {
users.remove(userId);
}
Collections.reverse(users);

//
if (users.size() > MAX_USER) {
users = users.subList(0, INDEX_USER);
}

//List<User> userOnLineList = new ArrayList<User>();
String lastActivity = "";
User userOnLine = null;
String userStatus = "";


for (String user : users) {
userOnLine = new User(user);
Identity userIdentity = identityManager.getOrCreateIdentity(OrganizationIdentityProvider.NAME, user);

if (userIdentity.equals(myIdentity))
continue;

lastActivity = getLastActivity(userIdentity);
userStatus = getStatus(myIdentity, userIdentity);

Profile userProfile = userIdentity.getProfile();
String avatar = userProfile.getAvatarImageSource();
if (avatar == null) {
avatar = LinkProvider.PROFILE_DEFAULT_AVATAR_URL;
}

String position = userProfile.getPosition();
if (position == null) {
position = "";
}
String relation = "";
if (userStatus.equals(RECEIVED)) {
relation = relationshipManager.getRelationship(myIdentity, userIdentity).getId();
}

userOnLine.setAvatar(avatar);
userOnLine.setPosition(position);
userOnLine.setFullName(userProfile.getFullName());
userOnLine.setId(userProfile.getId());
userOnLine.setProfileUrl(LinkProvider.getUserActivityUri(user));
userOnLine.setIdentity(userIdentity.getId());
userOnLine.setActivity(lastActivity);
userOnLine.setStatus(userStatus);
userOnLine.setRelationId(relation);
userOnLine.setProfileUrl(LinkProvider.getUserProfileUri(userIdentity.getRemoteId()));
userOnLine.setAvatar(userProfile.getAvatarImageSource() != null ? userProfile.getAvatarImageSource() : LinkProvider.PROFILE_DEFAULT_AVATAR_URL);
userOnLineList.add(userOnLine);
}
return userOnLineList;
Expand All @@ -109,131 +59,4 @@ public List<User> getFriends(String userId) {
return null;
}
}


private String getStatus(Identity identity1, Identity identity2) {
String status = "";
RelationshipManager relationshipManager = (RelationshipManager) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(RelationshipManager.class);
if (relationshipManager.getStatus(identity1, identity2) == null) {
status = "";
} else {
if (relationshipManager.getStatus(identity1, identity2).equals(Relationship.Type.CONFIRMED)) {
status = CONFIRMED;
} else {
if (relationshipManager.getStatus(identity1, identity2).equals(Relationship.Type.PENDING)) {

if (relationshipManager.getRelationship(identity2, identity1).getSender().equals(identity1)) {
status = PENDING;
} else {
status = RECEIVED;
}
} else {
status = IGNORED;
}
}
}

return status;
}

private String getLastActivity(Identity identity) {
String activity = "";
int count = COUNT;
int i = 0;
try{
ActivityManager activityManager = (ActivityManager) ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(ActivityManager.class);
RealtimeListAccess<ExoSocialActivity> activityList = activityManager.getActivitiesByPoster(identity);
for (ExoSocialActivity act : activityList.loadAsList(i, count)) {
i++;

if (act.getType() != null && (act.getType().equals(DEFAULT_ACTIVITY) || act.getType().equals(LINK_ACTIVITY) || act.getType().equals(DOC_ACTIVITY))) {

activity = act.getTitle().replaceAll("<br/>", " ").replaceAll("<br />", " ").replaceAll("<br>", " ").replaceAll("</br>", " ").trim();
activity = StringEscapeUtils.unescapeHtml(activity);
activity = activity.replaceAll("\"", "'");

if (activity.length() > MAX_CHAR && act.getType().equals(DEFAULT_ACTIVITY)) {
String maxBody = activity.substring(0, MAX_CHAR);
int tagEnterLocation = maxBody.indexOf('<', 0);
if (tagEnterLocation != -1) {
if (tagEnterLocation == 0) {
if (maxBody.indexOf("<", tagEnterLocation) == 0) {
int endtag = activity.indexOf(">", tagEnterLocation);
int tagend = activity.indexOf("<", endtag);
int tagend2 = activity.indexOf(">", tagend);
String linktitle = activity.substring(endtag + 1, tagend);
if (linktitle.length() > MAX_CHAR) {
linktitle = linktitle.substring(0, MAX_CHAR);
activity = activity.substring(0, endtag + 1) + linktitle + activity.substring(tagend, tagend2 + 1);
} else {
activity = activity.substring(0, tagend2);
}
}

activity = activity + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
} else {
int tagEndLocation = maxBody.indexOf("<", tagEnterLocation + 1);
int tagLocationEnd = maxBody.indexOf("/>", tagEnterLocation);
if ((tagEndLocation == -1 && tagLocationEnd == -1)) {
String str1 = maxBody.substring(0, tagEnterLocation - 1);
activity = str1 + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
}
if (tagEndLocation != -1) {

if (tagEndLocation > MAX_CHAR - 3) {
String charRest = activity.substring(0, tagEndLocation + 3);
activity = charRest + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
} else {
if (tagEndLocation <= MAX_CHAR - 3) {
activity = maxBody + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
}
}
}
if (tagLocationEnd != -1) {
activity = maxBody + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
}
}
} else {
activity = maxBody + "<span class='truncate_ellipsis'>" + THREE_DOTS + "</span>";
}
}

if (act.getType().equals(DOC_ACTIVITY)) {
try{
if ((activity.split(">")[1].split("<")[0]).length() > MAX_DOC_CHAR) {
String docName = activity.split(">")[1].split("<")[0].substring(0, MAX_DOC_CHAR).concat(THREE_DOTS);
String docUrl = activity.split(">")[0].split("=")[1].replace("\"", "'");
activity = "Shared a Document <a class='ColorLink' target='_blank' href=" + docUrl + "title='" + activity.split(">")[1].split("<")[0] + "'>" + docName + "</a>";
}
}catch(ArrayIndexOutOfBoundsException e) {
log.warn("Error while recovering activity of type DOC_ACTIVITY [Url of shared Document Not found ]") ;
return "";
}
}

if (act.getType().equals(LINK_ACTIVITY)) {

if (activity.indexOf("<", 0) != -1) {
activity = activity.substring(activity.indexOf(">", 0) + 1, activity.indexOf("<", activity.indexOf(">", 0)));
}
if (activity.length() > MAX_CHAR) {
activity = activity.substring(0, MAX_CHAR);
}

activity = "<a class='ColorLink' target='_blank' href='" + act.getUrl().replaceAll("\"", "'") + "'>" + activity + "</a>";
}
break;
}
if (i == 9 && activity.equals("")) {
count += COUNT;
}
}

return activity;
}catch (Exception e){
log.error("Error while recovering user's last activity [WhoIsOnLine rendering phase] :" + e.getMessage(), e);
return "";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,34 @@
import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.web.application.JavascriptManager;

import juzu.impl.request.Request;
import juzu.request.RequestContext;
import java.util.ResourceBundle;

RequestContext requestContext = Request.getCurrent().getContext();
ResourceBundle bundle= requestContext.getApplicationContext().resolveBundle(requestContext.getUserContext().getLocale()) ;

def statusTitle=bundle.getString("Loading.label");
def connectLabel=bundle.getString("Connect.label");
def confirmLabel=bundle.getString("Confirm.label");
def cancelRequestLabel=bundle.getString("CancelRequest.label");
def removeConnectionLabel=bundle.getString("RemoveConnection.label");
def ignoreLabel=bundle.getString("Ignore.label");
def messageLabel=bundle.getString("message.label");

def labels = """ {
StatusTitle: '${statusTitle}',
youHaveSentAnInvitation: '${messageLabel}',
Connect: '${connectLabel}',
Confirm: '${confirmLabel}',
CancelRequest: '${cancelRequestLabel}',
RemoveConnection: '${removeConnectionLabel}',
Ignore: '${ignoreLabel}'
} """

def pcontext = Util.getPortalRequestContext();
def jsManager = pcontext.getJavascriptManager();
jsManager.require("SHARED/jQueryWhoIsOnLine", "wos").addScripts("wos.ajaxWhoIsOnLine();");
jsManager.require("SHARED/jQueryWhoIsOnLine", "wos").addScripts("wos.ajaxWhoIsOnLine($labels);");
%>
<div id="OnlinePortlet" class="onlinePortlet">
<div id="onlineContent" class="uiBox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,9 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/ %>

<%

import juzu.impl.request.Request;
import juzu.request.RequestContext;
import java.util.ResourceBundle;

RequestContext requestContext = Request.getCurrent().getContext();
ResourceBundle bundle= requestContext.getApplicationContext().resolveBundle(requestContext.getUserContext().getLocale()) ;
if(users.empty){ %>
<script type="text/javascript">
$(function() {
$("#OnlinePortlet").hide();
});
</script>

<%}else{%>
<script type="text/javascript">
$(function() {
$("#OnlinePortlet").show();
});
</script>
<%}%>
<%users.each { user -> %>

<%
def connect="";
def message=bundle.getString("message.label");
def activity=user.getActivity();
if(user.getStatus().equals("") || user.getStatus().equals("ignored")){
connect="<div id='"+user.getId()+"connect' class='uiAction connectAction' ><a class='connect btn btn-primary' href='#'>"+bundle.getString("connect.label")+"</a></div>";

}else{
if( user.getStatus().equals("received")) {
connect="<div id='"+user.getId()+"accept' class='uiAction connectAction' ><a class='connect btn btn-primary' href='#'>"+bundle.getString("connect.label")+"</a></div>";
}else{
if(user.getStatus().equals("pending")) {
connect="<div id='connectMessge'>"+message+"</div>";
}
}}

if(!activity.equals("")){
activity="<blockquote>"+activity+"</blockquote>";
}


%>
<li id="${user.getId()}">
<a class="avatarXSmall"><img src="${user.getAvatar()}" alt="image" /></a>
<input name="activity" type="hidden" value="${activity}"/>
<input name="connect" type="hidden" value="${connect}"/>
<input name="messageLabel" type="hidden" value="&{message.label}" />

<input name="userId" type="hidden" value="${user.getId()}" />
<input name="userAvatar" type="hidden" value="${user.getAvatar()}"/>
<input name="profileURL" type="hidden" value="${user.getProfileUrl()}"/>
<input name="fullName" type="hidden" value="${user.getFullName()}"/>
<input name="userPosition" type="hidden" value="${user.getPosition()}"/>
<input name="userIdentity" type="hidden" value="${user.getIdentity()}"/>
<input name="userRelationId" type="hidden" value="${user.getRelationId()}"/>
<a class="avatarXSmall" href="${user.getProfileUrl()}"><img src="${user.getAvatar()}" alt="image" /></a>
</li>
<%}%>
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
header.label=Who's Online ?
connect.label=Connect
message.label=You have sent a connection request
message.label=You have sent a connection request

Loading.label=Loading...
Connect.label=Connect
Confirm.label=Confirm
CancelRequest.label=Cancel Request
RemoveConnection.label=Remove Connection
Ignore.label=Ignore
Loading