diff --git a/amadeus/static/js/socket.js b/amadeus/static/js/socket.js
index 5320872..f715017 100644
--- a/amadeus/static/js/socket.js
+++ b/amadeus/static/js/socket.js
@@ -21,6 +21,8 @@ socket.onmessage = function(e) {
}
} else if (content.type == "chat") {
messageReceived(content);
+ } else if (content.type == "user_status") {
+ changeUserStatus(content);
}
}
// Call onopen directly if socket is already open
@@ -297,4 +299,18 @@ function messageReceived(content) {
setTimeout(notification.close.bind(notification), 3000);
}
}
+}
+
+function changeUserStatus(content) {
+ var elem = $(".user_" + content.user_id + "_status");
+
+ elem.removeClass(content.remove_class);
+
+ if (content.status_class == "") {
+ elem.removeClass('active');
+ } else {
+ elem.addClass(content.status_class);
+ }
+
+ elem.attr('data-original-title', content.status);
}
\ No newline at end of file
diff --git a/chat/templates/chat/_profile.html b/chat/templates/chat/_profile.html
index 33e9aaa..4bbf518 100644
--- a/chat/templates/chat/_profile.html
+++ b/chat/templates/chat/_profile.html
@@ -14,7 +14,7 @@
diff --git a/chat/templates/chat/_view_participant.html b/chat/templates/chat/_view_participant.html
index 5391df2..4d65969 100644
--- a/chat/templates/chat/_view_participant.html
+++ b/chat/templates/chat/_view_participant.html
@@ -7,7 +7,7 @@
-
{{ participant }}
+
{{ participant }}
diff --git a/users/middleware.py b/users/middleware.py
index c89eaf8..57f5234 100644
--- a/users/middleware.py
+++ b/users/middleware.py
@@ -9,6 +9,11 @@ from session_security.utils import get_last_activity, set_last_activity
from log.models import Log
+from .models import User
+from django.utils.translation import ugettext as _u
+from channels import Group
+import json
+
class SessionExpireMiddleware(object):
def process_request(self, request):
@@ -33,4 +38,19 @@ class SessionExpireMiddleware(object):
log.action = "logout"
log.resource = "system"
- log.save()
\ No newline at end of file
+ log.save()
+
+ users = User.objects.all().exclude(email = request.user.email)
+
+ notification = {
+ "type": "user_status",
+ "user_id": str(request.user.id),
+ "status": _u("Offline"),
+ "status_class": "",
+ "remove_class": "away"
+ }
+
+ notification = json.dumps(notification)
+
+ for u in users:
+ Group("user-%s" % u.id).send({'text': notification})
\ No newline at end of file
diff --git a/users/views.py b/users/views.py
index 5b8731e..140184c 100644
--- a/users/views.py
+++ b/users/views.py
@@ -5,6 +5,7 @@ from django.contrib.auth import authenticate, login as login_user, logout as log
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext as _u
from django.db.models import Q, Count
from braces import views as braces_mixins
@@ -19,6 +20,10 @@ from .models import User
from .utils import has_dependencies
from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm
+#USER STATUS NOTIFICATION
+from channels import Group
+import json
+
#RECOVER PASS IMPORTS
from django.contrib.auth.tokens import default_token_generator
from django.core.mail import send_mail
@@ -501,6 +506,21 @@ def login(request):
if not security.maintence or user.is_staff:
login_user(request, user)
+ users = User.objects.all().exclude(email = username)
+
+ notification = {
+ "type": "user_status",
+ "user_id": str(user.id),
+ "status": _u("Online"),
+ "status_class": "active",
+ "remove_class": "away"
+ }
+
+ notification = json.dumps(notification)
+
+ for u in users:
+ Group("user-%s" % u.id).send({'text': notification})
+
next_url = request.GET.get('next', None)
if next_url:
@@ -519,8 +539,25 @@ def login(request):
@log_decorator('user', 'logout', 'system')
def logout(request, next_page = None):
+ user = request.user
+
logout_user(request)
+ users = User.objects.all().exclude(email = user.email)
+
+ notification = {
+ "type": "user_status",
+ "user_id": str(user.id),
+ "status": _u("Offline"),
+ "status_class": "",
+ "remove_class": "away"
+ }
+
+ notification = json.dumps(notification)
+
+ for u in users:
+ Group("user-%s" % u.id).send({'text': notification})
+
if next_page:
return redirect(next_page)
--
libgit2 0.21.2