Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
lalit mohan
Online/Offline status for Liferay user
March 15, 2010 4:16 AM
Answer

lalit mohan

Rank: Junior Member

Posts: 55

Join Date: February 2, 2010

Recent Posts

How can i get the the online/offline status of a user.

Please reply.
lalit mohan
RE: Online/Offline status for Liferay user
March 16, 2010 6:30 AM
Answer

lalit mohan

Rank: Junior Member

Posts: 55

Join Date: February 2, 2010

Recent Posts

I am creating a portlet in which i have to show users with their online/offline status. How can i get the online/offline status using Liferay code.
Mauro Mariuzzo
RE: Online/Offline status for Liferay user
March 16, 2010 7:29 AM
Answer

Mauro Mariuzzo

Rank: Regular Member

Posts: 141

Join Date: July 23, 2007

Recent Posts

Liferay has two different mechanism to store online/offline status.

One is called "Live User" and reflect login status. Is controlled by the properties "live.users.enabled" and "session.tracker.memory.enabled".

Here a sample code to check user on-line status. You have to write it into ext because LiveUsers isn't visible from a portlet.

 1
 2    public boolean isUserLoggedIn(long companyId, long userId) {
 3
 4        if (PropsValues.SESSION_TRACKER_MEMORY_ENABLED) {
 5
 6            Iterator itr = LiveUsers.getSessionUsers(companyId).entrySet().iterator();
 7
 8            while (itr.hasNext()) {
 9                Map.Entry entry = (Map.Entry)itr.next();
10
11                UserTracker userTracker = (UserTracker)entry.getValue();
12
13                if (userTracker.getUserId() == userId)
14                    return true;
15            }
16        }
17
18        return false;
19    }



The second one is "Chat". Only logged user are able to chat. An offline status means "I'm busy".
There isn't an easy way to obtain chat status from "chat" because you have to call a portlet service from another portlet
Rafael Bautista
RE: Online/Offline status for Liferay user
February 2, 2011 6:12 PM
Answer

Rafael Bautista

Rank: New Member

Posts: 6

Join Date: January 31, 2011

Recent Posts

mauro, i have tried your code, but it didn't work. i have already enabled live.users.enabled, and the other one in portal-ext.properties. getSessionUsers always returns null
Vikas R Khengare
RE: Online/Offline status for Liferay user
September 27, 2011 3:22 AM
Answer

Vikas R Khengare

Rank: Junior Member

Posts: 58

Join Date: August 1, 2008

Recent Posts

Hi,

I think we should put "chat-portlet-service.jar" jar file in tomcat's /lib/ext/ folder and try.
Be sure that we should remove "chat-portlet-service.jar" from /chat-portlet/WEB-INF/lib folder.

From your Plugin SDK portlet's JSP just out following code, it will give you status of current user. You can try with other user id (your friend's user id) to know the status of your friend.

 1<%
 2Status status = StatusLocalServiceUtil.getUserStatus(themeDisplay.getUserId());
 3boolean online = status.getOnline();
 4String statusMessage = HtmlUtil.escape(status.getMessage());
 5if(online)
 6    System.out.println("User name : "+user.getScreenName() +" is Online and Status Message :"+statusMessage);
 7else
 8    System.out.println("User name : "+user.getScreenName() +" is Offline and Status Message :"+statusMessage);
 9%>
Yannick Weinz
RE: Online/Offline status for Liferay user
June 6, 2012 11:38 AM
Answer

Yannick Weinz

Rank: Junior Member

Posts: 69

Join Date: November 15, 2010

Recent Posts

I'm currently also trying to find out if a user is online or not.

Unfortunately the "StatusLocalServiceUtil" always says that the User is online, although he's not.
ramveer singh narwariya
RE: Online/Offline status for Liferay user
November 6, 2012 3:12 AM
Answer

ramveer singh narwariya

Rank: Junior Member

Posts: 64

Join Date: April 13, 2012

Recent Posts

HI lalit,
please post code related to this issue if you got your solution.