MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Highlighting users who are logged in. (Closed) (Mono Support )

Viewed 17173 time(s), 8 post(s) 03.10.2012 14:14:58by johnsamuel
johnsamuel

johnsamuel

03.10.2012 14:14:58
Hi,
We want to show on the home page which show the avatar of Users when they are logged in. Additionally we want to show on the group pages members of those groups who are logged in. Finally on the friends section of the profile page we want to show which of the friends are logged in.

Is there away to identify people logged in and highlight them?

(We don't want formal tracking as in the Blog raised by Super 4 weeks ago)
Dieser Inhalt wurde noch nicht bewertet. 
429 Reputation 46 Total posts
denis

denis

04.10.2012 15:05:02
Tracking the login status of other users is a difficult task - you could use the LastLoginDate field from the aspnet_Membership table, but there are no guarantees that a user is still active on the site using any time window. MonoX does not have a built-in functionality that would support something like this.
Dieser Inhalt wurde noch nicht bewertet. 
7207 Reputation 956 Total posts
khorvat

khorvat

05.10.2012 07:57:35
I just want to add one more thing that you can use, although this is also not accurate as Denis mentioned, there is IsOnline property on the ASP.NET MembershipUser object but note that this relies on the LastActivityDate which isn't updated that much as per:

The LastActivityDate for a user is updated to the current date and time by the CreateUser and ValidateUser methods, and can be updated by some overloads of the GetUser method. You can use the UpdateUser method to set the LastActivityDate property to a specific date and time.
 
The LastActivityDate is used to determine whether a user is online. A user is considered online if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the LastActivityDate for the user.
In some scenarios we are using a small service method which will update that value and call to that service method is scheduled on client-side so that LastActivityDate can be more accurate.

/// <summary>
/// Updates users online status.
/// </summary>
/// <param name="userIds">User ids.</param>
[WebMethod]
public void UpdateUserOnlineStatus(string[] userIds)
{
    var userId = SecurityUtility.GetUserId();
    Task.Factory.StartNew(() => GenericRepository.GetInstance().UpdateLastActivityDate(userId, DateTime.Now));
}
private void UpdateLastActivityDate(Guid userId, DateTime date)
 {
     try
     {
         AspnetUsersEntity user = new AspnetUsersEntity();
         user.LastActivityDate = date.ToUniversalTime();
         RelationPredicateBucket bucket = new RelationPredicateBucket();
         bucket.PredicateExpression.Add(AspnetUsersFields.UserId == userId);
         UpdateEntitiesDirectly(user, bucket);
     }
     catch { }
 }
var users = new Array();
users.push('SomeUserId');
GenericService.UpdateUserOnlineStatus(users, function (result) {
});
Regards
Dieser Inhalt wurde noch nicht bewertet. 
15993 Reputation 2214 Total posts
johnsamuel

johnsamuel

19.10.2012 08:58:31
Thanks for your answers. From this am I correct in understanding that currently there is no way of monitoring logged in /logged out status? Please advise.

If this is not available I'll add this to the development request list as it is an important feature to encourage interactivity within a community.
Dieser Inhalt wurde noch nicht bewertet. 
429 Reputation 46 Total posts
khorvat

khorvat

19.10.2012 09:25:44
Yes you can track if user is online or not, but not as accurate as in solution I have provided you with.

there is IsOnline property on the ASP.NET MembershipUser object but note that this relies on the LastActivityDate which isn't updated that much as per:

The LastActivityDate for a user is updated to the current date and time by the CreateUser and ValidateUser methods, and can be updated by some overloads of the GetUser method. You can use the UpdateUser method to set the LastActivityDate property to a specific date and time. The LastActivityDate is used to determine whether a user is online. A user is considered online if the current date and time minus the UserIsOnlineTimeWindow property value is earlier than the LastActivityDate for the user.
I'm not sure that MonoX should have that kind of tracking (client-side one), but if you feel like it should please go ahead and add feature request.

Regards
Dieser Inhalt wurde noch nicht bewertet. 
15993 Reputation 2214 Total posts
johnsamuel

johnsamuel

19.10.2012 10:18:12
Thanks Khorvat, will logging in update the LastActivityDate for a User?
Dieser Inhalt wurde noch nicht bewertet. 
429 Reputation 46 Total posts
khorvat

khorvat

19.10.2012 10:30:42
Yes, it will update the LastActivityDate. This is ASP.NET Membership built-in behavior.
Dieser Inhalt wurde noch nicht bewertet. 
15993 Reputation 2214 Total posts
johnsamuel

johnsamuel

19.10.2012 10:34:43
Thanks Khorvat, pl close this topic.
Dieser Inhalt wurde noch nicht bewertet. 
429 Reputation 46 Total posts